diff --git a/filemanagement/fileshare/BUILD.gn b/filemanagement/fileshare/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..3027c40e5dd4f88dbda371842a57237cc17332bd --- /dev/null +++ b/filemanagement/fileshare/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/ohos/ndk/ndk.gni") + +ohos_ndk_library("libohfileshare") { + ndk_description_file = "./libfile_share.ndk.json" + min_compact_version = "12" + output_name = "ohfileshare" + output_extension = "so" + system_capability = + "SystemCapability.FileManagement.AppFileService.FolderAuthorization" + system_capability_headers = [ "filemanagement/fileshare/oh_file_share.h" ] +} + +ohos_ndk_headers("oh_file_share_header") { + dest_dir = "$ndk_headers_out_dir/filemanagement/fileshare/" + sources = [ + "../fileio/include/error_code.h", + "./include/oh_file_share.h", + ] +} diff --git a/filemanagement/fileshare/include/oh_file_share.h b/filemanagement/fileshare/include/oh_file_share.h new file mode 100644 index 0000000000000000000000000000000000000000..821336be5772181da11a7ccdd7ce22271f47104b --- /dev/null +++ b/filemanagement/fileshare/include/oh_file_share.h @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FILE_MANAGEMENT_OH_FILE_SHARE_H +#define FILE_MANAGEMENT_OH_FILE_SHARE_H + +#include "error_code.h" + +/** + * @addtogroup fileShare + * @{ + * + * @brief This module provides file sharing capabilities to authorize Uniform Resource Identifiers (URIs) + * for public directory files that have read and write access to other applications. + * @since 12 + */ + +/** + * @file oh_file_share.h + * + * @brief Provides URI-based file and directory authorization and persistence, permission activation, permission query, + * and other methods. + * @library libohfileshare.so + * @syscap SystemCapability.FileManagement.AppFileService.FolderAuthorization + * @since 12 + */ +#ifdef __cplusplus +extern "C" { +#endif +/** + * @brief Enumerates the uri operate mode types. + * + * @since 12 + */ +typedef enum FileShare_OperationMode { + /** + * @brief Indicates read permissions. + */ + READ_MODE = 1 << 0, + + /** + * @brief Indicates write permissions. + */ + WRITE_MODE = 1 << 1 +} FileShare_OperationMode; + +/** + * @brief Enumerates the error code of the permission policy for the URI operation. + * + * @since 12 + */ +typedef enum FileShare_PolicyErrorCode { + /** + * @brief Indicates that the policy is not allowed to be persisted. + */ + PERSISTENCE_FORBIDDEN = 1, + + /** + * @brief Indicates that the mode of this policy is invalid. + */ + INVALID_MODE = 2, + + /** + * @brief Indicates that the path of this policy is invalid. + */ + INVALID_PATH = 3, + + /** + * @brief Indicates that the policy is no persistent capability. + */ + PERMISSION_NOT_PERSISTED = 4 +} FileShare_PolicyErrorCode; + +/** + * @brief Define the FileShare_PolicyErrorResult structure type. + * + * Failed policy result on URI. + * + * @since 12 + */ +typedef struct FileShare_PolicyErrorResult { + /** + * Indicates the failed uri of the policy information. + */ + char *uri; + + /** + * Indicates the error code of the failure in the policy information. + */ + FileShare_PolicyErrorCode code; + + /** + * Indicates the reason of the failure in the policy information. + */ + char *message; +} FileShare_PolicyErrorResult; + +/** + * @brief Define the FileShare_PolicyInfo structure type. + * + * Policy information to manager permissions on a URI. + * + * @since 12 + */ +typedef struct FileShare_PolicyInfo { + /** + * Indicates the uri of the policy information. + */ + char *uri; + + /** + * Indicates The length of the uri. + */ + unsigned int length; + + /** + * Indicates the mode of operation for the URI. + * example { FileShare_OperationMode.READ_MODE } or { FileShare_OperationMode.READ_MODE | + * FileShare_OperationMode.WRITE_MODE }. + */ + unsigned int operationMode; +} FileShare_PolicyInfo; + +/** + * @brief Set persistent permissions for the URI. + * + * @permission ohos.permission.FILE_ACCESS_PERSIST + * @param policies Input a pointer to an {@link FileShare_PolicyInfo} instance. + * @param policyNum Indicates the size of the policies array. + * @param result Output a pointer to an {@link FileShare_PolicyErrorResult} instance. Please use + * OH_FileShare_ReleasePolicyErrorResult() to clear Resource. + * @param resultNum Output the size of the result array. + * @return Returns the status code of the execution. + * @since 12 + */ +FileManagement_ErrCode OH_FileShare_PersistPermission(const FileShare_PolicyInfo *policies, + unsigned int policyNum, + FileShare_PolicyErrorResult **result, + unsigned int *resultNum); + +/** + * @brief Revoke persistent permissions for the URI. + * + * @permission ohos.permission.FILE_ACCESS_PERSIST + * @param policies Input a pointer to an {@link FileShare_PolicyInfo} instance. + * @param policyNum Indicates the size of the policies array. + * @param result Output a pointer to an {@link FileShare_PolicyErrorResult} instance. Please use + * OH_FileShare_ReleasePolicyErrorResult() to clear Resource. + * @param resultNum Output the size of the result array. + * @return Returns the status code of the execution. + * @since 12 + */ +FileManagement_ErrCode OH_FileShare_RevokePermission(const FileShare_PolicyInfo *policies, + unsigned int policyNum, + FileShare_PolicyErrorResult **result, + unsigned int *resultNum); + +/** + * @brief Enable the URI that have been permanently authorized. + * + * @permission ohos.permission.FILE_ACCESS_PERSIST + * @param policies Input a pointer to an {@link FileShare_PolicyInfo} instance. + * @param policyNum Indicates the size of the policies array. + * @param result Output a pointer to an {@link FileShare_PolicyErrorResult} instance. Please use + * OH_FileShare_ReleasePolicyErrorResult() to clear Resource. + * @param resultNum Output the size of the result array. + * @return Returns the status code of the execution. + * @since 12 + */ +FileManagement_ErrCode OH_FileShare_ActivatePermission(const FileShare_PolicyInfo *policies, + unsigned int policyNum, + FileShare_PolicyErrorResult **result, + unsigned int *resultNum); + +/** + * @brief Stop the authorized URI that has been enabled. + * + * @permission ohos.permission.FILE_ACCESS_PERSIST + * @param policies Input a pointer to an {@link FileShare_PolicyInfo} instance. + * @param policyNum Indicates the size of the policies array. + * @param result Output a pointer to an {@link FileShare_PolicyErrorResult} instance. Please use + * OH_FileShare_ReleasePolicyErrorResult() to clear Resource. + * @param resultNum Output the size of the result array. + * @return Returns the status code of the execution. + * @since 12 + */ +FileManagement_ErrCode OH_FileShare_DeactivatePermission(const FileShare_PolicyInfo *policies, + unsigned int policyNum, + FileShare_PolicyErrorResult **result, + unsigned int *resultNum); + +/** + * @brief Check persistent permissions for the URI. + * + * @permission ohos.permission.FILE_ACCESS_PERSIST + * @param policies Input a pointer to an {@link FileShare_PolicyInfo} instance. + * @param policyNum Indicates the size of the policies array. + * @param result Output a pointer to an bool instance. Please use free() to clear Resource. + * @param resultNum Output the size of the result array. + * @return Returns the status code of the execution. + * @since 12 + */ +FileManagement_ErrCode OH_FileShare_CheckPersistentPermission(const FileShare_PolicyInfo *policies, + unsigned int policyNum, + bool **result, + unsigned int *resultNum); + +/** + * @brief Free FileShare_PolicyErrorResult pointer points to address memory. + * + * @param errorResult Input a pointer to an {@link FileShare_PolicyErrorResult} instance. + * @param resultNum Indicates the size of the errorResult array. + * @since 12 + */ +void OH_FileShare_ReleasePolicyErrorResult(FileShare_PolicyErrorResult *errorResult, unsigned int resultNum); +#ifdef __cplusplus +}; +#endif +/** @} */ +#endif // FILE_MANAGEMENT_OH_FILE_SHARE_H diff --git a/filemanagement/fileshare/libfile_share.ndk.json b/filemanagement/fileshare/libfile_share.ndk.json new file mode 100644 index 0000000000000000000000000000000000000000..fb133d6bd6e0f1c1e3cda248c50f2fdff631cf8c --- /dev/null +++ b/filemanagement/fileshare/libfile_share.ndk.json @@ -0,0 +1,26 @@ +[ + { + "first_introduced": "12", + "name": "OH_FileShare_PersistPermission" + }, + { + "first_introduced": "12", + "name": "OH_FileShare_RevokePermission" + }, + { + "first_introduced": "12", + "name": "OH_FileShare_ActivatePermission" + }, + { + "first_introduced": "12", + "name": "OH_FileShare_DeactivatePermission" + }, + { + "first_introduced": "12", + "name": "OH_FileShare_CheckPersistPermission" + }, + { + "first_introduced": "12", + "name": "OH_FileShare_ReleasePolicyErrorResult" + } +] \ No newline at end of file