diff --git a/filemanagement/environment/BUILD.gn b/filemanagement/environment/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..55538d9d5c4103e3ef10eef106f9104b74a24d36 --- /dev/null +++ b/filemanagement/environment/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("libohenvironment") { + ndk_description_file = "./libenvironment.ndk.json" + min_compact_version = "12" + output_name = "ohenvironment" + output_extension = "so" + system_capability = + "SystemCapability.FileManagement.File.Environment.FolderObtain" + system_capability_headers = [ "filemanagement/environment/oh_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", + ] +} diff --git a/filemanagement/environment/include/oh_environment.h b/filemanagement/environment/include/oh_environment.h new file mode 100644 index 0000000000000000000000000000000000000000..5621fd7a5baa137331b19cf0a1460abe9fe401d3 --- /dev/null +++ b/filemanagement/environment/include/oh_environment.h @@ -0,0 +1,74 @@ +/* + * 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_ENVIRONMENT_OH_ENVIRONMENT_H +#define FILE_MANAGEMENT_ENVIRONMENT_OH_ENVIRONMENT_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 oh_environment.h + * + * @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 Get the user Download directory. + * + * @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 + */ +FileManagement_ErrCode OH_Environment_GetUserDownloadDir(char **result); + +/** + * @brief Get the user Desktop directory. + * + * @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 + */ +FileManagement_ErrCode OH_Environment_GetUserDesktopDir(char **result); + +/** + * @brief Get the user Document directory. + * + * @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 + */ +FileManagement_ErrCode OH_Environment_GetUserDocumentDir(char **result); + +#ifdef __cplusplus +}; +#endif + +#endif //FILE_MANAGEMENT_ENVIRONMENT_OH_ENVIRONMENT_H diff --git a/filemanagement/environment/libenvironment.ndk.json b/filemanagement/environment/libenvironment.ndk.json new file mode 100644 index 0000000000000000000000000000000000000000..267a28cbee893a6acf9755f997206de012f50e79 --- /dev/null +++ b/filemanagement/environment/libenvironment.ndk.json @@ -0,0 +1,14 @@ +[ + { + "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 0000000000000000000000000000000000000000..30b5edb71b74936d8093e342004e103f7f9150c5 --- /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 0000000000000000000000000000000000000000..3a10047e6db848cdabf367246ebbd60323834326 --- /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 0000000000000000000000000000000000000000..65970bdca0cd46c73a65b5bf25409a029929f059 --- /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 0000000000000000000000000000000000000000..fdb265be1ba40046814d85d50cab0dd7964200a3 --- /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