diff --git a/interfaces/kits/ndk/clouddiskmanager/include/oh_cloud_disk_manager.h b/interfaces/kits/ndk/clouddiskmanager/include/oh_cloud_disk_manager.h
index 01701575620dbfda378a969bf8ac13b7961b0f2f..e0ce2a6c07d0188eefa3d476ef47e3950432a956 100644
--- a/interfaces/kits/ndk/clouddiskmanager/include/oh_cloud_disk_manager.h
+++ b/interfaces/kits/ndk/clouddiskmanager/include/oh_cloud_disk_manager.h
@@ -293,6 +293,59 @@ typedef struct CloudDisk_ResultList {
CloudDisk_ErrorReason errorReason;
} CloudDisk_ResultList;
+/**
+ * @brief Enumerates the state of sync folder.
+ * @since 21
+ */
+typedef enum CloudDisk_SyncFolderState {
+ /**
+ * Indicates that the state of sync folder is inactive.
+ */
+ INACTIVE = 0,
+ /**
+ * Indicates that the state of sync folder is active.
+ */
+ ACTIVE = 1,
+} CloudDisk_SyncFolderState;
+
+/**
+ * @brief Defines the sync folder displayName info of cloud disk.
+ * @since 21
+ */
+typedef struct CloudDisk_DisplayNameInfo {
+ /**
+ * Indicates the displayNameResId of sync folder.
+ */
+ uint32_t displayNameResId;
+ /**
+ * Indicates the user-defined alias.
+ */
+ char *customAlias;
+ /**
+ * Indicates the length of the customAlias.
+ */
+ size_t customAliasLength;
+} CloudDisk_DisplayNameInfo;
+
+/**
+ * @brief Defines the sync folder of cloud disk.
+ * @since 21
+ */
+typedef struct CloudDisk_SyncFolder {
+ /**
+ * Indicates the path of sync folder.
+ */
+ CloudDisk_SyncFolderPath path;
+ /**
+ * Indicates the state of sync folder.
+ */
+ CloudDisk_SyncFolderState state;
+ /**
+ * Indicates the displayName info of sync folder.
+ */
+ CloudDisk_DisplayNameInfo displayNameInfo;
+} CloudDisk_SyncFolder;
+
/**
* @brief Registers a callback function to notify the application of sync folder changes.
*
@@ -371,6 +424,72 @@ CloudDisk_ErrorCode OH_CloudDisk_GetFileSyncStates(const CloudDisk_SyncFolderPat
size_t length,
CloudDisk_ResultList **resultLists,
size_t *resultCount);
+
+/**
+ * @brief Registers a sync folder.
+ *
+ * @param syncFolder Indicates the sync folder.
+ * @return Returns {@link CLOUD_DISK_ERR_OK} if the operation is successful;
+ *
returns an error code defined in {@link oh_cloud_disk_error_code.h} otherwise.
+ * @since 21
+ */
+CloudDisk_ErrorCode OH_CloudDisk_RegisterSyncFolder(const CloudDisk_SyncFolder *syncFolder);
+
+/**
+ * @brief Unregisters a sync folder.
+ *
+ * @param syncFolderPath Indicates the sync folder path.
+ * @return Returns {@link CLOUD_DISK_ERR_OK} if the operation is successful;
+ *
returns an error code defined in {@link oh_cloud_disk_error_code.h} otherwise.
+ * @since 21
+ */
+CloudDisk_ErrorCode OH_CloudDisk_UnregisterSyncFolder(const CloudDisk_SyncFolderPath syncFolderPath);
+
+/**
+ * @brief Activates a sync folder.
+ *
+ * @param syncFolderPath Indicates the sync folder path.
+ * @return Returns {@link CLOUD_DISK_ERR_OK} if the operation is successful;
+ *
returns an error code defined in {@link oh_cloud_disk_error_code.h} otherwise.
+ * @since 21
+ */
+CloudDisk_ErrorCode OH_CloudDisk_ActiveSyncFolder(const CloudDisk_SyncFolderPath syncFolderPath);
+
+/**
+ * @brief Deactivates a sync folder.
+ *
+ * @param syncFolderPath Indicates the sync folder path.
+ * @return Returns {@link CLOUD_DISK_ERR_OK} if the operation is successful;
+ *
returns an error code defined in {@link oh_cloud_disk_error_code.h} otherwise.
+ * @since 21
+ */
+CloudDisk_ErrorCode OH_CloudDisk_DeactiveSyncFolder(const CloudDisk_SyncFolderPath syncFolderPath);
+
+/**
+ * @brief Gets the sync folders.
+ *
+ * @param syncFolders Output parameter. Returns the array of {@link CloudDisk_SyncFolder} to store the sync folders.
+ * @param count Output parameter. Returns the number of sync folders.
+ * @return Returns {@link CLOUD_DISK_ERR_OK} if the operation is successful;
+ *
returns an error code defined in {@link oh_cloud_disk_error_code.h} otherwise.
+ * @since 21
+ */
+CloudDisk_ErrorCode OH_CloudDisk_GetSyncFolders(CloudDisk_SyncFolder **syncFolders,
+ size_t *count);
+
+/**
+ * @brief Updates the display name of a sync folder.
+ *
+ * @param syncFolderPath Indicates the sync folder path.
+ * @param customAlias Indicates the user-defined alias.
+ * @param customAliasLength Indicates the length of the customAlias.
+ * @return Returns {@link CLOUD_DISK_ERR_OK} if the operation is successful;
+ *
returns an error code defined in {@link oh_cloud_disk_error_code.h} otherwise.
+ * @since 21
+ */
+CloudDisk_ErrorCode OH_CloudDisk_UpdateCustomAlias(const CloudDisk_SyncFolderPath syncFolderPath,
+ const char *customAlias,
+ size_t customAliasLength);
#ifdef __cplusplus
}
#endif
diff --git a/interfaces/kits/ndk/clouddiskmanager/include/oh_cloud_disk_utils.h b/interfaces/kits/ndk/clouddiskmanager/include/oh_cloud_disk_utils.h
index e1c13246d12c2add50e06729f77ea54fc5d6d318..c5e43cf3b6c914893d607c6c6370442df2b674e9 100644
--- a/interfaces/kits/ndk/clouddiskmanager/include/oh_cloud_disk_utils.h
+++ b/interfaces/kits/ndk/clouddiskmanager/include/oh_cloud_disk_utils.h
@@ -21,7 +21,7 @@
#include "cloud_disk_service_error.h"
#include "oh_cloud_disk_error_code.h"
-CloudDisk_ErrorCode CovertToErrorCode(int32_t innerErrorCode);
+CloudDisk_ErrorCode ConvertToErrorCode(int32_t innerErrorCode);
const std::unordered_map innerToNErrTable = {
{OHOS::FileManagement::CloudDiskService::CloudDiskServiceErrCode::E_OK, CLOUD_DISK_ERR_OK},
diff --git a/interfaces/kits/ndk/clouddiskmanager/liboh_cloud_disk_manager.ndk.json b/interfaces/kits/ndk/clouddiskmanager/liboh_cloud_disk_manager.ndk.json
index a1c510f753944788a5c7aa7da042126d094d2ed8..cacc3c771e2f9f31c22d0519649abfd06de66794 100644
--- a/interfaces/kits/ndk/clouddiskmanager/liboh_cloud_disk_manager.ndk.json
+++ b/interfaces/kits/ndk/clouddiskmanager/liboh_cloud_disk_manager.ndk.json
@@ -18,5 +18,29 @@
{
"first_introduced": "21",
"name": "OH_CloudDisk_GetFileSyncStates"
+ },
+ {
+ "first_introduced": "21",
+ "name": "OH_CloudDisk_RegisterSyncFolder"
+ },
+ {
+ "first_introduced": "21",
+ "name": "OH_CloudDisk_UnregisterSyncFolder"
+ },
+ {
+ "first_introduced": "21",
+ "name": "OH_CloudDisk_ActiveSyncFolder"
+ },
+ {
+ "first_introduced": "21",
+ "name": "OH_CloudDisk_DeactiveSyncFolder"
+ },
+ {
+ "first_introduced": "21",
+ "name": "OH_CloudDisk_GetSyncFolders"
+ },
+ {
+ "first_introduced": "21",
+ "name": "OH_CloudDisk_UpdateCustomAlias"
}
]
\ No newline at end of file
diff --git a/interfaces/kits/ndk/clouddiskmanager/src/oh_cloud_disk_manager.cpp b/interfaces/kits/ndk/clouddiskmanager/src/oh_cloud_disk_manager.cpp
index b0b09e26656db07c17ba81060bd0f9cd23b6d987..86ad44ac52f220058ba0bb85c82b25431463c86d 100644
--- a/interfaces/kits/ndk/clouddiskmanager/src/oh_cloud_disk_manager.cpp
+++ b/interfaces/kits/ndk/clouddiskmanager/src/oh_cloud_disk_manager.cpp
@@ -103,7 +103,7 @@ void CloudDiskServiceCallbackImpl::OnChangeData(const std::string &syncFolder,
CloudDisk_ChangeData *dataDatas = new (std::nothrow) CloudDisk_ChangeData[changeData.size()];
if (dataDatas == nullptr) {
LOGE("Failed to allocate memory for changeDatas");
- delete[] syncFolderPath.value = nullptr;
+ delete[] syncFolderPath.value;
syncFolderPath.value = nullptr;
return;
}
@@ -154,7 +154,7 @@ CloudDisk_ErrorCode
string(syncFolderPath.value, syncFolderPath.length), callbackImpl);
if (ret != CloudDiskServiceErrCode::E_OK) {
LOGE("Register sync folder change failed, ret: %{public}d", ret);
- return CovertToErrorCode(ret);
+ return ConvertToErrorCode(ret);
}
return CloudDisk_ErrorCode::CLOUD_DISK_ERR_OK;
}
@@ -169,7 +169,7 @@ CloudDisk_ErrorCode OH_CloudDisk_UnregisterSyncFolderChanges(const CloudDisk_Syn
string(syncFolderPath.value, syncFolderPath.length));
if (ret != CloudDiskServiceErrCode::E_OK) {
LOGE("Unegister sync folder change failed, ret: %{public}d", ret);
- return CovertToErrorCode(ret);
+ return ConvertToErrorCode(ret);
}
return CloudDisk_ErrorCode::CLOUD_DISK_ERR_OK;
}
@@ -188,7 +188,7 @@ CloudDisk_ErrorCode OH_CloudDisk_GetSyncFolderChanges(const CloudDisk_SyncFolder
string(syncFolderPath.value, syncFolderPath.length), count, startUsn, changesRes);
if (ret != CloudDiskServiceErrCode::E_OK) {
LOGE("Get sync folder change failed, ret: %{public}d", ret);
- return CovertToErrorCode(ret);
+ return ConvertToErrorCode(ret);
}
*changesResult = (CloudDisk_ChangesResult *)malloc(sizeof(CloudDisk_ChangesResult) +
sizeof(CloudDisk_ChangeData) * changesRes.changesData.size());
@@ -200,10 +200,6 @@ CloudDisk_ErrorCode OH_CloudDisk_GetSyncFolderChanges(const CloudDisk_SyncFolder
(*changesResult)->nextUsn = changesRes.nextUsn;
(*changesResult)->isEof = changesRes.isEof;
for (auto &item : changesRes.changesData) {
- LOGD("change data: fileId=%{public}s, parentFileId=%{public}s, relativePath=%{public}s, "
- "updateSequenceNumber=%{public}lu, operationType=%{public}hhu",
- item.fileId.c_str(), item.parentFileId.c_str(), item.relativePath.c_str(), item.updateSequenceNumber,
- item.operationType);
CloudDisk_ChangeData data;
data.fileId.value = AllocField(item.fileId.c_str(), item.fileId.length());
CHECK_NULLPTR_AND_CONTINUE(data.fileId.value);
@@ -247,7 +243,7 @@ CloudDisk_ErrorCode OH_CloudDisk_SetFileSyncStates(const CloudDisk_SyncFolderPat
string(syncFolderPath.value, syncFolderPath.length), syncStatesVec, failedVec);
if (ret != CloudDiskServiceErrCode::E_OK) {
LOGE("Get sync folder change failed, ret: %{public}d", ret);
- return CovertToErrorCode(ret);
+ return ConvertToErrorCode(ret);
}
*failedCount = failedVec.size();
if (*failedCount == 0) {
@@ -260,8 +256,6 @@ CloudDisk_ErrorCode OH_CloudDisk_SetFileSyncStates(const CloudDisk_SyncFolderPat
return CloudDisk_ErrorCode::CLOUD_DISK_INTERNAL_ERROR;
}
for (size_t index = 0; index < *failedCount; ++index) {
- LOGD("failed list: path=%{public}s, errorReason=%{public}d",
- failedVec[index].path.c_str(), failedVec[index].error);
(*failedLists)[index].pathInfo.value =
AllocField(failedVec[index].path.c_str(), failedVec[index].path.length());
CHECK_NULLPTR_AND_CONTINUE((*failedLists)[index].pathInfo.value);
@@ -294,7 +288,7 @@ CloudDisk_ErrorCode OH_CloudDisk_GetFileSyncStates(const CloudDisk_SyncFolderPat
string(syncFolderPath.value, syncFolderPath.length), pathVec, resultVec);
if (ret != CloudDiskServiceErrCode::E_OK) {
LOGE("Get file sync state failed, ret: %{public}d", ret);
- return CovertToErrorCode(ret);
+ return ConvertToErrorCode(ret);
}
*resultCount = resultVec.size();
if (*resultCount == 0) {
@@ -307,9 +301,6 @@ CloudDisk_ErrorCode OH_CloudDisk_GetFileSyncStates(const CloudDisk_SyncFolderPat
return CloudDisk_ErrorCode::CLOUD_DISK_INTERNAL_ERROR;
}
for (size_t index = 0; index < *resultCount; ++index) {
- LOGD("result list: path=%{public}s, isSuccess=%{public}d, syncState=%{public}d, errorReason=%{public}d",
- resultVec[index].path.c_str(), resultVec[index].isSuccess, resultVec[index].state,
- resultVec[index].error);
(*resultLists)[index].pathInfo.value =
AllocField(resultVec[index].path.c_str(), resultVec[index].path.length());
(*resultLists)[index].pathInfo.length = resultVec[index].path.length();
@@ -320,3 +311,142 @@ CloudDisk_ErrorCode OH_CloudDisk_GetFileSyncStates(const CloudDisk_SyncFolderPat
}
return CloudDisk_ErrorCode::CLOUD_DISK_ERR_OK;
}
+
+CloudDisk_ErrorCode OH_CloudDisk_RegisterSyncFolder(const CloudDisk_SyncFolder *syncFolder)
+{
+ if (syncFolder == nullptr) {
+ LOGE("Invalid argument, syncFolder is nullptr");
+ return CloudDisk_ErrorCode::CLOUD_DISK_INVALID_ARG;
+ }
+
+ if (!IsValidPathInfo(syncFolder->path.value, syncFolder->path.length)) {
+ LOGE("Invalid argument, path is invalid");
+ return CloudDisk_ErrorCode::CLOUD_DISK_INVALID_ARG;
+ }
+
+ OHOS::FileManagement::SyncFolder folder;
+ folder.path_ = std::string(syncFolder->path.value, syncFolder->path.length);
+ if (syncFolder->displayNameInfo.customAlias != nullptr && syncFolder->displayNameInfo.customAliasLength != 0) {
+ if (!IsValidPathInfo(syncFolder->displayNameInfo.customAlias, syncFolder->displayNameInfo.customAliasLength)) {
+ LOGE("Invalid argument, displayName is invalid");
+ return CloudDisk_ErrorCode::CLOUD_DISK_INVALID_ARG;
+ }
+ folder.displayName_ =
+ std::string(syncFolder->displayNameInfo.customAlias, syncFolder->displayNameInfo.customAliasLength);
+ }
+ if (syncFolder->displayNameInfo.displayNameResId != 0) {
+ folder.displayNameResId_ = syncFolder->displayNameInfo.displayNameResId;
+ }
+ int32_t ret = OHOS::FileManagement::CloudDiskSyncFolderManager::GetInstance().Register(folder);
+ LOGI("Register sync folder, ret: %{public}d", ret);
+ return ConvertToErrorCode(ret);
+}
+
+CloudDisk_ErrorCode OH_CloudDisk_UnregisterSyncFolder(const CloudDisk_SyncFolderPath syncFolderPath)
+{
+ if (!IsValidPathInfo(syncFolderPath.value, syncFolderPath.length)) {
+ LOGE("Invalid argument, path is invalid");
+ return CloudDisk_ErrorCode::CLOUD_DISK_INVALID_ARG;
+ }
+
+ int32_t ret = OHOS::FileManagement::CloudDiskSyncFolderManager::GetInstance().Unregister(
+ string(syncFolderPath.value, syncFolderPath.length));
+ LOGI("Unregister sync folder, ret: %{public}d", ret);
+ return ConvertToErrorCode(ret);
+}
+
+CloudDisk_ErrorCode OH_CloudDisk_ActiveSyncFolder(const CloudDisk_SyncFolderPath syncFolderPath)
+{
+ if (!IsValidPathInfo(syncFolderPath.value, syncFolderPath.length)) {
+ LOGE("Invalid argument, path is invalid");
+ return CloudDisk_ErrorCode::CLOUD_DISK_INVALID_ARG;
+ }
+
+ int32_t ret = OHOS::FileManagement::CloudDiskSyncFolderManager::GetInstance().Active(
+ string(syncFolderPath.value, syncFolderPath.length));
+ LOGI("Active sync folder, ret: %{public}d", ret);
+ return ConvertToErrorCode(ret);
+}
+CloudDisk_ErrorCode OH_CloudDisk_DeactiveSyncFolder(const CloudDisk_SyncFolderPath syncFolderPath)
+{
+ if (!IsValidPathInfo(syncFolderPath.value, syncFolderPath.length)) {
+ LOGE("Invalid argument, path is invalid");
+ return CloudDisk_ErrorCode::CLOUD_DISK_INVALID_ARG;
+ }
+
+ int32_t ret = OHOS::FileManagement::CloudDiskSyncFolderManager::GetInstance().Deactive(
+ string(syncFolderPath.value, syncFolderPath.length));
+ LOGI("Deactive sync folder, ret: %{public}d", ret);
+ return ConvertToErrorCode(ret);
+}
+
+CloudDisk_ErrorCode OH_CloudDisk_GetSyncFolders(CloudDisk_SyncFolder **syncFolders, size_t *count)
+{
+ if (syncFolders == nullptr || count == nullptr) {
+ LOGE("Invalid argument, syncFolders or count is nullptr");
+ return CloudDisk_ErrorCode::CLOUD_DISK_INVALID_ARG;
+ }
+ std::vector folderVec;
+ int32_t ret = OHOS::FileManagement::CloudDiskSyncFolderManager::GetInstance().GetSyncFolders(folderVec);
+ if (ret != 0) {
+ LOGE("Get sync folders failed, ret: %{public}d", ret);
+ return ConvertToErrorCode(ret);
+ }
+ *syncFolders = new (std::nothrow) CloudDisk_SyncFolder[folderVec.size()];
+ if (*syncFolders == nullptr) {
+ LOGE("Memory allocation failed for syncFolders");
+ return CloudDisk_ErrorCode::CLOUD_DISK_INTERNAL_ERROR;
+ }
+ for (size_t i = 0; i < folderVec.size(); ++i) {
+ (*syncFolders)[i].path.value = AllocField(folderVec[i].path_.c_str(), folderVec[i].path_.length());
+ if ((*syncFolders)[i].path.value == nullptr) {
+ for (size_t j = 0; j < i; ++j) {
+ delete[] (*syncFolders)[j].path.value;
+ }
+ delete[] (*syncFolders);
+ *syncFolders = nullptr;
+ LOGE("Memory allocation failed for path");
+ return CloudDisk_ErrorCode::CLOUD_DISK_INTERNAL_ERROR;
+ }
+ (*syncFolders)[i].path.length = folderVec[i].path_.length();
+ (*syncFolders)[i].state = static_cast(folderVec[i].state_);
+ (*syncFolders)[i].displayNameInfo.displayNameResId = folderVec[i].displayNameResId_;
+ (*syncFolders)[i].displayNameInfo.customAlias =
+ AllocField(folderVec[i].displayName_.c_str(), folderVec[i].displayName_.length());
+ if ((*syncFolders)[i].displayNameInfo.customAlias == nullptr) {
+ delete[] (*syncFolders)[i].path.value;
+ for (size_t j = 0; j < i; ++j) {
+ delete[] (*syncFolders)[j].path.value;
+ delete[] (*syncFolders)[j].displayNameInfo.customAlias;
+ }
+ delete[] (*syncFolders);
+ *syncFolders = nullptr;
+ LOGE("Memory allocation failed for displayName");
+ return CloudDisk_ErrorCode::CLOUD_DISK_INTERNAL_ERROR;
+ }
+ (*syncFolders)[i].displayNameInfo.customAliasLength = folderVec[i].displayName_.length();
+ }
+ *count = folderVec.size();
+ LOGI("Get sync folders success, count: %{public}zu", *count);
+ return CloudDisk_ErrorCode::CLOUD_DISK_ERR_OK;
+}
+
+CloudDisk_ErrorCode OH_CloudDisk_UpdateCustomAlias(const CloudDisk_SyncFolderPath syncFolderPath,
+ const char *customAlias,
+ size_t customAliasLength)
+{
+ if (!IsValidPathInfo(syncFolderPath.value, syncFolderPath.length)) {
+ LOGE("Invalid argument, path is invalid");
+ return CloudDisk_ErrorCode::CLOUD_DISK_INVALID_ARG;
+ }
+
+ if (!IsValidPathInfo(customAlias, customAliasLength)) {
+ LOGE("Invalid argument, name is invalid");
+ return CloudDisk_ErrorCode::CLOUD_DISK_INVALID_ARG;
+ }
+
+ int32_t ret = OHOS::FileManagement::CloudDiskSyncFolderManager::GetInstance().UpdateDisplayName(
+ string(syncFolderPath.value, syncFolderPath.length), string(customAlias, customAliasLength));
+ LOGI("Update display name, ret: %{public}d", ret);
+ return ConvertToErrorCode(ret);
+}
diff --git a/interfaces/kits/ndk/clouddiskmanager/src/oh_cloud_disk_utils.cpp b/interfaces/kits/ndk/clouddiskmanager/src/oh_cloud_disk_utils.cpp
index 3e54411b9d0c653609eb9fb81188d5211deda270..794e871932cf7ee57d530d1f7f01d6e3c59a624d 100644
--- a/interfaces/kits/ndk/clouddiskmanager/src/oh_cloud_disk_utils.cpp
+++ b/interfaces/kits/ndk/clouddiskmanager/src/oh_cloud_disk_utils.cpp
@@ -15,10 +15,11 @@
#include "oh_cloud_disk_utils.h"
-CloudDisk_ErrorCode CovertToErrorCode(int32_t innerErrorCode)
+CloudDisk_ErrorCode ConvertToErrorCode(int32_t innerErrorCode)
{
- if (innerToNErrTable.find(innerErrorCode) != innerToNErrTable.end()) {
- return innerToNErrTable.at(innerErrorCode);
+ auto iter = innerToNErrTable.find(innerErrorCode);
+ if (iter != innerToNErrTable.end()) {
+ return iter->second;
} else {
return CloudDisk_ErrorCode::CLOUD_DISK_INTERNAL_ERROR;
}