From 43d8891e41a37ca77bc8a255f6e61c33f00d098d Mon Sep 17 00:00:00 2001 From: cuiruibin Date: Tue, 30 Jan 2024 21:21:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EFileUri.NDK=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=85=AC=E5=85=B1=E4=BB=93=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: cuiruibin --- filemanagement/file_uri/BUILD.gn | 31 +++++++ filemanagement/file_uri/include/oh_file_uri.h | 85 +++++++++++++++++++ .../file_uri/liboh_file_uri.ndk.json | 17 ++++ 3 files changed, 133 insertions(+) create mode 100644 filemanagement/file_uri/BUILD.gn create mode 100644 filemanagement/file_uri/include/oh_file_uri.h create mode 100644 filemanagement/file_uri/liboh_file_uri.ndk.json diff --git a/filemanagement/file_uri/BUILD.gn b/filemanagement/file_uri/BUILD.gn new file mode 100644 index 000000000..b2c218f77 --- /dev/null +++ b/filemanagement/file_uri/BUILD.gn @@ -0,0 +1,31 @@ +# 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_headers("oh_file_uri_header") { + dest_dir = "$ndk_headers_out_dir/filemanagement/file_uri/" + sources = [ + "../fileio/include/error_code.h", + "./include/oh_file_uri.h", + ] +} + +ohos_ndk_library("libohfileuri") { + output_name = "ohfileuri" + output_extension = "so" + system_capability = "SystemCapability.FileManagement.AppFileService" + ndk_description_file = "./liboh_file_uri.ndk.json" + min_compact_version = "12" + system_capability_headers = [ "filemanagement/file_uri/oh_file_uri.h" ] +} diff --git a/filemanagement/file_uri/include/oh_file_uri.h b/filemanagement/file_uri/include/oh_file_uri.h new file mode 100644 index 000000000..0753a56b9 --- /dev/null +++ b/filemanagement/file_uri/include/oh_file_uri.h @@ -0,0 +1,85 @@ +/* + * 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_URI_H +#define FILE_MANAGEMENT_OH_FILE_URI_H + +/** + * @file oh_file_uri.h + * + * @brief uri verification and conversion + * @library libohfileuri.so + * @syscap SystemCapability.FileManagement.AppFileService + * @since 12 + */ + +#include "error_code.h" +#include "stdbool.h" +#include +#include +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Get uri From path. + * + * @param path Input a pointer to the path string. + * @param length The length of the input path. + * @param result Output a pointer to a uri string. Please use free() to clear the resource. + * @return Returns the status code of the execution. + * @syscap SystemCapability.FileManagement.AppFileService + * @since 12 + */ +FileManagement_ErrCode OH_FileUri_GetUriFromPath(const char *path, unsigned int length, char **result); + +/** + * @brief Get path From uri. + * + * @param uri Input a pointer to the uri string. + * @param length The length of the input uri. + * @param result Output a pointer to a path string. Please use free() to clear the resource. + * @return Returns the status code of the execution. + * @syscap SystemCapability.FileManagement.AppFileService + * @since 12 + */ +FileManagement_ErrCode OH_FileUri_GetPathFromUri(const char *uri, unsigned int length, char **result); + +/** + * @brief Gets the uri of the path or directory where the uri is located. + * + * @param uri Input a pointer to the uri string. + * @param length The length of the input uri. + * @param result Output a pointer to a uri string. Please use free() to clear the resource. + * @return Returns the status code of the execution. + * @syscap SystemCapability.FileManagement.AppFileService + * @since 12 + */ +FileManagement_ErrCode OH_FileUri_GetFullDirectoryUri(const char *uri, unsigned int length, char **result); + +/** + * @brief Check that the incoming uri is valid + * + * @param uri Input a pointer to the uri string. + * @param length The length of the input uri. + * @return Returns true: Valid incoming uri, false: Invalid incoming uri. + * @syscap SystemCapability.FileManagement.AppFileService + * @since 12 + */ +bool OH_FileUri_IsValidUri(const char *uri, unsigned int length); +#ifdef __cplusplus +}; +#endif +#endif // FILE_MANAGEMENT_OH_FILE_URI_H diff --git a/filemanagement/file_uri/liboh_file_uri.ndk.json b/filemanagement/file_uri/liboh_file_uri.ndk.json new file mode 100644 index 000000000..776c160a8 --- /dev/null +++ b/filemanagement/file_uri/liboh_file_uri.ndk.json @@ -0,0 +1,17 @@ +[ + { "first_introduced": "12", + "name":"OH_FileUri_GetUriFromPath" + }, + { + "first_introduced": "12", + "name":"OH_FileUri_GetPathFromUri" + }, + { + "first_introduced": "12", + "name":"OH_FileUri_GetFullDirectoryUri" + }, + { + "first_introduced": "12", + "name":"OH_FileUri_IsValidUri" + } +] \ No newline at end of file -- Gitee