From cf26a90a20c5f549d8ef26ce67226b805ee7182d Mon Sep 17 00:00:00 2001 From: 18721213663 Date: Sun, 4 Feb 2024 21:13:51 +0800 Subject: [PATCH 1/2] environment_add_ndk Signed-off-by: 18721213663 --- filemanagement/environment/BUILD.gn | 30 ++++++ .../environment/include/environment.h | 96 +++++++++++++++++++ .../environment/libenvironment.ndk.json | 6 ++ 3 files changed, 132 insertions(+) create mode 100644 filemanagement/environment/BUILD.gn create mode 100644 filemanagement/environment/include/environment.h create mode 100644 filemanagement/environment/libenvironment.ndk.json diff --git a/filemanagement/environment/BUILD.gn b/filemanagement/environment/BUILD.gn new file mode 100644 index 000000000..ad76c0df5 --- /dev/null +++ b/filemanagement/environment/BUILD.gn @@ -0,0 +1,30 @@ +# 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("libenvironment_ndk") { + ndk_description_file = "./libenvironment.ndk.json" + min_compact_version = "12" + output_name = "environment" +} + +ohos_ndk_headers("environment_header") { + dest_dir = "$ndk_headers_out_dir/environment/" + sources = [ "./include/environment.h" ] + system_capability = "SystemCapability.FileManagement.File.Environment.FolderObtain" + system_capability_headers = [ + "environment/environment.h", + ] +} \ No newline at end of file diff --git a/filemanagement/environment/include/environment.h b/filemanagement/environment/include/environment.h new file mode 100644 index 000000000..40bedcdaa --- /dev/null +++ b/filemanagement/environment/include/environment.h @@ -0,0 +1,96 @@ +/* + * 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 ENVIRONMENT_H +#define ENVIRONMENT_H_H +/** + * @addtogroup environment + * + * @brief This module provides the ability to access the environment directory and obtain the native interface + for public root directory. + * @since 12 + */ + +/** + * @file environment.h + * + * @brief Provides environment APIS. + * @library libenvironment_ndk.z.so + * @syscap SystemCapability.FileManagement.File.Environment.FolderObtain + * @since 12 + */ +#ifdef __cplusplus +extern "C" { +#endif +/** + * @brief Enumerates the file location. + * + * @since 12 + */ +typedef enum OH_Environment_FileLocation { + /** + * @brief Indicates the file located on the local. + */ + LOCAL = 1, + + /** + * @brief Indicates the file located on the cloud. + */ + CLOUD = 2 +} OH_Environment_FileLocation; + +/** + * @brief Get the file location. + * + * @param uri Represents a pointer to a uri. + * @param uriLength Indicates the length of the uri. + * @return Returns the file location enum. + * @see OH_Environment_FileLocation + * @since 12 + */ +OH_Environment_FileLocation OH_Environment_GetFileLocation(char *uri, int uriLength); + +/** + * @brief Get the user Download directory. + * + * @param result Represents a pointer to a string. + * @param resultNum Indicates the length of the result string. + * @return Returns the status code of the execution. + * @since 12 + */ +int OH_Environment_GetUserDownloadDir(char **result, int *resultLength); + +/** + * @brief Get the user Desktop directory. + * + * @param result Represents a pointer to a string. + * @param resultNum Indicates the length of the result string. + * @return Returns the status code of the execution. + * @since 12 + */ +int OH_Environment_GetUserDesktopDir(char **result, int *resultLength); + +/** + * @brief Get the user Document directory. + * + * @param result Represents a pointer to a string. + * @param resultNum Indicates the length of the result string. + * @return Returns the status code of the execution. + * @since 12 + */ +int OH_Environment_GetUserDocumentDir(char **result, int *resultLength); +#ifdef __cplusplus +}; +#endif +#endif //FILE_SHARE_H \ No newline at end of file diff --git a/filemanagement/environment/libenvironment.ndk.json b/filemanagement/environment/libenvironment.ndk.json new file mode 100644 index 000000000..152ed426a --- /dev/null +++ b/filemanagement/environment/libenvironment.ndk.json @@ -0,0 +1,6 @@ +[ + {"name":"OH_Environment_GetUserDownloadDir" }, + {"name":"OH_Environment_GetUserDesktopDir" }, + {"name":"OH_Environment_GetUserDownloadDir" }, + {"name":"OH_Environment_GetFileLocation" } +] \ No newline at end of file -- Gitee From 2e0807baee38bc6ab69daa433da4ddbbf559bcf0 Mon Sep 17 00:00:00 2001 From: 18721213663 Date: Mon, 5 Feb 2024 10:35:20 +0800 Subject: [PATCH 2/2] ndk_add_environment Signed-off-by: 18721213663 --- filemanagement/environment/BUILD.gn | 21 ++--- .../{environment.h => oh_environment.h} | 72 ++++++----------- .../environment/libenvironment.ndk.json | 16 +++- filemanagement/fileio/BUILD.gn | 32 ++++++++ filemanagement/fileio/include/error_code.h | 78 +++++++++++++++++++ filemanagement/fileio/include/oh_fileio.h | 75 ++++++++++++++++++ filemanagement/fileio/libfileio.ndk.json | 6 ++ 7 files changed, 240 insertions(+), 60 deletions(-) rename filemanagement/environment/include/{environment.h => oh_environment.h} (42%) create mode 100644 filemanagement/fileio/BUILD.gn create mode 100644 filemanagement/fileio/include/error_code.h create mode 100644 filemanagement/fileio/include/oh_fileio.h create mode 100644 filemanagement/fileio/libfileio.ndk.json diff --git a/filemanagement/environment/BUILD.gn b/filemanagement/environment/BUILD.gn index ad76c0df5..55538d9d5 100644 --- a/filemanagement/environment/BUILD.gn +++ b/filemanagement/environment/BUILD.gn @@ -14,17 +14,20 @@ import("//build/ohos.gni") import("//build/ohos/ndk/ndk.gni") -ohos_ndk_library("libenvironment_ndk") { +ohos_ndk_library("libohenvironment") { ndk_description_file = "./libenvironment.ndk.json" min_compact_version = "12" - output_name = "environment" + output_name = "ohenvironment" + output_extension = "so" + system_capability = + "SystemCapability.FileManagement.File.Environment.FolderObtain" + system_capability_headers = [ "filemanagement/environment/oh_environment.h" ] } -ohos_ndk_headers("environment_header") { - dest_dir = "$ndk_headers_out_dir/environment/" - sources = [ "./include/environment.h" ] - system_capability = "SystemCapability.FileManagement.File.Environment.FolderObtain" - system_capability_headers = [ - "environment/environment.h", +ohos_ndk_headers("oh_environment_header") { + dest_dir = "$ndk_headers_out_dir/filemanagement/environment/" + sources = [ + "../fileio/include/error_code.h", + "./include/oh_environment.h", ] -} \ No newline at end of file +} diff --git a/filemanagement/environment/include/environment.h b/filemanagement/environment/include/oh_environment.h similarity index 42% rename from filemanagement/environment/include/environment.h rename to filemanagement/environment/include/oh_environment.h index 40bedcdaa..5621fd7a5 100644 --- a/filemanagement/environment/include/environment.h +++ b/filemanagement/environment/include/oh_environment.h @@ -12,10 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef ENVIRONMENT_H -#define ENVIRONMENT_H_H +#ifndef FILE_MANAGEMENT_ENVIRONMENT_OH_ENVIRONMENT_H +#define FILE_MANAGEMENT_ENVIRONMENT_OH_ENVIRONMENT_H + /** - * @addtogroup environment + * @addtogroup Environment * * @brief This module provides the ability to access the environment directory and obtain the native interface for public root directory. @@ -23,74 +24,51 @@ */ /** - * @file environment.h + * @file oh_environment.h * - * @brief Provides environment APIS. - * @library libenvironment_ndk.z.so + * @brief Provide environment APIS. + * @library libohenvironment.so * @syscap SystemCapability.FileManagement.File.Environment.FolderObtain * @since 12 */ + +#include "error_code.h" + #ifdef __cplusplus extern "C" { #endif -/** - * @brief Enumerates the file location. - * - * @since 12 - */ -typedef enum OH_Environment_FileLocation { - /** - * @brief Indicates the file located on the local. - */ - LOCAL = 1, - - /** - * @brief Indicates the file located on the cloud. - */ - CLOUD = 2 -} OH_Environment_FileLocation; - -/** - * @brief Get the file location. - * - * @param uri Represents a pointer to a uri. - * @param uriLength Indicates the length of the uri. - * @return Returns the file location enum. - * @see OH_Environment_FileLocation - * @since 12 - */ -OH_Environment_FileLocation OH_Environment_GetFileLocation(char *uri, int uriLength); - /** * @brief Get the user Download directory. * - * @param result Represents a pointer to a string. - * @param resultNum Indicates the length of the result string. - * @return Returns the status code of the execution. + * @permission ohos.permission.READ_WRITE_DOWNLOAD_DIRECTORY + * @param result Output a pointer to a string. Please use free() to clear the resource. + * @return Return the status code of the execution. * @since 12 */ -int OH_Environment_GetUserDownloadDir(char **result, int *resultLength); +FileManagement_ErrCode OH_Environment_GetUserDownloadDir(char **result); /** * @brief Get the user Desktop directory. * - * @param result Represents a pointer to a string. - * @param resultNum Indicates the length of the result string. - * @return Returns the status code of the execution. + * @permission ohos.permission.READ_WRITE_DESKTOP_DIRECTORY + * @param result Output a pointer to a string. Please use free() to clear the resource. + * @return Return the status code of the execution. * @since 12 */ -int OH_Environment_GetUserDesktopDir(char **result, int *resultLength); +FileManagement_ErrCode OH_Environment_GetUserDesktopDir(char **result); /** * @brief Get the user Document directory. * - * @param result Represents a pointer to a string. - * @param resultNum Indicates the length of the result string. - * @return Returns the status code of the execution. + * @permission ohos.permission.READ_WRITE_DOCUMENTS_DIRECTORY + * @param result Output a pointer to a string. Please use free() to clear the resource. + * @return Return the status code of the execution. * @since 12 */ -int OH_Environment_GetUserDocumentDir(char **result, int *resultLength); +FileManagement_ErrCode OH_Environment_GetUserDocumentDir(char **result); + #ifdef __cplusplus }; #endif -#endif //FILE_SHARE_H \ No newline at end of file + +#endif //FILE_MANAGEMENT_ENVIRONMENT_OH_ENVIRONMENT_H diff --git a/filemanagement/environment/libenvironment.ndk.json b/filemanagement/environment/libenvironment.ndk.json index 152ed426a..267a28cbe 100644 --- a/filemanagement/environment/libenvironment.ndk.json +++ b/filemanagement/environment/libenvironment.ndk.json @@ -1,6 +1,14 @@ [ - {"name":"OH_Environment_GetUserDownloadDir" }, - {"name":"OH_Environment_GetUserDesktopDir" }, - {"name":"OH_Environment_GetUserDownloadDir" }, - {"name":"OH_Environment_GetFileLocation" } + { + "first_introduced": "12", + "name":"OH_Environment_GetUserDownloadDir" + }, + { + "first_introduced": "12", + "name":"OH_Environment_GetUserDesktopDir" + }, + { + "first_introduced": "12", + "name":"OH_Environment_GetUserDocumentDir" + } ] \ No newline at end of file diff --git a/filemanagement/fileio/BUILD.gn b/filemanagement/fileio/BUILD.gn new file mode 100644 index 000000000..30b5edb71 --- /dev/null +++ b/filemanagement/fileio/BUILD.gn @@ -0,0 +1,32 @@ +# 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("libohfileio") { + ndk_description_file = "./libfileio.ndk.json" + min_compact_version = "12" + output_name = "ohfileio" + output_extension = "so" + system_capability = "SystemCapability.FileManagement.File.FileIO" + system_capability_headers = [ "filemanagement/fileio/oh_fileio.h" ] +} + +ohos_ndk_headers("oh_fileio_header") { + dest_dir = "$ndk_headers_out_dir/filemanagement/fileio/" + sources = [ + "./include/error_code.h", + "./include/oh_fileio.h", + ] +} diff --git a/filemanagement/fileio/include/error_code.h b/filemanagement/fileio/include/error_code.h new file mode 100644 index 000000000..3a10047e6 --- /dev/null +++ b/filemanagement/fileio/include/error_code.h @@ -0,0 +1,78 @@ +/* + * 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_FILEIO_ERROR_CODE_H +#define FILE_MANAGEMENT_FILEIO_ERROR_CODE_H + +/** + * @addtogroup FileIO + * @{ + * + * @brief Provide the definition of the error codes. + * @since 12 + */ + +/** + * @file error_code.h + * + * @brief Declare the error codes of file management module. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 12 + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief error codes of file management + * @since 12 + */ +typedef enum FileManagement_ErrCode { + /** + * operation completed successfully. + */ + ERR_OK = 0, + /** + * permission verification failed. + */ + ERR_PERMISSION_ERROR = 201, + /** + * device not supported. + */ + ERR_DEVICE_NOT_SUPPORTED = 801, + /** + * operation not permitted. + */ + ERR_EPERM = 13900001, + /** + * no such file or directory. + */ + ERR_ENOENT = 13900002, + /** + * out of memory. + */ + ERR_ENOMEM = 139000011, + /** + * unknown error. + */ + ERR_UNKNOWN = 13900042 +} FileManagement_ErrCode; + +#ifdef __cplusplus +} +#endif + +#endif // FILE_MANAGEMENT_FILEIO_ERROR_CODE_H diff --git a/filemanagement/fileio/include/oh_fileio.h b/filemanagement/fileio/include/oh_fileio.h new file mode 100644 index 000000000..65970bdca --- /dev/null +++ b/filemanagement/fileio/include/oh_fileio.h @@ -0,0 +1,75 @@ +/* + * 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_FILEIO_OH_FILEIO_H +#define FILE_MANAGEMENT_FILEIO_OH_FILEIO_H + +/** + * @addtogroup FileIO + * + * @brief This module provides the basic file operations. + * @since 12 + */ + +/** + * @file oh_fileio.h + * + * @brief Provide fileio APIS. + * @library libohfileio.so + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 12 + */ + +#include "error_code.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Enumerates the file location. + * @since 12 + */ +typedef enum FileIO_FileLocation { + /** + * @brief Indicates the file located on the local. + */ + LOCAL = 1, + /** + * @brief Indicates the file located on the cloud. + */ + CLOUD = 2, + /** + * @brief Indicates the file located on the local and cloud. + */ + LOCAL_AND_CLOUD = 3 +} FileIO_FileLocation; + +/** + * @brief Get the file location. + * + * @param uri Input a pointer to a uri. + * @param uriLength Input the length of the uri. + * @param location Output the result of file location. + * @return Return the status code of the execution. + * @since 12 + */ +FileManagement_ErrCode OH_FileIO_GetFileLocation(char *uri, int uriLength, + FileIO_FileLocation *location); + +#ifdef __cplusplus +}; +#endif + +#endif //FILE_MANAGEMENT_FILEIO_OH_FILEIO_H diff --git a/filemanagement/fileio/libfileio.ndk.json b/filemanagement/fileio/libfileio.ndk.json new file mode 100644 index 000000000..fdb265be1 --- /dev/null +++ b/filemanagement/fileio/libfileio.ndk.json @@ -0,0 +1,6 @@ +[ + { + "first_introduced": "12", + "name":"OH_FileIO_GetFileLocation" + } +] \ No newline at end of file -- Gitee