diff --git a/LICENSE b/LICENSE index 4947287f7b5ccb5d1e8b7b2d3aa5d89f322c160d..2bb9ad240fa04c8cf706a4901c4807878e90c2dc 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,3 @@ - Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ diff --git a/README.md b/README.md deleted file mode 100644 index 1d37300cd840f7d346b5553f06617c2d87cf57ba..0000000000000000000000000000000000000000 --- a/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# storage_user_file_manger - -#### Description -{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**} - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README_zh.md b/README_zh.md deleted file mode 100644 index 6b659a73f1daa32d97977b92f9359080f57d4a20..0000000000000000000000000000000000000000 --- a/README_zh.md +++ /dev/null @@ -1,39 +0,0 @@ -# 公共文件服务 - -## 简介 - -公共文件服务提供公共文件访问和管理的服务接口。 - -公共文件服务中File Manager Service服务向下对接底层文件管理服务,如媒体库、外卡管理。File Manager Service服务向上对接应用提供公共文件查询、创建的能力,如图1。 File Manager Service接口能力当前只对系统应用如文件选择器提供。 - -支持能力列举如下: -- 查询、创建公共文件路径下媒体文件。媒体文件包括图片、音频、视频。媒体文件通过相册方式呈现。 - -- 查询、创建公共文件路径下文档文件。文档文件包括其他文件、外部存储卡内的文件。文件以目录树方式呈现。 - -**图 1** 公共文件管理架构图 -![](figures/user_file_manager.png "公共文件管理架构图") - -## 目录 - -仓目录结构如下: -``` -/foundation/storage/user_file_service -├── figures # 插图文件 -├── serivce # 服务实现 -│   ├── etc # 内部接口实现 -│   ├── src # 内部接口实现 -├── interfaces # 接口代码 -│   ├── innerkits # 内部 Native 接口 -│   └── kits # 外部 JS 接口 -├── BUILD.gn # 编译入口 -└── bundle.json # 部件描述文件 -``` -## 说明 -### 使用说明 -1. 创建文件 - - 提供createFile接口,传入文件名与相册uri进行文件创建。 - - 文件创建成功后,可获得文件uri。应用可通过uri进行文件打开并进行读写操作。 -2. 查询文件 - - 提供listFile接口,传入文件类型、相册uri进行文件查询。 - - 获得相册下文件信息的集合,包括文件名、文件类型、文件大小、文件创建时间等信息。 \ No newline at end of file diff --git a/bundle.json b/bundle.json index 95dbc537d0a3d2fcb80f4ae861bdfb655108e715..3ba13c4ebdd866747e8dd726bfce448cd283bc6e 100644 --- a/bundle.json +++ b/bundle.json @@ -33,12 +33,11 @@ }, "build": { "sub_component": [ - "//foundation/filemanagement/user_file_service/services:fms", - "//foundation/filemanagement/user_file_service/services/sa_profile:filemanager_service_sa_profile", - "//foundation/filemanagement/user_file_service/interfaces/kits/js:filemanager" + "//foundation/filemanagement/user_file_service/frameworks/innerkits:frameworks_innerkits", + "//foundation/filemanagement/user_file_service/interfaces/kits/napi/file_access_module:fileaccess", + "//foundation/filemanagement/user_file_service/interfaces/kits/napi/file_ext_ability:fileextensionability_napi" ], "test": [ - "//foundation/filemanagement/user_file_service/services/test:user_file_manager_test" ] } } diff --git a/figures/user_file_manager.png b/figures/user_file_manager.png deleted file mode 100644 index 597ec2aa841410c412dbe7517a95eed5fe9377f4..0000000000000000000000000000000000000000 Binary files a/figures/user_file_manager.png and /dev/null differ diff --git a/interfaces/kits/js/BUILD.gn b/frameworks/innerkits/BUILD.gn similarity index 32% rename from interfaces/kits/js/BUILD.gn rename to frameworks/innerkits/BUILD.gn index bc9b9e5c359a90b04a2ecce5e09cd71e6726dd41..0c10968c00cac66b3a780ff5da09d7cc472ae45f 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/frameworks/innerkits/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022 Huawei Device Co., Ltd. +# Copyright (c) 2022 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 @@ -12,49 +12,47 @@ # limitations under the License. import("//build/ohos.gni") -FMS_BASE_DIR = "//foundation/filemanagement/user_file_service/services" -ohos_shared_library("filemanager") { +group("frameworks_innerkits") { + deps = [ + ":file_extension_hap", + "file_extension:file_extension_ability_kit", + "file_extension:file_extension_ability_module", + ] +} + +#### file extension hap +ohos_hap("file_extension_hap") { + hap_profile = "file_extension_hap/entry/src/main/module.json" + deps = [ + ":file_extension_js_assets", + ":file_extension_resources", + ] + certificate_profile = "signature/fileextension.p7b" + hap_name = "file_extension" subsystem_name = "filemanagement" part_name = "user_file_service" + module_install_dir = "app/com.ohos.FileExtension" +} - relative_install_dir = "module" +ohos_js_assets("file_extension_js_assets") { + hap_profile = "file_extension_hap/entry/src/main/module.json" + ets2abc = true + source_dir = "file_extension_hap/entry/src/main/ets" +} - include_dirs = [ - "//third_party/node/src", - "//foundation/arkui/napi/interfaces/kits", - "//utils/native/base/include", - "//third_party/libuv/include", - "$FMS_BASE_DIR/include", - "$FMS_BASE_DIR/src/client", - "$FMS_BASE_DIR/src/server", - "$FMS_BASE_DIR/src/fileoper", - "//foundation/distributeddatamgr/distributedfile/interfaces/kits/js/src/common/napi/n_async", - "//foundation/distributeddatamgr/distributedfile/interfaces/kits/js/src/common/napi", - "//foundation/distributeddatamgr/distributedfile/interfaces/kits/js/src/common", - "//foundation/multimedia/medialibrary_standard/interfaces/inner_api/media_library_helper/include", - ] +ohos_app_scope("file_extension_app_profile") { + app_profile = "file_extension_hap/AppScope/app.json" + sources = [ "file_extension_hap/AppScope/resources" ] +} +ohos_resources("file_extension_resources") { sources = [ - "src/file_manager_napi.cpp", - "src/module.cpp", + "file_extension_hap/entry/src/main/resources", ] - deps = [ - "$FMS_BASE_DIR:fms_server", - "//foundation/arkui/napi:ace_napi", - "//foundation/distributeddatamgr/distributedfile/interfaces/kits/js:fileio", - "//foundation/multimedia/medialibrary_standard/frameworks/services/media_library:medialibrary_data_ability", - "//utils/native/base:utils", - ] - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", + ":file_extension_app_profile", ] + hap_profile = "file_extension_hap/entry/src/main/module.json" } +#### file extension hap \ No newline at end of file diff --git a/services/BUILD.gn b/frameworks/innerkits/file_extension/BUILD.gn similarity index 31% rename from services/BUILD.gn rename to frameworks/innerkits/file_extension/BUILD.gn index 20af46633e911135823ce79c7370b7227f33c909..aba44d064430e840ce2289a01998b00d4cae28cf 100644 --- a/services/BUILD.gn +++ b/frameworks/innerkits/file_extension/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2022 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 @@ -12,80 +12,105 @@ # limitations under the License. import("//build/ohos.gni") -FMS_BASE_DIR = "//foundation/filemanagement/user_file_service/services" -group("fms") { - deps = [ - ":fms_server", - ":fms_service.cfg", +BASE_DIR = "//foundation/filemanagement/user_file_service" + +config("ability_config") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "${BASE_DIR}/utils", + "//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include", + "//foundation/aafwk/standard/services/common/include", + "//foundation/aafwk/standard/frameworks/kits/ability/native/include/continuation/distributed", + "//foundation/aafwk/standard/frameworks/kits/ability/native/include/continuation/kits", + "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", ] -} -ohos_prebuilt_etc("fms_service.cfg") { - source = "etc/fms_service.cfg" - relative_install_dir = "init" - subsystem_name = "filemanagement" - part_name = "user_file_service" + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } } -ohos_shared_library("fms_server") { - subsystem_name = "filemanagement" - part_name = "user_file_service" - +config("ability_public_config") { + visibility = [ ":*" ] include_dirs = [ - "$FMS_BASE_DIR/include", - "$FMS_BASE_DIR/src/client", - "$FMS_BASE_DIR/src/server", - "$FMS_BASE_DIR/src/fileoper", - "$FMS_BASE_DIR/include/fileoper", - "//base/hiviewdfx/hilog/interfaces/native/innerkits/include/hilog", - "//foundation/filemanagement/storage_service/services/storage_manager/include", - "//foundation/filemanagement/storage_service/interfaces/innerkits/storage_manager/native", - "//foundation/aafwk/standard/interfaces/innerkits/base/include/ohos/aafwk/base", + "include", + "${BASE_DIR}/utils", + "//foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime/app", + "//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include", + "//foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime/context", ] +} + +ohos_shared_library("file_extension_ability_kit") { + include_dirs = [] sources = [ - "src/client/file_manager_proxy.cpp", - "src/fileoper/ext_storage/ext_storage_subscriber.cpp", - "src/fileoper/ext_storage/storage_manager_inf.cpp", - "src/fileoper/external_storage_oper.cpp", - "src/fileoper/external_storage_utils.cpp", - "src/fileoper/file_info.cpp", - "src/fileoper/media_file_oper.cpp", - "src/fileoper/media_file_utils.cpp", - "src/fileoper/oper_factory.cpp", - "src/server/file_manager_service.cpp", - "src/server/file_manager_service_stub.cpp", + "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_access_helper.cpp", + "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_ability.cpp", + "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_connection.cpp", + "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp", + "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp", + "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_stub.cpp", + "${BASE_DIR}/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp", + ] + configs = [ ":ability_config" ] + public_configs = [ + ":ability_public_config", + "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime:ability_context_public_config", ] deps = [ - "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", - "//foundation/aafwk/standard/interfaces/innerkits/base:base", - "//foundation/aafwk/standard/services/abilitymgr:abilityms", - "//foundation/filemanagement/storage_service/interfaces/innerkits/storage_manager/native:storage_manager_sa_proxy", - "//foundation/filemanagement/storage_service/services/storage_manager:storage_manager", - "//foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/media_library_helper:media_library", - "//foundation/multimedia/medialibrary_standard/frameworks/services/media_library:medialibrary_data_ability", - "//utils/native/base:utils", + "//foundation/aafwk/standard/frameworks/kits/appkit:app_context", ] - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } + external_deps = [ "ability_base:want", "ability_base:zuri", + "ability_runtime:ability_context_native", "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "ability_runtime:runtime", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", - "common_event_service:cesfwk_innerkits", - "hiviewdfx_hilog_native:libhilog", + "bytrace_standard:bytrace_core", "ipc:ipc_core", - "native_appdatamgr:native_appdatafwk", - "native_appdatamgr:native_dataability", - "native_appdatamgr:native_rdb", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", + "ipc_js:rpc", + "permission_standard:libpermissionsdk_standard", + "utils_base:utils", + ] + + public_deps = [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//foundation/arkui/napi:ace_napi", + ] + + subsystem_name = "filemanagement" + part_name = "user_file_service" +} + +ohos_shared_library("file_extension_ability_module") { + sources = [ "${BASE_DIR}/frameworks/innerkits/file_extension/src/file_ext_ability_module_loader.cpp" ] + + configs = [ ":ability_config" ] + public_configs = [ ":ability_public_config" ] + + deps = [ + ":file_extension_ability_kit", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", ] + + external_deps = [ + "ability_base:want", + "ability_runtime:runtime", + "hiviewdfx_hilog_native:libhilog", + "utils_base:utils", + ] + + subsystem_name = "filemanagement" + part_name = "user_file_service" } diff --git a/frameworks/innerkits/file_extension/include/file_access_helper.h b/frameworks/innerkits/file_extension/include/file_access_helper.h new file mode 100644 index 0000000000000000000000000000000000000000..a3f7e3cac3a904cebdfe39bf43b019813e20798e --- /dev/null +++ b/frameworks/innerkits/file_extension/include/file_access_helper.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_APPEXECFWK_OHOS_FILEACCESS_HELPER_H +#define FOUNDATION_APPEXECFWK_OHOS_FILEACCESS_HELPER_H + +#include +#include +#include + +#include "file_ext_connection.h" +#include "foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime/context/context.h" +#include "ifile_ext_base.h" +#include "uri.h" +#include "want.h" + +using Uri = OHOS::Uri; + +namespace OHOS { +namespace AppExecFwk { +using string = std::string; +class FileAccessHelper final : public std::enable_shared_from_this { +public: + ~FileAccessHelper() = default; + + static std::shared_ptr Creator(const std::shared_ptr &context, + const AAFwk::Want &want); + + bool Release(); + + int OpenFile(Uri &uri, const std::string &mode); + int CreateFile(Uri &parentUri, const std::string &displayName, Uri &newFileUri); + int Mkdir(Uri &parentUri, const std::string &displayName, Uri &newDirUri); + int Delete(Uri &selectFileUri); + int Move(Uri &sourceFileUri, Uri &targetParentUri, Uri &newFileUri); + int Rename(Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri); + int CloseFile(int fd, const std::string &uri); +private: + FileAccessHelper(const std::shared_ptr &context, const AAFwk::Want &want, + const sptr &fileExtProxy); + void AddFileAccessDeathRecipient(const sptr &token); + void OnSchedulerDied(const wptr &remote); + + sptr token_ = {}; + AAFwk::Want want_ = {}; + sptr fileExtProxy_ = nullptr; + bool isSystemCaller_ = false; + sptr callerDeathRecipient_ = nullptr; + sptr fileExtConnection_ = nullptr; +}; + +class FileAccessDeathRecipient : public IRemoteObject::DeathRecipient { +public: + using RemoteDiedHandler = std::function &)>; + + explicit FileAccessDeathRecipient(RemoteDiedHandler handler); + + virtual ~FileAccessDeathRecipient(); + + virtual void OnRemoteDied(const wptr &remote); + +private: + RemoteDiedHandler handler_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // FOUNDATION_APPEXECFWK_OHOS_FILEACCESS_HELPER_H diff --git a/frameworks/innerkits/file_extension/include/file_ext_ability.h b/frameworks/innerkits/file_extension/include/file_ext_ability.h new file mode 100644 index 0000000000000000000000000000000000000000..8c9aaa706a41ca4b80f726a0629a6292aab89e90 --- /dev/null +++ b/frameworks/innerkits/file_extension/include/file_ext_ability.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_ABILITYRUNTIME_OHOS_FILE_EXT_ABILITY_H +#define FOUNDATION_ABILITYRUNTIME_OHOS_FILE_EXT_ABILITY_H + +#include "extension_base.h" + +namespace OHOS { +namespace AbilityRuntime { +class Runtime; +class FileExtAbility; +using CreatorFunc = std::function& runtime)>; +class FileExtAbility : public ExtensionBase<> { +public: + FileExtAbility() = default; + virtual ~FileExtAbility() = default; + + virtual void Init(const std::shared_ptr &record, + const std::shared_ptr &application, + std::shared_ptr &handler, + const sptr &token) override; + + static FileExtAbility* Create(const std::unique_ptr& runtime); + + virtual int OpenFile(const Uri &uri, const std::string &mode); + virtual int CloseFile(int fd, const std::string &uri); + virtual int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri); + virtual int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri); + virtual int Delete(const Uri &sourceFileUri); + virtual int Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri); + virtual int Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri); + + /** + * @brief Set a creator function. + * + * @param creator The function for create a file extension ability. + */ + static void SetCreator(const CreatorFunc& creator); +private: + static CreatorFunc creator_; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // FOUNDATION_ABILITYRUNTIME_OHOS_FILE_EXT_ABILITY_H \ No newline at end of file diff --git a/services/src/server/file_manager_service.h b/frameworks/innerkits/file_extension/include/file_ext_ability_module_loader.h similarity index 43% rename from services/src/server/file_manager_service.h rename to frameworks/innerkits/file_extension/include/file_ext_ability_module_loader.h index 3410c40973e31563e488848469326085990e6c2e..81cd27ac4f48e148d482ffcca56e3022f05b31f6 100644 --- a/services/src/server/file_manager_service.h +++ b/frameworks/innerkits/file_extension/include/file_ext_ability_module_loader.h @@ -1,36 +1,36 @@ -/* - * Copyright (C) 2021 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 STORAGE_FILE_MANAGER_SERVICE_H -#define STORAGE_FILE_MANAGER_SERVICE_H - -#include "file_manager_service_stub.h" -#include "iremote_stub.h" -#include "system_ability.h" - -namespace OHOS { -namespace FileManagerService { -class FileManagerService : public SystemAbility, public FileManagerServiceStub { - DECLARE_SYSTEM_ABILITY(FileManagerService); -public: - DISALLOW_COPY_AND_MOVE(FileManagerService); - explicit FileManagerService(int32_t systemAbilityId, bool runOnCreate = true); - virtual ~FileManagerService() = default; - void OnDump() override; - void OnStart() override; - void OnStop() override; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_FILE_MANAGER_SERVICE_H \ No newline at end of file +/* + * Copyright (c) 2022 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 FOUNDATION_ABILITYRUTIME_FILE_EXT_ABILITY_MODULE_LOADER_H +#define FOUNDATION_ABILITYRUTIME_FILE_EXT_ABILITY_MODULE_LOADER_H + +#include "extension_module_loader.h" + +namespace OHOS::AbilityRuntime { +class FileExtAbilityModuleLoader : public ExtensionModuleLoader, + public Singleton { + DECLARE_SINGLETON(FileExtAbilityModuleLoader); + +public: + /** + * @brief Create Extension. + * + * @param runtime The runtime. + * @return The Extension instance. + */ + virtual Extension *Create(const std::unique_ptr& runtime) const override; +}; +} +#endif // FOUNDATION_ABILITYRUTIME_FILE_EXT_ABILITY_MODULE_LOADER_H \ No newline at end of file diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.h b/frameworks/innerkits/file_extension/include/file_ext_connection.h similarity index 33% rename from services/src/fileoper/ext_storage/ext_storage_subscriber.h rename to frameworks/innerkits/file_extension/include/file_ext_connection.h index 18a34b779970bb9b509c5aa06372bfea2e18ed16..292a913037ec124a9728725bc6c6301847868d88 100644 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.h +++ b/frameworks/innerkits/file_extension/include/file_ext_connection.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -12,42 +12,50 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef STORAGE_FILE_SYS_EVENT_RECEIVER_H -#define STORAGE_FILE_SYS_EVENT_RECEIVER_H -#include -#include +#ifndef FOUNDATION_APPEXECFWK_OHOS_FILEEXT_CONNECTION_H +#define FOUNDATION_APPEXECFWK_OHOS_FILEEXT_CONNECTION_H -#include "common_event_manager.h" -#include "common_event_subscribe_info.h" -#include "common_event_subscriber.h" -#include "common_event_support.h" -#include "ext_storage_status.h" -#include "matching_skills.h" +#include + +#include "ability_connect_callback_stub.h" +#include "event_handler.h" +#include "ifile_ext_base.h" +#include "want.h" namespace OHOS { -namespace FileManagerService { -/** - * @class ExtStorageSubscriber - * Receive system common event. - */ -class ExtStorageSubscriber : public EventFwk::CommonEventSubscriber { +namespace AppExecFwk { +class FileExtConnection : public AAFwk::AbilityConnectionStub { public: - ExtStorageSubscriber() = default; - explicit ExtStorageSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo); - static bool Subscriber(void); - virtual ~ExtStorageSubscriber() = default; - /** - * @brief System common event receiver. - * @param eventData Common event data. - */ - virtual void OnReceiveEvent(const EventFwk::CommonEventData &eventData) override; - - bool CheckMountPoint(const std::string &path); - - std::unordered_map mountStatus; + FileExtConnection() = default; + virtual ~FileExtConnection() = default; + + + static sptr GetInstance(); + + void OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) override; + + void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; + + + void ConnectFileExtAbility(const AAFwk::Want &want, const sptr &token); + + + void DisconnectFileExtAbility(); + + + bool IsExtAbilityConnected(); + + + sptr GetFileExtProxy(); + +private: + static sptr instance_; + static std::mutex mutex_; + std::atomic isConnected_ = {false}; + sptr fileExtProxy_; }; -} // namespace FileManagerService +} // namespace AppExecFwk } // namespace OHOS - -#endif // STORAGE_FILE_SYS_EVENT_RECEIVER_H \ No newline at end of file +#endif // FOUNDATION_APPEXECFWK_OHOS_DATASHARE_CONNECTION_H diff --git a/services/src/fileoper/media_file_oper.h b/frameworks/innerkits/file_extension/include/file_ext_proxy.h similarity index 34% rename from services/src/fileoper/media_file_oper.h rename to frameworks/innerkits/file_extension/include/file_ext_proxy.h index bc4374b212fd9a7909a7bd1d2b5ab2e2c660b98d..1a3d2126d05d641d300f5e5298f7c6cb7d451390 100644 --- a/services/src/fileoper/media_file_oper.h +++ b/frameworks/innerkits/file_extension/include/file_ext_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -12,24 +12,32 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef STORAGE_SERVICES_MEDIA_FILE_OPER_H -#define STORAGE_SERVICES_MEDIA_FILE_OPER_H -#include -#include "file_oper.h" +#ifndef OHOS_APPEXECFWK_FILEEXT_PROXY_H +#define OHOS_APPEXECFWK_FILEEXT_PROXY_H + +#include +#include "ifile_ext_base.h" + namespace OHOS { -namespace FileManagerService { -class MediaFileOper : public FileOper { +namespace AppExecFwk { +class FileExtProxy : public IRemoteProxy { public: - MediaFileOper() = default; - virtual ~MediaFileOper() = default; - int OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) const override; + explicit FileExtProxy(const sptr& remote) : IRemoteProxy(remote) {} + + virtual ~FileExtProxy() {} + + virtual int OpenFile(const Uri &uri, const std::string &mode) override; + virtual int CloseFile(int fd, const std::string &uri) override; + virtual int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; + virtual int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; + virtual int Delete(const Uri &sourceFileUri) override; + virtual int Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) override; + virtual int Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) override; private: - int CreateFile(const std::string &name, const std::string &path, MessageParcel &reply) const; - int ListFile(const std::string &type, const std::string &path, int offset, int count, MessageParcel &data) const; - int GetRoot(const std::string &name, const std::string &path, MessageParcel &reply) const; - int Mkdir(const std::string &name, const std::string &path) const; + static inline BrokerDelegator delegator_; }; -} // namespace FileManagerService +} // namespace AppExecFwk } // namespace OHOS -#endif // STORAGE_SERVICES_MEDIA_FILE_OPER_H \ No newline at end of file +#endif // OHOS_APPEXECFWK_DATASHARE_PROXY_H + diff --git a/services/src/client/file_manager_proxy.h b/frameworks/innerkits/file_extension/include/file_ext_stub.h similarity index 35% rename from services/src/client/file_manager_proxy.h rename to frameworks/innerkits/file_extension/include/file_ext_stub.h index 494648ed26703f008083ec301e84e68a30329f74..356e4cff8b702458f45d193f74db3c42df04fbd9 100644 --- a/services/src/client/file_manager_proxy.h +++ b/frameworks/innerkits/file_extension/include/file_ext_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -12,30 +12,34 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef STORAGE_FILE_MANAGER_PROXY_H -#define STORAGE_FILE_MANAGER_PROXY_H -#include "file_manager_service_stub.h" -#include "ifms_client.h" -#include "iremote_proxy.h" -#include "iservice_registry.h" -#include "system_ability_definition.h" +#ifndef OHOS_APPEXECFWK_FILEEXT_STUB_H +#define OHOS_APPEXECFWK_FILEEXT_STUB_H + +#include +#include + +#include "ifile_ext_base.h" namespace OHOS { -namespace FileManagerService { -class FileManagerProxy : public IRemoteProxy, public IFmsClient { +namespace AppExecFwk { +class FileExtStub : public IRemoteStub { public: - explicit FileManagerProxy(const sptr &impl); - virtual ~FileManagerProxy() = default; - int Mkdir(const std::string &name, const std::string &path) override; - int ListFile(const std::string &type, const std::string &path, const CmdOptions &option, - std::vector> &fileRes) override; - int CreateFile(const std::string &path, const std::string &fileName, - const CmdOptions &option, std::string &uri) override; - int GetRoot(const CmdOptions &option, std::vector> &fileRes) override; + FileExtStub(); + ~FileExtStub(); + int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; private: - static inline BrokerDelegator delegator_; + ErrCode CmdOpenFile(MessageParcel &data, MessageParcel &reply); + ErrCode CmdCloseFile(MessageParcel &data, MessageParcel &reply); + ErrCode CmdCreateFile(MessageParcel &data, MessageParcel &reply); + ErrCode CmdMkdir(MessageParcel &data, MessageParcel &reply); + ErrCode CmdDelete(MessageParcel &data, MessageParcel &reply); + ErrCode CmdMove(MessageParcel &data, MessageParcel &reply); + ErrCode CmdRename(MessageParcel &data, MessageParcel &reply); + using RequestFuncType = int (FileExtStub::*)(MessageParcel &data, MessageParcel &reply); + std::map stubFuncMap_; }; -} // namespace FileManagerService +} // namespace AppExecFwk } // namespace OHOS -#endif // STORAGE_FILE_MANAGER_PROXY_H \ No newline at end of file +#endif // OHOS_APPEXECFWK_FILEEXT_STUB_H + diff --git a/services/src/fileoper/external_storage_utils.h b/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h similarity index 33% rename from services/src/fileoper/external_storage_utils.h rename to frameworks/innerkits/file_extension/include/file_ext_stub_impl.h index a975ba179ed3c28989364afe8ce732ccc086b831..9f964953dd0fbff0b3c4cc4d50bb38fccd7ef609 100644 --- a/services/src/fileoper/external_storage_utils.h +++ b/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -12,29 +12,39 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef STORAGE_SERIVCES_EXTERNAL_STORAGE_UTILS_H -#define STORAGE_SERIVCES_EXTERNAL_STORAGE_UTILS_H -#include -#include -#include +#ifndef OHOS_APPEXECFWK_FILEEXT_STUB_IMPL_H +#define OHOS_APPEXECFWK_FILEEXT_STUB_IMPL_H -#include "cmd_options.h" -#include "file_info.h" -#include "file_oper.h" +#include +#include "file_ext_stub.h" +#include "js_file_ext_ability.h" +#include "native_engine/native_value.h" namespace OHOS { -namespace FileManagerService { -class ExternalStorageUtils { +namespace AppExecFwk { +using AbilityRuntime::JsFileExtAbility; +class FileExtStubImpl : public FileExtStub { public: - ExternalStorageUtils(); - ~ExternalStorageUtils(); - static int DoListFile(const std::string &type, const std::string &uri, const CmdOptions &option, - std::vector> &fileList); - static int DoCreateFile(const std::string &uri, const std::string &name, std::string &resultUri); - static int DoGetRoot(const std::string &name, const std::string &path, - std::vector> &fileList); + explicit FileExtStubImpl(const std::shared_ptr& extension, napi_env env) + : extension_(extension) {} + + virtual ~FileExtStubImpl() {} + + int OpenFile(const Uri &uri, const std::string &mode) override; + int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; + int CloseFile(int fd, const std::string &uri) override; + int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; + int Delete(const Uri &sourceFileUri) override; + int Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) override; + int Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) override; +private: + std::shared_ptr GetOwner(); + +private: + std::shared_ptr extension_; }; -} // namespace FileManagerService +} // namespace AppExecFwk } // namespace OHOS -#endif // STORAGE_SERIVCES_EXTERNAL_STORAGE_UTILS_H \ No newline at end of file +#endif // OHOS_APPEXECFWK_FILEEXT_STUB_IMPL_H + diff --git a/frameworks/innerkits/file_extension/include/ifile_ext_base.h b/frameworks/innerkits/file_extension/include/ifile_ext_base.h new file mode 100644 index 0000000000000000000000000000000000000000..ad7399cf34d738d906162275e77f920a72b9a921 --- /dev/null +++ b/frameworks/innerkits/file_extension/include/ifile_ext_base.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2022 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 OHOS_APPEXECFWK_I_FILEEXTBASE_H +#define OHOS_APPEXECFWK_I_FILEEXTBASE_H + +#include +#include +#include +#include "uri.h" + +namespace OHOS { +namespace AppExecFwk { +struct FileInfo +{ + Uri uri; + std::string fileName; + std::string mode; + size_t size; + int64_t mtime; + std::string mimiType; + std::bitset<32> flags; +}; + +struct DeviceInfo +{ + Uri uri; + std::string displayname; + std::string deviceId; + std::bitset<32> flags; +}; + +const std::string ATTRIBUTE_COLUMN_SUMMARY = "summary"; +const std::string ATTRIBUTE_COLUMN_LAST_MODIFIED = "last_modified"; +const std::string ATTRIBUTE_COLUMN_ICON = "icon"; +const std::string ATTRIBUTE_COLUMN_FLAGS = "flags"; +const std::string ATTRIBUTE_COLUMN_SIZE = "size"; + +const std::bitset<32> FLAG_SUPPORTS_THUMBNAIL = 1; +const std::bitset<32> FLAG_SUPPORTS_WRITE = 1 << 1; +const std::bitset<32> FLAG_SUPPORTS_DELETE = 1 << 2; +const std::bitset<32> FLAG_DIR_SUPPORTS_CREATE = 1 << 3; +const std::bitset<32> FLAG_DIR_PREFERS_LAST_MODIFIED = 1 << 4; +const std::bitset<32> FLAG_SUPPORTS_RENAME = 1 << 5; +const std::bitset<32> FLAG_SUPPORTS_COPY = 1 << 6; +const std::bitset<32> FLAG_SUPPORTS_MOVE = 1 << 7; +const std::bitset<32> FLAG_SUPPORTS_REMOVE = 1 << 8; + +class IFileExtBase : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.AppExecFwk.IFileExtBase"); + + enum { + CMD_OPEN_FILE = 1, + CMD_CLOSE_FILE = 2, + CMD_CREATE_FILE = 3, + CMD_MKDIR = 4, + CMD_DELETE = 5, + CMD_MOVE = 6, + CMD_RENAME = 7 + }; + + virtual int OpenFile(const Uri &uri, const std::string &mode) = 0; + virtual int CloseFile(int fd, const std::string &uri) = 0; + virtual int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) = 0; + virtual int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) = 0; + virtual int Delete(const Uri &sourceFileUri) = 0; + virtual int Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) = 0; + virtual int Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) = 0; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_APPEXECFWK_I_FILEEXTBASE_H diff --git a/frameworks/innerkits/file_extension/include/js_file_ext_ability.h b/frameworks/innerkits/file_extension/include/js_file_ext_ability.h new file mode 100644 index 0000000000000000000000000000000000000000..ae17d3e46f25357d16588324f190bd997e4d98c6 --- /dev/null +++ b/frameworks/innerkits/file_extension/include/js_file_ext_ability.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 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 FOUNDATION_ABILITYRUNTIME_OHOS_JS_FILE_EXT_ABILITY_H +#define FOUNDATION_ABILITYRUNTIME_OHOS_JS_FILE_EXT_ABILITY_H + +#include "file_ext_ability.h" + +#include "js_runtime.h" +#include "native_engine/native_reference.h" +#include "native_engine/native_value.h" + +namespace OHOS { +namespace AbilityRuntime { + +class JsFileExtAbility : public FileExtAbility { +public: + JsFileExtAbility(JsRuntime& jsRuntime); + virtual ~JsFileExtAbility() override; + + static JsFileExtAbility* Create(const std::unique_ptr& runtime); + + void Init(const std::shared_ptr &record, + const std::shared_ptr &application, + std::shared_ptr &handler, + const sptr &token) override; + + + void OnStart(const AAFwk::Want &want) override; + + sptr OnConnect(const AAFwk::Want &want) override; + + int OpenFile(const Uri &uri, const std::string &mode) override; + int CloseFile(int fd, const std::string &uri) override; + int CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; + int Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) override; + int Delete(const Uri &sourceFileUri) override; + int Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) override; + int Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) override; + +private: + NativeValue* CallObjectMethod(const char* name, NativeValue* const* argv = nullptr, size_t argc = 0); + void GetSrcPath(std::string &srcPath); + + JsRuntime& jsRuntime_; + std::unique_ptr jsObj_; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // FOUNDATION_ABILITYRUNTIME_OHOS_JS_DATASHARE_EXT_ABILITY_H \ No newline at end of file diff --git a/frameworks/innerkits/file_extension/src/file_access_helper.cpp b/frameworks/innerkits/file_extension/src/file_access_helper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6a62e048edb8bdd955cc13fa4cca487d62ec9ead --- /dev/null +++ b/frameworks/innerkits/file_extension/src/file_access_helper.cpp @@ -0,0 +1,317 @@ +/* + * Copyright (c) 2022 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. + */ + +#include "file_access_helper.h" + +#include "hilog_wrapper.h" +#include "ifile_ext_base.h" + +namespace OHOS { +namespace AppExecFwk { +namespace { +constexpr int INVALID_VALUE = -1; +} // namespace + + +FileAccessHelper::FileAccessHelper(const std::shared_ptr &context, + const AAFwk::Want &want, const sptr &fileExtProxy) +{ + HILOG_INFO("tag dsa FileAccessHelper::FileAccessHelper start"); + token_ = context->GetToken(); + want_ = want; + fileExtProxy_ = fileExtProxy; + fileExtConnection_ = FileExtConnection::GetInstance(); + HILOG_INFO("tag dsa FileAccessHelper::FileAccessHelper end"); +} + +void FileAccessHelper::AddFileAccessDeathRecipient(const sptr &token) +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + if (token != nullptr && callerDeathRecipient_ != nullptr) { + HILOG_INFO("tag dsa token RemoveDeathRecipient."); + token->RemoveDeathRecipient(callerDeathRecipient_); + } + if (callerDeathRecipient_ == nullptr) { + callerDeathRecipient_ = + new FileAccessDeathRecipient(std::bind(&FileAccessHelper::OnSchedulerDied, this, std::placeholders::_1)); + } + if (token != nullptr) { + HILOG_INFO("tag dsa token AddDeathRecipient."); + token->AddDeathRecipient(callerDeathRecipient_); + } + HILOG_INFO("tag dsa %{public}s called end", __func__); +} + +void FileAccessHelper::OnSchedulerDied(const wptr &remote) +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + auto object = remote.promote(); + object = nullptr; + fileExtProxy_ = nullptr; + HILOG_INFO("tag dsa %{public}s called end", __func__); +} + +std::shared_ptr FileAccessHelper::Creator( + const std::shared_ptr &context, const AAFwk::Want &want) +{ + HILOG_INFO("tag dsa FileAccessHelper::Creator with runtime context, want and uri called start."); + if (context == nullptr) { + HILOG_ERROR("tag dsa ileAccessHelper::Creator failed, context == nullptr"); + return nullptr; + } + + HILOG_INFO("tag dsa FileAccessHelper::Creator before ConnectFileExtAbility."); + sptr fileExtProxy = nullptr; + + sptr fileExtConnection = FileExtConnection::GetInstance(); + if (!fileExtConnection->IsExtAbilityConnected()) { + fileExtConnection->ConnectFileExtAbility(want, context->GetToken()); + } + fileExtProxy = fileExtConnection->GetFileExtProxy(); + if (fileExtProxy == nullptr) { + HILOG_WARN("tag dsa FileAccessHelper::Creator get invalid fileExtProxy"); + } + HILOG_INFO("tag dsa FileAccessHelper::Creator after ConnectFileExtAbility."); + + FileAccessHelper *ptrDataShareHelper = new (std::nothrow) FileAccessHelper(context, want, fileExtProxy); + if (ptrDataShareHelper == nullptr) { + HILOG_ERROR("tag dsa FileAccessHelper::Creator failed, create FileAccessHelper failed"); + return nullptr; + } + + HILOG_INFO("tag dsa FileAccessHelper::Creator with runtime context, want and uri called end."); + return std::shared_ptr(ptrDataShareHelper); +} + +bool FileAccessHelper::Release() +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + + HILOG_INFO("tag dsa FileAccessHelper::Release before DisconnectFileExtAbility."); + if (fileExtConnection_->IsExtAbilityConnected()) { + fileExtConnection_->DisconnectFileExtAbility(); + } + HILOG_INFO("tag dsa FileAccessHelper::Release after DisconnectFileExtAbility."); + fileExtProxy_ = nullptr; + HILOG_INFO("tag dsa %{public}s called end", __func__); + return true; +} + +int FileAccessHelper::OpenFile(Uri &uri, const std::string &mode) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int fd = INVALID_VALUE; + + HILOG_INFO("tag dsa FileAccessHelper::OpenFile before ConnectFileExtAbility."); + if (!fileExtConnection_->IsExtAbilityConnected()) { + fileExtConnection_->ConnectFileExtAbility(want_, token_); + } + fileExtProxy_ = fileExtConnection_->GetFileExtProxy(); + HILOG_INFO("tag dsa FileAccessHelper::OpenFile after ConnectFileExtAbility."); + if (isSystemCaller_ && fileExtProxy_) { + AddFileAccessDeathRecipient(fileExtProxy_->AsObject()); + } + + if (fileExtProxy_ == nullptr) { + HILOG_ERROR("tag dsa %{public}s failed with invalid fileExtProxy_", __func__); + return fd; + } + + HILOG_INFO("tag dsa FileAccessHelper::OpenFile before fileExtProxy_->OpenFile."); + fd = fileExtProxy_->OpenFile(uri, mode); + HILOG_INFO("tag dsa %{public}s begin.", __func__); + return fd; +} + +int FileAccessHelper::CreateFile(Uri &parentUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa FileAccessHelper::CreateFile start."); + int index = INVALID_VALUE; + + HILOG_INFO("tag dsa FileAccessHelper::CreateFile before ConnectDataShareExtAbility."); + if (!fileExtConnection_->IsExtAbilityConnected()) { + fileExtConnection_->ConnectFileExtAbility(want_, token_); + } + fileExtProxy_ = fileExtConnection_->GetFileExtProxy(); + HILOG_INFO("tag dsa FileAccessHelper::CreateFile after ConnectDataShareExtAbility."); + if (isSystemCaller_ && fileExtProxy_) { + AddFileAccessDeathRecipient(fileExtProxy_->AsObject()); + } + + if (fileExtProxy_ == nullptr) { + HILOG_ERROR("tag dsa %{public}s failed with invalid fileExtProxy_", __func__); + return index; + } + + HILOG_INFO("tag dsa FileAccessHelper::CreateFile before fileExtProxy_->CreateFile."); + index = fileExtProxy_->CreateFile(parentUri, displayName, newFileUri); + HILOG_INFO("tag dsa FileAccessHelper::CreateFile end. index = %{public}d", index); + HILOG_INFO("tag dsa FileAccessHelper::CreateFile end. newDirUri = %{public}s", newFileUri.ToString().c_str()); + return index; +} + +int FileAccessHelper::Mkdir(Uri &parentUri, const std::string &displayName, Uri &newDirUri) +{ + HILOG_INFO("tag dsa FileAccessHelper::Mkdir start."); + int index = INVALID_VALUE; + + HILOG_INFO("tag dsa FileAccessHelper::Mkdir before ConnectDataShareExtAbility."); + if (!fileExtConnection_->IsExtAbilityConnected()) { + fileExtConnection_->ConnectFileExtAbility(want_, token_); + } + fileExtProxy_ = fileExtConnection_->GetFileExtProxy(); + HILOG_INFO("tag dsa FileAccessHelper::Mkdir after ConnectDataShareExtAbility."); + if (isSystemCaller_ && fileExtProxy_) { + AddFileAccessDeathRecipient(fileExtProxy_->AsObject()); + } + + if (fileExtProxy_ == nullptr) { + HILOG_ERROR("tag dsa %{public}s failed with invalid fileExtProxy_", __func__); + return index; + } + + HILOG_INFO("tag dsa FileAccessHelper::Mkdir before fileExtProxy_->Mkdir."); + index = fileExtProxy_->Mkdir(parentUri, displayName, newDirUri); + HILOG_INFO("tag dsa FileAccessHelper::Mkdir end. index = %{public}d", index); + HILOG_INFO("tag dsa FileAccessHelper::Mkdir end. newDirUri = %{public}s", newDirUri.ToString().c_str()); + return index; +} + +int FileAccessHelper::Delete(Uri &selectFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int index = INVALID_VALUE; + + HILOG_INFO("tag dsa FileAccessHelper::Delete before ConnectFileExtAbility."); + if (!fileExtConnection_->IsExtAbilityConnected()) { + fileExtConnection_->ConnectFileExtAbility(want_, token_); + } + fileExtProxy_ = fileExtConnection_->GetFileExtProxy(); + HILOG_INFO("tag dsa FileAccessHelper::Delete after ConnectFileExtAbility."); + if (isSystemCaller_ && fileExtProxy_) { + AddFileAccessDeathRecipient(fileExtProxy_->AsObject()); + } + + if (fileExtProxy_ == nullptr) { + HILOG_ERROR("tag dsa %{public}s failed with invalid fileExtProxy_", __func__); + return index; + } + + HILOG_INFO("tag dsa FileAccessHelper::Delete before fileExtProxy_->Delete."); + index = fileExtProxy_->Delete(selectFileUri); + HILOG_INFO("tag dsa %{public}s begin.", __func__); + return index; +} + +int FileAccessHelper::Move(Uri &sourceFileUri, Uri &targetParentUri, Uri &newFileUri) +{ + HILOG_INFO("tag dsa FileAccessHelper::Move start."); + int index = INVALID_VALUE; + + HILOG_INFO("tag dsa FileAccessHelper::Move before ConnectDataShareExtAbility."); + if (!fileExtConnection_->IsExtAbilityConnected()) { + fileExtConnection_->ConnectFileExtAbility(want_, token_); + } + fileExtProxy_ = fileExtConnection_->GetFileExtProxy(); + HILOG_INFO("tag dsa FileAccessHelper::Move after ConnectDataShareExtAbility."); + if (isSystemCaller_ && fileExtProxy_) { + AddFileAccessDeathRecipient(fileExtProxy_->AsObject()); + } + + if (fileExtProxy_ == nullptr) { + HILOG_ERROR("tag dsa %{public}s failed with invalid fileExtProxy_", __func__); + return index; + } + + HILOG_INFO("tag dsa FileAccessHelper::Move before fileExtProxy_->Move."); + index = fileExtProxy_->Move(sourceFileUri, targetParentUri, newFileUri); + HILOG_INFO("tag dsa FileAccessHelper::Move end. index = %{public}d", index); + HILOG_INFO("tag dsa FileAccessHelper::Move end. newFileUri = %{public}s", newFileUri.ToString().c_str()); + return index; +} + +int FileAccessHelper::Rename(Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa FileAccessHelper::Rename start."); + int index = INVALID_VALUE; + + HILOG_INFO("tag dsa FileAccessHelper::Rename before ConnectDataShareExtAbility."); + if (!fileExtConnection_->IsExtAbilityConnected()) { + fileExtConnection_->ConnectFileExtAbility(want_, token_); + } + fileExtProxy_ = fileExtConnection_->GetFileExtProxy(); + HILOG_INFO("tag dsa FileAccessHelper::Rename after ConnectDataShareExtAbility."); + if (isSystemCaller_ && fileExtProxy_) { + AddFileAccessDeathRecipient(fileExtProxy_->AsObject()); + } + + if (fileExtProxy_ == nullptr) { + HILOG_ERROR("tag dsa %{public}s failed with invalid fileExtProxy_", __func__); + return index; + } + + HILOG_INFO("tag dsa FileAccessHelper::Rename before fileExtProxy_->Rename."); + index = fileExtProxy_->Rename(sourceFileUri, displayName, newFileUri); + HILOG_INFO("tag dsa FileAccessHelper::Rename end. index = %{public}d", index); + HILOG_INFO("tag dsa FileAccessHelper::Rename end. newFileUri = %{public}s", newFileUri.ToString().c_str()); + return index; +} + +int FileAccessHelper::CloseFile(int fd, const std::string &uri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int index = INVALID_VALUE; + + HILOG_INFO("tag dsa FileAccessHelper::CloseFile before ConnectFileExtAbility."); + if (!fileExtConnection_->IsExtAbilityConnected()) { + fileExtConnection_->ConnectFileExtAbility(want_, token_); + } + fileExtProxy_ = fileExtConnection_->GetFileExtProxy(); + HILOG_INFO("tag dsa FileAccessHelper::CloseFile after ConnectFileExtAbility."); + if (isSystemCaller_ && fileExtProxy_) { + AddFileAccessDeathRecipient(fileExtProxy_->AsObject()); + } + + if (fileExtProxy_ == nullptr) { + HILOG_ERROR("tag dsa %{public}s failed with invalid fileExtProxy_", __func__); + return index; + } + + HILOG_INFO("tag dsa FileAccessHelper::CloseFile before fileExtProxy_->CloseFile."); + index = fileExtProxy_->CloseFile(fd, uri); + HILOG_INFO("tag dsa %{public}s begin.", __func__); + return index; +} + +void FileAccessDeathRecipient::OnRemoteDied(const wptr &remote) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + if (handler_) { + handler_(remote); + } + HILOG_INFO("tag dsa %{public}s begin.", __func__); +} + +FileAccessDeathRecipient::FileAccessDeathRecipient(RemoteDiedHandler handler) : handler_(handler) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); +} + +FileAccessDeathRecipient::~FileAccessDeathRecipient() +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkits/file_extension/src/file_ext_ability.cpp b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0610ef521921e6a7a7fe8645f978f2729eab9e4c --- /dev/null +++ b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2022 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. + */ + +#include "file_ext_ability.h" + +#include "ability_loader.h" +#include "connection_manager.h" +#include "extension_context.h" +#include "hilog_wrapper.h" +#include "js_file_ext_ability.h" +#include "runtime.h" + +namespace OHOS { +namespace AbilityRuntime { +using namespace OHOS::AppExecFwk; + +CreatorFunc FileExtAbility::creator_ = nullptr; +void FileExtAbility::SetCreator(const CreatorFunc& creator) +{ + creator_ = creator; +} +FileExtAbility* FileExtAbility::Create(const std::unique_ptr& runtime) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + if (!runtime) { + return new FileExtAbility(); + } + if (creator_) { + return creator_(runtime); + } + HILOG_INFO("tag dsa FileExtAbility::Create runtime"); + switch (runtime->GetLanguage()) { + case Runtime::Language::JS: + HILOG_INFO("tag dsa Runtime::Language::JS --> JsFileExtAbility"); + return JsFileExtAbility::Create(runtime); + + default: + HILOG_INFO("tag dsa default --> FileExtAbility"); + return new FileExtAbility(); + } + HILOG_INFO("tag dsa %{public}s begin.", __func__); +} + +void FileExtAbility::Init(const std::shared_ptr &record, + const std::shared_ptr &application, + std::shared_ptr &handler, + const sptr &token) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + ExtensionBase<>::Init(record, application, handler, token); + HILOG_INFO("tag dsa %{public}s end.", __func__); +} + +int FileExtAbility::OpenFile(const Uri &uri, const std::string &mode) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HILOG_INFO("tag dsa %{public}s end.", __func__); + return 0; +} + +int FileExtAbility::CloseFile(int fd, const std::string &uri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HILOG_INFO("tag dsa %{public}s end.", __func__); + return 0; +} + +int FileExtAbility::CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HILOG_INFO("tag dsa %{public}s end.", __func__); + return 0; +} + +int FileExtAbility::Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HILOG_INFO("tag dsa %{public}s end.", __func__); + return 0; +} + +int FileExtAbility::Delete(const Uri &sourceFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HILOG_INFO("tag dsa %{public}s end.", __func__); + return 0; +} + +int FileExtAbility::Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HILOG_INFO("tag dsa %{public}s end.", __func__); + return 0; +} + +int FileExtAbility::Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HILOG_INFO("tag dsa %{public}s end.", __func__); + return 0; +} + +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/services/src/server/file_manager_service.cpp b/frameworks/innerkits/file_extension/src/file_ext_ability_module_loader.cpp similarity index 38% rename from services/src/server/file_manager_service.cpp rename to frameworks/innerkits/file_extension/src/file_ext_ability_module_loader.cpp index f1471a258eb289e954b2bb2a84232d22fa129583..99be25075ca51e311a434a12564ef504cc8326f4 100644 --- a/services/src/server/file_manager_service.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_ability_module_loader.cpp @@ -1,46 +1,39 @@ -/* - * Copyright (C) 2021 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. - */ - -#include "file_manager_service.h" - -#include "iservice_registry.h" -#include "log.h" -#include "system_ability_definition.h" -#include "ext_storage/ext_storage_subscriber.h" - -namespace OHOS { -namespace FileManagerService { -REGISTER_SYSTEM_ABILITY_BY_ID(FileManagerService, FILE_MANAGER_SERVICE_ID, true); - -FileManagerService::FileManagerService(int32_t systemAbilityId, bool runOnCreate) - : SystemAbility(systemAbilityId, runOnCreate) {} -void FileManagerService::OnDump() {} - -void FileManagerService::OnStart() -{ - DEBUG_LOG("FileManagerService OnStart"); - ExtStorageSubscriber::Subscriber(); - bool res = Publish(this); - if (!res) { - ERR_LOG("FileManagerService OnStart invalid"); - } -} - -void FileManagerService::OnStop() -{ - DEBUG_LOG("FileManagerService OnStop"); -} -} // namespace FileManagerService -} // namespace OHOS \ No newline at end of file +/* + * Copyright (c) 2022 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. + */ + +#include "file_ext_ability_module_loader.h" +#include "file_ext_ability.h" + +namespace OHOS::AbilityRuntime { +FileExtAbilityModuleLoader::FileExtAbilityModuleLoader() = default; +FileExtAbilityModuleLoader::~FileExtAbilityModuleLoader() = default; + +Extension *FileExtAbilityModuleLoader::Create(const std::unique_ptr& runtime) const +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + return FileExtAbility::Create(runtime); +} + +extern "C" __attribute__((visibility("default"))) void* OHOS_EXTENSION_GetExtensionModule() +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + return &FileExtAbilityModuleLoader::GetInstance(); +} + +extern "C" __attribute__((visibility("default"))) void SetCreator(const CreatorFunc& creator) +{ + return FileExtAbility::SetCreator(creator); +} +} // namespace OHOS::AbilityRuntime \ No newline at end of file diff --git a/frameworks/innerkits/file_extension/src/file_ext_connection.cpp b/frameworks/innerkits/file_extension/src/file_ext_connection.cpp new file mode 100644 index 0000000000000000000000000000000000000000..088932339a54aa73329b04489f35c60eba8438d9 --- /dev/null +++ b/frameworks/innerkits/file_extension/src/file_ext_connection.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2022 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. + */ + +#include "file_ext_connection.h" + +#include "ability_manager_client.h" +#include "bytrace.h" +#include "file_ext_proxy.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AppExecFwk { +sptr FileExtConnection::instance_ = nullptr; +std::mutex FileExtConnection::mutex_; + +sptr FileExtConnection::GetInstance() +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + if (instance_ == nullptr) { + std::lock_guard lock(mutex_); + if (instance_ == nullptr) { + instance_ = sptr(new (std::nothrow) FileExtConnection()); + } + } + HILOG_INFO("tag dsa %{public}s end.", __func__); + return instance_; +} + +void FileExtConnection::OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + BYTRACE_NAME(BYTRACE_TAG_DISTRIBUTEDDATA, __PRETTY_FUNCTION__); + if (remoteObject == nullptr) { + HILOG_ERROR("tag dsa FileExtConnection::OnAbilityConnectDone failed, remote is nullptr"); + return; + } + fileExtProxy_ = iface_cast(remoteObject); + if (fileExtProxy_ == nullptr) { + HILOG_ERROR("tag dsa FileExtConnection::OnAbilityConnectDone failed, fileExtProxy_ is nullptr"); + return; + } + isConnected_.store(true); + HILOG_INFO("tag dsa %{public}s end.", __func__); +} + +void FileExtConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + BYTRACE_NAME(BYTRACE_TAG_DISTRIBUTEDDATA, __PRETTY_FUNCTION__); + fileExtProxy_ = nullptr; + isConnected_.store(false); + HILOG_INFO("tag dsa %{public}s called end", __func__); +} + +void FileExtConnection::ConnectFileExtAbility(const AAFwk::Want &want, const sptr &token) +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, this, token); + HILOG_INFO("tag dsa %{public}s called end, ret=%{public}d", __func__, ret); +} + +void FileExtConnection::DisconnectFileExtAbility() +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + fileExtProxy_ = nullptr; + isConnected_.store(false); + ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(this); + HILOG_INFO("tag dsa %{public}s called end, ret=%{public}d", __func__, ret); +} + +bool FileExtConnection::IsExtAbilityConnected() +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + return isConnected_.load(); +} + +sptr FileExtConnection::GetFileExtProxy() +{ + HILOG_INFO("tag dsa %{public}s called begin", __func__); + return fileExtProxy_; +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp b/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..085c7b41e8d73b0c990d0ba7baa06a52727d0bb6 --- /dev/null +++ b/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp @@ -0,0 +1,343 @@ +/* + * Copyright (c) 2022 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. + */ + +#include "file_ext_proxy.h" + +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AppExecFwk { +int FileExtProxy::OpenFile(const Uri &uri, const std::string &mode) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int fd = -1; + MessageParcel data; + if (!data.WriteInterfaceToken(FileExtProxy::GetDescriptor())) { + HILOG_ERROR("tag dsa %{public}s WriteInterfaceToken failed", __func__); + return fd; + } + + if (!data.WriteParcelable(&uri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable uri"); + return fd; + } + + if (!data.WriteString(mode)) { + HILOG_ERROR("tag dsa fail to WriteString mode"); + return fd; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_OPEN_FILE, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("tag dsa OpenFile fail to SendRequest. err: %d", err); + return fd; + } + + fd = reply.ReadFileDescriptor(); + if (fd == -1) { + HILOG_ERROR("tag dsa fail to ReadFileDescriptor fd"); + return fd; + } + + HILOG_INFO("tag dsa %{public}s end successfully, return fd=%{public}d", __func__, fd); + return fd; +} + +int FileExtProxy::CloseFile(int fd, const std::string &uri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + MessageParcel data; + if (!data.WriteInterfaceToken(FileExtProxy::GetDescriptor())) { + HILOG_ERROR("tag dsa %{public}s WriteInterfaceToken failed", __func__); + return ret; + } + + if (!data.WriteFileDescriptor(fd)) { + HILOG_ERROR("tag dsa fail to WriteFileDescriptor fd"); + return ret; + } + + if (!data.WriteString(uri)) { + HILOG_ERROR("tag dsa fail to WriteString uri"); + return ret; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_CLOSE_FILE, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("tag dsa CloseFile fail to SendRequest. err: %d", err); + return ret; + } + + ret = reply.ReadInt32(); + if (ret < 0) { + HILOG_ERROR("tag dsa fail to ReadInt32 ret"); + return ret; + } + + HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d", __func__, ret); + return ret; +} + +int FileExtProxy::CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + MessageParcel data; + if (!data.WriteInterfaceToken(FileExtProxy::GetDescriptor())) { + HILOG_ERROR("tag dsa %{public}s WriteInterfaceToken failed", __func__); + return ret; + } + + if (!data.WriteParcelable(&parentUri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable parentUri"); + return ret; + } + + if (!data.WriteString(displayName)) { + HILOG_ERROR("tag dsa fail to WriteString mode"); + return ret; + } + + if (!data.WriteParcelable(&newFileUri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable newFileUri"); + return ret; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_CREATE_FILE, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("tag dsa OpenFile fail to SendRequest. err: %d", err); + return ret; + } + + ret = reply.ReadInt32(); + if (ret < 0) { + HILOG_ERROR("tag dsa fail to ReadInt32 ret"); + return ret; + } + + std::unique_ptr tempUri(reply.ReadParcelable()); + if (!tempUri) { + HILOG_ERROR("ReadParcelable value is nullptr."); + ret = -1; + return ret; + } + + HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d, newFileUri=%{public}s", __func__, ret, newFileUri.ToString().c_str()); + newFileUri = Uri(*tempUri); + HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d, newFileUri=%{public}s", __func__, ret, newFileUri.ToString().c_str()); + HILOG_INFO("tag dsa %{public}s end successfully, tempUri=%{public}s", __func__, tempUri->ToString().c_str()); + return ret; +} + +int FileExtProxy::Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + MessageParcel data; + if (!data.WriteInterfaceToken(FileExtProxy::GetDescriptor())) { + HILOG_ERROR("tag dsa %{public}s WriteInterfaceToken failed", __func__); + return ret; + } + + if (!data.WriteParcelable(&parentUri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable parentUri"); + return ret; + } + + if (!data.WriteString(displayName)) { + HILOG_ERROR("tag dsa fail to WriteString displayName"); + return ret; + } + + if (!data.WriteParcelable(&newFileUri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable newFileUri"); + return ret; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_MKDIR, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("tag dsa OpenFile fail to SendRequest. err: %d", err); + return ret; + } + + ret = reply.ReadInt32(); + if (ret < 0) { + HILOG_ERROR("tag dsa fail to ReadInt32 ret"); + return ret; + } + + std::unique_ptr tempUri(reply.ReadParcelable()); + if (!tempUri) { + HILOG_ERROR("ReadParcelable value is nullptr."); + ret = -1; + return ret; + } + + HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d, newFileUri=%{public}s", __func__, ret, newFileUri.ToString().c_str()); + newFileUri = Uri(*tempUri); + HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d, newFileUri=%{public}s", __func__, ret, newFileUri.ToString().c_str()); + HILOG_INFO("tag dsa %{public}s end successfully, tempUri=%{public}s", __func__, tempUri->ToString().c_str()); + return ret; +} + +int FileExtProxy::Delete(const Uri &sourceFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + MessageParcel data; + if (!data.WriteInterfaceToken(FileExtProxy::GetDescriptor())) { + HILOG_ERROR("tag dsa %{public}s WriteInterfaceToken failed", __func__); + return ret; + } + + if (!data.WriteParcelable(&sourceFileUri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable sourceFileUri"); + return ret; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_DELETE, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("tag dsa OpenFile fail to SendRequest. err: %d", err); + return ret; + } + + ret = reply.ReadInt32(); + if (ret < 0) { + HILOG_ERROR("tag dsa fail to ReadInt32 ret"); + return ret; + } + + HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d", __func__, ret); + return ret; +} + +int FileExtProxy::Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + MessageParcel data; + if (!data.WriteInterfaceToken(FileExtProxy::GetDescriptor())) { + HILOG_ERROR("tag dsa %{public}s WriteInterfaceToken failed", __func__); + return ret; + } + + if (!data.WriteParcelable(&sourceFileUri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable sourceFileUri"); + return ret; + } + + if (!data.WriteParcelable(&targetParentUri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable targetParentUri"); + return ret; + } + + if (!data.WriteParcelable(&newFileUri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable newFileUri"); + return ret; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_MOVE, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("tag dsa OpenFile fail to SendRequest. err: %d", err); + return ret; + } + + ret = reply.ReadInt32(); + if (ret < 0) { + HILOG_ERROR("tag dsa fail to ReadInt32 ret"); + return ret; + } + + std::unique_ptr tempUri(reply.ReadParcelable()); + if (!tempUri) { + HILOG_ERROR("ReadParcelable value is nullptr."); + ret = -1; + return ret; + } + + HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d, newFileUri=%{public}s", __func__, ret, newFileUri.ToString().c_str()); + newFileUri = Uri(*tempUri); + HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d, newFileUri=%{public}s", __func__, ret, newFileUri.ToString().c_str()); + HILOG_INFO("tag dsa %{public}s end successfully, tempUri=%{public}s", __func__, tempUri->ToString().c_str()); + return ret; +} + +int FileExtProxy::Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + MessageParcel data; + if (!data.WriteInterfaceToken(FileExtProxy::GetDescriptor())) { + HILOG_ERROR("tag dsa %{public}s WriteInterfaceToken failed", __func__); + return ret; + } + + if (!data.WriteParcelable(&sourceFileUri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable sourceFileUri"); + return ret; + } + + if (!data.WriteString(displayName)) { + HILOG_ERROR("tag dsa fail to WriteString displayName"); + return ret; + } + + if (!data.WriteParcelable(&newFileUri)) { + HILOG_ERROR("tag dsa fail to WriteParcelable newFileUri"); + return ret; + } + + MessageParcel reply; + MessageOption option; + int32_t err = Remote()->SendRequest(CMD_RENAME, data, reply, option); + if (err != NO_ERROR) { + HILOG_ERROR("tag dsa OpenFile fail to SendRequest. err: %d", err); + return ret; + } + + ret = reply.ReadInt32(); + if (ret < 0) { + HILOG_ERROR("tag dsa fail to ReadInt32 ret"); + return ret; + } + + std::unique_ptr tempUri(reply.ReadParcelable()); + if (!tempUri) { + HILOG_ERROR("ReadParcelable value is nullptr."); + ret = -1; + return ret; + } + + HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d, newFileUri=%{public}s", __func__, ret, newFileUri.ToString().c_str()); + newFileUri = Uri(*tempUri); + HILOG_INFO("tag dsa %{public}s end successfully, return ret=%{public}d, newFileUri=%{public}s", __func__, ret, newFileUri.ToString().c_str()); + HILOG_INFO("tag dsa %{public}s end successfully, tempUri=%{public}s", __func__, tempUri->ToString().c_str()); + return ret; +} +} // namespace AAFwk +} // namespace OHOS diff --git a/frameworks/innerkits/file_extension/src/file_ext_stub.cpp b/frameworks/innerkits/file_extension/src/file_ext_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e81ddb29a2a375fb261968e794b0f991d63bd9b8 --- /dev/null +++ b/frameworks/innerkits/file_extension/src/file_ext_stub.cpp @@ -0,0 +1,298 @@ +/* + * Copyright (c) 2022 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. + */ + +#include "file_ext_stub.h" + +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AppExecFwk { +FileExtStub::FileExtStub() +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + stubFuncMap_[CMD_OPEN_FILE] = &FileExtStub::CmdOpenFile; + stubFuncMap_[CMD_CLOSE_FILE] = &FileExtStub::CmdCloseFile; + stubFuncMap_[CMD_CREATE_FILE] = &FileExtStub::CmdCreateFile; + stubFuncMap_[CMD_MKDIR] = &FileExtStub::CmdMkdir; + stubFuncMap_[CMD_DELETE] = &FileExtStub::CmdDelete; + stubFuncMap_[CMD_MOVE] = &FileExtStub::CmdMove; + stubFuncMap_[CMD_RENAME] = &FileExtStub::CmdRename; +} + +FileExtStub::~FileExtStub() +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + stubFuncMap_.clear(); +} + +int FileExtStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, + MessageOption& option) +{ + HILOG_INFO("tag dsa %{public}s Received stub message: %{public}d", __func__, code); + std::u16string descriptor = FileExtStub::GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (descriptor != remoteDescriptor) { + HILOG_INFO("tag dsa local descriptor is not equal to remote"); + return ERR_INVALID_STATE; + } + + const auto &itFunc = stubFuncMap_.find(code); + if (itFunc != stubFuncMap_.end()) { + return (this->*(itFunc->second))(data, reply); + } + + HILOG_INFO("tag dsa %{public}s remote request unhandled: %{public}d", __func__, code); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} + +ErrCode FileExtStub::CmdOpenFile(MessageParcel &data, MessageParcel &reply) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + std::shared_ptr uri(data.ReadParcelable()); + if (uri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub uri is nullptr"); + return ERR_INVALID_VALUE; + } + std::string mode = data.ReadString(); + if (mode.empty()) { + HILOG_ERROR("tag dsa FileExtStub mode is nullptr"); + return ERR_INVALID_VALUE; + } + int fd = OpenFile(*uri, mode); + if (fd < 0) { + HILOG_ERROR("tag dsa OpenFile fail, fd is %{pubilc}d", fd); + return ERR_INVALID_VALUE; + } + HILOG_INFO("tag dsa %{public}s retutn fd: %{public}d.", __func__, fd); + + if (!reply.WriteFileDescriptor(fd)) { + HILOG_ERROR("tag dsa fail to WriteFileDescriptor fd"); + return ERR_INVALID_VALUE; + } + HILOG_INFO("tag dsa %{public}s end.", __func__); + return NO_ERROR; +} + +ErrCode FileExtStub::CmdCloseFile(MessageParcel &data, MessageParcel &reply) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int fd = data.ReadFileDescriptor(); + if (fd < 0) { + HILOG_ERROR("tag dsa FileExtStub fd is invalid"); + return ERR_INVALID_VALUE; + } + std::string uri = data.ReadString(); + if (uri.empty()) { + HILOG_ERROR("tag dsa FileExtStub uri is nullptr"); + return ERR_INVALID_VALUE; + } + + int ret = CloseFile(fd, uri); + if (ret < 0) { + HILOG_ERROR("tag dsa CloseFile fail, ret is %{pubilc}d", ret); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteInt32(ret)) { + HILOG_ERROR("tag dsa fail to WriteInt32 ret"); + return ERR_INVALID_VALUE; + } + HILOG_INFO("tag dsa %{public}s end.", __func__); + return NO_ERROR; +} + +ErrCode FileExtStub::CmdCreateFile(MessageParcel &data, MessageParcel &reply) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + std::shared_ptr parentUri(data.ReadParcelable()); + if (parentUri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub parentUri is nullptr"); + return ERR_INVALID_VALUE; + } + std::string displayName = data.ReadString(); + if (displayName.empty()) { + HILOG_ERROR("tag dsa FileExtStub mode is nullptr"); + return ERR_INVALID_VALUE; + } + std::shared_ptr newFileUri(data.ReadParcelable()); + if (newFileUri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub newFileUri is nullptr"); + return ERR_INVALID_VALUE; + } + + int ret = CreateFile(*parentUri, displayName, *newFileUri); + if (ret < 0) { + HILOG_ERROR("tag dsa CreateFile fail, ret is %{pubilc}d", ret); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteInt32(ret)) { + HILOG_ERROR("tag dsa fail to WriteInt32 ret"); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteParcelable(&(*newFileUri))) { + HILOG_ERROR("fail to WriteParcelable type"); + return ERR_INVALID_VALUE; + } + HILOG_INFO("tag dsa %{public}s end. ret:%d, newFileUri = %{public}s", __func__, ret, newFileUri->ToString().c_str()); + HILOG_INFO("tag dsa %{public}s end. newFileUri = %{public}s", __func__, newFileUri->ToString().c_str()); + return NO_ERROR; +} + +ErrCode FileExtStub::CmdMkdir(MessageParcel &data, MessageParcel &reply) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + std::shared_ptr parentUri(data.ReadParcelable()); + if (parentUri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub parentUri is nullptr"); + return ERR_INVALID_VALUE; + } + std::string displayName = data.ReadString(); + if (displayName.empty()) { + HILOG_ERROR("tag dsa FileExtStub mode is nullptr"); + return ERR_INVALID_VALUE; + } + std::shared_ptr newFileUri(data.ReadParcelable()); + if (newFileUri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub newFileUri is nullptr"); + return ERR_INVALID_VALUE; + } + + int ret = Mkdir(*parentUri, displayName, *newFileUri); + if (ret < 0) { + HILOG_ERROR("tag dsa Mkdir fail, ret is %{pubilc}d", ret); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteInt32(ret)) { + HILOG_ERROR("tag dsa fail to WriteInt32 ret"); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteParcelable(&(*newFileUri))) { + HILOG_ERROR("fail to WriteParcelable type"); + return ERR_INVALID_VALUE; + } + + HILOG_INFO("tag dsa %{public}s end. ret:%d, newFileUri = %{public}s", __func__, ret, newFileUri->ToString().c_str()); + HILOG_INFO("tag dsa %{public}s end. newFileUri = %{public}s", __func__, newFileUri->ToString().c_str()); + return NO_ERROR; +} + +ErrCode FileExtStub::CmdDelete(MessageParcel &data, MessageParcel &reply) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + std::shared_ptr uri(data.ReadParcelable()); + if (uri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub uri is nullptr"); + return ERR_INVALID_VALUE; + } + + int ret = Delete(*uri); + if (ret < 0) { + HILOG_ERROR("tag dsa Delete fail, ret is %{pubilc}d", ret); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteInt32(ret)) { + HILOG_ERROR("tag dsa fail to WriteFileDescriptor ret"); + return ERR_INVALID_VALUE; + } + HILOG_INFO("tag dsa %{public}s end.", __func__); + return NO_ERROR; +} + +ErrCode FileExtStub::CmdMove(MessageParcel &data, MessageParcel &reply) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + std::shared_ptr sourceFileUri(data.ReadParcelable()); + if (sourceFileUri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub sourceFileUri is nullptr"); + return ERR_INVALID_VALUE; + } + std::shared_ptr targetParentUri(data.ReadParcelable()); + if (targetParentUri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub targetParentUri is nullptr"); + return ERR_INVALID_VALUE; + } + std::shared_ptr newFileUri(data.ReadParcelable()); + if (newFileUri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub newFileUri is nullptr"); + return ERR_INVALID_VALUE; + } + + int ret = Move(*sourceFileUri, *targetParentUri, *newFileUri); + if (ret < 0) { + HILOG_ERROR("tag dsa Move fail, ret is %{pubilc}d", ret); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteInt32(ret)) { + HILOG_ERROR("tag dsa fail to WriteInt32 ret"); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteParcelable(&(*newFileUri))) { + HILOG_ERROR("fail to WriteParcelable type"); + return ERR_INVALID_VALUE; + } + + HILOG_INFO("tag dsa %{public}s end. ret:%d, newFileUri = %{public}s", __func__, ret, newFileUri->ToString().c_str()); + HILOG_INFO("tag dsa %{public}s end. newFileUri = %{public}s", __func__, newFileUri->ToString().c_str()); + return NO_ERROR; +} + +ErrCode FileExtStub::CmdRename(MessageParcel &data, MessageParcel &reply) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + std::shared_ptr sourceFileUri(data.ReadParcelable()); + if (sourceFileUri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub sourceFileUri is nullptr"); + return ERR_INVALID_VALUE; + } + std::string displayName = data.ReadString(); + if (displayName.empty()) { + HILOG_ERROR("tag dsa FileExtStub mode is nullptr"); + return ERR_INVALID_VALUE; + } + std::shared_ptr newFileUri(data.ReadParcelable()); + if (newFileUri == nullptr) { + HILOG_ERROR("tag dsa FileExtStub newFileUri is nullptr"); + return ERR_INVALID_VALUE; + } + + int ret = Rename(*sourceFileUri, displayName, *newFileUri); + if (ret < 0) { + HILOG_ERROR("tag dsa Rename fail, ret is %{pubilc}d", ret); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteInt32(ret)) { + HILOG_ERROR("tag dsa fail to WriteInt32 ret"); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteParcelable(&(*newFileUri))) { + HILOG_ERROR("fail to WriteParcelable type"); + return ERR_INVALID_VALUE; + } + + HILOG_INFO("tag dsa %{public}s end. ret:%d, newFileUri = %{public}s", __func__, ret, newFileUri->ToString().c_str()); + HILOG_INFO("tag dsa %{public}s end. newFileUri = %{public}s", __func__, newFileUri->ToString().c_str()); + return NO_ERROR; +} +} // namespace AAFwk +} // namespace OHOS diff --git a/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp b/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ced9fe2123848002bb0acd9de3fc5f5666dc59e3 --- /dev/null +++ b/frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2022 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. + */ + +#include "file_ext_stub_impl.h" + +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AppExecFwk { +std::shared_ptr FileExtStubImpl::GetOwner() +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + return extension_; +} + +int FileExtStubImpl::OpenFile(const Uri &uri, const std::string &mode) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + auto extension = GetOwner(); + if (extension == nullptr) { + HILOG_ERROR("tag dsa %{public}s end failed.", __func__); + return ret; + } + ret = extension->OpenFile(uri, mode); + HILOG_INFO("tag dsa %{public}s end successfully, return fd:%{public}d", __func__, ret); + return ret; +} + +int FileExtStubImpl::CloseFile(int fd, const std::string &uri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + auto extension = GetOwner(); + if (extension == nullptr) { + HILOG_ERROR("tag dsa %{public}s end failed.", __func__); + return ret; + } + ret = extension->CloseFile(fd, uri); + HILOG_INFO("tag dsa %{public}s end successfully, return fd:%{public}d", __func__, ret); + return ret; +} + +int FileExtStubImpl::CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + auto extension = GetOwner(); + if (extension == nullptr) { + HILOG_ERROR("tag dsa %{public}s end failed.", __func__); + return ret; + } + ret = extension->CreateFile(parentUri, displayName, newFileUri); + HILOG_INFO("tag dsa %{public}s end successfully, return ret:%{public}d, %{public}s", __func__, ret,newFileUri.ToString().c_str()); + return ret; +} + +int FileExtStubImpl::Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + auto extension = GetOwner(); + if (extension == nullptr) { + HILOG_ERROR("tag dsa %{public}s end failed.", __func__); + return ret; + } + ret = extension->Mkdir(parentUri, displayName, newFileUri); + HILOG_INFO("tag dsa %{public}s end successfully, return ret:%{public}d, %{public}s", __func__, ret,newFileUri.ToString().c_str()); + return ret; +} + +int FileExtStubImpl::Delete(const Uri &sourceFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + auto extension = GetOwner(); + if (extension == nullptr) { + HILOG_ERROR("tag dsa %{public}s end failed.", __func__); + return ret; + } + ret = extension->Delete(sourceFileUri); + HILOG_INFO("tag dsa %{public}s end successfully, return fd:%{public}d", __func__, ret); + return ret; +} +int FileExtStubImpl::Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + auto extension = GetOwner(); + if (extension == nullptr) { + HILOG_ERROR("tag dsa %{public}s end failed.", __func__); + return ret; + } + ret = extension->Move(sourceFileUri, targetParentUri, newFileUri); + HILOG_INFO("tag dsa %{public}s end successfully, return ret:%{public}d, %{public}s", __func__, ret,newFileUri.ToString().c_str()); + return ret; +} +int FileExtStubImpl::Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + int ret = -1; + auto extension = GetOwner(); + if (extension == nullptr) { + HILOG_ERROR("tag dsa %{public}s end failed.", __func__); + return ret; + } + ret = extension->Rename(sourceFileUri, displayName, newFileUri); + HILOG_INFO("tag dsa %{public}s end successfully, return ret:%{public}d, %{public}s", __func__, ret,newFileUri.ToString().c_str()); + return ret; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp b/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cc6509748d42685c1ee9fc31ba442e420eca6018 --- /dev/null +++ b/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp @@ -0,0 +1,365 @@ +/* + * Copyright (c) 2022 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. + */ + +#include "js_file_ext_ability.h" + +#include "extension_context.h" +#include "ability_info.h" +#include "accesstoken_kit.h" +#include "bytrace.h" +#include "file_ext_stub_impl.h" +#include "hilog_wrapper.h" +#include "ipc_skeleton.h" +#include "js_runtime.h" +#include "js_runtime_utils.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "napi_common_util.h" +#include "napi_common_want.h" +#include "napi_remote_object.h" + +namespace OHOS { +namespace AbilityRuntime { +namespace { +constexpr size_t ARGC_ONE = 1; +constexpr size_t ARGC_TWO = 2; +} + +using namespace OHOS::AppExecFwk; +using OHOS::Security::AccessToken::AccessTokenKit; + +JsFileExtAbility* JsFileExtAbility::Create(const std::unique_ptr& runtime) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + return new JsFileExtAbility(static_cast(*runtime)); +} + +JsFileExtAbility::JsFileExtAbility(JsRuntime& jsRuntime) : jsRuntime_(jsRuntime) {} +JsFileExtAbility::~JsFileExtAbility() = default; + +void JsFileExtAbility::Init(const std::shared_ptr &record, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + FileExtAbility::Init(record, application, handler, token); + std::string srcPath = ""; + GetSrcPath(srcPath); + if (srcPath.empty()) { + HILOG_ERROR("tag dsa Failed to get srcPath"); + return; + } + + std::string moduleName(Extension::abilityInfo_->moduleName); + moduleName.append("::").append(abilityInfo_->name); + HILOG_INFO("tag dsa %{public}s module:%{public}s, srcPath:%{public}s.", __func__, moduleName.c_str(), srcPath.c_str()); + HandleScope handleScope(jsRuntime_); + + jsObj_ = jsRuntime_.LoadModule(moduleName, srcPath); + if (jsObj_ == nullptr) { + HILOG_ERROR("tag dsa Failed to get jsObj_"); + return; + } + HILOG_INFO("tag dsa JsFileExtAbility::Init ConvertNativeValueTo."); + NativeObject* obj = ConvertNativeValueTo(jsObj_->Get()); + if (obj == nullptr) { + HILOG_ERROR("tag dsa Failed to get JsFileExtAbility object"); + return; + } + HILOG_INFO("tag dsa JsFileExtAbility::Init end."); +} + +void JsFileExtAbility::OnStart(const AAFwk::Want &want) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + Extension::OnStart(want); + HandleScope handleScope(jsRuntime_); + napi_env env = reinterpret_cast(&jsRuntime_.GetNativeEngine()); + napi_value napiWant = OHOS::AppExecFwk::WrapWant(env, want); + NativeValue* nativeWant = reinterpret_cast(napiWant); + NativeValue* argv[] = {nativeWant}; + CallObjectMethod("onCreate", argv, ARGC_ONE); + HILOG_INFO("tag dsa %{public}s end.", __func__); +} + +sptr JsFileExtAbility::OnConnect(const AAFwk::Want &want) +{ + BYTRACE_NAME(BYTRACE_TAG_DISTRIBUTEDDATA, __PRETTY_FUNCTION__); + HILOG_INFO("tag dsa %{public}s begin.", __func__); + Extension::OnConnect(want); + sptr remoteObject = new (std::nothrow) FileExtStubImpl( + std::static_pointer_cast(shared_from_this()), + reinterpret_cast(&jsRuntime_.GetNativeEngine())); + if (remoteObject == nullptr) { + HILOG_ERROR("tag dsa %{public}s No memory allocated for FileExtStubImpl", __func__); + return nullptr; + } + HILOG_INFO("tag dsa %{public}s end. ", __func__); + return remoteObject->AsObject(); +} + +NativeValue* JsFileExtAbility::CallObjectMethod(const char* name, NativeValue* const* argv, size_t argc) +{ + HILOG_INFO("tag dsa JsFileExtAbility::CallObjectMethod(%{public}s), begin", name); + + if (!jsObj_) { + HILOG_WARN("Not found FileExtAbility.js"); + return nullptr; + } + + HandleScope handleScope(jsRuntime_); + auto& nativeEngine = jsRuntime_.GetNativeEngine(); + + NativeValue* value = jsObj_->Get(); + NativeObject* obj = ConvertNativeValueTo(value); + if (obj == nullptr) { + HILOG_ERROR("tag dsa Failed to get FileExtAbility object"); + return nullptr; + } + + NativeValue* method = obj->GetProperty(name); + if (method == nullptr) { + HILOG_ERROR("tag dsa Failed to get '%{public}s' from FileExtAbility object", name); + return nullptr; + } + HILOG_INFO("tag dsa JsFileExtAbility::CallFunction(%{public}s), success", name); + return handleScope.Escape(nativeEngine.CallFunction(value, method, argv, argc)); +} + +void JsFileExtAbility::GetSrcPath(std::string &srcPath) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + if (!Extension::abilityInfo_->isStageBasedModel) { + /* temporary compatibility api8 + config.json */ + srcPath.append(Extension::abilityInfo_->package); + srcPath.append("/assets/js/"); + if (!Extension::abilityInfo_->srcPath.empty()) { + srcPath.append(Extension::abilityInfo_->srcPath); + } + srcPath.append("/").append(Extension::abilityInfo_->name).append(".abc"); + HILOG_INFO("tag dsa %{public}s end1, srcPath:%{public}s", __func__, srcPath.c_str()); + return; + } + + if (!Extension::abilityInfo_->srcEntrance.empty()) { + srcPath.append(Extension::abilityInfo_->moduleName + "/"); + srcPath.append(Extension::abilityInfo_->srcEntrance); + srcPath.erase(srcPath.rfind('.')); + srcPath.append(".abc"); + } + HILOG_INFO("tag dsa %{public}s end2, srcPath:%{public}s", __func__, srcPath.c_str()); +} + +int JsFileExtAbility::OpenFile(const Uri &uri, const std::string &mode) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HandleScope handleScope(jsRuntime_); + napi_env env = reinterpret_cast(&jsRuntime_.GetNativeEngine()); + + napi_value napiUri = nullptr; + napi_create_string_utf8(env, uri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiUri); + napi_value napiMode = nullptr; + napi_create_string_utf8(env, mode.c_str(), NAPI_AUTO_LENGTH, &napiMode); + + NativeValue* nativeUri = reinterpret_cast(napiUri); + NativeValue* nativeMode = reinterpret_cast(napiMode); + NativeValue* argv[] = {nativeUri, nativeMode}; + NativeValue* nativeResult = CallObjectMethod("openFile", argv, ARGC_TWO); + int ret = -1; + if (nativeResult == nullptr) { + HILOG_ERROR("tag dsa %{public}s call openFile with return null.", __func__); + return ret; + } + ret = OHOS::AppExecFwk::UnwrapInt32FromJS(env, reinterpret_cast(nativeResult)); + HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d", __func__, ret); + return ret; +} + +int JsFileExtAbility::CloseFile(int fd, const std::string &uri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HandleScope handleScope(jsRuntime_); + napi_env env = reinterpret_cast(&jsRuntime_.GetNativeEngine()); + + napi_value napiFd = nullptr; + napi_create_int32(env, fd, &napiFd); + napi_value napiUri = nullptr; + napi_create_string_utf8(env, uri.c_str(), NAPI_AUTO_LENGTH, &napiUri); + + NativeValue* nativeFd = reinterpret_cast(napiFd); + NativeValue* nativeUri = reinterpret_cast(napiUri); + NativeValue* argv[] = {nativeFd, nativeUri}; + NativeValue* nativeResult = CallObjectMethod("closeFile", argv, ARGC_TWO); + int ret = -1; + if (nativeResult == nullptr) { + HILOG_ERROR("tag dsa %{public}s call closeFile with return null.", __func__); + return ret; + } + ret = OHOS::AppExecFwk::UnwrapInt32FromJS(env, reinterpret_cast(nativeResult)); + HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d", __func__, ret); + return ret; +} + +int JsFileExtAbility::CreateFile(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HandleScope handleScope(jsRuntime_); + napi_env env = reinterpret_cast(&jsRuntime_.GetNativeEngine()); + + napi_value napiParentUri = nullptr; + napi_create_string_utf8(env, parentUri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiParentUri); + napi_value napiDisplayName = nullptr; + napi_create_string_utf8(env, displayName.c_str(), NAPI_AUTO_LENGTH, &napiDisplayName); + + NativeValue* nativeParentUri = reinterpret_cast(napiParentUri); + NativeValue* nativeDisplayName = reinterpret_cast(napiDisplayName); + NativeValue* argv[] = {nativeParentUri, nativeDisplayName}; + NativeValue* nativeResult = CallObjectMethod("createFile", argv, ARGC_TWO); + int ret = -1; + if (nativeResult == nullptr) { + HILOG_ERROR("tag dsa %{public}s call createFile with return null.", __func__); + return ret; + } + std::string uriStr = OHOS::AppExecFwk::UnwrapStringFromJS(env, reinterpret_cast(nativeResult)); + if (uriStr.empty()) { + HILOG_ERROR("tag dsa %{public}s call Mkdir with return empty.", __func__); + return ret; + } else { + ret = NO_ERROR; + } + newFileUri = Uri(uriStr); + HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d, newFileUri = %{public}s", __func__, ret, uriStr.c_str()); + return ret; +} + +int JsFileExtAbility::Mkdir(const Uri &parentUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HandleScope handleScope(jsRuntime_); + napi_env env = reinterpret_cast(&jsRuntime_.GetNativeEngine()); + + napi_value napiParentUri = nullptr; + napi_create_string_utf8(env, parentUri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiParentUri); + napi_value napiDisplayName = nullptr; + napi_create_string_utf8(env, displayName.c_str(), NAPI_AUTO_LENGTH, &napiDisplayName); + + NativeValue* nativeParentUri = reinterpret_cast(napiParentUri); + NativeValue* nativeDisplayName = reinterpret_cast(napiDisplayName); + NativeValue* argv[] = {nativeParentUri, nativeDisplayName}; + NativeValue* nativeResult = CallObjectMethod("mkdir", argv, ARGC_TWO); + int ret = -1; + if (nativeResult == nullptr) { + HILOG_ERROR("tag dsa %{public}s call Mkdir with return null.", __func__); + return ret; + } + std::string uriStr = OHOS::AppExecFwk::UnwrapStringFromJS(env, reinterpret_cast(nativeResult)); + if (uriStr.empty()) { + HILOG_ERROR("tag dsa %{public}s call Mkdir with return empty.", __func__); + return ret; + } else { + ret = NO_ERROR; + } + newFileUri = Uri(uriStr); + HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d, newFileUri = %{public}s", __func__, ret, uriStr.c_str()); + return ret; +} + +int JsFileExtAbility::Delete(const Uri &sourceFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HandleScope handleScope(jsRuntime_); + napi_env env = reinterpret_cast(&jsRuntime_.GetNativeEngine()); + + napi_value napiUri = nullptr; + napi_create_string_utf8(env, sourceFileUri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiUri); + + NativeValue* nativeUri = reinterpret_cast(napiUri); + NativeValue* argv[] = {nativeUri}; + NativeValue* nativeResult = CallObjectMethod("delete", argv, ARGC_ONE); + int ret = -1; + if (nativeResult == nullptr) { + HILOG_ERROR("tag dsa %{public}s call delete with return null.", __func__); + return ret; + } + ret = OHOS::AppExecFwk::UnwrapInt32FromJS(env, reinterpret_cast(nativeResult)); + HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d", __func__, ret); + return ret; +} + +int JsFileExtAbility::Move(const Uri &sourceFileUri, const Uri &targetParentUri, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HandleScope handleScope(jsRuntime_); + napi_env env = reinterpret_cast(&jsRuntime_.GetNativeEngine()); + + napi_value napiSourceFileUri = nullptr; + napi_create_string_utf8(env, sourceFileUri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiSourceFileUri); + napi_value napiTargetParentUri = nullptr; + napi_create_string_utf8(env, targetParentUri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiTargetParentUri); + + NativeValue* nativeSourceFileUri = reinterpret_cast(napiSourceFileUri); + NativeValue* nativeTargetParentUri = reinterpret_cast(napiTargetParentUri); + NativeValue* argv[] = {nativeSourceFileUri, nativeTargetParentUri}; + NativeValue* nativeResult = CallObjectMethod("move", argv, ARGC_TWO); + int ret = -1; + if (nativeResult == nullptr) { + HILOG_ERROR("tag dsa %{public}s call move with return null.", __func__); + return ret; + } + std::string uriStr = OHOS::AppExecFwk::UnwrapStringFromJS(env, reinterpret_cast(nativeResult)); + if (uriStr.empty()) { + HILOG_ERROR("tag dsa %{public}s call move with return empty.", __func__); + return ret; + } else { + ret = NO_ERROR; + } + newFileUri = Uri(uriStr); + HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d, newFileUri = %{public}s", __func__, ret, uriStr.c_str()); + return ret; +} + +int JsFileExtAbility::Rename(const Uri &sourceFileUri, const std::string &displayName, Uri &newFileUri) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + HandleScope handleScope(jsRuntime_); + napi_env env = reinterpret_cast(&jsRuntime_.GetNativeEngine()); + + napi_value napiSourceFileUri = nullptr; + napi_create_string_utf8(env, sourceFileUri.ToString().c_str(), NAPI_AUTO_LENGTH, &napiSourceFileUri); + napi_value napiDisplayName = nullptr; + napi_create_string_utf8(env, displayName.c_str(), NAPI_AUTO_LENGTH, &napiDisplayName); + + NativeValue* nativeSourceFileUri = reinterpret_cast(napiSourceFileUri); + NativeValue* nativeDisplayName = reinterpret_cast(napiDisplayName); + NativeValue* argv[] = {nativeSourceFileUri, nativeDisplayName}; + NativeValue* nativeResult = CallObjectMethod("rename", argv, ARGC_TWO); + int ret = -1; + if (nativeResult == nullptr) { + HILOG_ERROR("tag dsa %{public}s call rename with return null.", __func__); + return ret; + } + std::string uriStr = OHOS::AppExecFwk::UnwrapStringFromJS(env, reinterpret_cast(nativeResult)); + if (uriStr.empty()) { + HILOG_ERROR("tag dsa %{public}s call rename with return empty.", __func__); + return ret; + } else { + ret = NO_ERROR; + } + newFileUri = Uri(uriStr); + HILOG_INFO("tag dsa %{public}s end. return fd:%{public}d, newFileUri = %{public}s", __func__, ret, uriStr.c_str()); + return ret; +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/AppScope/app.json b/frameworks/innerkits/file_extension_hap/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..f86c4521221f0205e4f70ebd8021a1b16a9dcafb --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/AppScope/app.json @@ -0,0 +1,13 @@ +{ + "app": { + "bundleName": "com.ohos.FileExtension.FileExtensionData", + "vendor": "FileExtension", + "versionCode": 1000000, + "versionName": "1.0.0", + "minAPIVersion": 9, + "targetAPIVersion": 9, + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true + } +} diff --git a/frameworks/innerkits/file_extension_hap/AppScope/resources/base/element/string.json b/frameworks/innerkits/file_extension_hap/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..7863972bd0ae5e0b33860b0912141dec95c82652 --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "FileExtension" + } + ] +} diff --git a/frameworks/innerkits/file_extension_hap/AppScope/resources/base/media/app_icon.png b/frameworks/innerkits/file_extension_hap/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/frameworks/innerkits/file_extension_hap/AppScope/resources/base/media/app_icon.png differ diff --git a/frameworks/innerkits/file_extension_hap/build-profile.json5 b/frameworks/innerkits/file_extension_hap/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..fc53829be062f3a883f815802e6039c733ebb352 --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/build-profile.json5 @@ -0,0 +1,26 @@ +{ + "app": { + "compileSdkVersion": 9, + "compatibleSdkVersion": 9, + "products": [ + { + "name": "default", + "signingConfig": "default", + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/build-profile.json5 b/frameworks/innerkits/file_extension_hap/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7dc37bb919dada5132609c409200db266559004f --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/entry/build-profile.json5 @@ -0,0 +1,13 @@ +{ + "apiType": 'stageMode', + "buildOption": { + }, + "targets": [ + { + "name": "default", + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/hvigorfile.js b/frameworks/innerkits/file_extension_hap/entry/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..d7720ee6a7aad5c617d1fd2f6fc8c87067bfa32c --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/entry/hvigorfile.js @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').hapTasks diff --git a/frameworks/innerkits/file_extension_hap/entry/package-lock.json b/frameworks/innerkits/file_extension_hap/entry/package-lock.json new file mode 100644 index 0000000000000000000000000000000000000000..15bc7145be1490029883067847743ea7134cf545 --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/entry/package-lock.json @@ -0,0 +1,5 @@ +{ + "name": "entry", + "version": "1.0.0", + "lockfileVersion": 1 +} diff --git a/frameworks/innerkits/file_extension_hap/entry/package.json b/frameworks/innerkits/file_extension_hap/entry/package.json new file mode 100644 index 0000000000000000000000000000000000000000..4693ae0c35e3dee3d45bc1c52885c088c11d476c --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/entry/package.json @@ -0,0 +1,14 @@ +{ + "license":"ISC", + "devDependencies":{}, + "name":"entry", + "ohos":{ + "org":"huawei", + "directoryLevel":"module", + "buildTool":"hvigor" + }, + "description":"FileExtension", + "repository":{}, + "version":"1.0.0", + "dependencies":{} +} \ No newline at end of file diff --git a/services/src/fileoper/oper_factory.h b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/Application/AbilityStage.ts similarity index 57% rename from services/src/fileoper/oper_factory.h rename to frameworks/innerkits/file_extension_hap/entry/src/main/ets/Application/AbilityStage.ts index 90443b054695ec6866aa735a58b652920c992288..21eabd6ae36ea484ad7775078b8faed89aef4c8b 100644 --- a/services/src/fileoper/oper_factory.h +++ b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/Application/AbilityStage.ts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -12,20 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef STORAGE_SERVICES_OPER_FACTORY_H -#define STORAGE_SERVICES_OPER_FACTORY_H -#pragma once +import AbilityStage from "@ohos.application.AbilityStage" -#include - -#include "file_oper.h" - -namespace OHOS { -namespace FileManagerService { -class OperFactory { -public: - std::unique_ptr GetFileOper(int equipmentId); -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERVICES_OPER_FACTORY_H \ No newline at end of file +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("MyAbilityStage onCreate") + } +} \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..ef8d617a6609d393473e797a38c032db857b37cd --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022 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 Extension from '@ohos.application.FileExtensionAbility' + +export default class FileExtAbility extends Extension { + onCreate(want) { + console.log('js server tag dsa FileExtAbility onCreate, want:' + want.abilityName); + console.log('js server tag dsa FileExtAbility this.context:' + this.context); + } + + openFile(uri, mode) { + console.log('js server tag dsa openFile, uri:' + uri + ',mode:' + mode); + return 2; + } + + closeFile(fd, uri) { + console.log('js server tag dsa delete, fd:' + fd + ",uri: " + uri); + return 0; + } + + createFile(parentUri, displayName) { + console.log('js server tag dsa CreateFile, parentUri:' + parentUri + ',displayName:' + displayName ); + return "filetest://fileext.share/temp/test/CreateFile001.txt"; + } + + mkdir(parentUri, displayName) { + console.log('js server tag dsa mkdir, parentUri:' + parentUri + ',displayName:' + displayName); + return "filetest://fileext.share/temp/test/Mkdir001"; + } + + delete(sourceFileUri) { + console.log('js server tag dsa delete, sourceFileUri:' + sourceFileUri); + return 0; + } + + move(sourceFileUri, targetParentUri) { + console.log('js server tag dsa move, sourceFileUri:' + sourceFileUri + ',targetParentUri:' + targetParentUri); + return "filetest://fileext.share/temp/test/move001.xl"; + } + + rename(sourceFileUri, displayName) { + console.log('js server tag dsa rename, sourceFileUri:' + sourceFileUri + ',displayName:' + displayName); + return "filetest://fileext.share/temp/test/rename001.ttt"; + } +}; \ No newline at end of file diff --git a/services/src/fileoper/oper_factory.cpp b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/MainAbility/MainAbility.ts similarity index 34% rename from services/src/fileoper/oper_factory.cpp rename to frameworks/innerkits/file_extension_hap/entry/src/main/ets/MainAbility/MainAbility.ts index e0b8ea24e41297c2f9ffd3c512e09c6c5d1548a1..2f1022041fa5df0f291a0faf5243ecb592785d08 100644 --- a/services/src/fileoper/oper_factory.cpp +++ b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/MainAbility/MainAbility.ts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -12,37 +12,37 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import Ability from '@ohos.application.Ability' -#include "oper_factory.h" +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + console.log("[tag dsa] MainAbility onCreate") + globalThis.abilityWant = want; + } + + onDestroy() { + console.log("[tag dsa] MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[tag dsa] MainAbility onWindowStageCreate") + globalThis.context = this.context; + windowStage.setUIContent(this.context, "pages/index", null) + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[tag dsa] MainAbility onWindowStageDestroy") + } -#include "external_storage_oper.h" -#include "file_manager_service_def.h" -#include "file_oper.h" -#include "log.h" -#include "media_file_oper.h" + onForeground() { + // Ability has brought to foreground + console.log("[tag dsa] MainAbility onForeground") + } -using namespace std; -namespace OHOS { -namespace FileManagerService { -unique_ptr OperFactory::GetFileOper(int equipmentId) -{ - unique_ptr fp; - DEBUG_LOG("FileOper %{public}d.", equipmentId); - switch (equipmentId) { - case Equipment::INTERNAL_STORAGE: { - fp = make_unique(); - break; - } - case Equipment::EXTERNAL_STORAGE: { - fp = make_unique(); - break; - } - default: { - DEBUG_LOG("default FileOper %{public}d.", equipmentId); - break; - } + onBackground() { + // Ability has back to background + console.log("[tag dsa] MainAbility onBackground") } - return fp; -} -} // namespace FileManagerService -} // namespace OHOS \ No newline at end of file +}; diff --git a/services/src/fileoper/file_oper.h b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/pages/index.ets similarity index 49% rename from services/src/fileoper/file_oper.h rename to frameworks/innerkits/file_extension_hap/entry/src/main/ets/pages/index.ets index 57839af34e1f371b0e4909ddf0081c07775c6df0..a3361dc31925163a44aa2ed457be90de88aae2d5 100644 --- a/services/src/fileoper/file_oper.h +++ b/frameworks/innerkits/file_extension_hap/entry/src/main/ets/pages/index.ets @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -12,23 +12,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef STORAGE_SERVICES_FILE_OPER_H -#define STORAGE_SERVICES_FILE_OPER_H +@Entry +@Component +struct Index { + @State message: string = 'Hello World' -#include -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" - -namespace OHOS { -namespace FileManagerService { -class FileOper { -public: - FileOper() = default; - virtual ~FileOper() = default; - virtual int OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) const = 0; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERVICES_FILE_OPER_H \ No newline at end of file + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/main/module.json b/frameworks/innerkits/file_extension_hap/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..9a88ff84a9614f50826c35f0fe0f751cb0c5a3e3 --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/entry/src/main/module.json @@ -0,0 +1,37 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:entry_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "phone", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "visible": false + } + ], + "extensionAbilities": [ + { + "srcEntrance": "./ets/FileExtensionAbility/FileExtensionAbility.ts", + "name": "FileExtensionAbility", + "icon": "$media:icon", + "description": "$string:description_serviceability", + "type": "file", + "visible": true + } + ] + } +} diff --git a/frameworks/innerkits/file_extension_hap/entry/src/main/resources/base/element/string.json b/frameworks/innerkits/file_extension_hap/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..db5e76342178fdffa784213058059bfa2c07590a --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "description_serviceability", + "value": "description_serviceability" + } + ] +} \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/main/resources/base/media/icon.png b/frameworks/innerkits/file_extension_hap/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/frameworks/innerkits/file_extension_hap/entry/src/main/resources/base/media/icon.png differ diff --git a/frameworks/innerkits/file_extension_hap/entry/src/main/resources/base/profile/main_pages.json b/frameworks/innerkits/file_extension_hap/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..feec276e105eeb8d621c20aaf838f318b0a94150 --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/index" + ] +} diff --git a/frameworks/innerkits/file_extension_hap/hvigorfile.js b/frameworks/innerkits/file_extension_hap/hvigorfile.js new file mode 100644 index 0000000000000000000000000000000000000000..5f2735e3deeaf655828407544bbed9365c258278 --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/hvigorfile.js @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +module.exports = require('@ohos/hvigor-ohos-plugin').appTasks \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/package-lock.json b/frameworks/innerkits/file_extension_hap/package-lock.json new file mode 100644 index 0000000000000000000000000000000000000000..f88881ba3717724fbad26822b5615718d37a1f03 --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/package-lock.json @@ -0,0 +1,1652 @@ +{ + "name": "FileExtension", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@ohos/hvigor": { + "version": "1.0.6", + "resolved": "https://repo.harmonyos.com/npm/@ohos/hvigor/-/@ohos/hvigor-1.0.6.tgz", + "integrity": "sha512-jjp7vpvUOMW1Nf7TdyhOtonwWHoSyBJLUiZTQqIx/GJV4UJyIqsiURUOqFwncQ4L7PDdeHuWly4uEelknYeWhg==", + "requires": { + "@ohos/hvigor-base": "1.0.6", + "interpret": "1.4.0", + "liftoff": "4.0.0", + "mute-stdout": "1.0.0", + "pretty-hrtime": "1.0.0", + "v8flags": "3.2.0", + "yargs": "7.1.0" + } + }, + "@ohos/hvigor-base": { + "version": "1.0.6", + "resolved": "https://repo.harmonyos.com/npm/@ohos/hvigor-base/-/@ohos/hvigor-base-1.0.6.tgz", + "integrity": "sha512-cRDnWICTxmpNiFb9clIioqP5Oik1seLCICztXVhZqultrHuxwTheCRUZrHwlpyWdkSB2Al+FFBqmSwzIgZX4IQ==", + "requires": { + "json5": "2.2.0", + "log4js": "6.4.1", + "undertaker": "1.2.1" + } + }, + "@ohos/hvigor-ohos-plugin": { + "version": "1.0.6", + "resolved": "https://repo.harmonyos.com/npm/@ohos/hvigor-ohos-plugin/-/@ohos/hvigor-ohos-plugin-1.0.6.tgz", + "integrity": "sha512-MAAi8uJxMzODUoSSNfBr+fU4HQ20dfQtkje9I+X4asc7qY2kAplW/q9f5XS8IOvv8zhC8OcSgsAXOAJuLMstOQ==", + "requires": { + "@ohos/hvigor-base": "1.0.6", + "@ohos/sdkmanager-common": "1.1.3", + "ajv": "8.10.0", + "archiver": "5.3.0", + "execa": "5.1.1", + "fs-extra": "10.0.0", + "glob": "7.2.0", + "iconv-lite": "0.6.3", + "json5": "2.2.0", + "lodash": "4.17.21", + "pretty-hrtime": "1.0.3", + "resolve-package-path": "4.0.3" + }, + "dependencies": { + "fs-extra": { + "version": "10.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/fs-extra/-/fs-extra-10.0.0.tgz", + "integrity": "sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==", + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + } + }, + "pretty-hrtime": { + "version": "1.0.3", + "resolved": "https://repo.huaweicloud.com/repository/npm/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz", + "integrity": "sha1-t+PqQkNaTJsnWdmeDyAesZWALuE=" + } + } + }, + "@ohos/sdkmanager-common": { + "version": "1.1.3", + "resolved": "https://repo.harmonyos.com/npm/@ohos/sdkmanager-common/-/@ohos/sdkmanager-common-1.1.3.tgz", + "integrity": "sha512-d2uhVauDDJZIUvyyaWWoavG4N/jLyfF5IH5kEXKV6R8HNf3606H1zDQzA+UZtOfwwJFXhD9djRjnVFNB8xc7aw==" + }, + "ajv": { + "version": "8.10.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/ajv/-/ajv-8.10.0.tgz", + "integrity": "sha512-bzqAEZOjkrUMl2afH8dknrq5KEk2SrwdBROR+vH1EKVQTqaUbJVPdc/gEdggTMM0Se+s+Ja4ju4TlNcStKl2Hw==", + "requires": { + "fast-deep-equal": "^3.1.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2", + "uri-js": "^4.2.2" + } + }, + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + }, + "archiver": { + "version": "5.3.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/archiver/-/archiver-5.3.0.tgz", + "integrity": "sha512-iUw+oDwK0fgNpvveEsdQ0Ase6IIKztBJU2U0E9MzszMfmVVUyv1QJhS2ITW9ZCqx8dktAxVAjWWkKehuZE8OPg==", + "requires": { + "archiver-utils": "^2.1.0", + "async": "^3.2.0", + "buffer-crc32": "^0.2.1", + "readable-stream": "^3.6.0", + "readdir-glob": "^1.0.0", + "tar-stream": "^2.2.0", + "zip-stream": "^4.1.0" + } + }, + "archiver-utils": { + "version": "2.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/archiver-utils/-/archiver-utils-2.1.0.tgz", + "integrity": "sha512-bEL/yUb/fNNiNTuUz979Z0Yg5L+LzLxGJz8x79lYmR54fmTIb6ob/hNQgkQnIUDWIFjZVQwl9Xs356I6BAMHfw==", + "requires": { + "glob": "^7.1.4", + "graceful-fs": "^4.2.0", + "lazystream": "^1.0.0", + "lodash.defaults": "^4.2.0", + "lodash.difference": "^4.5.0", + "lodash.flatten": "^4.4.0", + "lodash.isplainobject": "^4.0.6", + "lodash.union": "^4.6.0", + "normalize-path": "^3.0.0", + "readable-stream": "^2.0.0" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.7", + "resolved": "https://repo.huaweicloud.com/repository/npm/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + } + } + }, + "arr-filter": { + "version": "1.1.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/arr-filter/-/arr-filter-1.1.2.tgz", + "integrity": "sha1-Q/3d0JHo7xGqTEXZzcGOLf8XEe4=", + "requires": { + "make-iterator": "^1.0.0" + } + }, + "arr-flatten": { + "version": "1.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/arr-flatten/-/arr-flatten-1.1.0.tgz", + "integrity": "sha512-L3hKV5R/p5o81R7O02IGnwpDmkp6E982XhtbuwSe3O4qOtMMMtodicASA1Cny2U+aCXcNpml+m4dPsvsJ3jatg==" + }, + "arr-map": { + "version": "2.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/arr-map/-/arr-map-2.0.2.tgz", + "integrity": "sha1-Onc0X/wc814qkYJWAfnljy4kysQ=", + "requires": { + "make-iterator": "^1.0.0" + } + }, + "array-each": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/array-each/-/array-each-1.0.1.tgz", + "integrity": "sha1-p5SvDAWrF1KEbudTofIRoFugxE8=" + }, + "array-initial": { + "version": "1.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/array-initial/-/array-initial-1.1.0.tgz", + "integrity": "sha1-L6dLJnOTccOUe9enrcc74zSz15U=", + "requires": { + "array-slice": "^1.0.0", + "is-number": "^4.0.0" + } + }, + "array-last": { + "version": "1.3.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/array-last/-/array-last-1.3.0.tgz", + "integrity": "sha512-eOCut5rXlI6aCOS7Z7kCplKRKyiFQ6dHFBem4PwlwKeNFk2/XxTrhRh5T9PyaEWGy/NHTZWbY+nsZlNFJu9rYg==", + "requires": { + "is-number": "^4.0.0" + } + }, + "array-slice": { + "version": "1.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/array-slice/-/array-slice-1.1.0.tgz", + "integrity": "sha512-B1qMD3RBP7O8o0H2KbrXDyB0IccejMF15+87Lvlor12ONPRHP6gTjXMNkt/d3ZuOGbAe66hFmaCfECI24Ufp6w==" + }, + "async": { + "version": "3.2.3", + "resolved": "https://repo.huaweicloud.com/repository/npm/async/-/async-3.2.3.tgz", + "integrity": "sha512-spZRyzKL5l5BZQrr/6m/SqFdBN0q3OCI0f9rjfBzCMBIP4p75P620rR3gTmaksNOhmzgdxcaxdNfMy6anrbM0g==" + }, + "async-done": { + "version": "1.3.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/async-done/-/async-done-1.3.2.tgz", + "integrity": "sha512-uYkTP8dw2og1tu1nmza1n1CMW0qb8gWWlwqMmLb7MhBVs4BXrFziT6HXUd+/RlRA/i4H9AkofYloUbs1fwMqlw==", + "requires": { + "end-of-stream": "^1.1.0", + "once": "^1.3.2", + "process-nextick-args": "^2.0.0", + "stream-exhaust": "^1.0.1" + } + }, + "async-settle": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/async-settle/-/async-settle-1.0.0.tgz", + "integrity": "sha1-HQqRS7Aldb7IqPOnTlCA9yssDGs=", + "requires": { + "async-done": "^1.2.2" + } + }, + "bach": { + "version": "1.2.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/bach/-/bach-1.2.0.tgz", + "integrity": "sha1-Szzpa/JxNPeaG0FKUcFONMO9mIA=", + "requires": { + "arr-filter": "^1.1.1", + "arr-flatten": "^1.0.1", + "arr-map": "^2.0.0", + "array-each": "^1.0.0", + "array-initial": "^1.0.0", + "array-last": "^1.1.1", + "async-done": "^1.2.2", + "async-settle": "^1.0.0", + "now-and-later": "^2.0.0" + } + }, + "balanced-match": { + "version": "1.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + }, + "base64-js": { + "version": "1.5.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==" + }, + "bl": { + "version": "4.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/bl/-/bl-4.1.0.tgz", + "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==", + "requires": { + "buffer": "^5.5.0", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" + } + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://repo.huaweicloud.com/repository/npm/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "braces": { + "version": "3.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "requires": { + "fill-range": "^7.0.1" + } + }, + "buffer": { + "version": "5.7.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/buffer/-/buffer-5.7.1.tgz", + "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", + "requires": { + "base64-js": "^1.3.1", + "ieee754": "^1.1.13" + } + }, + "buffer-crc32": { + "version": "0.2.13", + "resolved": "https://repo.huaweicloud.com/repository/npm/buffer-crc32/-/buffer-crc32-0.2.13.tgz", + "integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=" + }, + "call-bind": { + "version": "1.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/call-bind/-/call-bind-1.0.2.tgz", + "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "requires": { + "function-bind": "^1.1.1", + "get-intrinsic": "^1.0.2" + } + }, + "camelcase": { + "version": "3.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/camelcase/-/camelcase-3.0.0.tgz", + "integrity": "sha1-MvxLn82vhF/N9+c7uXysImHwqwo=" + }, + "cliui": { + "version": "3.2.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/cliui/-/cliui-3.2.0.tgz", + "integrity": "sha1-EgYBU3qRbSmUD5NNo7SNWFo5IT0=", + "requires": { + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1", + "wrap-ansi": "^2.0.0" + } + }, + "code-point-at": { + "version": "1.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/code-point-at/-/code-point-at-1.1.0.tgz", + "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=" + }, + "collection-map": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/collection-map/-/collection-map-1.0.0.tgz", + "integrity": "sha1-rqDwb40mx4DCt1SUOFVEsiVa8Yw=", + "requires": { + "arr-map": "^2.0.2", + "for-own": "^1.0.0", + "make-iterator": "^1.0.0" + } + }, + "compress-commons": { + "version": "4.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/compress-commons/-/compress-commons-4.1.1.tgz", + "integrity": "sha512-QLdDLCKNV2dtoTorqgxngQCMA+gWXkM/Nwu7FpeBhk/RdkzimqC3jueb/FDmaZeXh+uby1jkBqE3xArsLBE5wQ==", + "requires": { + "buffer-crc32": "^0.2.13", + "crc32-stream": "^4.0.2", + "normalize-path": "^3.0.0", + "readable-stream": "^3.6.0" + } + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + }, + "core-util-is": { + "version": "1.0.3", + "resolved": "https://repo.huaweicloud.com/repository/npm/core-util-is/-/core-util-is-1.0.3.tgz", + "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" + }, + "crc-32": { + "version": "1.2.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/crc-32/-/crc-32-1.2.2.tgz", + "integrity": "sha512-ROmzCKrTnOwybPcJApAA6WBWij23HVfGVNKqqrZpuyZOHqK2CwHSvpGuyt/UNNvaIjEd8X5IFGp4Mh+Ie1IHJQ==" + }, + "crc32-stream": { + "version": "4.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/crc32-stream/-/crc32-stream-4.0.2.tgz", + "integrity": "sha512-DxFZ/Hk473b/muq1VJ///PMNLj0ZMnzye9thBpmjpJKCc5eMgB95aK8zCGrGfQ90cWo561Te6HK9D+j4KPdM6w==", + "requires": { + "crc-32": "^1.2.0", + "readable-stream": "^3.4.0" + } + }, + "cross-spawn": { + "version": "7.0.3", + "resolved": "https://repo.huaweicloud.com/repository/npm/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "requires": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "dependencies": { + "which": { + "version": "2.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "requires": { + "isexe": "^2.0.0" + } + } + } + }, + "d": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/d/-/d-1.0.1.tgz", + "integrity": "sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==", + "requires": { + "es5-ext": "^0.10.50", + "type": "^1.0.1" + } + }, + "date-format": { + "version": "4.0.7", + "resolved": "https://repo.huaweicloud.com/repository/npm/date-format/-/date-format-4.0.7.tgz", + "integrity": "sha512-k5xqlzDGIfv2N/DHR/BR8Kc4N9CRy9ReuDkmdxeX/jNfit94QXd36emWMm40ZOEDKNm/c91yV9EO3uGPkR7wWQ==" + }, + "debug": { + "version": "4.3.4", + "resolved": "https://repo.huaweicloud.com/repository/npm/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "requires": { + "ms": "2.1.2" + } + }, + "decamelize": { + "version": "1.2.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=" + }, + "default-resolution": { + "version": "2.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/default-resolution/-/default-resolution-2.0.0.tgz", + "integrity": "sha1-vLgrqnKtebQmp2cy8aga1t8m1oQ=" + }, + "define-properties": { + "version": "1.1.4", + "resolved": "https://repo.huaweicloud.com/repository/npm/define-properties/-/define-properties-1.1.4.tgz", + "integrity": "sha512-uckOqKcfaVvtBdsVkdPv3XjveQJsNQqmhXgRi8uhvWWuPYZCNlzT8qAyblUgNoXdHdjMTzAqeGjAoli8f+bzPA==", + "requires": { + "has-property-descriptors": "^1.0.0", + "object-keys": "^1.1.1" + } + }, + "detect-file": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/detect-file/-/detect-file-1.0.0.tgz", + "integrity": "sha1-8NZtA2cqglyxtzvbP+YjEMjlUrc=" + }, + "end-of-stream": { + "version": "1.4.4", + "resolved": "https://repo.huaweicloud.com/repository/npm/end-of-stream/-/end-of-stream-1.4.4.tgz", + "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", + "requires": { + "once": "^1.4.0" + } + }, + "error-ex": { + "version": "1.3.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/error-ex/-/error-ex-1.3.2.tgz", + "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", + "requires": { + "is-arrayish": "^0.2.1" + } + }, + "es5-ext": { + "version": "0.10.61", + "resolved": "https://repo.huaweicloud.com/repository/npm/es5-ext/-/es5-ext-0.10.61.tgz", + "integrity": "sha512-yFhIqQAzu2Ca2I4SE2Au3rxVfmohU9Y7wqGR+s7+H7krk26NXhIRAZDgqd6xqjCEFUomDEA3/Bo/7fKmIkW1kA==", + "requires": { + "es6-iterator": "^2.0.3", + "es6-symbol": "^3.1.3", + "next-tick": "^1.1.0" + } + }, + "es6-iterator": { + "version": "2.0.3", + "resolved": "https://repo.huaweicloud.com/repository/npm/es6-iterator/-/es6-iterator-2.0.3.tgz", + "integrity": "sha1-p96IkUGgWpSwhUQDstCg+/qY87c=", + "requires": { + "d": "1", + "es5-ext": "^0.10.35", + "es6-symbol": "^3.1.1" + } + }, + "es6-symbol": { + "version": "3.1.3", + "resolved": "https://repo.huaweicloud.com/repository/npm/es6-symbol/-/es6-symbol-3.1.3.tgz", + "integrity": "sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==", + "requires": { + "d": "^1.0.1", + "ext": "^1.1.2" + } + }, + "es6-weak-map": { + "version": "2.0.3", + "resolved": "https://repo.huaweicloud.com/repository/npm/es6-weak-map/-/es6-weak-map-2.0.3.tgz", + "integrity": "sha512-p5um32HOTO1kP+w7PRnB+5lQ43Z6muuMuIMffvDN8ZB4GcnjLBV6zGStpbASIMk4DCAvEaamhe2zhyCb/QXXsA==", + "requires": { + "d": "1", + "es5-ext": "^0.10.46", + "es6-iterator": "^2.0.3", + "es6-symbol": "^3.1.1" + } + }, + "execa": { + "version": "5.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/execa/-/execa-5.1.1.tgz", + "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", + "requires": { + "cross-spawn": "^7.0.3", + "get-stream": "^6.0.0", + "human-signals": "^2.1.0", + "is-stream": "^2.0.0", + "merge-stream": "^2.0.0", + "npm-run-path": "^4.0.1", + "onetime": "^5.1.2", + "signal-exit": "^3.0.3", + "strip-final-newline": "^2.0.0" + } + }, + "expand-tilde": { + "version": "2.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/expand-tilde/-/expand-tilde-2.0.2.tgz", + "integrity": "sha1-l+gBqgUt8CRU3kawK/YhZCzchQI=", + "requires": { + "homedir-polyfill": "^1.0.1" + } + }, + "ext": { + "version": "1.6.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/ext/-/ext-1.6.0.tgz", + "integrity": "sha512-sdBImtzkq2HpkdRLtlLWDa6w4DX22ijZLKx8BMPUuKe1c5lbN6xwQDQCxSfxBQnHZ13ls/FH0MQZx/q/gr6FQg==", + "requires": { + "type": "^2.5.0" + }, + "dependencies": { + "type": { + "version": "2.6.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/type/-/type-2.6.0.tgz", + "integrity": "sha512-eiDBDOmkih5pMbo9OqsqPRGMljLodLcwd5XD5JbtNB0o89xZAwynY9EdCDsJU7LtcVCClu9DvM7/0Ep1hYX3EQ==" + } + } + }, + "extend": { + "version": "3.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/extend/-/extend-3.0.2.tgz", + "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==" + }, + "fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://repo.huaweicloud.com/repository/npm/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" + }, + "fill-range": { + "version": "7.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "requires": { + "to-regex-range": "^5.0.1" + } + }, + "find-up": { + "version": "1.1.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/find-up/-/find-up-1.1.2.tgz", + "integrity": "sha1-ay6YIrGizgpgq2TWEOzK1TyyTQ8=", + "requires": { + "path-exists": "^2.0.0", + "pinkie-promise": "^2.0.0" + } + }, + "findup-sync": { + "version": "5.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/findup-sync/-/findup-sync-5.0.0.tgz", + "integrity": "sha512-MzwXju70AuyflbgeOhzvQWAvvQdo1XL0A9bVvlXsYcFEBM87WR4OakL4OfZq+QRmr+duJubio+UtNQCPsVESzQ==", + "requires": { + "detect-file": "^1.0.0", + "is-glob": "^4.0.3", + "micromatch": "^4.0.4", + "resolve-dir": "^1.0.1" + } + }, + "fined": { + "version": "2.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/fined/-/fined-2.0.0.tgz", + "integrity": "sha512-OFRzsL6ZMHz5s0JrsEr+TpdGNCtrVtnuG3x1yzGNiQHT0yaDnXAj8V/lWcpJVrnoDpcwXcASxAZYbuXda2Y82A==", + "requires": { + "expand-tilde": "^2.0.2", + "is-plain-object": "^5.0.0", + "object.defaults": "^1.1.0", + "object.pick": "^1.3.0", + "parse-filepath": "^1.0.2" + } + }, + "flagged-respawn": { + "version": "2.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/flagged-respawn/-/flagged-respawn-2.0.0.tgz", + "integrity": "sha512-Gq/a6YCi8zexmGHMuJwahTGzXlAZAOsbCVKduWXC6TlLCjjFRlExMJc4GC2NYPYZ0r/brw9P7CpRgQmlPVeOoA==" + }, + "flatted": { + "version": "3.2.5", + "resolved": "https://repo.huaweicloud.com/repository/npm/flatted/-/flatted-3.2.5.tgz", + "integrity": "sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==" + }, + "for-in": { + "version": "1.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/for-in/-/for-in-1.0.2.tgz", + "integrity": "sha1-gQaNKVqBQuwKxybG4iAMMPttXoA=" + }, + "for-own": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/for-own/-/for-own-1.0.0.tgz", + "integrity": "sha1-xjMy9BXO3EsE2/5wz4NklMU8tEs=", + "requires": { + "for-in": "^1.0.1" + } + }, + "fs-constants": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/fs-constants/-/fs-constants-1.0.0.tgz", + "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==" + }, + "fs-extra": { + "version": "10.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/fs-extra/-/fs-extra-10.1.0.tgz", + "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", + "requires": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + } + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + }, + "function-bind": { + "version": "1.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + }, + "get-caller-file": { + "version": "1.0.3", + "resolved": "https://repo.huaweicloud.com/repository/npm/get-caller-file/-/get-caller-file-1.0.3.tgz", + "integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==" + }, + "get-intrinsic": { + "version": "1.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/get-intrinsic/-/get-intrinsic-1.1.1.tgz", + "integrity": "sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==", + "requires": { + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1" + } + }, + "get-stream": { + "version": "6.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/get-stream/-/get-stream-6.0.1.tgz", + "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==" + }, + "glob": { + "version": "7.2.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/glob/-/glob-7.2.0.tgz", + "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "global-modules": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/global-modules/-/global-modules-1.0.0.tgz", + "integrity": "sha512-sKzpEkf11GpOFuw0Zzjzmt4B4UZwjOcG757PPvrfhxcLFbq0wpsgpOqxpxtxFiCG4DtG93M6XRVbF2oGdev7bg==", + "requires": { + "global-prefix": "^1.0.1", + "is-windows": "^1.0.1", + "resolve-dir": "^1.0.0" + } + }, + "global-prefix": { + "version": "1.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/global-prefix/-/global-prefix-1.0.2.tgz", + "integrity": "sha1-2/dDxsFJklk8ZVVoy2btMsASLr4=", + "requires": { + "expand-tilde": "^2.0.2", + "homedir-polyfill": "^1.0.1", + "ini": "^1.3.4", + "is-windows": "^1.0.1", + "which": "^1.2.14" + } + }, + "graceful-fs": { + "version": "4.2.10", + "resolved": "https://repo.huaweicloud.com/repository/npm/graceful-fs/-/graceful-fs-4.2.10.tgz", + "integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==" + }, + "has": { + "version": "1.0.3", + "resolved": "https://repo.huaweicloud.com/repository/npm/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "requires": { + "function-bind": "^1.1.1" + } + }, + "has-property-descriptors": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/has-property-descriptors/-/has-property-descriptors-1.0.0.tgz", + "integrity": "sha512-62DVLZGoiEBDHQyqG4w9xCuZ7eJEwNmJRWw2VY84Oedb7WFcA27fiEVe8oUQx9hAUJ4ekurquucTGwsyO1XGdQ==", + "requires": { + "get-intrinsic": "^1.1.1" + } + }, + "has-symbols": { + "version": "1.0.3", + "resolved": "https://repo.huaweicloud.com/repository/npm/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==" + }, + "homedir-polyfill": { + "version": "1.0.3", + "resolved": "https://repo.huaweicloud.com/repository/npm/homedir-polyfill/-/homedir-polyfill-1.0.3.tgz", + "integrity": "sha512-eSmmWE5bZTK2Nou4g0AI3zZ9rswp7GRKoKXS1BLUkvPviOqs4YTN1djQIqrXy9k5gEtdLPy86JjRwsNM9tnDcA==", + "requires": { + "parse-passwd": "^1.0.0" + } + }, + "hosted-git-info": { + "version": "2.8.9", + "resolved": "https://repo.huaweicloud.com/repository/npm/hosted-git-info/-/hosted-git-info-2.8.9.tgz", + "integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==" + }, + "human-signals": { + "version": "2.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/human-signals/-/human-signals-2.1.0.tgz", + "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==" + }, + "hypium": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/hypium/-/hypium-1.0.0.tgz", + "integrity": "sha512-nl+RQVv2AU/5FvFRhsXyWO5wh+2huhdqRZ3bszBWZzW+kpNI3AT4ydvVRYIfaQbYwV4UlX/rSc7BtFjLAezhow==" + }, + "iconv-lite": { + "version": "0.6.3", + "resolved": "https://repo.huaweicloud.com/repository/npm/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "requires": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + } + }, + "ieee754": { + "version": "1.2.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==" + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://repo.huaweicloud.com/repository/npm/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://repo.huaweicloud.com/repository/npm/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "ini": { + "version": "1.3.8", + "resolved": "https://repo.huaweicloud.com/repository/npm/ini/-/ini-1.3.8.tgz", + "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==" + }, + "interpret": { + "version": "1.4.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/interpret/-/interpret-1.4.0.tgz", + "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==" + }, + "invert-kv": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/invert-kv/-/invert-kv-1.0.0.tgz", + "integrity": "sha1-EEqOSqym09jNFXqO+L+rLXo//bY=" + }, + "is-absolute": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-absolute/-/is-absolute-1.0.0.tgz", + "integrity": "sha512-dOWoqflvcydARa360Gvv18DZ/gRuHKi2NU/wU5X1ZFzdYfH29nkiNZsF3mp4OJ3H4yo9Mx8A/uAGNzpzPN3yBA==", + "requires": { + "is-relative": "^1.0.0", + "is-windows": "^1.0.1" + } + }, + "is-arrayish": { + "version": "0.2.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-arrayish/-/is-arrayish-0.2.1.tgz", + "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=" + }, + "is-core-module": { + "version": "2.9.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-core-module/-/is-core-module-2.9.0.tgz", + "integrity": "sha512-+5FPy5PnwmO3lvfMb0AsoPaBG+5KHUI0wYFXOtYPnVVVspTFUuMZNfNaNVRt3FZadstu2c8x23vykRW/NBoU6A==", + "requires": { + "has": "^1.0.3" + } + }, + "is-extglob": { + "version": "2.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=" + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", + "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", + "requires": { + "number-is-nan": "^1.0.0" + } + }, + "is-glob": { + "version": "4.0.3", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "requires": { + "is-extglob": "^2.1.1" + } + }, + "is-number": { + "version": "4.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-number/-/is-number-4.0.0.tgz", + "integrity": "sha512-rSklcAIlf1OmFdyAqbnWTLVelsQ58uvZ66S/ZyawjWqIviTWCjg2PzVGw8WUA+nNuPTqb4wgA+NszrJ+08LlgQ==" + }, + "is-plain-object": { + "version": "5.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-plain-object/-/is-plain-object-5.0.0.tgz", + "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==" + }, + "is-relative": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-relative/-/is-relative-1.0.0.tgz", + "integrity": "sha512-Kw/ReK0iqwKeu0MITLFuj0jbPAmEiOsIwyIXvvbfa6QfmN9pkD1M+8pdk7Rl/dTKbH34/XBFMbgD4iMJhLQbGA==", + "requires": { + "is-unc-path": "^1.0.0" + } + }, + "is-stream": { + "version": "2.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-stream/-/is-stream-2.0.1.tgz", + "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==" + }, + "is-unc-path": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-unc-path/-/is-unc-path-1.0.0.tgz", + "integrity": "sha512-mrGpVd0fs7WWLfVsStvgF6iEJnbjDFZh9/emhRDcGWTduTfNHd9CHeUwH3gYIjdbwo4On6hunkztwOaAw0yllQ==", + "requires": { + "unc-path-regex": "^0.1.2" + } + }, + "is-utf8": { + "version": "0.2.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-utf8/-/is-utf8-0.2.1.tgz", + "integrity": "sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI=" + }, + "is-windows": { + "version": "1.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-windows/-/is-windows-1.0.2.tgz", + "integrity": "sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==" + }, + "isarray": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" + }, + "isexe": { + "version": "2.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" + }, + "isobject": { + "version": "3.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=" + }, + "json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" + }, + "json5": { + "version": "2.2.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/json5/-/json5-2.2.0.tgz", + "integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==", + "requires": { + "minimist": "^1.2.5" + } + }, + "jsonfile": { + "version": "6.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "requires": { + "graceful-fs": "^4.1.6", + "universalify": "^2.0.0" + } + }, + "kind-of": { + "version": "6.0.3", + "resolved": "https://repo.huaweicloud.com/repository/npm/kind-of/-/kind-of-6.0.3.tgz", + "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==" + }, + "last-run": { + "version": "1.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/last-run/-/last-run-1.1.1.tgz", + "integrity": "sha1-RblpQsF7HHnHchmCWbqUO+v4yls=", + "requires": { + "default-resolution": "^2.0.0", + "es6-weak-map": "^2.0.1" + } + }, + "lazystream": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/lazystream/-/lazystream-1.0.1.tgz", + "integrity": "sha512-b94GiNHQNy6JNTrt5w6zNyffMrNkXZb3KTkCZJb2V1xaEGCk093vkZ2jk3tpaeP33/OiXC+WvK9AxUebnf5nbw==", + "requires": { + "readable-stream": "^2.0.5" + }, + "dependencies": { + "readable-stream": { + "version": "2.3.7", + "resolved": "https://repo.huaweicloud.com/repository/npm/readable-stream/-/readable-stream-2.3.7.tgz", + "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + } + } + }, + "lcid": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/lcid/-/lcid-1.0.0.tgz", + "integrity": "sha1-MIrMr6C8SDo4Z7S28rlQYlHRuDU=", + "requires": { + "invert-kv": "^1.0.0" + } + }, + "liftoff": { + "version": "4.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/liftoff/-/liftoff-4.0.0.tgz", + "integrity": "sha512-rMGwYF8q7g2XhG2ulBmmJgWv25qBsqRbDn5gH0+wnuyeFt7QBJlHJmtg5qEdn4pN6WVAUMgXnIxytMFRX9c1aA==", + "requires": { + "extend": "^3.0.2", + "findup-sync": "^5.0.0", + "fined": "^2.0.0", + "flagged-respawn": "^2.0.0", + "is-plain-object": "^5.0.0", + "object.map": "^1.0.1", + "rechoir": "^0.8.0", + "resolve": "^1.20.0" + } + }, + "load-json-file": { + "version": "1.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/load-json-file/-/load-json-file-1.1.0.tgz", + "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=", + "requires": { + "graceful-fs": "^4.1.2", + "parse-json": "^2.2.0", + "pify": "^2.0.0", + "pinkie-promise": "^2.0.0", + "strip-bom": "^2.0.0" + } + }, + "lodash": { + "version": "4.17.21", + "resolved": "https://repo.huaweicloud.com/repository/npm/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, + "lodash.defaults": { + "version": "4.2.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/lodash.defaults/-/lodash.defaults-4.2.0.tgz", + "integrity": "sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw=" + }, + "lodash.difference": { + "version": "4.5.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/lodash.difference/-/lodash.difference-4.5.0.tgz", + "integrity": "sha1-nMtOUF1Ia5FlE0V3KIWi3yf9AXw=" + }, + "lodash.flatten": { + "version": "4.4.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/lodash.flatten/-/lodash.flatten-4.4.0.tgz", + "integrity": "sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8=" + }, + "lodash.isplainobject": { + "version": "4.0.6", + "resolved": "https://repo.huaweicloud.com/repository/npm/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", + "integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=" + }, + "lodash.union": { + "version": "4.6.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/lodash.union/-/lodash.union-4.6.0.tgz", + "integrity": "sha1-SLtQiECfFvGCFmZkHETdGqrjzYg=" + }, + "log4js": { + "version": "6.4.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/log4js/-/log4js-6.4.1.tgz", + "integrity": "sha512-iUiYnXqAmNKiIZ1XSAitQ4TmNs8CdZYTAWINARF3LjnsLN8tY5m0vRwd6uuWj/yNY0YHxeZodnbmxKFUOM2rMg==", + "requires": { + "date-format": "^4.0.3", + "debug": "^4.3.3", + "flatted": "^3.2.4", + "rfdc": "^1.3.0", + "streamroller": "^3.0.2" + } + }, + "make-iterator": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/make-iterator/-/make-iterator-1.0.1.tgz", + "integrity": "sha512-pxiuXh0iVEq7VM7KMIhs5gxsfxCux2URptUQaXo4iZZJxBAzTPOLE2BumO5dbfVYq/hBJFBR/a1mFDmOx5AGmw==", + "requires": { + "kind-of": "^6.0.2" + } + }, + "map-cache": { + "version": "0.2.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/map-cache/-/map-cache-0.2.2.tgz", + "integrity": "sha1-wyq9C9ZSXZsFFkW7TyasXcmKDb8=" + }, + "merge-stream": { + "version": "2.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/merge-stream/-/merge-stream-2.0.0.tgz", + "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==" + }, + "micromatch": { + "version": "4.0.5", + "resolved": "https://repo.huaweicloud.com/repository/npm/micromatch/-/micromatch-4.0.5.tgz", + "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "requires": { + "braces": "^3.0.2", + "picomatch": "^2.3.1" + } + }, + "mimic-fn": { + "version": "2.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/mimic-fn/-/mimic-fn-2.1.0.tgz", + "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==" + }, + "minimatch": { + "version": "3.1.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "requires": { + "brace-expansion": "^1.1.7" + } + }, + "minimist": { + "version": "1.2.6", + "resolved": "https://repo.huaweicloud.com/repository/npm/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==" + }, + "ms": { + "version": "2.1.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, + "mute-stdout": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/mute-stdout/-/mute-stdout-1.0.0.tgz", + "integrity": "sha1-WzLqB+tDyd7WEwQ0z5JvRrKn/U0=" + }, + "next-tick": { + "version": "1.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/next-tick/-/next-tick-1.1.0.tgz", + "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" + }, + "normalize-package-data": { + "version": "2.5.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/normalize-package-data/-/normalize-package-data-2.5.0.tgz", + "integrity": "sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==", + "requires": { + "hosted-git-info": "^2.1.4", + "resolve": "^1.10.0", + "semver": "2 || 3 || 4 || 5", + "validate-npm-package-license": "^3.0.1" + } + }, + "normalize-path": { + "version": "3.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==" + }, + "now-and-later": { + "version": "2.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/now-and-later/-/now-and-later-2.0.1.tgz", + "integrity": "sha512-KGvQ0cB70AQfg107Xvs/Fbu+dGmZoTRJp2TaPwcwQm3/7PteUyN2BCgk8KBMPGBUXZdVwyWS8fDCGFygBm19UQ==", + "requires": { + "once": "^1.3.2" + } + }, + "npm-run-path": { + "version": "4.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/npm-run-path/-/npm-run-path-4.0.1.tgz", + "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", + "requires": { + "path-key": "^3.0.0" + } + }, + "number-is-nan": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/number-is-nan/-/number-is-nan-1.0.1.tgz", + "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" + }, + "object-keys": { + "version": "1.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/object-keys/-/object-keys-1.1.1.tgz", + "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==" + }, + "object.assign": { + "version": "4.1.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/object.assign/-/object.assign-4.1.2.tgz", + "integrity": "sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ==", + "requires": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3", + "has-symbols": "^1.0.1", + "object-keys": "^1.1.1" + } + }, + "object.defaults": { + "version": "1.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/object.defaults/-/object.defaults-1.1.0.tgz", + "integrity": "sha1-On+GgzS0B96gbaFtiNXNKeQ1/s8=", + "requires": { + "array-each": "^1.0.1", + "array-slice": "^1.0.0", + "for-own": "^1.0.0", + "isobject": "^3.0.0" + } + }, + "object.map": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/object.map/-/object.map-1.0.1.tgz", + "integrity": "sha1-z4Plncj8wK1fQlDh94s7gb2AHTc=", + "requires": { + "for-own": "^1.0.0", + "make-iterator": "^1.0.0" + } + }, + "object.pick": { + "version": "1.3.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/object.pick/-/object.pick-1.3.0.tgz", + "integrity": "sha1-h6EKxMFpS9Lhy/U1kaZhQftd10c=", + "requires": { + "isobject": "^3.0.1" + } + }, + "object.reduce": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/object.reduce/-/object.reduce-1.0.1.tgz", + "integrity": "sha1-b+NI8qx/oPlcpiEiZZkJaCW7A60=", + "requires": { + "for-own": "^1.0.0", + "make-iterator": "^1.0.0" + } + }, + "once": { + "version": "1.4.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "1" + } + }, + "onetime": { + "version": "5.1.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/onetime/-/onetime-5.1.2.tgz", + "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", + "requires": { + "mimic-fn": "^2.1.0" + } + }, + "os-locale": { + "version": "1.4.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/os-locale/-/os-locale-1.4.0.tgz", + "integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=", + "requires": { + "lcid": "^1.0.0" + } + }, + "parse-filepath": { + "version": "1.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/parse-filepath/-/parse-filepath-1.0.2.tgz", + "integrity": "sha1-pjISf1Oq89FYdvWHLz/6x2PWyJE=", + "requires": { + "is-absolute": "^1.0.0", + "map-cache": "^0.2.0", + "path-root": "^0.1.1" + } + }, + "parse-json": { + "version": "2.2.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/parse-json/-/parse-json-2.2.0.tgz", + "integrity": "sha1-9ID0BDTvgHQfhGkJn43qGPVaTck=", + "requires": { + "error-ex": "^1.2.0" + } + }, + "parse-passwd": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/parse-passwd/-/parse-passwd-1.0.0.tgz", + "integrity": "sha1-bVuTSkVpk7I9N/QKOC1vFmao5cY=" + }, + "path-exists": { + "version": "2.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/path-exists/-/path-exists-2.1.0.tgz", + "integrity": "sha1-D+tsZPD8UY2adU3V77YscCJ2H0s=", + "requires": { + "pinkie-promise": "^2.0.0" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + }, + "path-key": { + "version": "3.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==" + }, + "path-parse": { + "version": "1.0.7", + "resolved": "https://repo.huaweicloud.com/repository/npm/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" + }, + "path-root": { + "version": "0.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/path-root/-/path-root-0.1.1.tgz", + "integrity": "sha1-mkpoFMrBwM1zNgqV8yCDyOpHRbc=", + "requires": { + "path-root-regex": "^0.1.0" + } + }, + "path-root-regex": { + "version": "0.1.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/path-root-regex/-/path-root-regex-0.1.2.tgz", + "integrity": "sha1-v8zcjfWxLcUsi0PsONGNcsBLqW0=" + }, + "path-type": { + "version": "1.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/path-type/-/path-type-1.1.0.tgz", + "integrity": "sha1-WcRPfuSR2nBNpBXaWkBwuk+P5EE=", + "requires": { + "graceful-fs": "^4.1.2", + "pify": "^2.0.0", + "pinkie-promise": "^2.0.0" + } + }, + "picomatch": { + "version": "2.3.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==" + }, + "pify": { + "version": "2.3.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/pify/-/pify-2.3.0.tgz", + "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=" + }, + "pinkie": { + "version": "2.0.4", + "resolved": "https://repo.huaweicloud.com/repository/npm/pinkie/-/pinkie-2.0.4.tgz", + "integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA=" + }, + "pinkie-promise": { + "version": "2.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/pinkie-promise/-/pinkie-promise-2.0.1.tgz", + "integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=", + "requires": { + "pinkie": "^2.0.0" + } + }, + "pretty-hrtime": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/pretty-hrtime/-/pretty-hrtime-1.0.0.tgz", + "integrity": "sha1-9ualItPmBwRSK/Db5oVu0g515Nw=" + }, + "process-nextick-args": { + "version": "2.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/process-nextick-args/-/process-nextick-args-2.0.1.tgz", + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" + }, + "punycode": { + "version": "2.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/punycode/-/punycode-2.1.1.tgz", + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" + }, + "read-pkg": { + "version": "1.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/read-pkg/-/read-pkg-1.1.0.tgz", + "integrity": "sha1-9f+qXs0pyzHAR0vKfXVra7KePyg=", + "requires": { + "load-json-file": "^1.0.0", + "normalize-package-data": "^2.3.2", + "path-type": "^1.0.0" + } + }, + "read-pkg-up": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/read-pkg-up/-/read-pkg-up-1.0.1.tgz", + "integrity": "sha1-nWPBMnbAZZGNV/ACpX9AobZD+wI=", + "requires": { + "find-up": "^1.0.0", + "read-pkg": "^1.0.0" + } + }, + "readable-stream": { + "version": "3.6.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + }, + "readdir-glob": { + "version": "1.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/readdir-glob/-/readdir-glob-1.1.1.tgz", + "integrity": "sha512-91/k1EzZwDx6HbERR+zucygRFfiPl2zkIYZtv3Jjr6Mn7SkKcVct8aVO+sSRiGMc6fLf72du3d92/uY63YPdEA==", + "requires": { + "minimatch": "^3.0.4" + } + }, + "rechoir": { + "version": "0.8.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/rechoir/-/rechoir-0.8.0.tgz", + "integrity": "sha512-/vxpCXddiX8NGfGO/mTafwjq4aFa/71pvamip0++IQk3zG8cbCj0fifNPrjjF1XMXUne91jL9OoxmdykoEtifQ==", + "requires": { + "resolve": "^1.20.0" + } + }, + "require-directory": { + "version": "2.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=" + }, + "require-from-string": { + "version": "2.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==" + }, + "require-main-filename": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/require-main-filename/-/require-main-filename-1.0.1.tgz", + "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=" + }, + "resolve": { + "version": "1.22.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/resolve/-/resolve-1.22.0.tgz", + "integrity": "sha512-Hhtrw0nLeSrFQ7phPp4OOcVjLPIeMnRlr5mcnVuMe7M/7eBn98A3hmFRLoFo3DLZkivSYwhRUJTyPyWAk56WLw==", + "requires": { + "is-core-module": "^2.8.1", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + } + }, + "resolve-dir": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/resolve-dir/-/resolve-dir-1.0.1.tgz", + "integrity": "sha1-eaQGRMNivoLybv/nOcm7U4IEb0M=", + "requires": { + "expand-tilde": "^2.0.0", + "global-modules": "^1.0.0" + } + }, + "resolve-package-path": { + "version": "4.0.3", + "resolved": "https://repo.huaweicloud.com/repository/npm/resolve-package-path/-/resolve-package-path-4.0.3.tgz", + "integrity": "sha512-SRpNAPW4kewOaNUt8VPqhJ0UMxawMwzJD8V7m1cJfdSTK9ieZwS6K7Dabsm4bmLFM96Z5Y/UznrpG5kt1im8yA==", + "requires": { + "path-root": "^0.1.1" + } + }, + "rfdc": { + "version": "1.3.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/rfdc/-/rfdc-1.3.0.tgz", + "integrity": "sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA==" + }, + "safe-buffer": { + "version": "5.1.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, + "semver": { + "version": "5.7.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" + }, + "set-blocking": { + "version": "2.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" + }, + "shebang-command": { + "version": "2.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "requires": { + "shebang-regex": "^3.0.0" + } + }, + "shebang-regex": { + "version": "3.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==" + }, + "signal-exit": { + "version": "3.0.7", + "resolved": "https://repo.huaweicloud.com/repository/npm/signal-exit/-/signal-exit-3.0.7.tgz", + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" + }, + "spdx-correct": { + "version": "3.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/spdx-correct/-/spdx-correct-3.1.1.tgz", + "integrity": "sha512-cOYcUWwhCuHCXi49RhFRCyJEK3iPj1Ziz9DpViV3tbZOwXD49QzIN3MpOLJNxh2qwq2lJJZaKMVw9qNi4jTC0w==", + "requires": { + "spdx-expression-parse": "^3.0.0", + "spdx-license-ids": "^3.0.0" + } + }, + "spdx-exceptions": { + "version": "2.3.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/spdx-exceptions/-/spdx-exceptions-2.3.0.tgz", + "integrity": "sha512-/tTrYOC7PPI1nUAgx34hUpqXuyJG+DTHJTnIULG4rDygi4xu/tfgmq1e1cIRwRzwZgo4NLySi+ricLkZkw4i5A==" + }, + "spdx-expression-parse": { + "version": "3.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/spdx-expression-parse/-/spdx-expression-parse-3.0.1.tgz", + "integrity": "sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q==", + "requires": { + "spdx-exceptions": "^2.1.0", + "spdx-license-ids": "^3.0.0" + } + }, + "spdx-license-ids": { + "version": "3.0.11", + "resolved": "https://repo.huaweicloud.com/repository/npm/spdx-license-ids/-/spdx-license-ids-3.0.11.tgz", + "integrity": "sha512-Ctl2BrFiM0X3MANYgj3CkygxhRmr9mi6xhejbdO960nF6EDJApTYpn0BQnDKlnNBULKiCN1n3w9EBkHK8ZWg+g==" + }, + "stream-exhaust": { + "version": "1.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/stream-exhaust/-/stream-exhaust-1.0.2.tgz", + "integrity": "sha512-b/qaq/GlBK5xaq1yrK9/zFcyRSTNxmcZwFLGSTG0mXgZl/4Z6GgiyYOXOvY7N3eEvFRAG1bkDRz5EPGSvPYQlw==" + }, + "streamroller": { + "version": "3.0.7", + "resolved": "https://repo.huaweicloud.com/repository/npm/streamroller/-/streamroller-3.0.7.tgz", + "integrity": "sha512-kh68kwiDGuIPiPDWwRbEC5us+kfARP1e9AsQiaLaSqGrctOvMn0mtL8iNY3r4/o5nIoYi3gPI1jexguZsXDlxw==", + "requires": { + "date-format": "^4.0.7", + "debug": "^4.3.4", + "fs-extra": "^10.0.1" + } + }, + "string-width": { + "version": "1.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/string-width/-/string-width-1.0.2.tgz", + "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", + "requires": { + "code-point-at": "^1.0.0", + "is-fullwidth-code-point": "^1.0.0", + "strip-ansi": "^3.0.0" + } + }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "requires": { + "safe-buffer": "~5.1.0" + } + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "strip-bom": { + "version": "2.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/strip-bom/-/strip-bom-2.0.0.tgz", + "integrity": "sha1-YhmoVhZSBJHzV4i9vxRHqZx+aw4=", + "requires": { + "is-utf8": "^0.2.0" + } + }, + "strip-final-newline": { + "version": "2.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/strip-final-newline/-/strip-final-newline-2.0.0.tgz", + "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==" + }, + "supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==" + }, + "tar-stream": { + "version": "2.2.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/tar-stream/-/tar-stream-2.2.0.tgz", + "integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==", + "requires": { + "bl": "^4.0.3", + "end-of-stream": "^1.4.1", + "fs-constants": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^3.1.1" + } + }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "requires": { + "is-number": "^7.0.0" + }, + "dependencies": { + "is-number": { + "version": "7.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==" + } + } + }, + "type": { + "version": "1.2.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/type/-/type-1.2.0.tgz", + "integrity": "sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==" + }, + "unc-path-regex": { + "version": "0.1.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/unc-path-regex/-/unc-path-regex-0.1.2.tgz", + "integrity": "sha1-5z3T17DXxe2G+6xrCufYxqadUPo=" + }, + "undertaker": { + "version": "1.2.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/undertaker/-/undertaker-1.2.1.tgz", + "integrity": "sha512-71WxIzDkgYk9ZS+spIB8iZXchFhAdEo2YU8xYqBYJ39DIUIqziK78ftm26eecoIY49X0J2MLhG4hr18Yp6/CMA==", + "requires": { + "arr-flatten": "^1.0.1", + "arr-map": "^2.0.0", + "bach": "^1.0.0", + "collection-map": "^1.0.0", + "es6-weak-map": "^2.0.1", + "last-run": "^1.1.0", + "object.defaults": "^1.0.0", + "object.reduce": "^1.0.0", + "undertaker-registry": "^1.0.0" + } + }, + "undertaker-registry": { + "version": "1.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/undertaker-registry/-/undertaker-registry-1.0.1.tgz", + "integrity": "sha1-XkvaMI5KiirlhPm5pDWaSZglzFA=" + }, + "universalify": { + "version": "2.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==" + }, + "uri-js": { + "version": "4.4.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/uri-js/-/uri-js-4.4.1.tgz", + "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", + "requires": { + "punycode": "^2.1.0" + } + }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + }, + "v8flags": { + "version": "3.2.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/v8flags/-/v8flags-3.2.0.tgz", + "integrity": "sha512-mH8etigqMfiGWdeXpaaqGfs6BndypxusHHcv2qSHyZkGEznCd/qAXCWWRzeowtL54147cktFOC4P5y+kl8d8Jg==", + "requires": { + "homedir-polyfill": "^1.0.1" + } + }, + "validate-npm-package-license": { + "version": "3.0.4", + "resolved": "https://repo.huaweicloud.com/repository/npm/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", + "integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==", + "requires": { + "spdx-correct": "^3.0.0", + "spdx-expression-parse": "^3.0.0" + } + }, + "which": { + "version": "1.3.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/which/-/which-1.3.1.tgz", + "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", + "requires": { + "isexe": "^2.0.0" + } + }, + "which-module": { + "version": "1.0.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/which-module/-/which-module-1.0.0.tgz", + "integrity": "sha1-u6Y8qGGUiZT/MHc2CJ47lgJsKk8=" + }, + "wrap-ansi": { + "version": "2.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/wrap-ansi/-/wrap-ansi-2.1.0.tgz", + "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", + "requires": { + "string-width": "^1.0.1", + "strip-ansi": "^3.0.1" + } + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + }, + "y18n": { + "version": "3.2.2", + "resolved": "https://repo.huaweicloud.com/repository/npm/y18n/-/y18n-3.2.2.tgz", + "integrity": "sha512-uGZHXkHnhF0XeeAPgnKfPv1bgKAYyVvmNL1xlKsPYZPaIHxGti2hHqvOCQv71XMsLxu1QjergkqogUnms5D3YQ==" + }, + "yargs": { + "version": "7.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/yargs/-/yargs-7.1.0.tgz", + "integrity": "sha1-a6MY6xaWFyf10oT46gA+jWFU0Mg=", + "requires": { + "camelcase": "^3.0.0", + "cliui": "^3.2.0", + "decamelize": "^1.1.1", + "get-caller-file": "^1.0.1", + "os-locale": "^1.4.0", + "read-pkg-up": "^1.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^1.0.1", + "set-blocking": "^2.0.0", + "string-width": "^1.0.2", + "which-module": "^1.0.0", + "y18n": "^3.2.1", + "yargs-parser": "^5.0.0" + } + }, + "yargs-parser": { + "version": "5.0.1", + "resolved": "https://repo.huaweicloud.com/repository/npm/yargs-parser/-/yargs-parser-5.0.1.tgz", + "integrity": "sha512-wpav5XYiddjXxirPoCTUPbqM0PXvJ9hiBMvuJgInvo4/lAOTZzUprArw17q2O1P2+GHhbBr18/iQwjL5Z9BqfA==", + "requires": { + "camelcase": "^3.0.0", + "object.assign": "^4.1.0" + } + }, + "zip-stream": { + "version": "4.1.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/zip-stream/-/zip-stream-4.1.0.tgz", + "integrity": "sha512-zshzwQW7gG7hjpBlgeQP9RuyPGNxvJdzR8SUM3QhxCnLjWN2E7j3dOvpeDcQoETfHx0urRS7EtmVToql7YpU4A==", + "requires": { + "archiver-utils": "^2.1.0", + "compress-commons": "^4.1.0", + "readable-stream": "^3.6.0" + } + } + } +} diff --git a/frameworks/innerkits/file_extension_hap/package.json b/frameworks/innerkits/file_extension_hap/package.json new file mode 100644 index 0000000000000000000000000000000000000000..15be3afb1043ac71fba88cd603817b8cb9bbe2b7 --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/package.json @@ -0,0 +1,18 @@ +{ + "license":"ISC", + "devDependencies":{}, + "name":"fileextension", + "ohos":{ + "org":"huawei", + "directoryLevel":"project", + "buildTool":"hvigor" + }, + "description":"FileExtension", + "repository":{}, + "version":"1.0.0", + "dependencies":{ + "@ohos/hvigor-ohos-plugin":"1.0.6", + "hypium":"^1.0.0", + "@ohos/hvigor":"1.0.6" + } +} \ No newline at end of file diff --git a/frameworks/innerkits/signature/fileextension.p7b b/frameworks/innerkits/signature/fileextension.p7b new file mode 100644 index 0000000000000000000000000000000000000000..5b1328605f9fda63b5b61fa317f25bcff26028fa Binary files /dev/null and b/frameworks/innerkits/signature/fileextension.p7b differ diff --git a/interfaces/kits/js/src/file_manager_napi.cpp b/interfaces/kits/js/src/file_manager_napi.cpp deleted file mode 100644 index 399c37d59097bd7aa3bda506b31a4af2198fae0c..0000000000000000000000000000000000000000 --- a/interfaces/kits/js/src/file_manager_napi.cpp +++ /dev/null @@ -1,412 +0,0 @@ -/* - * Copyright (c) 2021-2022 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. - */ - -#include "file_manager_napi.h" - -#include -#include -#include -#include - -#include "file_manager_napi_def.h" -#include "file_manager_proxy.h" -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "ifms_client.h" -#include "log.h" -namespace OHOS { -namespace FileManagerService { -using namespace std; -using namespace DistributedFS; -struct AsyncFileInfoArg { - NRef ref_; - vector> fileRes_; - explicit AsyncFileInfoArg(NVal ref) : ref_(ref), fileRes_() {}; - ~AsyncFileInfoArg() = default; -}; - -struct AsyncUriArg { - NRef ref_; - string uri_; - explicit AsyncUriArg(NVal ref) : ref_(ref), uri_() {}; - ~AsyncUriArg() = default; -}; - -tuple FileManagerNapi::GetFmsClient() -{ - if (fmsClient_ == nullptr) { - fmsClient_ = IFmsClient::GetFmsInstance(); - } - if (fmsClient_ == nullptr) { - ERR_LOG("fms get instance fails"); - return make_tuple(false, nullptr); - } else { - return make_tuple(true, fmsClient_); - } -} - -UniError DealWithErrno(int err) -{ - unordered_map errMap = { - {FAIL, ESRCH}, - {E_CREATE_FAIL, EPERM}, - {E_NOEXIST, ENOENT}, - {E_EMPTYFOLDER, ENOTDIR}, - {SUCCESS, ERRNO_NOERR}, - }; - if (errMap.count(err) == 0) { - ERR_LOG("unhandler err number %{public}d", err); - return UniError(EACCES); - } else { - return UniError(errMap[err]); - } -} - -bool GetDevInfoArg(const NVal &prop, DevInfo &dev) -{ - if (prop.HasProp("name")) { - bool ret = false; - unique_ptr name; - tie(ret, name, ignore) = prop.GetProp("name").ToUTF8String(); - if (!ret) { - return false; - } - dev.SetName(std::string(name.get())); - } - return true; -} - -tuple, unique_ptr, CmdOptions> GetCreateFileArgs(napi_env env, NFuncArg &funcArg) -{ - bool succ = false; - unique_ptr path; - unique_ptr fileName; - CmdOptions option("local", "", 0, MAX_NUM, false); - tie(succ, path, ignore) = NVal(env, funcArg[CreateFileArgs::CF_PATH]).ToUTF8String(); - if (!succ) { - return {false, nullptr, nullptr, option}; - } - tie(succ, fileName, ignore) = NVal(env, funcArg[CreateFileArgs::CF_FILENAME]).ToUTF8String(); - if (!succ) { - return {false, nullptr, nullptr, option}; - } - - if (funcArg.GetArgc() < CreateFileArgs::CF_OPTION) { - return {false, nullptr, nullptr, option}; - } - - NVal op(env, NVal(env, funcArg[CreateFileArgs::CF_OPTION]).val_); - if (op.TypeIs(napi_function)) { - return {true, move(path), move(fileName), option}; - } - - option.SetHasOpt(true); - if (!op.HasProp("dev")) { - return {true, move(path), move(fileName), option}; - } - - NVal prop(op.GetProp("dev")); - DevInfo dev("local", ""); - if (!GetDevInfoArg(prop, dev)) { - ERR_LOG("CreateFile func get dev para fails"); - option.SetDevInfo(dev); - return {false, nullptr, nullptr, option}; - } - - option.SetDevInfo(dev); - return {true, move(path), move(fileName), option}; -} - -napi_value FileManagerNapi::CreateFile(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(CREATE_FILE_PARA_MIN, CREATE_FILE_PARA_MAX)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - bool succ = false; - unique_ptr path; - unique_ptr fileName; - CmdOptions option; - tie(succ, path, fileName, option) = GetCreateFileArgs(env, funcArg); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "CreateFile func get args fails"); - return nullptr; - } - auto arg = make_shared(NVal(env, funcArg.GetThisVar())); - auto cbExec = [arg, path = string(path.get()), fileName = string(fileName.get()), option = option] - (napi_env env) -> UniError { - IFmsClient* client = nullptr; - bool succ = false; - tie(succ, client) = GetFmsClient(); - if (!succ) { - return UniError(ESRCH); - } - string uri = ""; - int err = client->CreateFile(path, fileName, option, arg->uri_); - return DealWithErrno(err); - }; - auto cbComplete = [arg](napi_env env, UniError err) -> NVal { - if (err) { - return { env, err.GetNapiErr(env) }; - } else { - return NVal::CreateUTF8String(env, arg->uri_); - } - }; - string procedureName = "CreateFile"; - size_t argc = funcArg.GetArgc(); - NVal thisVar(env, funcArg.GetThisVar()); - if (argc == CREATE_FILE_PARA_MIN || (argc != CREATE_FILE_PARA_MAX && option.GetHasOpt())) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; - } else { - int cbIdx = (!option.GetHasOpt() ? - CreateFileArgs::CF_CALLBACK_WITHOUT_OP : CreateFileArgs::CF_CALLBACK_WITH_OP); - NVal cb(env, funcArg[cbIdx]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; - } -} - -static bool CreateFileArray(napi_env env, shared_ptr arg) -{ - for (size_t i = 0; i < arg->fileRes_.size(); i++) { - NVal obj = NVal::CreateObject(env); - shared_ptr res = arg->fileRes_[i]; - if (res == nullptr) { - ERR_LOG("inner error, lack of memory, file count %{public}zu", arg->fileRes_.size()); - return false; - } - obj.AddProp("name", NVal::CreateUTF8String(env, res->GetName()).val_); - obj.AddProp("path", NVal::CreateUTF8String(env, res->GetPath()).val_); - obj.AddProp("type", NVal::CreateUTF8String(env, res->GetType()).val_); - obj.AddProp("size", NVal::CreateInt64(env, res->GetSize()).val_); - obj.AddProp("added_time", NVal::CreateInt64(env, res->GetAddedTime()).val_); - obj.AddProp("modified_time", NVal::CreateInt64(env, res->GetModifiedTime()).val_); - napi_set_property(env, arg->ref_.Deref(env).val_, NVal::CreateInt32(env, i).val_, obj.val_); - } - return true; -} - -bool GetRootArgs(napi_env env, NFuncArg &funcArg, CmdOptions &option) -{ - NVal op(env, NVal(env, funcArg[GetRootArgs::GR_OPTION]).val_); - if (op.TypeIs(napi_function)) { - return true; - } - - option.SetHasOpt(true); - if (!op.HasProp("dev")) { - return true; - } - - NVal prop(op.GetProp("dev")); - DevInfo dev("local", ""); - if (!GetDevInfoArg(prop, dev)) { - option.SetDevInfo(dev); - return false; - } - - option.SetDevInfo(dev); - return true; -} - -napi_value FileManagerNapi::GetRoot(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(GET_ROOT_PARA_MIN, GET_ROOT_PARA_MAX)) { - UniError(EINVAL).ThrowErr(env, "Number of argments unmatched"); - return nullptr; - } - - CmdOptions option("local", "", 0, MAX_NUM, false); - if (funcArg.GetArgc() != 0) { - if (!GetRootArgs(env, funcArg, option)) { - UniError(EINVAL).ThrowErr(env, "GetRoot func get dev para fails"); - return nullptr; - } - } - - napi_value fileArr; - napi_create_array(env, &fileArr); - auto arg = make_shared(NVal(env, fileArr)); - auto cbExec = [option = option, arg] (napi_env env) -> UniError { - IFmsClient* client = nullptr; - bool succ = false; - tie(succ, client) = GetFmsClient(); - if (!succ) { - return UniError(ESRCH); - } - int err = client->GetRoot(option, arg->fileRes_); - return DealWithErrno(err); - }; - auto cbComplete = [arg](napi_env env, UniError err) -> NVal { - if (!err && !CreateFileArray(env, arg)) { - err = UniError(ENOMEM); - } - if (err) { - return { env, err.GetNapiErr(env) }; - } else { - return NVal(env, arg->ref_.Deref(env).val_); - } - }; - string procedureName = "GetRoot"; - size_t argc = funcArg.GetArgc(); - NVal thisVar(env, funcArg.GetThisVar()); - if (argc == GET_ROOT_PARA_MIN || (argc != GET_ROOT_PARA_MAX && option.GetHasOpt())) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; - } else { - int cbIdx = (!option.GetHasOpt() ? GetRootArgs::GR_CALLBACK_WITHOUT_OP : GetRootArgs::GR_CALLBACK_WITH_OP); - NVal cb(env, funcArg[cbIdx]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; - } -} - -bool GetListFileOption(const NVal &argv, CmdOptions &option) -{ - bool ret = false; - if (argv.HasProp("dev")) { - NVal prop(argv.GetProp("dev")); - DevInfo dev("local", ""); - if (!GetDevInfoArg(prop, dev)) { - option.SetDevInfo(dev); - return false; - } - option.SetDevInfo(dev); - } - if (argv.HasProp("offset")) { - int64_t offset; - tie(ret, offset) = argv.GetProp("offset").ToInt64(); - if (!ret) { - ERR_LOG("ListFileArgs LF_OPTION offset para fails"); - return false; - } - option.SetOffset(offset); - } - if (argv.HasProp("count")) { - int64_t count; - tie(ret, count) = argv.GetProp("count").ToInt64(); - if (!ret) { - ERR_LOG("ListFileArgs LF_OPTION count para fails"); - return false; - } - option.setCount(count); - } - return true; -} - -tuple, unique_ptr, CmdOptions> GetListFileArg( - napi_env env, NFuncArg &funcArg) -{ - bool succ = false; - unique_ptr path; - unique_ptr type; - CmdOptions option("local", "", 0, MAX_NUM, false); - tie(succ, path, ignore) = NVal(env, funcArg[ListFileArgs::LF_PATH]).ToUTF8String(); - if (!succ) { - ERR_LOG("ListFileArgs LF_PATH para fails"); - return {false, nullptr, nullptr, option}; - } - tie(succ, type, ignore) = NVal(env, funcArg[ListFileArgs::LF_TYPE]).ToUTF8String(); - if (!succ) { - ERR_LOG("ListFileArgs LF_TYPE para fails"); - return {false, nullptr, nullptr, option}; - } - - NVal op(env, NVal(env, funcArg[ListFileArgs::LF_OPTION]).val_); - if (op.TypeIs(napi_function)) { - return {true, move(type), move(path), option}; - } - option.SetHasOpt(true); - if (!GetListFileOption(op, option)) { - return {false, nullptr, nullptr, option}; - } - return {true, move(type), move(path), option}; -} - -napi_value FileManagerNapi::ListFile(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(LIST_FILE_PARA_MIN, LIST_FILE_PARA_MAX)) { - UniError(EINVAL).ThrowErr(env, "Number of argments unmatched"); - return nullptr; - } - bool succ = false; - unique_ptr type; - unique_ptr path; - CmdOptions option; - tie(succ, type, path, option) = GetListFileArg(env, funcArg); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Get argments fails"); - return nullptr; - } - napi_value fileArr; - napi_create_array(env, &fileArr); - auto arg = make_shared(NVal(env, fileArr)); - auto cbExec = [type = string(type.get()), path = string(path.get()), option, arg](napi_env env) -> UniError { - IFmsClient* client = nullptr; - bool succ = false; - tie(succ, client) = GetFmsClient(); - if (!succ) { - return UniError(ESRCH); - } - int err = client->ListFile(type, path, option, arg->fileRes_); - return DealWithErrno(err); - }; - - auto cbComplete = [arg](napi_env env, UniError err) -> NVal { - if (!err && !CreateFileArray(env, arg)) { - err = UniError(ENOMEM); - } - if (err) { - return { env, err.GetNapiErr(env) }; - } else { - return NVal(env, arg->ref_.Deref(env).val_); - } - }; - string procedureName = "ListFile"; - size_t argc = funcArg.GetArgc(); - NVal thisVar(env, funcArg.GetThisVar()); - if (argc == LIST_FILE_PARA_MIN || (argc != LIST_FILE_PARA_MAX && option.GetHasOpt())) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; - } else { - int cbIdx = ((!option.GetHasOpt()) ? ListFileArgs::LF_CALLBACK_WITHOUT_OP : ListFileArgs::LF_CALLBACK_WITH_OP); - NVal cb(env, funcArg[cbIdx]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; - } -} - -napi_value FileManagerNapi::Mkdir(napi_env env, napi_callback_info info) -{ - return NVal::CreateUndefined(env).val_; -} - -bool FileManagerNapi::Export() -{ - return exports_.AddProp( { - NVal::DeclareNapiFunction("listFile", ListFile), - NVal::DeclareNapiFunction("createFile", CreateFile), - NVal::DeclareNapiFunction("getRoot", GetRoot), - }); -} - -string FileManagerNapi::GetClassName() -{ - return FileManagerNapi::className_; -} - -FileManagerNapi::FileManagerNapi(napi_env env, napi_value exports) : NExporter(env, exports) {} - -FileManagerNapi::~FileManagerNapi() {} -} // namespace FileManagerService -} // namespace OHOS diff --git a/interfaces/kits/js/src/file_manager_napi.h b/interfaces/kits/js/src/file_manager_napi.h deleted file mode 100644 index 8b06b57af5786ed8d4cf9c04eab819839b870ec9..0000000000000000000000000000000000000000 --- a/interfaces/kits/js/src/file_manager_napi.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2021 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 STORAGE_FILE_MANAGER_NAPI_H -#define STORAGE_FILE_MANAGER_NAPI_H - -#include "ifms_client.h" -#include "n_exporter.h" - -namespace OHOS { -namespace FileManagerService { -class FileManagerNapi final : public DistributedFS::NExporter { -public: - static napi_value CreateFile(napi_env env, napi_callback_info info); - static napi_value ListFile(napi_env env, napi_callback_info info); - static napi_value Mkdir(napi_env env, napi_callback_info info); - static napi_value GetRoot(napi_env env, napi_callback_info info); - bool Export() override; - std::string GetClassName() override; - static std::tuple GetFmsClient(); - FileManagerNapi(napi_env env, napi_value exports); - ~FileManagerNapi() override; -private: - inline static const std::string className_ = "__properities__"; - inline static IFmsClient* fmsClient_ = nullptr; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_FILE_MANAGER_NAPI_H \ No newline at end of file diff --git a/interfaces/kits/js/src/file_manager_napi_def.h b/interfaces/kits/js/src/file_manager_napi_def.h deleted file mode 100644 index 05d753484fda359baf38733764dac37cc666e9fc..0000000000000000000000000000000000000000 --- a/interfaces/kits/js/src/file_manager_napi_def.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2021 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 STORAGE_FILE_MANAGER_NAPI_DEF_H -#define STORAGE_FILE_MANAGER_NAPI_DEF_H -#include "n_async_work_callback.h" -#include "n_async_work_promise.h" -#include "n_func_arg.h" -#include "uni_error.h" - -namespace OHOS { -namespace FileManagerService { -enum CreateFileArgs { - CF_PATH = 0, - CF_FILENAME = 1, - CF_OPTION = 2, - CF_CALLBACK_WITHOUT_OP = 2, - CF_CALLBACK_WITH_OP = 3, -}; - -enum GetRootArgs { - GR_OPTION = 0, - GR_CALLBACK_WITHOUT_OP = 0, - GR_CALLBACK_WITH_OP = 1, -}; - -enum ListFileArgs { - LF_PATH = 0, - LF_TYPE = 1, - LF_OPTION = 2, - LF_CALLBACK_WITHOUT_OP = 2, - LF_CALLBACK_WITH_OP = 3, -}; - -constexpr int CREATE_FILE_PARA_MAX = 4; -constexpr int CREATE_FILE_PARA_MIN = 2; -constexpr int GET_ROOT_PARA_MAX = 2; -constexpr int GET_ROOT_PARA_MIN = 0; -constexpr int LIST_FILE_PARA_MAX = 4; -constexpr int LIST_FILE_PARA_MIN = 2; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_FILE_MANAGER_NAPI_DEF_H diff --git a/services/sa_profile/BUILD.gn b/interfaces/kits/napi/file_access_module/BUILD.gn similarity index 40% rename from services/sa_profile/BUILD.gn rename to interfaces/kits/napi/file_access_module/BUILD.gn index 16b9a8ba94688faed169197bd470cd5b5da7aea6..cb6a0605d65030f707c76ae67e553bdae5361a4a 100644 --- a/services/sa_profile/BUILD.gn +++ b/interfaces/kits/napi/file_access_module/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2022 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 @@ -11,10 +11,38 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//build/ohos/sa_profile/sa_profile.gni") - -ohos_sa_profile("filemanager_service_sa_profile") { - sources = [ "5010.xml" ] +import("//build/ohos.gni") +BASE_DIR = "//foundation/filemanagement/user_file_service" +ohos_shared_library("fileaccess") { + subsystem_name = "filemanagement" part_name = "user_file_service" -} + + relative_install_dir = "module/data" + + include_dirs = [ + "./", + "${BASE_DIR}/utils", + ] + + sources = [ + "napi_fileaccess_helper.cpp", + "native_fileaccess_module.cpp", + ] + + deps = [ + "${BASE_DIR}/frameworks/innerkits/file_extension:file_extension_ability_kit", + "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common:napi_common", + ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:abilitykit_native", + "ability_runtime:napi_base_context", + "hiviewdfx_hilog_native:libhilog", + "napi:ace_napi", + "utils_base:utils", + ] +} \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/file_access_common.h b/interfaces/kits/napi/file_access_module/file_access_common.h new file mode 100644 index 0000000000000000000000000000000000000000..3dae7588e73df5dcde2140cb266918fc8a8ce680 --- /dev/null +++ b/interfaces/kits/napi/file_access_module/file_access_common.h @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2022 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 OHOS_APPEXECFWK_FILEACCESS_COMMON_H +#define OHOS_APPEXECFWK_FILEACCESS_COMMON_H + +#include "ability.h" +#include "file_access_helper.h" +#include "napi/native_api.h" +#include "napi/native_common.h" +#include "napi/native_node_api.h" +#include "napi_common.h" +#include "napi_common_util.h" +#include "want.h" + +using Want = OHOS::AAFwk::Want; +using Ability = OHOS::AppExecFwk::Ability; +using AbilityStartSetting = OHOS::AppExecFwk::AbilityStartSetting; + +namespace OHOS { +namespace AppExecFwk { + +struct CBBase { + CallbackInfo cbInfo; + napi_async_work asyncWork; + napi_deferred deferred; + Ability *ability = nullptr; + AbilityType abilityType = AbilityType::UNKNOWN; + int errCode = 0; +}; + +struct FileAccessHelperCB { + CBBase cbBase; + napi_ref uri = nullptr; + napi_value result = nullptr; +}; + +struct FileAccessHelperOpenFileCB { + CBBase cbBase; + FileAccessHelper *fileAccessHelper = nullptr; + std::string uri; + std::string mode; + int result = 0; + int execResult; +}; + +struct FileAccessHelperCreateFileCB { + CBBase cbBase; + FileAccessHelper *fileAccessHelper = nullptr; + std::string parentUri; + std::string name; + std::string result; + int execResult; +}; + +struct FileAccessHelperMkdirCB { + CBBase cbBase; + FileAccessHelper *fileAccessHelper = nullptr; + std::string parentUri; + std::string name; + std::string result; + int execResult; +}; + +struct FileAccessHelperDeleteCB { + CBBase cbBase; + FileAccessHelper *fileAccessHelper = nullptr; + std::string selectFileUri; + int result = 0; + int execResult; +}; + +struct FileAccessHelperMoveCB { + CBBase cbBase; + FileAccessHelper *fileAccessHelper = nullptr; + std::string sourceFileUri; + std::string targetParentUri; + std::string result; + int execResult; +}; + +struct FileAccessHelperRenameCB { + CBBase cbBase; + FileAccessHelper *fileAccessHelper = nullptr; + std::string sourceFileUri; + std::string displayName; + std::string result; + int execResult; +}; + +struct FileAccessHelperCloseFileCB { + CBBase cbBase; + FileAccessHelper *fileAccessHelper = nullptr; + int fd; + std::string uri; + int result; + int execResult; +}; + +struct FileAccessHelperReleaseCB { + CBBase cbBase; + FileAccessHelper *fileAccessHelper = nullptr; + bool result = false; +}; +} +} +#endif \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7a0c45d9bd7244ed33b640ae86a1c534a54ae9fb --- /dev/null +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp @@ -0,0 +1,1651 @@ +/* + * Copyright (C) 2022 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. + */ + +#include "napi_fileaccess_helper.h" + +#include +#include + +#include "uri.h" + +#include "hilog_wrapper.h" +#include "napi_base_context.h" +#include "securec.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace AppExecFwk { +namespace { +const std::string FILEACCESS_CLASS_NAME = "FileAccessHelper"; +constexpr int NO_ERROR = 0; +constexpr int INVALID_PARAMETER = -1; + +std::string NapiValueToStringUtf8(napi_env env, napi_value value) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + std::string result = ""; + return UnwrapStringFromJS(env, value, result); +} + +int NapiValueToInt32Utf8(napi_env env, napi_value value) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + int result = 0; + return UnwrapInt32FromJS(env, value, result); +} +} + +std::list> g_fileAccessHelperList; +static napi_ref g_constructorRef = nullptr; + +napi_value AcquireFileAccessHelperWrap(napi_env env, napi_callback_info info, FileAccessHelperCB *fileAccessHelperCB) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + if (fileAccessHelperCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s,fileAccessHelperCB == nullptr", __func__); + return nullptr; + } + + size_t requireArgc = ARGS_THREE; + size_t argc = ARGS_THREE; + napi_value args[ARGS_THREE] = {nullptr}; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr)); + if (argc > requireArgc) { + HILOG_ERROR("tag dsa %{public}s, Wrong argument count %{public}zu.", __func__, argc); + return nullptr; + } + + napi_value result = nullptr; + napi_value cons = nullptr; + if (napi_get_reference_value(env, g_constructorRef, &cons) != napi_ok) { + return nullptr; + } + NAPI_CALL(env, napi_new_instance(env, cons, ARGS_THREE, args, &result)); + + if (!IsTypeForNapiValue(env, result, napi_object)) { + HILOG_ERROR("tag dsa %{public}s, IsTypeForNapiValue isn`t object", __func__); + return nullptr; + } + + if (IsTypeForNapiValue(env, result, napi_null)) { + HILOG_ERROR("tag dsa %{public}s, IsTypeForNapiValue is null", __func__); + return nullptr; + } + + if (IsTypeForNapiValue(env, result, napi_undefined)) { + HILOG_ERROR("tag dsa %{public}s, IsTypeForNapiValue is undefined", __func__); + return nullptr; + } + + delete fileAccessHelperCB; + fileAccessHelperCB = nullptr; + HILOG_INFO("tag dsa %{public}s,end", __func__); + return result; +} + +napi_value NAPI_AcquireFileAccessHelperCommon(napi_env env, napi_callback_info info, AbilityType abilityType) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + FileAccessHelperCB *fileAccessHelperCB = new (std::nothrow) FileAccessHelperCB; + if (fileAccessHelperCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, FileAccessHelperCB == nullptr", __func__); + return WrapVoidToJS(env); + } + + fileAccessHelperCB->cbBase.cbInfo.env = env; + fileAccessHelperCB->cbBase.errCode = NAPI_ERR_NO_ERROR; + fileAccessHelperCB->cbBase.abilityType = abilityType; + napi_value ret = AcquireFileAccessHelperWrap(env, info, fileAccessHelperCB); + if (ret == nullptr) { + HILOG_ERROR("tag dsa %{public}s, ret == nullptr", __func__); + if (fileAccessHelperCB != nullptr) { + delete fileAccessHelperCB; + fileAccessHelperCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value NAPI_CreateFileAccessHelper(napi_env env, napi_callback_info info) +{ + HILOG_INFO("tag dsa %{public}s, called", __func__); + return NAPI_AcquireFileAccessHelperCommon(env, info, AbilityType::EXTENSION); +} + +napi_value FileAccessHelperInit(napi_env env, napi_value exports) +{ + HILOG_INFO("tag dsa %{public}s,called start ", __func__); + napi_property_descriptor properties[] = { + DECLARE_NAPI_FUNCTION("openFile", NAPI_OpenFile), + DECLARE_NAPI_FUNCTION("mkdir", NAPI_Mkdir), + DECLARE_NAPI_FUNCTION("createFile", NAPI_CreateFile), + DECLARE_NAPI_FUNCTION("delete", NAPI_Delete), + DECLARE_NAPI_FUNCTION("move", NAPI_Move), + DECLARE_NAPI_FUNCTION("rename", NAPI_Rename), + DECLARE_NAPI_FUNCTION("closeFile", NAPI_CloseFile), + DECLARE_NAPI_FUNCTION("release", NAPI_Release), + }; + napi_value cons = nullptr; + NAPI_CALL(env, + napi_define_class(env, + FILEACCESS_CLASS_NAME.c_str(), + NAPI_AUTO_LENGTH, + FileAccessHelperConstructor, + nullptr, + sizeof(properties) / sizeof(*properties), + properties, + &cons)); + g_fileAccessHelperList.clear(); + NAPI_CALL(env, napi_create_reference(env, cons, 1, &g_constructorRef)); + NAPI_CALL(env, napi_set_named_property(env, exports, FILEACCESS_CLASS_NAME.c_str(), cons)); + + napi_property_descriptor export_properties[] = { + DECLARE_NAPI_FUNCTION("createFileAccessHelper", NAPI_CreateFileAccessHelper), + }; + NAPI_CALL(env, napi_define_properties(env, exports, sizeof(export_properties) / sizeof(export_properties[0]), + export_properties)); + return exports; +} + +napi_value FileAccessHelperConstructor(napi_env env, napi_callback_info info) +{ + HILOG_INFO("tag dsa %{public}s, called", __func__); + size_t argc = ARGS_TWO; + napi_value argv[ARGS_TWO] = {nullptr}; + napi_value thisVar = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr)); + NAPI_ASSERT(env, argc > 0, "Wrong number of arguments"); + AAFwk::Want want; + OHOS::AppExecFwk::UnwrapWant(env, argv[PARAM1], want); + std::shared_ptr fileAccessHelper = nullptr; + bool isStageMode = false; + napi_status status = AbilityRuntime::IsStageContext(env, argv[PARAM0], isStageMode); + if (status != napi_ok || !isStageMode) { + HILOG_INFO("tag dsa FA Model"); + return nullptr; + } else { + auto context = OHOS::AbilityRuntime::GetStageModeContext(env, argv[PARAM0]); + NAPI_ASSERT(env, context != nullptr, "FileAccessHelperConstructor: failed to get native context"); + HILOG_INFO("tag dsa Stage Model"); + fileAccessHelper = FileAccessHelper::Creator(context, want); + } + NAPI_ASSERT(env, fileAccessHelper != nullptr, "FileAccessHelperConstructor: fileAccessHelper is nullptr"); + g_fileAccessHelperList.emplace_back(fileAccessHelper); + napi_wrap(env, thisVar, fileAccessHelper.get(), [](napi_env env, void *data, void *hint) { + FileAccessHelper *objectInfo = static_cast(data); + g_fileAccessHelperList.remove_if([objectInfo](const std::shared_ptr &fileAccessHelper) { + return objectInfo == fileAccessHelper.get(); + }); + }, nullptr, nullptr); + HILOG_INFO("tag dsa %{public}s,called end", __func__); + return thisVar; +} + +napi_value NAPI_OpenFile(napi_env env, napi_callback_info info) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + FileAccessHelperOpenFileCB *openFileCB = new (std::nothrow) FileAccessHelperOpenFileCB; + if (openFileCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, openFileCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + openFileCB->cbBase.cbInfo.env = env; + openFileCB->cbBase.asyncWork = nullptr; + openFileCB->cbBase.deferred = nullptr; + openFileCB->cbBase.ability = nullptr; + + napi_value ret = OpenFileWrap(env, info, openFileCB); + if (ret == nullptr) { + HILOG_ERROR("tag dsa %{public}s,ret == nullptr", __func__); + if (openFileCB != nullptr) { + delete openFileCB; + openFileCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value OpenFileWrap(napi_env env, napi_callback_info info, FileAccessHelperOpenFileCB *openFileCB) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + size_t argcAsync = ARGS_THREE; + const size_t argcPromise = ARGS_TWO; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = 0; + napi_value thisVar = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("tag dsa %{public}s, Wrong argument count.", __func__); + return nullptr; + } + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); + if (valuetype == napi_string) { + openFileCB->uri = NapiValueToStringUtf8(env, args[PARAM0]); + HILOG_INFO("tag dsa %{public}s,uri=%{public}s", __func__, openFileCB->uri.c_str()); + } + + NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); + if (valuetype == napi_string) { + openFileCB->mode = NapiValueToStringUtf8(env, args[PARAM1]); + HILOG_INFO("tag dsa %{public}s,mode=%{public}s", __func__, openFileCB->mode.c_str()); + } + + FileAccessHelper *objectInfo = nullptr; + napi_unwrap(env, thisVar, (void **)&objectInfo); + HILOG_INFO("tag dsa %{public}s,FileAccessHelper objectInfo", __func__); + openFileCB->fileAccessHelper = objectInfo; + + if (argcAsync > argcPromise) { + ret = OpenFileAsync(env, args, ARGS_TWO, openFileCB); + } else { + ret = OpenFilePromise(env, openFileCB); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value OpenFileAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperOpenFileCB *openFileCB) +{ + HILOG_INFO("tag dsa %{public}s, asyncCallback.", __func__); + if (args == nullptr || openFileCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = 0; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argCallback], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &openFileCB->cbBase.cbInfo.callback)); + } + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + OpenFileExecuteCB, + OpenFileAsyncCompleteCB, + (void *)openFileCB, + &openFileCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, openFileCB->cbBase.asyncWork)); + napi_value result = 0; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("tag dsa %{public}s, asyncCallback end.", __func__); + return result; +} + +napi_value OpenFilePromise(napi_env env, FileAccessHelperOpenFileCB *openFileCB) +{ + HILOG_INFO("tag dsa %{public}s, promise.", __func__); + if (openFileCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = 0; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + openFileCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + OpenFileExecuteCB, + OpenFilePromiseCompleteCB, + (void *)openFileCB, + &openFileCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, openFileCB->cbBase.asyncWork)); + HILOG_INFO("tag dsa %{public}s, promise end.", __func__); + return promise; +} + +void OpenFileExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("tag dsa NAPI_OpenFile, worker pool thread execute."); + FileAccessHelperOpenFileCB *OpenFileCB = static_cast(data); + if (OpenFileCB->fileAccessHelper != nullptr) { + OpenFileCB->execResult = INVALID_PARAMETER; + if (!OpenFileCB->uri.empty()) { + OHOS::Uri uri(OpenFileCB->uri); + OpenFileCB->result = OpenFileCB->fileAccessHelper->OpenFile(uri, OpenFileCB->mode); + OpenFileCB->execResult = NO_ERROR; + } else { + HILOG_ERROR("tag dsa NAPI_OpenFile, fileAccessHelper uri is empty"); + } + } else { + HILOG_ERROR("tag dsa NAPI_OpenFile, fileAccessHelper == nullptr"); + } + HILOG_INFO("tag dsa NAPI_OpenFile, worker pool thread execute end."); +} + +void OpenFileAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_OpenFile, main event thread complete."); + FileAccessHelperOpenFileCB *OpenFileCB = static_cast(data); + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, OpenFileCB->cbBase.cbInfo.callback, &callback)); + + result[PARAM0] = GetCallbackErrorValue(env, OpenFileCB->execResult); + napi_create_int32(env, OpenFileCB->result, &result[PARAM1]); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (OpenFileCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, OpenFileCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, OpenFileCB->cbBase.asyncWork)); + delete OpenFileCB; + OpenFileCB = nullptr; + HILOG_INFO("tag dsa NAPI_OpenFile, main event thread complete end."); +} + +void OpenFilePromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_OpenFileCB, main event thread complete."); + FileAccessHelperOpenFileCB *OpenFileCB = static_cast(data); + napi_value result = nullptr; + napi_create_int32(env, OpenFileCB->result, &result); + NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, OpenFileCB->cbBase.deferred, result)); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, OpenFileCB->cbBase.asyncWork)); + delete OpenFileCB; + OpenFileCB = nullptr; + HILOG_INFO("tag dsa NAPI_OpenFileCB, main event thread complete end."); +} + +napi_value NAPI_CreateFile(napi_env env, napi_callback_info info) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + FileAccessHelperCreateFileCB *createFileCB = new (std::nothrow) FileAccessHelperCreateFileCB; + if (createFileCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, createFileCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + createFileCB->cbBase.cbInfo.env = env; + createFileCB->cbBase.asyncWork = nullptr; + createFileCB->cbBase.deferred = nullptr; + createFileCB->cbBase.ability = nullptr; + + napi_value ret = CreateFileWrap(env, info, createFileCB); + if (ret == nullptr) { + HILOG_ERROR("tag dsa %{public}s,ret == nullptr", __func__); + if (createFileCB != nullptr) { + delete createFileCB; + createFileCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value CreateFileWrap(napi_env env, napi_callback_info info, FileAccessHelperCreateFileCB *createFileCB) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + size_t argcAsync = ARGS_THREE; + const size_t argcPromise = ARGS_TWO; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = 0; + napi_value thisVar = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("tag dsa %{public}s, Wrong argument count.", __func__); + return nullptr; + } + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); + if (valuetype == napi_string) { + createFileCB->parentUri = NapiValueToStringUtf8(env, args[PARAM0]); + HILOG_INFO("tag dsa %{public}s,parentUri=%{public}s", __func__, createFileCB->parentUri.c_str()); + } + + NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); + if (valuetype == napi_string) { + createFileCB->name = NapiValueToStringUtf8(env, args[PARAM1]); + HILOG_INFO("tag dsa %{public}s,name=%{public}s", __func__, createFileCB->name.c_str()); + } + + FileAccessHelper *objectInfo = nullptr; + napi_unwrap(env, thisVar, (void **)&objectInfo); + HILOG_INFO("tag dsa %{public}s,FileAccessHelper objectInfo", __func__); + createFileCB->fileAccessHelper = objectInfo; + + if (argcAsync > argcPromise) { + ret = CreateFileAsync(env, args, ARGS_TWO, createFileCB); + } else { + ret = CreateFilePromise(env, createFileCB); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value CreateFileAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperCreateFileCB *createFileCB) +{ + HILOG_INFO("tag dsa %{public}s, asyncCallback.", __func__); + if (args == nullptr || createFileCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = 0; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argCallback], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &createFileCB->cbBase.cbInfo.callback)); + } + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + CreateFileExecuteCB, + CreateFileAsyncCompleteCB, + (void *)createFileCB, + &createFileCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, createFileCB->cbBase.asyncWork)); + napi_value result = 0; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("tag dsa %{public}s, asyncCallback end.", __func__); + return result; +} + +napi_value CreateFilePromise(napi_env env, FileAccessHelperCreateFileCB *createFileCB) +{ + HILOG_INFO("tag dsa %{public}s, promise.", __func__); + if (createFileCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = 0; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + createFileCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + CreateFileExecuteCB, + CreateFilePromiseCompleteCB, + (void *)createFileCB, + &createFileCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, createFileCB->cbBase.asyncWork)); + HILOG_INFO("tag dsa %{public}s, promise end.", __func__); + return promise; +} + +void CreateFileExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("tag dsa NAPI_CreateFile, worker pool thread execute."); + FileAccessHelperCreateFileCB *CreateFileCB = static_cast(data); + if (CreateFileCB->fileAccessHelper != nullptr) { + CreateFileCB->execResult = INVALID_PARAMETER; + if (!CreateFileCB->parentUri.empty()) { + OHOS::Uri parentUri(CreateFileCB->parentUri); + std::string newFile = ""; + OHOS::Uri newFileUri(newFile); + int err = CreateFileCB->fileAccessHelper->CreateFile(parentUri, CreateFileCB->name, newFileUri); + CreateFileCB->result = newFileUri.ToString(); + CreateFileCB->execResult = err; + } else { + HILOG_ERROR("tag dsa NAPI_CreateFile, fileAccessHelper uri is empty"); + } + } else { + HILOG_ERROR("tag dsa NAPI_CreateFile, fileAccessHelper == nullptr"); + } + HILOG_INFO("tag dsa NAPI_CreateFile, worker pool thread execute end."); +} + +void CreateFileAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_CreateFile, main event thread complete."); + FileAccessHelperCreateFileCB *CreateFileCB = static_cast(data); + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, CreateFileCB->cbBase.cbInfo.callback, &callback)); + + result[PARAM0] = GetCallbackErrorValue(env, CreateFileCB->execResult); + NAPI_CALL_RETURN_VOID( + env, napi_create_string_utf8(env, CreateFileCB->result.c_str(), NAPI_AUTO_LENGTH, &result[PARAM1])); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (CreateFileCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, CreateFileCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, CreateFileCB->cbBase.asyncWork)); + delete CreateFileCB; + CreateFileCB = nullptr; + HILOG_INFO("tag dsa NAPI_CreateFile, main event thread complete end."); +} + +void CreateFilePromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_CreateFile, main event thread complete."); + FileAccessHelperCreateFileCB *CreateFileCB = static_cast(data); + napi_value result = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, CreateFileCB->result.c_str(), NAPI_AUTO_LENGTH, &result)); + NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, CreateFileCB->cbBase.deferred, result)); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, CreateFileCB->cbBase.asyncWork)); + delete CreateFileCB; + CreateFileCB = nullptr; + HILOG_INFO("tag dsa NAPI_CreateFile, main event thread complete end."); +} + +napi_value NAPI_Mkdir(napi_env env, napi_callback_info info) +{ + HILOG_INFO("tag dsa%{public}s,called", __func__); + FileAccessHelperMkdirCB *mkdirCB = new (std::nothrow) FileAccessHelperMkdirCB; + if (mkdirCB == nullptr) { + HILOG_ERROR("tag dsa%{public}s, mkdirCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + mkdirCB->cbBase.cbInfo.env = env; + mkdirCB->cbBase.asyncWork = nullptr; + mkdirCB->cbBase.deferred = nullptr; + mkdirCB->cbBase.ability = nullptr; + + napi_value ret = MkdirWrap(env, info, mkdirCB); + if (ret == nullptr) { + HILOG_ERROR("tag dsa%{public}s,ret == nullptr", __func__); + if (mkdirCB != nullptr) { + delete mkdirCB; + mkdirCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("tag dsa%{public}s,end", __func__); + return ret; +} + +napi_value MkdirWrap(napi_env env, napi_callback_info info, FileAccessHelperMkdirCB *mkdirCB) +{ + HILOG_INFO("tag dsa%{public}s,called", __func__); + size_t argcAsync = ARGS_THREE; + const size_t argcPromise = ARGS_TWO; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = 0; + napi_value thisVar = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("tag dsa%{public}s, Wrong argument count.", __func__); + return nullptr; + } + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); + if (valuetype == napi_string) { + mkdirCB->parentUri = NapiValueToStringUtf8(env, args[PARAM0]); + HILOG_INFO("tag dsa%{public}s,parentUri=%{public}s", __func__, mkdirCB->parentUri.c_str()); + } + + NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); + if (valuetype == napi_string) { + mkdirCB->name = NapiValueToStringUtf8(env, args[PARAM1]); + HILOG_INFO("tag dsa%{public}s,name=%{public}s", __func__, mkdirCB->name.c_str()); + } + + FileAccessHelper *objectInfo = nullptr; + napi_unwrap(env, thisVar, (void **)&objectInfo); + HILOG_INFO("tag dsa%{public}s,FileAccessHelper objectInfo", __func__); + mkdirCB->fileAccessHelper = objectInfo; + + if (argcAsync > argcPromise) { + ret = MkdirAsync(env, args, ARGS_TWO, mkdirCB); + } else { + ret = MkdirPromise(env, mkdirCB); + } + HILOG_INFO("tag dsa%{public}s,end", __func__); + return ret; +} + +napi_value MkdirAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperMkdirCB *mkdirCB) +{ + HILOG_INFO("tag dsa%{public}s, asyncCallback.", __func__); + if (args == nullptr || mkdirCB == nullptr) { + HILOG_ERROR("tag dsa%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = 0; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argCallback], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &mkdirCB->cbBase.cbInfo.callback)); + } + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + MkdirExecuteCB, + MkdirAsyncCompleteCB, + (void *)mkdirCB, + &mkdirCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, mkdirCB->cbBase.asyncWork)); + napi_value result = 0; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("tag dsa%{public}s, asyncCallback end.", __func__); + return result; +} + +napi_value MkdirPromise(napi_env env, FileAccessHelperMkdirCB *mkdirCB) +{ + HILOG_INFO("tag dsa%{public}s, promise.", __func__); + if (mkdirCB == nullptr) { + HILOG_ERROR("tag dsa%{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = 0; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + mkdirCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + MkdirExecuteCB, + MkdirPromiseCompleteCB, + (void *)mkdirCB, + &mkdirCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, mkdirCB->cbBase.asyncWork)); + HILOG_INFO("tag dsa%{public}s, promise end.", __func__); + return promise; +} + +void MkdirExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("tag dsaNAPI_Mkdir, worker pool thread execute."); + FileAccessHelperMkdirCB *MkdirCB = static_cast(data); + if (MkdirCB->fileAccessHelper != nullptr) { + MkdirCB->execResult = INVALID_PARAMETER; + if (!MkdirCB->parentUri.empty()) { + OHOS::Uri parentUri(MkdirCB->parentUri); + std::string newDir = ""; + OHOS::Uri newDirUri(newDir); + int err = MkdirCB->fileAccessHelper->Mkdir(parentUri, MkdirCB->name, newDirUri); + MkdirCB->result = newDirUri.ToString(); + MkdirCB->execResult = err; + } else { + HILOG_ERROR("tag dsaNAPI_Mkdir, fileAccessHelper parentUri is empty"); + } + } else { + HILOG_ERROR("tag dsaNAPI_Mkdir, fileAccessHelper == nullptr"); + } + HILOG_INFO("tag dsaNAPI_Mkdir, worker pool thread execute end."); +} + +void MkdirAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsaNAPI_Mkdir, main event thread complete."); + FileAccessHelperMkdirCB *MkdirCB = static_cast(data); + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, MkdirCB->cbBase.cbInfo.callback, &callback)); + + result[PARAM0] = GetCallbackErrorValue(env, MkdirCB->execResult); + NAPI_CALL_RETURN_VOID( + env, napi_create_string_utf8(env, MkdirCB->result.c_str(), NAPI_AUTO_LENGTH, &result[PARAM1])); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (MkdirCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, MkdirCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, MkdirCB->cbBase.asyncWork)); + delete MkdirCB; + MkdirCB = nullptr; + HILOG_INFO("tag dsaNAPI_Mkdir, main event thread complete end."); +} + +void MkdirPromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsaNAPI_Mkdir, main event thread complete."); + FileAccessHelperMkdirCB *MkdirCB = static_cast(data); + napi_value result = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, MkdirCB->result.c_str(), NAPI_AUTO_LENGTH, &result)); + NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, MkdirCB->cbBase.deferred, result)); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, MkdirCB->cbBase.asyncWork)); + delete MkdirCB; + MkdirCB = nullptr; + HILOG_INFO("tag dsaNAPI_Mkdir, main event thread complete end."); +} + +napi_value NAPI_Delete(napi_env env, napi_callback_info info) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + FileAccessHelperDeleteCB *deleteCB = new (std::nothrow) FileAccessHelperDeleteCB; + if (deleteCB == nullptr) { + HILOG_ERROR("%{public}s, deleteCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + deleteCB->cbBase.cbInfo.env = env; + deleteCB->cbBase.asyncWork = nullptr; + deleteCB->cbBase.deferred = nullptr; + deleteCB->cbBase.ability = nullptr; + + napi_value ret = DeleteWrap(env, info, deleteCB); + if (ret == nullptr) { + HILOG_ERROR("tag dsa %{public}s,ret == nullptr", __func__); + if (deleteCB != nullptr) { + delete deleteCB; + deleteCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value DeleteWrap(napi_env env, napi_callback_info info, FileAccessHelperDeleteCB *deleteCB) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + size_t argcAsync = ARGS_TWO; + const size_t argcPromise = ARGS_ONE; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = 0; + napi_value thisVar = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("tag dsa %{public}s, Wrong argument count.", __func__); + return nullptr; + } + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); + if (valuetype == napi_string) { + deleteCB->selectFileUri = NapiValueToStringUtf8(env, args[PARAM0]); + HILOG_INFO("tag dsa %{public}s,selectFileUri=%{public}s", __func__, deleteCB->selectFileUri.c_str()); + } + + FileAccessHelper *objectInfo = nullptr; + napi_unwrap(env, thisVar, (void **)&objectInfo); + HILOG_INFO("tag dsa %{public}s,FileAccessHelper objectInfo", __func__); + deleteCB->fileAccessHelper = objectInfo; + + if (argcAsync > argcPromise) { + ret = DeleteAsync(env, args, ARGS_ONE, deleteCB); + } else { + ret = DeletePromise(env, deleteCB); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value DeleteAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperDeleteCB *deleteCB) +{ + HILOG_INFO("tag dsa %{public}s, asyncCallback.", __func__); + if (args == nullptr || deleteCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = 0; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argCallback], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &deleteCB->cbBase.cbInfo.callback)); + } + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + DeleteExecuteCB, + DeleteAsyncCompleteCB, + (void *)deleteCB, + &deleteCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, deleteCB->cbBase.asyncWork)); + napi_value result = 0; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("tag dsa %{public}s, asyncCallback end.", __func__); + return result; +} + +napi_value DeletePromise(napi_env env, FileAccessHelperDeleteCB *deleteCB) +{ + HILOG_INFO("tag dsa %{public}s, promise.", __func__); + if (deleteCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = 0; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + deleteCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + DeleteExecuteCB, + DeletePromiseCompleteCB, + (void *)deleteCB, + &deleteCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, deleteCB->cbBase.asyncWork)); + HILOG_INFO("tag dsa %{public}s, promise end.", __func__); + return promise; +} + +void DeleteExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("tag dsa NAPI_Delete, worker pool thread execute."); + FileAccessHelperDeleteCB *DeleteCB = static_cast(data); + if (DeleteCB->fileAccessHelper != nullptr) { + DeleteCB->execResult = INVALID_PARAMETER; + if (!DeleteCB->selectFileUri.empty()) { + OHOS::Uri selectFileUri(DeleteCB->selectFileUri); + DeleteCB->result = DeleteCB->fileAccessHelper->Delete(selectFileUri); + DeleteCB->execResult = NO_ERROR; + } else { + HILOG_ERROR("tag dsa NAPI_Delete, fileAccessHelper selectFileUri is empty"); + } + } else { + HILOG_ERROR("tag dsa NAPI_Delete, fileAccessHelper == nullptr"); + } + HILOG_INFO("tag dsa NAPI_Delete, worker pool thread execute end."); +} + +void DeleteAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_Delete, main event thread complete."); + FileAccessHelperDeleteCB *DeleteCB = static_cast(data); + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, DeleteCB->cbBase.cbInfo.callback, &callback)); + + result[PARAM0] = GetCallbackErrorValue(env, DeleteCB->execResult); + napi_create_int32(env, DeleteCB->result, &result[PARAM1]); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (DeleteCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, DeleteCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, DeleteCB->cbBase.asyncWork)); + delete DeleteCB; + DeleteCB = nullptr; + HILOG_INFO("tag dsa NAPI_Delete, main event thread complete end."); +} + +void DeletePromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_Delete, main event thread complete."); + FileAccessHelperDeleteCB *DeleteCB = static_cast(data); + napi_value result = nullptr; + napi_create_int32(env, DeleteCB->result, &result); + NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, DeleteCB->cbBase.deferred, result)); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, DeleteCB->cbBase.asyncWork)); + delete DeleteCB; + DeleteCB = nullptr; + HILOG_INFO("tag dsa NAPI_Delete, main event thread complete end."); +} + +napi_value NAPI_Move(napi_env env, napi_callback_info info) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + FileAccessHelperMoveCB *moveCB = new (std::nothrow) FileAccessHelperMoveCB; + if (moveCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, moveCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + moveCB->cbBase.cbInfo.env = env; + moveCB->cbBase.asyncWork = nullptr; + moveCB->cbBase.deferred = nullptr; + moveCB->cbBase.ability = nullptr; + + napi_value ret = MoveWrap(env, info, moveCB); + if (ret == nullptr) { + HILOG_ERROR("tag dsa %{public}s,ret == nullptr", __func__); + if (moveCB != nullptr) { + delete moveCB; + moveCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value MoveWrap(napi_env env, napi_callback_info info, FileAccessHelperMoveCB *moveCB) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + size_t argcAsync = ARGS_THREE; + const size_t argcPromise = ARGS_TWO; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = 0; + napi_value thisVar = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("tag dsa %{public}s, Wrong argument count.", __func__); + return nullptr; + } + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); + if (valuetype == napi_string) { + moveCB->sourceFileUri = NapiValueToStringUtf8(env, args[PARAM0]); + HILOG_INFO("tag dsa %{public}s,sourceFileUri=%{public}s", __func__, moveCB->sourceFileUri.c_str()); + } + + NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); + if (valuetype == napi_string) { + moveCB->targetParentUri = NapiValueToStringUtf8(env, args[PARAM1]); + HILOG_INFO("tag dsa %{public}s,targetParentUri=%{public}s", __func__, moveCB->targetParentUri.c_str()); + } + + FileAccessHelper *objectInfo = nullptr; + napi_unwrap(env, thisVar, (void **)&objectInfo); + HILOG_INFO("tag dsa %{public}s,FileAccessHelper objectInfo", __func__); + moveCB->fileAccessHelper = objectInfo; + + if (argcAsync > argcPromise) { + ret = MoveAsync(env, args, ARGS_TWO, moveCB); + } else { + ret = MovePromise(env, moveCB); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value MoveAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperMoveCB *moveCB) +{ + HILOG_INFO("tag dsa %{public}s, asyncCallback.", __func__); + if (args == nullptr || moveCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = 0; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argCallback], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &moveCB->cbBase.cbInfo.callback)); + } + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + MoveExecuteCB, + MoveAsyncCompleteCB, + (void *)moveCB, + &moveCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, moveCB->cbBase.asyncWork)); + napi_value result = 0; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("tag dsa %{public}s, asyncCallback end.", __func__); + return result; +} + +napi_value MovePromise(napi_env env, FileAccessHelperMoveCB *moveCB) +{ + HILOG_INFO("tag dsa %{public}s, promise.", __func__); + if (moveCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = 0; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + moveCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + MoveExecuteCB, + MovePromiseCompleteCB, + (void *)moveCB, + &moveCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, moveCB->cbBase.asyncWork)); + HILOG_INFO("tag dsa %{public}s, promise end.", __func__); + return promise; +} + +void MoveExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("tag dsa NAPI_Move, worker pool thread execute."); + FileAccessHelperMoveCB *MoveCB = static_cast(data); + if (MoveCB->fileAccessHelper != nullptr) { + MoveCB->execResult = INVALID_PARAMETER; + if (!MoveCB->sourceFileUri.empty()) { + OHOS::Uri sourceFileUri(MoveCB->sourceFileUri); + OHOS::Uri targetParentUri(MoveCB->targetParentUri); + std::string newFile = ""; + OHOS::Uri newFileUri(newFile); + int err = MoveCB->fileAccessHelper->Move(sourceFileUri, targetParentUri, newFileUri); + MoveCB->result = newFileUri.ToString(); + MoveCB->execResult = err; + } else { + HILOG_ERROR("tag dsa NAPI_Move, fileAccessHelper sourceFileUri is empty"); + } + } else { + HILOG_ERROR("tag dsa NAPI_Move, fileAccessHelper == nullptr"); + } + HILOG_INFO("tag dsa NAPI_Move, worker pool thread execute end."); +} + +void MoveAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_Move, main event thread complete."); + FileAccessHelperCreateFileCB *MoveCB = static_cast(data); + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, MoveCB->cbBase.cbInfo.callback, &callback)); + + result[PARAM0] = GetCallbackErrorValue(env, MoveCB->execResult); + NAPI_CALL_RETURN_VOID( + env, napi_create_string_utf8(env, MoveCB->result.c_str(), NAPI_AUTO_LENGTH, &result[PARAM1])); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (MoveCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, MoveCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, MoveCB->cbBase.asyncWork)); + delete MoveCB; + MoveCB = nullptr; + HILOG_INFO("tag dsa NAPI_Move, main event thread complete end."); +} + +void MovePromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_Move, main event thread complete."); + FileAccessHelperCreateFileCB *MoveCB = static_cast(data); + napi_value result = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, MoveCB->result.c_str(), NAPI_AUTO_LENGTH, &result)); + NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, MoveCB->cbBase.deferred, result)); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, MoveCB->cbBase.asyncWork)); + delete MoveCB; + MoveCB = nullptr; + HILOG_INFO("tag dsa NAPI_Move, main event thread complete end."); +} + +napi_value NAPI_Rename(napi_env env, napi_callback_info info) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + FileAccessHelperRenameCB *renameCB = new (std::nothrow) FileAccessHelperRenameCB; + if (renameCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, renameCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + renameCB->cbBase.cbInfo.env = env; + renameCB->cbBase.asyncWork = nullptr; + renameCB->cbBase.deferred = nullptr; + renameCB->cbBase.ability = nullptr; + + napi_value ret = RenameWrap(env, info, renameCB); + if (ret == nullptr) { + HILOG_ERROR("tag dsa %{public}s,ret == nullptr", __func__); + if (renameCB != nullptr) { + delete renameCB; + renameCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value RenameWrap(napi_env env, napi_callback_info info, FileAccessHelperRenameCB *renameCB) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + size_t argcAsync = ARGS_THREE; + const size_t argcPromise = ARGS_TWO; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = 0; + napi_value thisVar = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("tag dsa %{public}s, Wrong argument count.", __func__); + return nullptr; + } + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); + if (valuetype == napi_string) { + renameCB->sourceFileUri = NapiValueToStringUtf8(env, args[PARAM0]); + HILOG_INFO("tag dsa %{public}s,sourceFileUri=%{public}s", __func__, renameCB->sourceFileUri.c_str()); + } + + NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); + if (valuetype == napi_string) { + renameCB->displayName = NapiValueToStringUtf8(env, args[PARAM1]); + HILOG_INFO("tag dsa %{public}s,displayName=%{public}s", __func__, renameCB->displayName.c_str()); + } + + FileAccessHelper *objectInfo = nullptr; + napi_unwrap(env, thisVar, (void **)&objectInfo); + HILOG_INFO("tag dsa %{public}s,FileAccessHelper objectInfo", __func__); + renameCB->fileAccessHelper = objectInfo; + + if (argcAsync > argcPromise) { + ret = RenameAsync(env, args, ARGS_TWO, renameCB); + } else { + ret = RenamePromise(env, renameCB); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value RenameAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperRenameCB *renameCB) +{ + HILOG_INFO("tag dsa %{public}s, asyncCallback.", __func__); + if (args == nullptr || renameCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = 0; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argCallback], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &renameCB->cbBase.cbInfo.callback)); + } + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + RenameExecuteCB, + RenameAsyncCompleteCB, + (void *)renameCB, + &renameCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, renameCB->cbBase.asyncWork)); + napi_value result = 0; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("tag dsa %{public}s, asyncCallback end.", __func__); + return result; +} + +napi_value RenamePromise(napi_env env, FileAccessHelperRenameCB *renameCB) +{ + HILOG_INFO("tag dsa %{public}s, promise.", __func__); + if (renameCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = 0; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + renameCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + RenameExecuteCB, + RenamePromiseCompleteCB, + (void *)renameCB, + &renameCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, renameCB->cbBase.asyncWork)); + HILOG_INFO("tag dsa %{public}s, promise end.", __func__); + return promise; +} + +void RenameExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("tag dsa NAPI_Rename, worker pool thread execute."); + FileAccessHelperRenameCB *renameCB = static_cast(data); + if (renameCB->fileAccessHelper != nullptr) { + renameCB->execResult = INVALID_PARAMETER; + if (!renameCB->sourceFileUri.empty()) { + OHOS::Uri sourceFileUri(renameCB->sourceFileUri); + std::string newFile = ""; + OHOS::Uri newFileUri(newFile); + int err = renameCB->fileAccessHelper->Rename(sourceFileUri, renameCB->displayName, newFileUri); + renameCB->result = newFileUri.ToString(); + renameCB->execResult = err; + } else { + HILOG_ERROR("tag dsa NAPI_Rename, fileAccessHelper sourceFileUri is empty"); + } + } else { + HILOG_ERROR("tag dsa NAPI_Rename, fileAccessHelper == nullptr"); + } + HILOG_INFO("tag dsa NAPI_Rename, worker pool thread execute end."); +} + +void RenameAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_Rename, main event thread complete."); + FileAccessHelperRenameCB *RenameCB = static_cast(data); + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, RenameCB->cbBase.cbInfo.callback, &callback)); + + result[PARAM0] = GetCallbackErrorValue(env, RenameCB->execResult); + NAPI_CALL_RETURN_VOID( + env, napi_create_string_utf8(env, RenameCB->result.c_str(), NAPI_AUTO_LENGTH, &result[PARAM1])); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (RenameCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, RenameCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, RenameCB->cbBase.asyncWork)); + delete RenameCB; + RenameCB = nullptr; + HILOG_INFO("tag dsa NAPI_Rename, main event thread complete end."); +} + +void RenamePromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_Rename, main event thread complete."); + FileAccessHelperRenameCB *RenameCB = static_cast(data); + napi_value result = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_create_string_utf8(env, RenameCB->result.c_str(), NAPI_AUTO_LENGTH, &result)); + NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, RenameCB->cbBase.deferred, result)); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, RenameCB->cbBase.asyncWork)); + delete RenameCB; + RenameCB = nullptr; + HILOG_INFO("tag dsa NAPI_Rename, main event thread complete end."); +} + +napi_value NAPI_CloseFile(napi_env env, napi_callback_info info) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + FileAccessHelperCloseFileCB *closeFileCB = new (std::nothrow) FileAccessHelperCloseFileCB; + if (closeFileCB == nullptr) { + HILOG_ERROR("%{public}s, closeFileCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + closeFileCB->cbBase.cbInfo.env = env; + closeFileCB->cbBase.asyncWork = nullptr; + closeFileCB->cbBase.deferred = nullptr; + closeFileCB->cbBase.ability = nullptr; + + napi_value ret = CloseFileWrap(env, info, closeFileCB); + if (ret == nullptr) { + HILOG_ERROR("tag dsa %{public}s,ret == nullptr", __func__); + if (closeFileCB != nullptr) { + delete closeFileCB; + closeFileCB = nullptr; + } + ret = WrapVoidToJS(env); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value CloseFileWrap(napi_env env, napi_callback_info info, FileAccessHelperCloseFileCB *closeFileCB) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + size_t argcAsync = ARGS_THREE; + const size_t argcPromise = ARGS_TWO; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = 0; + napi_value thisVar = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("tag dsa %{public}s, Wrong argument count.", __func__); + return nullptr; + } + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype)); + if (valuetype == napi_number) { + closeFileCB->fd = NapiValueToInt32Utf8(env, args[PARAM0]); + HILOG_INFO("tag dsa %{public}s,fd=%d", __func__, closeFileCB->fd); + } + + NAPI_CALL(env, napi_typeof(env, args[PARAM1], &valuetype)); + if (valuetype == napi_string) { + closeFileCB->uri = NapiValueToStringUtf8(env, args[PARAM1]); + HILOG_INFO("tag dsa %{public}s,uri=%{public}s", __func__, closeFileCB->uri.c_str()); + } + + FileAccessHelper *objectInfo = nullptr; + napi_unwrap(env, thisVar, (void **)&objectInfo); + HILOG_INFO("tag dsa %{public}s,FileAccessHelper objectInfo", __func__); + closeFileCB->fileAccessHelper = objectInfo; + + if (argcAsync > argcPromise) { + ret = CloseFileAsync(env, args, ARGS_TWO, closeFileCB); + } else { + ret = CloseFilePromise(env, closeFileCB); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value CloseFileAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperCloseFileCB *closeFileCB) +{ + HILOG_INFO("tag dsa %{public}s, asyncCallback.", __func__); + if (args == nullptr || closeFileCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = 0; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argCallback], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &closeFileCB->cbBase.cbInfo.callback)); + } + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + CloseFileExecuteCB, + CloseFileAsyncCompleteCB, + (void *)closeFileCB, + &closeFileCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, closeFileCB->cbBase.asyncWork)); + napi_value result = 0; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("tag dsa %{public}s, asyncCallback end.", __func__); + return result; +} + +napi_value CloseFilePromise(napi_env env, FileAccessHelperCloseFileCB *closeFileCB) +{ + HILOG_INFO("tag dsa %{public}s, promise.", __func__); + if (closeFileCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = 0; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + closeFileCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + CloseFileExecuteCB, + CloseFilePromiseCompleteCB, + (void *)closeFileCB, + &closeFileCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, closeFileCB->cbBase.asyncWork)); + HILOG_INFO("tag dsa %{public}s, promise end.", __func__); + return promise; +} + +void CloseFileExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("tag dsa NAPI_CloseFile, worker pool thread execute."); + FileAccessHelperCloseFileCB *CloseFileCB = static_cast(data); + if (CloseFileCB->fileAccessHelper != nullptr) { + CloseFileCB->execResult = INVALID_PARAMETER; + if (CloseFileCB->fd!=NO_ERROR) { + CloseFileCB->result = CloseFileCB->fileAccessHelper->CloseFile(CloseFileCB->fd, CloseFileCB->uri); + CloseFileCB->execResult = NO_ERROR; + } else { + HILOG_ERROR("tag dsa NAPI_CloseFile, fileAccessHelper fd != NO_ERROR"); + } + } else { + HILOG_ERROR("tag dsa NAPI_CloseFile, fileAccessHelper == nullptr"); + } + HILOG_INFO("tag dsa NAPI_CloseFile, worker pool thread execute end."); +} + +void CloseFileAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_CloseFile, main event thread complete."); + FileAccessHelperCloseFileCB *CloseFileCB = static_cast(data); + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, CloseFileCB->cbBase.cbInfo.callback, &callback)); + + result[PARAM0] = GetCallbackErrorValue(env, CloseFileCB->execResult); + napi_create_int32(env, CloseFileCB->result, &result[PARAM1]); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (CloseFileCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, CloseFileCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, CloseFileCB->cbBase.asyncWork)); + delete CloseFileCB; + CloseFileCB = nullptr; + HILOG_INFO("tag dsa NAPI_CloseFile, main event thread complete end."); +} + +void CloseFilePromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_CloseFile, main event thread complete."); + FileAccessHelperCloseFileCB *CloseFileCB = static_cast(data); + napi_value result = nullptr; + napi_create_int32(env, CloseFileCB->result, &result); + NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, CloseFileCB->cbBase.deferred, result)); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, CloseFileCB->cbBase.asyncWork)); + delete CloseFileCB; + CloseFileCB = nullptr; + HILOG_INFO("tag dsa NAPI_CloseFile, main event thread complete end."); +} + +napi_value NAPI_Release(napi_env env, napi_callback_info info) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + FileAccessHelperReleaseCB *releaseCB = new (std::nothrow) FileAccessHelperReleaseCB; + if (releaseCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, releaseCB == nullptr.", __func__); + return WrapVoidToJS(env); + } + releaseCB->cbBase.cbInfo.env = env; + releaseCB->cbBase.asyncWork = nullptr; + releaseCB->cbBase.deferred = nullptr; + + napi_value ret = ReleaseWrap(env, info, releaseCB); + if (ret == nullptr) { + HILOG_ERROR("tag dsa %{public}s,ret == nullptr", __func__); + delete releaseCB; + releaseCB = nullptr; + ret = WrapVoidToJS(env); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value ReleaseWrap(napi_env env, napi_callback_info info, FileAccessHelperReleaseCB *releaseCB) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + size_t argcAsync = ARGS_ONE; + const size_t argcPromise = ARGS_ZERO; + const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT; + napi_value args[ARGS_MAX_COUNT] = {nullptr}; + napi_value ret = nullptr; + napi_value thisVar = nullptr; + + NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr)); + if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) { + HILOG_ERROR("tag dsa %{public}s, Wrong argument count.", __func__); + return nullptr; + } + + FileAccessHelper *objectInfo = nullptr; + napi_unwrap(env, thisVar, (void **)&objectInfo); + HILOG_INFO("tag dsa FileAccessHelper ReleaseWrap objectInfo = %{public}p", objectInfo); + releaseCB->fileAccessHelper = objectInfo; + + if (argcAsync > argcPromise) { + ret = ReleaseAsync(env, args, PARAM0, releaseCB); + } else { + ret = ReleasePromise(env, releaseCB); + } + HILOG_INFO("tag dsa %{public}s,end", __func__); + return ret; +} + +napi_value ReleaseAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperReleaseCB *releaseCB) +{ + HILOG_INFO("tag dsa %{public}s, asyncCallback.", __func__); + if (args == nullptr || releaseCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName = 0; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, args[argCallback], &valuetype)); + if (valuetype == napi_function) { + NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &releaseCB->cbBase.cbInfo.callback)); + } + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + ReleaseExecuteCB, + ReleaseAsyncCompleteCB, + (void *)releaseCB, + &releaseCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, releaseCB->cbBase.asyncWork)); + napi_value result = 0; + NAPI_CALL(env, napi_get_null(env, &result)); + HILOG_INFO("tag dsa %{public}s, asyncCallback end.", __func__); + return result; +} + +napi_value ReleasePromise(napi_env env, FileAccessHelperReleaseCB *releaseCB) +{ + HILOG_INFO("tag dsa %{public}s, promise.", __func__); + if (releaseCB == nullptr) { + HILOG_ERROR("tag dsa %{public}s, param == nullptr.", __func__); + return nullptr; + } + napi_value resourceName; + NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName)); + napi_deferred deferred; + napi_value promise = 0; + NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); + releaseCB->cbBase.deferred = deferred; + + NAPI_CALL(env, + napi_create_async_work(env, + nullptr, + resourceName, + ReleaseExecuteCB, + ReleasePromiseCompleteCB, + (void *)releaseCB, + &releaseCB->cbBase.asyncWork)); + NAPI_CALL(env, napi_queue_async_work(env, releaseCB->cbBase.asyncWork)); + HILOG_INFO("tag dsa %{public}s, promise end.", __func__); + return promise; +} + +void ReleaseExecuteCB(napi_env env, void *data) +{ + HILOG_INFO("tag dsa NAPI_Release, worker pool thread execute."); + FileAccessHelperReleaseCB *releaseCB = static_cast(data); + if (releaseCB->fileAccessHelper != nullptr) { + releaseCB->result = releaseCB->fileAccessHelper->Release(); + } else { + HILOG_ERROR("tag dsa NAPI_Release, fileAccessHelper == nullptr"); + } + HILOG_INFO("tag dsa NAPI_Release, worker pool thread execute end."); +} + +void ReleaseAsyncCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_Release, main event thread complete."); + FileAccessHelperReleaseCB *releaseCB = static_cast(data); + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_value result[ARGS_TWO] = {nullptr}; + napi_value callResult = nullptr; + NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); + NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, releaseCB->cbBase.cbInfo.callback, &callback)); + + result[PARAM0] = GetCallbackErrorValue(env, NO_ERROR); + napi_get_boolean(env, releaseCB->result, &result[PARAM1]); + NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult)); + + if (releaseCB->cbBase.cbInfo.callback != nullptr) { + NAPI_CALL_RETURN_VOID(env, napi_delete_reference(env, releaseCB->cbBase.cbInfo.callback)); + } + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, releaseCB->cbBase.asyncWork)); + delete releaseCB; + releaseCB = nullptr; + HILOG_INFO("tag dsa NAPI_Release, main event thread complete end."); +} + +void ReleasePromiseCompleteCB(napi_env env, napi_status status, void *data) +{ + HILOG_INFO("tag dsa NAPI_Release, main event thread complete."); + FileAccessHelperReleaseCB *releaseCB = static_cast(data); + napi_value result = nullptr; + napi_get_boolean(env, releaseCB->result, &result); + NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(env, releaseCB->cbBase.deferred, result)); + NAPI_CALL_RETURN_VOID(env, napi_delete_async_work(env, releaseCB->cbBase.asyncWork)); + delete releaseCB; + releaseCB = nullptr; + HILOG_INFO("tag dsa NAPI_Release, main event thread complete end."); +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h new file mode 100644 index 0000000000000000000000000000000000000000..aa9348d7732e9cae386d8d59581dc128fa46de5a --- /dev/null +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2022 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_ACCESS_NAPI_H +#define FILE_ACCESS_NAPI_H + +#include "file_access_common.h" + +namespace OHOS { +namespace AppExecFwk { + napi_value FileAccessHelperInit(napi_env env, napi_value exports); + napi_value FileAccessHelperConstructor(napi_env env, napi_callback_info info); + napi_value NAPI_OpenFile(napi_env env, napi_callback_info info); + napi_value OpenFileWrap(napi_env env, napi_callback_info info, FileAccessHelperOpenFileCB *openFileCB); + napi_value OpenFileAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperOpenFileCB *openFileCB); + napi_value OpenFilePromise(napi_env env, FileAccessHelperOpenFileCB *openFileCB); + void OpenFileExecuteCB(napi_env env, void *data); + void OpenFileAsyncCompleteCB(napi_env env, napi_status status, void *data); + void OpenFilePromiseCompleteCB(napi_env env, napi_status status, void *data); + + napi_value NAPI_CreateFile(napi_env env, napi_callback_info info); + napi_value CreateFileWrap(napi_env env, napi_callback_info info, FileAccessHelperCreateFileCB *createFileCB); + napi_value CreateFileAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperCreateFileCB *createFileCB); + napi_value CreateFilePromise(napi_env env, FileAccessHelperCreateFileCB *createFileCB); + void CreateFileExecuteCB(napi_env env, void *data); + void CreateFileAsyncCompleteCB(napi_env env, napi_status status, void *data); + void CreateFilePromiseCompleteCB(napi_env env, napi_status status, void *data); + + napi_value NAPI_Mkdir(napi_env env, napi_callback_info info); + napi_value MkdirWrap(napi_env env, napi_callback_info info, FileAccessHelperMkdirCB *mkdirCB); + napi_value MkdirAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperMkdirCB *mkdirCB); + napi_value MkdirPromise(napi_env env, FileAccessHelperMkdirCB *mkdirCB); + void MkdirExecuteCB(napi_env env, void *data); + void MkdirAsyncCompleteCB(napi_env env, napi_status status, void *data); + void MkdirPromiseCompleteCB(napi_env env, napi_status status, void *data); + + napi_value NAPI_Delete(napi_env env, napi_callback_info info); + napi_value DeleteWrap(napi_env env, napi_callback_info info, FileAccessHelperDeleteCB *deleteCB); + napi_value DeleteAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperDeleteCB *deleteCB); + napi_value DeletePromise(napi_env env, FileAccessHelperDeleteCB *deleteCB); + void DeleteExecuteCB(napi_env env, void *data); + void DeleteAsyncCompleteCB(napi_env env, napi_status status, void *data); + void DeletePromiseCompleteCB(napi_env env, napi_status status, void *data); + + napi_value NAPI_Move(napi_env env, napi_callback_info info); + napi_value MoveWrap(napi_env env, napi_callback_info info, FileAccessHelperMoveCB *moveCB); + napi_value MoveAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperMoveCB *moveCB); + napi_value MovePromise(napi_env env, FileAccessHelperMoveCB *moveCB); + void MoveExecuteCB(napi_env env, void *data); + void MoveAsyncCompleteCB(napi_env env, napi_status status, void *data); + void MovePromiseCompleteCB(napi_env env, napi_status status, void *data); + + napi_value NAPI_Rename(napi_env env, napi_callback_info info); + napi_value RenameWrap(napi_env env, napi_callback_info info, FileAccessHelperRenameCB *renameCB); + napi_value RenameAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperRenameCB *renameCB); + napi_value RenamePromise(napi_env env, FileAccessHelperRenameCB *renameCB); + void RenameExecuteCB(napi_env env, void *data); + void RenameAsyncCompleteCB(napi_env env, napi_status status, void *data); + void RenamePromiseCompleteCB(napi_env env, napi_status status, void *data); + + napi_value NAPI_CloseFile(napi_env env, napi_callback_info info); + napi_value CloseFileWrap(napi_env env, napi_callback_info info, FileAccessHelperCloseFileCB *closeFileCB); + napi_value CloseFileAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperCloseFileCB *closeFileCB); + napi_value CloseFilePromise(napi_env env, FileAccessHelperCloseFileCB *closeFileCB); + void CloseFileExecuteCB(napi_env env, void *data); + void CloseFileAsyncCompleteCB(napi_env env, napi_status status, void *data); + void CloseFilePromiseCompleteCB(napi_env env, napi_status status, void *data); + + napi_value NAPI_Release(napi_env env, napi_callback_info info); + napi_value ReleaseWrap(napi_env env, napi_callback_info info, FileAccessHelperReleaseCB *releaseCB); + napi_value ReleaseAsync(napi_env env, napi_value *args, const size_t argCallback, FileAccessHelperReleaseCB *releaseCB); + napi_value ReleasePromise(napi_env env, FileAccessHelperReleaseCB *releaseCB); + void ReleaseExecuteCB(napi_env env, void *data); + void ReleaseAsyncCompleteCB(napi_env env, napi_status status, void *data); + void ReleasePromiseCompleteCB(napi_env env, napi_status status, void *data); +} +} +#endif \ No newline at end of file diff --git a/interfaces/kits/js/src/module.cpp b/interfaces/kits/napi/file_access_module/native_fileaccess_module.cpp similarity index 41% rename from interfaces/kits/js/src/module.cpp rename to interfaces/kits/napi/file_access_module/native_fileaccess_module.cpp index 5c5b7a2c310e6e20d3bf722a7f493d398845c982..22d41c9696717b7253a7aadebc89696d44e2aa3f 100644 --- a/interfaces/kits/js/src/module.cpp +++ b/interfaces/kits/napi/file_access_module/native_fileaccess_module.cpp @@ -1,10 +1,10 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2022 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 + * 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, @@ -16,29 +16,47 @@ #include #include -#include "file_manager_napi.h" -#include "log.h" - +#include "napi_fileaccess_helper.h" +#include "napi/native_api.h" +#include "napi/native_node_api.h" +#include "hilog_wrapper.h" using namespace std; namespace OHOS { -namespace FileManagerService { -using namespace DistributedFS; -static napi_value Export(napi_env env, napi_value exports) -{ - std::vector> products; - products.emplace_back(make_unique(env, exports)); - for (auto &&product : products) { - if (!product->Export()) { - ERR_LOG("INNER BUG. Failed to export class %{public}s for module filemanager", - product->GetClassName().c_str()); - return nullptr; - } - } +namespace AppExecFwk { +EXTERN_C_START +/* + * The module initialization. + */ +static napi_value Init(napi_env env, napi_value exports) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + FileAccessHelperInit(env, exports); return exports; } +EXTERN_C_END -NAPI_MODULE(filemanager, Export) -} // namespace FileManagerService +/* + * The module definition. + */ +static napi_module _module = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "data.fileAccess", + .nm_priv = ((void *)0), + .reserved = {0} +}; + +/* + * The module registration. + */ +extern "C" __attribute__((constructor)) void RegisterModule(void) +{ + HILOG_INFO("tag dsa %{public}s,called", __func__); + napi_module_register(&_module); +} +} } // namespace OHOS \ No newline at end of file diff --git a/services/etc/fms_service.rc b/interfaces/kits/napi/file_ext_ability/BUILD.gn similarity index 33% rename from services/etc/fms_service.rc rename to interfaces/kits/napi/file_ext_ability/BUILD.gn index 41f1e4d141e30319b75b0a9bfcf327649c68a687..b0e794e8343d5ca28a9d0a3a9f38d881b7a27f4c 100644 --- a/services/etc/fms_service.rc +++ b/interfaces/kits/napi/file_ext_ability/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (C) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2022 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 @@ -11,10 +11,40 @@ # See the License for the specific language governing permissions and # limitations under the License. -service fms_service /system/bin/sa_main /system/profile/fms_service.xml - class z_core - seclabel u:r:audiodistributedservice:s0 +import("//ark/ts2abc/ts2panda/ts2abc_config.gni") +import("//build/ohos.gni") -on boot - start fms_service +ts2abc_gen_abc("gen_file_ext_ability_abc") { + src_js = rebase_path("file_ext_ability.js") + dst_file = rebase_path(target_out_dir + "/file_ext_ability.abc") + in_puts = [ "file_ext_ability.js" ] + out_puts = [ target_out_dir + "/file_ext_ability.abc" ] + extra_args = [ "--module" ] +} +gen_js_obj("file_ext_ability_js") { + input = "file_ext_ability.js" + output = target_out_dir + "/file_ext_ability.o" +} + +gen_js_obj("file_ext_ability_abc") { + input = get_label_info(":gen_file_ext_ability_abc", "target_out_dir") + + "/file_ext_ability.abc" + output = target_out_dir + "/file_ext_ability_abc.o" + dep = ":gen_file_ext_ability_abc" +} + +ohos_shared_library("fileextensionability_napi") { + sources = [ "file_ext_ability_module.cpp" ] + + deps = [ + ":file_ext_ability_abc", + ":file_ext_ability_js", + ] + + external_deps = [ "napi:ace_napi" ] + + relative_install_dir = "module/application" + subsystem_name = "filemanagement" + part_name = "user_file_service" +} diff --git a/interfaces/kits/napi/file_ext_ability/file_ext_ability.js b/interfaces/kits/napi/file_ext_ability/file_ext_ability.js new file mode 100644 index 0000000000000000000000000000000000000000..7ecdc1bccb004dc2557b0d61b71ee7e455929e1c --- /dev/null +++ b/interfaces/kits/napi/file_ext_ability/file_ext_ability.js @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 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. + */ + +class FileExtensionAbility { + onCreate(want) { + console.log('js c++ tag dsa onCreate, want:' + want.abilityName); + } + + openFile(uri, mode) { + console.log('js c++ tag dsa openFile, uri:' + uri + ',mode: ' + mode); + return 0; + } + + createFile(parentUri, displayName) { + console.log('js c++ tag dsa CreateFile, parentUri:' + parentUri + ',displayName:' + displayName ); + return "filetest://fileext.share/temp/test/CreateFile000.txt"; + } + + mkdir(parentUri, displayName) { + console.log('js c++ tag dsa mkdir, parentUri:' + parentUri + ',displayName:' + displayName); + return "filetest://fileext.share/temp/test/Mkdir000"; + } + + delete(sourceFileUri) { + console.log('js c++ tag dsa delete, sourceFileUri:' + sourceFileUri); + return 0; + } + + move(sourceFileUri, targetParentUri) { + console.log('js c++ tag dsa move, sourceFileUri:' + sourceFileUri + ',targetParentUri:' + targetParentUri); + return "filetest://fileext.share/temp/test/move000.xl"; + } + + rename(sourceFileUri, displayName) { + console.log('js c++ tag dsa rename, sourceFileUri:' + sourceFileUri + ',displayName:' + displayName); + return "filetest://fileext.share/temp/test/rename000.ttt"; + } +} + +export default FileExtensionAbility \ No newline at end of file diff --git a/interfaces/kits/napi/file_ext_ability/file_ext_ability_module.cpp b/interfaces/kits/napi/file_ext_ability/file_ext_ability_module.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6dca96b582bb8bf7270b2888fb4b7b921b96d386 --- /dev/null +++ b/interfaces/kits/napi/file_ext_ability/file_ext_ability_module.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022 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. + */ + +#include "native_engine/native_engine.h" + +extern const char _binary_file_ext_ability_js_start[]; +extern const char _binary_file_ext_ability_js_end[]; +extern const char _binary_file_ext_ability_abc_start[]; +extern const char _binary_file_ext_ability_abc_end[]; + +extern "C" __attribute__((constructor)) +void NAPI_application_FileExtensionAbility_AutoRegister() +{ + auto moduleManager = NativeModuleManager::GetInstance(); + NativeModule newModuleInfo = { + .name = "application.FileExtensionAbility", + .fileName = "application/libfileextensionability_napi.so/FileExtensionAbility.js", + }; + + moduleManager->Register(&newModuleInfo); +} + +extern "C" __attribute__((visibility("default"))) +void NAPI_application_FileExtensionAbility_GetJSCode(const char **buf, int *bufLen) +{ + if (buf != nullptr) { + *buf = _binary_file_ext_ability_js_start; + } + + if (bufLen != nullptr) { + *bufLen = _binary_file_ext_ability_js_end - _binary_file_ext_ability_js_start; + } +} + +// file extension ability JS register +extern "C" __attribute__((visibility("default"))) +void NAPI_application_FileExtensionAbility_GetABCCode(const char **buf, int *buflen) +{ + if (buf != nullptr) { + *buf = _binary_file_ext_ability_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_file_ext_ability_abc_end - _binary_file_ext_ability_abc_start; + } +} \ No newline at end of file diff --git a/services/etc/fms_service.cfg b/services/etc/fms_service.cfg deleted file mode 100644 index a271b4155f7b1275160ab535e80443b972899335..0000000000000000000000000000000000000000 --- a/services/etc/fms_service.cfg +++ /dev/null @@ -1,9 +0,0 @@ -{ - "services" : [{ - "name" : "fms_service", - "path" : ["/system/bin/sa_main", "/system/profile/fms_service.xml"], - "uid" : "1006", - "gid" : ["system", "shell"] - } - ] -} diff --git a/services/include/file_manager_service_def.h b/services/include/file_manager_service_def.h deleted file mode 100644 index 1cd2f1681a3eddcf90cd821f2f47265b7c922951..0000000000000000000000000000000000000000 --- a/services/include/file_manager_service_def.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2021 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 STORAGE_FILE_MANAGER_SERVICE_DEF_H -#define STORAGE_FILE_MANAGER_SERVICE_DEF_H - -#include -#include -#include -#include "media_data_ability_const.h" -#include "media_lib_service_const.h" - -namespace OHOS { -namespace FileManagerService { -enum Operation { - GET_ROOT, - MAKE_DIR, - LIST_FILE, - CREATE_FILE -}; - -enum Equipment { - INTERNAL_STORAGE, - EXTERNAL_STORAGE -}; - -enum VolumeState { - UNMOUNTED = 0, - CHECKING, - MOUNTED, - EJECTING -}; -constexpr int64_t MAX_NUM = 200; -constexpr int32_t CODE_MASK = 0xff; -constexpr int32_t EQUIPMENT_SHIFT = 16; - -const std::string FISRT_LEVEL_ALBUM = "dataability:///album"; -// use to find out album in the root dir -const std::string RELATIVE_ROOT_PATH = ""; - -const std::string MEDIA_ROOT_PATH = "/storage/media/local/files"; -const std::string IMAGE_ROOT_NAME = "image_album"; -const std::string VIDEO_ROOT_NAME = "video_album"; -const std::string AUDIO_ROOT_NAME = "audio_album"; -const std::string FILE_ROOT_NAME = "file_folder"; - -const std::string ALBUM_TYPE = "album"; -const std::string FILE_MIME_TYPE = "file/*"; - -const std::string EXTERNAL_STORAGE_URI = "dataability:///external_storage"; -const std::string MOUNT_POINT_ROOT = "/mnt/"; - -constexpr int FILE_MEDIA_TYPE = Media::MediaType::MEDIA_TYPE_FILE; -constexpr int RESULTSET_EMPTY = 0; -constexpr int RESULTSET_ONE = 1; - -const std::unordered_map FILE_MIME_TYPE_MAPS = { - {Media::MediaType::MEDIA_TYPE_IMAGE, "image/*"}, - {Media::MediaType::MEDIA_TYPE_AUDIO, "audio/*"}, - {Media::MediaType::MEDIA_TYPE_VIDEO, "video/*"}, - {Media::MediaType::MEDIA_TYPE_FILE, "file/*"}, - {Media::MediaType::MEDIA_TYPE_ALBUM, "file/*"}, -}; - -const std::unordered_map MEDIA_TYPE_FOLDER_MAPS = { - {Media::MediaType::MEDIA_TYPE_IMAGE, "image/"}, - {Media::MediaType::MEDIA_TYPE_AUDIO, "audio/"}, - {Media::MediaType::MEDIA_TYPE_VIDEO, "video/"}, - {Media::MediaType::MEDIA_TYPE_FILE, "document/"}, -}; - -const std::unordered_map MEDIA_TYPE_URI_MAPS = { - {Media::MediaType::MEDIA_TYPE_IMAGE, Media::MEDIALIBRARY_IMAGE_URI}, - {Media::MediaType::MEDIA_TYPE_AUDIO, Media::MEDIALIBRARY_AUDIO_URI}, - {Media::MediaType::MEDIA_TYPE_VIDEO, Media::MEDIALIBRARY_VIDEO_URI}, - {Media::MediaType::MEDIA_TYPE_FILE, Media::MEDIALIBRARY_FILE_URI}, -}; - -#define GET_COLUMN_INDEX_FROM_NAME(result, name, index) \ - do { \ - if (result->GetColumnIndex(name, index) != NativeRdb::E_OK) { \ - ERR_LOG("NativeRdb gets %{public}s index fail", name.c_str()); \ - return false; \ - } \ - } while (0) -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_FILE_MANAGER_SERVICE_DEF_H diff --git a/services/include/file_manager_service_errno.h b/services/include/file_manager_service_errno.h deleted file mode 100644 index dcc22b5fc7bbfcddd4a7f84fcbcdd10ed83efcb4..0000000000000000000000000000000000000000 --- a/services/include/file_manager_service_errno.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2021 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 STORAGE_SERVICES_INCLUDE_ERRNO_H -#define STORAGE_SERVICES_INCLUDE_ERRNO_H -namespace OHOS { -namespace FileManagerService { -constexpr int32_t SUCCESS = 0; -constexpr int32_t FAIL = -1; // internal Error -constexpr int32_t E_NOEXIST = -2; // file not exist -constexpr int32_t E_EMPTYFOLDER = -3; // folder empty -constexpr int32_t E_INVALID_OPERCODE = -4; // not valid oper code -constexpr int32_t E_CREATE_FAIL = -5; // create file fail -constexpr int32_t E_INVALID_FILE_NUMBER = -6; // file count or offset invalid -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERVICES_INCLUDE_ERRNO_H diff --git a/services/include/log.h b/services/include/log.h deleted file mode 100644 index db1322ef993ba3509af8465817d38da0dbf09c2f..0000000000000000000000000000000000000000 --- a/services/include/log.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2021 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 STORAGE_SERIVCE_INCLUDE_LOG_H -#define STORAGE_SERIVCE_INCLUDE_LOG_H - -#include -#include "hilog/log.h" - -#undef LOG_DOMAIN -#undef LOG_TAG -#define LOG_DOMAIN 0xD00430A -#define LOG_TAG "FileManagerment:FMS" - -#define DEBUG_LOG(fmt, args...) \ - HILOG_DEBUG(LOG_CORE, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args) -#define ERR_LOG(fmt, args...) \ - HILOG_ERROR(LOG_CORE, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args) -#define WARNING_LOG(fmt, args...) \ - HILOG_WARN(LOG_CORE, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args) -#define INFO_LOG(fmt, args...) \ - HILOG_INFO(LOG_CORE, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args) -#define FATAL_LOG(fmt, args...) \ - HILOG_FATAL(LOG_CORE, "{%{public}s():%{public}d} " fmt, __FUNCTION__, __LINE__, ##args) -#endif // STORAGE_SERIVCE_INCLUDE_LOG_H diff --git a/services/include/storage_manager_inf.h b/services/include/storage_manager_inf.h deleted file mode 100644 index 4f294f16092a418c3a42a8b3351ea262d08fce4f..0000000000000000000000000000000000000000 --- a/services/include/storage_manager_inf.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 STORAGE_MANAGER_INTERFACE_H -#define STORAGE_MANAGER_INTERFACE_H -#include -#include -#include "ipc/storage_manager_proxy.h" -#include "ipc/storage_manager.h" -#include "istorage_manager.h" -namespace OHOS { -namespace FileManagerService { -class StorageManagerInf { -public: - StorageManagerInf() = default; - ~StorageManagerInf() = default; - static int Connect(); - static std::vector GetAllVolumes(); - static bool GetMountedVolumes(std::vector &vecRootPath); - static bool StoragePathValidCheck(const std::string &path); -private: - inline static sptr storageManager_; -}; -} // FileManagerService -} // OHOS -#endif // STORAGE_MANAGER_INTERFACE_H \ No newline at end of file diff --git a/services/sa_profile/5010.xml b/services/sa_profile/5010.xml deleted file mode 100644 index 49e5224220cb322f1126fb066b5e486986ee5a7e..0000000000000000000000000000000000000000 --- a/services/sa_profile/5010.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - fms_service - - libfms_server.z.so - - - 5010 - libfms_server.z.so - true - false - 1 - - diff --git a/services/src/client/file_manager_proxy.cpp b/services/src/client/file_manager_proxy.cpp deleted file mode 100644 index 0c15b609f7cdeb7e79115a1c865568ade14a77d6..0000000000000000000000000000000000000000 --- a/services/src/client/file_manager_proxy.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (C) 2021 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. - */ -#include "file_manager_proxy.h" - -#include "cmd_response.h" -#include "file_info.h" -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "file_manager_service_stub.h" -#include "log.h" -#include "media_file_utils.h" - -using namespace std; - -namespace OHOS { -namespace FileManagerService { -static int GetCmdResponse(MessageParcel &reply, sptr &cmdResponse) -{ - cmdResponse = reply.ReadParcelable(); - if (cmdResponse == nullptr) { - ERR_LOG("Unmarshalling cmdResponse fail"); - return FAIL; - } - return cmdResponse->GetErr(); -} - -FileManagerProxy::FileManagerProxy(const sptr &impl) - : IRemoteProxy(impl) {} -int FileManagerProxy::GetRoot(const CmdOptions &option, vector> &fileRes) -{ - CmdOptions op(option); - int code = Operation::GET_ROOT; - if (op.GetDevInfo().GetName() == "external_storage") { - code = (Equipment::EXTERNAL_STORAGE << EQUIPMENT_SHIFT) | Operation::GET_ROOT; - } - MessageParcel data; - data.WriteInterfaceToken(GetDescriptor()); - data.WriteString(op.GetDevInfo().GetName()); - MessageParcel reply; - MessageOption messageOption; - int err = Remote()->SendRequest(code, data, reply, messageOption); - if (err != ERR_NONE) { - ERR_LOG("GetRoot inner error send request fail %{public}d", err); - return FAIL; - } - sptr cmdResponse; - err = GetCmdResponse(reply, cmdResponse); - if (err != ERR_NONE) { - return err; - } - fileRes = cmdResponse->GetFileInfoList(); - return err; -} - -int FileManagerProxy::CreateFile(const std::string &path, const std::string &fileName, - const CmdOptions &option, std::string &uri) -{ - MessageParcel data; - data.WriteInterfaceToken(GetDescriptor()); - data.WriteString(fileName); - data.WriteString(path); - MessageParcel reply; - MessageOption messageOption; - int code = Operation::CREATE_FILE; - CmdOptions op(option); - if (op.GetDevInfo().GetName() == "external_storage") { - code = (Equipment::EXTERNAL_STORAGE << EQUIPMENT_SHIFT) | Operation::CREATE_FILE; - } - int err = Remote()->SendRequest(code, data, reply, messageOption); - if (err != ERR_NONE) { - ERR_LOG("inner error send request fail %{public}d", err); - return FAIL; - } - sptr cmdResponse; - err = GetCmdResponse(reply, cmdResponse); - if (err != ERR_NONE) { - return err; - } - uri = cmdResponse->GetUri(); - return err; -} - -IFmsClient *IFmsClient::GetFmsInstance() -{ - auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (samgr == nullptr) { - ERR_LOG("samgr object is NULL."); - return nullptr; - } - sptr object = samgr->GetSystemAbility(FILE_MANAGER_SERVICE_ID); - if (object == nullptr) { - ERR_LOG("FileManager Service object is NULL."); - return nullptr; - } - static FileManagerProxy proxy = FileManagerProxy(object); - return &proxy; -} - -int FileManagerProxy::ListFile(const std::string &type, const std::string &path, const CmdOptions &option, - std::vector> &fileRes) -{ - CmdOptions op(option); - std::string devName(op.GetDevInfo().GetName()); - std::string devPath(op.GetDevInfo().GetPath()); - int64_t offset = op.GetOffset(); - int64_t count = op.GetCount(); - MessageParcel data; - data.WriteInterfaceToken(GetDescriptor()); - data.WriteString(devName); - data.WriteString(devPath); - data.WriteString(type); - data.WriteString(path); - data.WriteInt64(offset); - data.WriteInt64(count); - MessageParcel reply; - MessageOption messageOption; - uint32_t code = Operation::LIST_FILE; - if (op.GetDevInfo().GetName() == "external_storage") { - code = (Equipment::EXTERNAL_STORAGE << EQUIPMENT_SHIFT) | Operation::LIST_FILE; - } - int err = Remote()->SendRequest(code, data, reply, messageOption); - if (err != ERR_NONE) { - ERR_LOG("inner error send request fail %{public}d", err); - return FAIL; - } - sptr cmdResponse; - err = GetCmdResponse(reply, cmdResponse); - if (err != ERR_NONE) { - return err; - } - fileRes = cmdResponse->GetFileInfoList(); - return err; -} - -int FileManagerProxy::Mkdir(const string &name, const string &path) -{ - MessageParcel data; - data.WriteInterfaceToken(GetDescriptor()); - data.WriteString(name); - data.WriteString(path); - MessageParcel reply; - MessageOption option; - int err = Remote()->SendRequest(Operation::MAKE_DIR, data, reply, option); - if (err != ERR_NONE) { - ERR_LOG("inner error send request fail %{public}d", err); - return FAIL; - } - reply.ReadInt32(err); - return err; -} -} // FileManagerService -} // namespace OHOS \ No newline at end of file diff --git a/services/src/client/ifms_client.h b/services/src/client/ifms_client.h deleted file mode 100644 index ba0ce14abfe063493042b82988963f0a168dee63..0000000000000000000000000000000000000000 --- a/services/src/client/ifms_client.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2021 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 STORAGE_IFILE_MANAGER_CLIENT_H -#define STORAGE_IFILE_MANAGER_CLIENT_H -#include "cmd_options.h" -#include "file_info.h" -namespace OHOS { -namespace FileManagerService { -class IFmsClient { -public: - virtual ~IFmsClient() {} - static IFmsClient *GetFmsInstance(); - virtual int Mkdir(const std::string &name, const std::string &path) = 0; - virtual int ListFile(const std::string &type, const std::string &path, const CmdOptions &option, - std::vector> &fileRes) = 0; - virtual int GetRoot(const CmdOptions &option, std::vector> &fileRes) = 0; - virtual int CreateFile(const std::string &path, const std::string &fileName, - const CmdOptions &option, std::string &uri) = 0; -}; -} // namespace FileManagerService { -} // namespace OHOS -#endif // STORAGE_IFILE_MANAGER_CLIENT_H \ No newline at end of file diff --git a/services/src/fileoper/cmd_options.h b/services/src/fileoper/cmd_options.h deleted file mode 100644 index b119ead8f919ce13ab53080cb181971149537dd4..0000000000000000000000000000000000000000 --- a/services/src/fileoper/cmd_options.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (C) 2021 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 STORAGE_SERVICES_DEV_INFO_H -#define STORAGE_SERVICES_DEV_INFO_H - -#include -#include "file_manager_service_def.h" -namespace OHOS { -namespace FileManagerService { -class DevInfo { -public: - DevInfo() = default; - ~DevInfo() = default; - DevInfo(const std::string &nameIn, const std::string &pathIn) : name_(nameIn), path_(pathIn) - {} - - DevInfo(const DevInfo &dev) - { - this->name_ = dev.name_; - this->path_ = dev.path_; - } - - DevInfo& operator=(const DevInfo& dev) - { - this->name_ = dev.name_; - this->path_ = dev.path_; - return *this; - } - - std::string GetName() const - { - return name_; - } - - void SetName(const std::string& name) - { - name_ = name; - } - - std::string GetPath() const - { - return path_; - } - - void SetPath(const std::string& path) - { - path_ = path; - } - -private: - std::string name_ {""}; - std::string path_ {""}; -}; - -class CmdOptions { -public: - CmdOptions() = default; - ~CmdOptions() = default; - - CmdOptions(DevInfo devIn, int64_t offsetIn, int64_t countIn, bool hasOptIn) - : dev_(devIn), offset_(offsetIn), count_(countIn), hasOpt_(hasOptIn) - {} - CmdOptions(const std::string &nameIn, const std::string &pathIn, - int64_t offsetIn, int64_t countIn, bool hasOptIn) - : dev_(nameIn, pathIn), offset_(offsetIn), count_(countIn), hasOpt_(hasOptIn) - {} - - CmdOptions(const CmdOptions &option) = default; - CmdOptions& operator=(const CmdOptions& option) = default; - - DevInfo GetDevInfo() const - { - return dev_; - } - - void SetDevInfo(const DevInfo& dev) - { - dev_ = dev; - } - - int64_t GetOffset() const - { - return offset_; - } - - void SetOffset(int64_t offset) - { - offset_ = offset; - } - - int64_t GetCount() const - { - return count_; - } - - void setCount(int64_t count) - { - count_ = count; - } - - bool GetHasOpt() const - { - return hasOpt_; - } - - void SetHasOpt(bool hasOpt) - { - hasOpt_ = hasOpt; - } - -private: - DevInfo dev_; - int64_t offset_ {0}; - int64_t count_ {MAX_NUM}; - bool hasOpt_ {false}; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERVICES_DEV_INFO_H \ No newline at end of file diff --git a/services/src/fileoper/cmd_response.h b/services/src/fileoper/cmd_response.h deleted file mode 100644 index f4a3b445b6d7634f95ea52e490f6f1f1e667f14b..0000000000000000000000000000000000000000 --- a/services/src/fileoper/cmd_response.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2021 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 STORAGE_SERVICES_CMD_RESPONSE_H -#define STORAGE_SERVICES_CMD_RESPONSE_H - -#include -#include -#include - -#include "file_info.h" -#include "log.h" -#include "parcel.h" -namespace OHOS { -namespace FileManagerService { -class CmdResponse : public Parcelable { -public: - CmdResponse() = default; - CmdResponse(int &err, std::string &uri, std::vector> &fileInfoList) - : err_(err), uri_(uri), vecFileInfo_(fileInfoList) - {} - ~CmdResponse() = default; - - void SetErr(const int err) - { - err_ = err; - } - - int GetErr() const - { - return err_; - } - - void SetUri(const std::string &uri) - { - uri_ = uri; - } - - std::string GetUri() const - { - return uri_; - } - - void SetFileInfoList(std::vector> &fileInfoList) - { - vecFileInfo_ = fileInfoList; - } - - std::vector> GetFileInfoList() - { - return vecFileInfo_; - } - - virtual bool Marshalling(Parcel &parcel) const override - { - parcel.WriteInt32(err_); - parcel.WriteString(uri_); - size_t fileCount = vecFileInfo_.size(); - parcel.WriteUint64(fileCount); - for (size_t i = 0; i < fileCount; i++) { - if (parcel.WriteParcelable(vecFileInfo_[i].get()) != true) { - ERR_LOG("Marshalling FileInfo fails!"); - return false; - } - } - return true; - } - - static CmdResponse* Unmarshalling(Parcel &parcel) - { - auto *obj = new (std::nothrow) CmdResponse(); - if (obj == nullptr) { - return nullptr; - } - obj->err_ = parcel.ReadInt32(); - obj->uri_ = parcel.ReadString(); - size_t fileCount = parcel.ReadUint64(); - for (size_t i = 0; i < fileCount; i++) { - std::shared_ptr file(parcel.ReadParcelable()); - obj->vecFileInfo_.emplace_back(file); - } - return obj; - } -private: - int err_; - std::string uri_; - std::vector> vecFileInfo_; -}; -} // FileManagerService -} // namespace OHOS -#endif // STORAGE_SERVICES_CMD_RESPONSE_H \ No newline at end of file diff --git a/services/src/fileoper/ext_storage/ext_storage_status.h b/services/src/fileoper/ext_storage/ext_storage_status.h deleted file mode 100644 index a2b27b0e35c31b2e9f68263f888d5929efe91b8f..0000000000000000000000000000000000000000 --- a/services/src/fileoper/ext_storage/ext_storage_status.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (C) 2021 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 STORAGE_EXT_STORAGE_STATUS_H -#define STORAGE_EXT_STORAGE_STATUS_H - -#include - -#include "file_manager_service_def.h" - -namespace OHOS { -namespace FileManagerService { -class ExtStorageStatus { -public: - ExtStorageStatus() = default; - ~ExtStorageStatus() = default; - ExtStorageStatus(const std::string &id, const std::string &diskId, - const std::string &fsUuid, const std::string &path, const VolumeState &volumeState) - : id_(id), diskId_(diskId), fsUuid_(fsUuid), path_(path), volumeState_(volumeState) {} - - ExtStorageStatus(const ExtStorageStatus &extStatus) - { - this->id_ = extStatus.id_; - this->diskId_ = extStatus.diskId_; - this->fsUuid_ = extStatus.fsUuid_; - this->path_ = extStatus.path_; - this->volumeState_ = extStatus.volumeState_; - } - - ExtStorageStatus& operator=(const ExtStorageStatus &extStatus) - { - if (this != &extStatus) { - this->id_ = extStatus.id_; - this->diskId_ = extStatus.diskId_; - this->fsUuid_ = extStatus.fsUuid_; - this->path_ = extStatus.path_; - this->volumeState_ = extStatus.volumeState_; - } - return *this; - } - - std::string GetId() - { - return id_; - } - - void SetId(const std::string &id) - { - id_ = id; - } - - std::string GetDiskId() - { - return diskId_; - } - - void SetDiskId(const std::string &diskId) - { - diskId_ = diskId; - } - - std::string GetFsUuid() - { - return fsUuid_; - } - - void SetFsUuid(const std::string &fsUuid) - { - fsUuid_ = fsUuid; - } - - std::string GetPath() - { - return path_; - } - - void SetPath(const std::string &path) - { - path_ = path; - } - - VolumeState GetVolumeState() - { - return volumeState_; - } - - void SetVolumeState(const VolumeState &volumeState) - { - volumeState_ = volumeState; - } - -private: - std::string id_; - std::string diskId_; - std::string fsUuid_; - std::string path_; - VolumeState volumeState_; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_EXT_STORAGE_STATUS_H \ No newline at end of file diff --git a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp b/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp deleted file mode 100644 index 7211fc701b6594a977b1ee78eae99a9f0fa3a6e0..0000000000000000000000000000000000000000 --- a/services/src/fileoper/ext_storage/ext_storage_subscriber.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2021 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. - */ -#include "ext_storage_subscriber.h" - -#include - -#include "appexecfwk_errors.h" -#include "bundle_info.h" -#include "common_event_manager.h" -#include "common_event_support.h" -#include "log.h" -#include "string_wrapper.h" -#include "int_wrapper.h" -#include "want.h" - -using namespace OHOS::AAFwk; -namespace OHOS { -namespace FileManagerService { -/** - * @brief Receiver Constructor. - * @param subscriberInfo Subscriber info. - */ -ExtStorageSubscriber::ExtStorageSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo) - : EventFwk::CommonEventSubscriber(subscriberInfo) -{} - -std::shared_ptr ExtStorageSubscriber_ = nullptr; -bool ExtStorageSubscriber::Subscriber(void) -{ - if (ExtStorageSubscriber_ == nullptr) { - EventFwk::MatchingSkills matchingSkills; - matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_DISK_UNMOUNTED); - matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_DISK_MOUNTED); - - EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); - ExtStorageSubscriber_ = std::make_shared(subscribeInfo); - EventFwk::CommonEventManager::SubscribeCommonEvent(ExtStorageSubscriber_); - } - return true; -} - -/** - * @brief Receive common event. - * @param eventData Common event data. - */ -void ExtStorageSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &eventData) -{ - const AAFwk::Want& want = eventData.GetWant(); - std::string action = want.GetAction(); - DEBUG_LOG("%{public}s, action:%{public}s.", __func__, action.c_str()); - - const AAFwk::WantParams wantParams = want.GetParams(); - std::string id = AAFwk::String::Unbox(AAFwk::IString::Query(wantParams.GetParam("id"))); - std::string diskId = AAFwk::String::Unbox(AAFwk::IString::Query(wantParams.GetParam("diskId"))); - DEBUG_LOG("%{public}s, id:%{public}s.", __func__, id.c_str()); - DEBUG_LOG("%{public}s, diskId:%{public}s.", __func__, diskId.c_str()); - - if (action == EventFwk::CommonEventSupport::COMMON_EVENT_DISK_MOUNTED) { - int32_t volumeState = AAFwk::Integer::Unbox(AAFwk::IInteger::Query(wantParams.GetParam("volumeState"))); - std::string fsUuid = AAFwk::String::Unbox(AAFwk::IString::Query(wantParams.GetParam("fsUuid"))); - std::string path = AAFwk::String::Unbox(AAFwk::IString::Query(wantParams.GetParam("path"))); - DEBUG_LOG("%{public}s, volumeState:%{public}d.", __func__, volumeState); - DEBUG_LOG("%{public}s, id:%{public}s, fsUuid:%{public}s, path:%{public}s.", - __func__, id.c_str(), fsUuid.c_str(), path.c_str()); - - ExtStorageStatus extStatus(id, diskId, fsUuid, path, VolumeState(volumeState)); - mountStatus.insert(std::pair(path, extStatus)); - } -} - -bool ExtStorageSubscriber::CheckMountPoint(const std::string &path) -{ - auto extStorageStatus = mountStatus.find(path); - if (extStorageStatus == mountStatus.end()) { - return false; - } else { - if (extStorageStatus->second.GetVolumeState() == VolumeState::MOUNTED) { - return true; - } - return false; - } -} -} // namespace FileManagerService -} // namespace OHOS \ No newline at end of file diff --git a/services/src/fileoper/ext_storage/storage_manager_inf.cpp b/services/src/fileoper/ext_storage/storage_manager_inf.cpp deleted file mode 100644 index 02481edfd3ece04e0a94196ae11b68fdcad631d9..0000000000000000000000000000000000000000 --- a/services/src/fileoper/ext_storage/storage_manager_inf.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright (c) 2021-2022 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. - */ - -#include "storage_manager_inf.h" - -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "log.h" - -using namespace std; -namespace OHOS { -namespace FileManagerService { -static bool GetMountPointFromPath(const string &path, string &mountPoint) -{ - size_t len = MOUNT_POINT_ROOT.size(); - std::string head = path.substr(0, len); - std::string body = path.substr(len); - if (head != MOUNT_POINT_ROOT || body.size() == 0) { - ERR_LOG("invalid mountPoint %{public}s, head check fail", path.c_str()); - return false; - } - - size_t index = body.find("/"); - if (index != std::string::npos) { - mountPoint = MOUNT_POINT_ROOT + body.substr(0, index); - } else { - mountPoint = path; - } - return true; -} - -int StorageManagerInf::Connect() -{ - DEBUG_LOG("StorageManagerConnect::Connect start"); - auto sam = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (sam == nullptr) { - ERR_LOG("StorageManagerConnect::Connect samgr == nullptr"); - return FAIL; - } - auto object = sam->GetSystemAbility(STORAGE_MANAGER_MANAGER_ID); - if (object == nullptr) { - ERR_LOG("StorageManagerConnect::Connect object == nullptr"); - return FAIL; - } - storageManager_ = iface_cast(object); - if (storageManager_ == nullptr) { - ERR_LOG("StorageManagerConnect::Connect service == nullptr"); - return FAIL; - } - DEBUG_LOG("StorageManagerConnect::Connect end"); - return SUCCESS; -} - -std::vector StorageManagerInf::GetAllVolumes() -{ - vector result = {}; - if (Connect() != SUCCESS) { - ERR_LOG("GetTotalSizeOfVolume:Connect error"); - return result; - } - return storageManager_->GetAllVolumes(); -} - -bool StorageManagerInf::GetMountedVolumes(vector &vecRootPath) -{ - bool succ = false; - vector result = GetAllVolumes(); - if (result.size() == 0) { - ERR_LOG("empty volume result"); - return succ; - } - for (auto vol : result) { - DEBUG_LOG("find vol.GetPath() %{public}d %{public}d", vol.GetState(), VolumeState::MOUNTED); - if (vol.GetState() == VolumeState::MOUNTED) { - DEBUG_LOG("mounted find vol.GetPath() %{public}d %{public}d", vol.GetState(), VolumeState::MOUNTED); - vecRootPath.emplace_back(EXTERNAL_STORAGE_URI + vol.GetPath()); - succ = true; - } - } - return succ; -} - -bool StorageManagerInf::StoragePathValidCheck(const string &path) -{ - string mountPoint; - if (!GetMountPointFromPath(path, mountPoint)) { - ERR_LOG("uri path is invalid"); - return false; - } - vector result = GetAllVolumes(); - if (result.size() == 0) { - ERR_LOG("empty volume result"); - return false; - } - bool succ = false; - for (auto vol : result) { - if (vol.GetPath() == mountPoint && vol.GetState() == VolumeState::MOUNTED) { - succ = true; - break; - } - } - return succ; -} -} // FileManagerService -} // OHOS diff --git a/services/src/fileoper/external_storage_oper.cpp b/services/src/fileoper/external_storage_oper.cpp deleted file mode 100644 index af9c01d6b7cfccf5c6863c56bf109a062866ca96..0000000000000000000000000000000000000000 --- a/services/src/fileoper/external_storage_oper.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) 2021 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. - */ - -#include "external_storage_oper.h" - -#include - -#include "cmd_response.h" -#include "external_storage_utils.h" -#include "file_info.h" -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "log.h" - -using namespace std; -namespace OHOS { -namespace FileManagerService { -int ExternalStorageOper::OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) const -{ - DEBUG_LOG("ExternalStorageOper::OperProcess"); - int errCode = SUCCESS; - switch (code) { - case Operation::LIST_FILE: { - std::string devName = data.ReadString(); - std::string devPath = data.ReadString(); - std::string type = data.ReadString(); - std::string path = data.ReadString(); - int64_t offset = data.ReadInt64(); - int64_t count = data.ReadInt64(); - - CmdOptions option(devName, devPath, offset, count, true); - errCode = this->ListFile(type, path, option, reply); - break; - } - case Operation::CREATE_FILE: { - std::string name = data.ReadString(); - std::string uri = data.ReadString(); - errCode = this->CreateFile(uri, name, reply); - break; - } - case Operation::GET_ROOT: { - string path = data.ReadString(); - // name for extension - string name = "name"; - errCode = GetRoot(name, path, reply); - break; - } - default: { - DEBUG_LOG("not valid code %{public}d.", code); - break; - } - } - return errCode; -} - -int ExternalStorageOper::GetRoot(const std::string &name, const std::string &path, MessageParcel &reply) const -{ - std::vector> fileList; - int ret = ExternalStorageUtils::DoGetRoot(name, path, fileList); - CmdResponse cmdResponse; - cmdResponse.SetErr(ret); - cmdResponse.SetFileInfoList(fileList); - if (!reply.WriteParcelable(&cmdResponse)) { - ERR_LOG("reply write err parcel capacity%{public}zu", reply.GetDataCapacity()); - } - return ret; -} - -int ExternalStorageOper::CreateFile(const std::string &uri, const std::string &name, MessageParcel &reply) const -{ - std::string resultUir; - int ret = ExternalStorageUtils::DoCreateFile(uri, name, resultUir); - CmdResponse cmdResponse; - cmdResponse.SetErr(ret); - cmdResponse.SetUri(resultUir); - if (!reply.WriteParcelable(&cmdResponse)) { - ERR_LOG("reply write err parcel capacity:%{public}zu", reply.GetDataCapacity()); - } - return ret; -} - -int ExternalStorageOper::ListFile(const std::string &type, const std::string &uri, const CmdOptions &option, - MessageParcel &reply) const -{ - std::vector> fileList; - int ret = ExternalStorageUtils::DoListFile(type, uri, option, fileList); - CmdResponse cmdResponse; - cmdResponse.SetErr(ret); - cmdResponse.SetFileInfoList(fileList); - if (!reply.WriteParcelable(&cmdResponse)) { - ERR_LOG("reply write err parcel capacity:%{public}zu", reply.GetDataCapacity()); - } - return ret; -} -} // namespace FileManagerService -} // namespace OHOS diff --git a/services/src/fileoper/external_storage_oper.h b/services/src/fileoper/external_storage_oper.h deleted file mode 100644 index af5ee57a4d0c23f826e175370fbc8fcd06918b99..0000000000000000000000000000000000000000 --- a/services/src/fileoper/external_storage_oper.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2021 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 STORAGE_SERIVCES_EXTERNAL_STORAGE_OPER_H -#define STORAGE_SERIVCES_EXTERNAL_STORAGE_OPER_H - -#include -#include "cmd_options.h" -#include "file_oper.h" -namespace OHOS { -namespace FileManagerService { -class ExternalStorageOper : public FileOper { -public: - ExternalStorageOper() = default; - virtual ~ExternalStorageOper() = default; - int OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) const override; -private: - int CreateFile(const std::string &uri, const std::string &name, MessageParcel &reply) const; - int ListFile(const std::string &type, const std::string &uri, const CmdOptions &option, - MessageParcel &reply) const; - int GetRoot(const std::string &name, const std::string &path, MessageParcel &reply) const; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERIVCES_EXTERNAL_STORAGE_OPER_H \ No newline at end of file diff --git a/services/src/fileoper/external_storage_utils.cpp b/services/src/fileoper/external_storage_utils.cpp deleted file mode 100644 index 1cff272a39f2eb3384b77be18c2e25cbe8afb438..0000000000000000000000000000000000000000 --- a/services/src/fileoper/external_storage_utils.cpp +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (C) 2021 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. - */ - -#include "external_storage_utils.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "log.h" -#include "storage_manager_inf.h" -using namespace std; -using namespace OHOS::StorageManager; -namespace OHOS { -namespace FileManagerService { -static bool GetPathFromUri(const string &uri, string &path) -{ - uint len = EXTERNAL_STORAGE_URI.size(); - string head = uri.substr(0, len); - if (head != EXTERNAL_STORAGE_URI) { - ERR_LOG("invalid format uri %{private}s, head check fail", uri.c_str()); - return false; - } - if (uri.size() == len) { - ERR_LOG("uri content is invalid %{private}s", uri.c_str()); - return false; - } - path = uri.substr(len); - return true; -} - -static bool GetRealPath(string &path) -{ - char filePath[PATH_MAX + 1] = { 0 }; - if (realpath(path.c_str(), filePath) == nullptr) { - ERR_LOG("untrustPath invalid %{public}d\n", errno); - return false; - } - path = string(filePath); - return true; -} - -static bool GetFileInfo(const std::string &path, const std::string &name, shared_ptr &fileInfo) -{ - std::string fullPath(path); - size_t len = fullPath.size(); - if (fullPath.at(len - 1) != '/') { - fullPath.append("/").append(name); - } else { - fullPath.append(name); - } - struct stat st; - if (lstat(fullPath.c_str(), &st) != 0) { - ERR_LOG("check file info fail."); - return false; - } - std::string uri(EXTERNAL_STORAGE_URI); - std::string fName(name.c_str()); - - uri.append(fullPath); - fileInfo->SetPath(uri); - std::string type = S_ISDIR(st.st_mode) ? "album" : "file"; - fileInfo->SetType(type); - fileInfo->SetName(fName); - fileInfo->SetSize(st.st_size); - fileInfo->SetAddedTime(static_cast(st.st_ctim.tv_sec)); - fileInfo->SetModifiedTime(static_cast(st.st_mtim.tv_sec)); - return true; -} - -static bool ConvertUriToAbsolutePath(const std::string &uri, std::string &path) -{ - if (!GetPathFromUri(uri, path)) { - ERR_LOG("GetPathFromUri fail"); - return false; - } - if (!GetRealPath(path)) { - ERR_LOG("get real path fail"); - return false; - } - if (!StorageManagerInf::StoragePathValidCheck(path)) { - ERR_LOG("external uri path was ejected"); - return false; - } - return true; -} - -int ExternalStorageUtils::DoListFile(const std::string &type, const std::string &uri, const CmdOptions &option, - std::vector> &fileList) -{ - int64_t count = option.GetCount(); - int64_t offset = option.GetOffset(); - if (count < 0 || count > MAX_NUM || offset < 0) { - ERR_LOG("invalid file count or offset."); - return E_INVALID_FILE_NUMBER; - } - DEBUG_LOG("limit %{public}lld, offset %{public}lld", (long long)count, (long long)offset); - std::string path; - if (!ConvertUriToAbsolutePath(uri, path)) { - ERR_LOG("invalid uri[%{private}s].", uri.c_str()); - return E_NOEXIST; - } - - DIR *dir = opendir(path.c_str()); - if (!dir) { - ERR_LOG("opendir path[%{private}s] fail.", path.c_str()); - return E_NOEXIST; - } - if (offset != 0) { - int64_t index = 0; - for (dirent *ent = readdir(dir); ent != nullptr; ent = readdir(dir)) { - if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) { - continue; - } - if (index == offset - 1) { - break; - } - index++; - } - } - for (dirent *ent = readdir(dir); ent != nullptr; ent = readdir(dir)) { - if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) { - continue; - } - if (count > 0) { - shared_ptr fileInfo = make_shared(); - if (!GetFileInfo(path, ent->d_name, fileInfo)) { - continue; - } - fileList.push_back(fileInfo); - count--; - if (count == 0) { - break; - } - } - } - closedir(dir); - if (option.GetCount() == MAX_NUM && count == 0) { - DEBUG_LOG("get files with MAX_NUM:[%{public}lld].", (long long)MAX_NUM); - } - return SUCCESS; -} - -int ExternalStorageUtils::DoCreateFile(const std::string &uri, const std::string &name, std::string &resultUri) -{ - std::string path; - if (!ConvertUriToAbsolutePath(uri, path)) { - ERR_LOG("invalid uri[%{public}s].", uri.c_str()); - return E_NOEXIST; - } - size_t len = path.size(); - if (path.at(len - 1) != '/') { - path.append("/").append(name); - } else { - path.append(name); - } - if (access(path.c_str(), F_OK) == 0) { - ERR_LOG("target file[%{public}s] exist.", path.c_str()); - return E_CREATE_FAIL; - } - - int fd = open(path.c_str(), O_RDWR | O_CREAT | O_TRUNC, 0771); - if (fd == -1) { - ERR_LOG("create file[%{public}s] fail.", path.c_str()); - return E_CREATE_FAIL; - } - close(fd); - resultUri = EXTERNAL_STORAGE_URI + path; - return SUCCESS; -} - -int ExternalStorageUtils::DoGetRoot(const std::string &name, const std::string &path, - std::vector> &fileList) -{ - vector vecRootPath; - if (!StorageManagerInf::GetMountedVolumes(vecRootPath)) { - ERR_LOG("none valid extorage storage"); - return FAIL; - } - for (auto rootPath : vecRootPath) { - shared_ptr fileInfo = make_shared(FILE_ROOT_NAME, rootPath, ALBUM_TYPE); - fileList.push_back(fileInfo); - } - return SUCCESS; -} -} // namespace FileManagerService -} // namespace OHOS diff --git a/services/src/fileoper/file_info.cpp b/services/src/fileoper/file_info.cpp deleted file mode 100644 index 3eaf90067c1e03dc9f90954ed76c30fed9b15017..0000000000000000000000000000000000000000 --- a/services/src/fileoper/file_info.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2021 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. - */ -#include "file_info.h" -#include "log.h" -using namespace std; - -namespace OHOS { -namespace FileManagerService { -bool FileInfo::Marshalling(Parcel &parcel) const -{ - parcel.WriteString(path_); - parcel.WriteString(name_); - parcel.WriteString(type_); - parcel.WriteInt64(size_); - parcel.WriteInt64(addedTime_); - parcel.WriteInt64(modifiedTime_); - return true; -} - -FileInfo* FileInfo::Unmarshalling(Parcel &parcel) -{ - auto *obj = new (std::nothrow) FileInfo(); - if (obj == nullptr) { - ERR_LOG("Unmarshalling fail"); - return nullptr; - } - obj->path_ = parcel.ReadString(); - obj->name_ = parcel.ReadString(); - obj->type_ = parcel.ReadString(); - obj->size_ = parcel.ReadInt64(); - obj->addedTime_ = parcel.ReadInt64(); - obj->modifiedTime_ = parcel.ReadInt64(); - return obj; -} -} // namespace FileManagerService -} // namespace OHOS \ No newline at end of file diff --git a/services/src/fileoper/file_info.h b/services/src/fileoper/file_info.h deleted file mode 100644 index 8a8742b69811f060918fbf61092aa89ea283bc9e..0000000000000000000000000000000000000000 --- a/services/src/fileoper/file_info.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2021 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 STORAGE_SERVICES_FILE_INFO_H -#define STORAGE_SERVICES_FILE_INFO_H - -#include -#include -#include "parcel.h" - -namespace OHOS { -namespace FileManagerService { -class FileInfo : public Parcelable { -public: - FileInfo(const std::string &name, const std::string &path, const std::string &type) : path_(path), - name_(name), type_(type) {} - FileInfo() = default; - ~FileInfo() = default; - - void SetName(std::string &name) - { - name_ = name; - } - void SetPath(std::string &path) - { - path_ = path; - } - void SetType(std::string &type) - { - type_ = type; - } - void SetSize(int64_t size) - { - size_ = size; - } - void SetAddedTime(int64_t time) - { - addedTime_ = time; - } - void SetModifiedTime(int64_t time) - { - modifiedTime_ = time; - } - std::string GetName() const - { - return name_; - } - std::string GetPath() const - { - return path_; - } - std::string GetType() const - { - return type_; - } - int64_t GetSize() const - { - return size_; - } - int64_t GetAddedTime() const - { - return addedTime_; - } - int64_t GetModifiedTime() const - { - return modifiedTime_; - } - bool Marshalling(Parcel &parcel) const override; - static FileInfo* Unmarshalling(Parcel &parcel); -private: - std::string path_; - std::string name_; - std::string type_; - int64_t size_ {0}; - int64_t addedTime_ {0}; - int64_t modifiedTime_ {0}; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERVICES_FILE_INFO_H \ No newline at end of file diff --git a/services/src/fileoper/media_file_oper.cpp b/services/src/fileoper/media_file_oper.cpp deleted file mode 100644 index 3d5e69eed8ae3ca107dbdcfc4c795042101dc5a9..0000000000000000000000000000000000000000 --- a/services/src/fileoper/media_file_oper.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (C) 2021 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. - */ - -#include "media_file_oper.h" - -#include - -#include "cmd_options.h" -#include "cmd_response.h" -#include "file_info.h" -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" -#include "log.h" -#include "media_data_ability_const.h" -#include "media_file_utils.h" - -using namespace std; - -namespace OHOS { -namespace FileManagerService { -int MediaFileOper::OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) const -{ - int errCode = SUCCESS; - // media process - switch (code) { - case Operation::MAKE_DIR: { - string name = data.ReadString(); - string path = data.ReadString(); - errCode = Mkdir(name, path); - break; - } - case Operation::GET_ROOT: { - string path = data.ReadString(); - // name for extension - string name = "name"; - errCode = GetRoot(name, path, reply); - break; - } - case Operation::LIST_FILE: { - string devName = data.ReadString(); - string devPath = data.ReadString(); - string type = data.ReadString(); - string path = data.ReadString(); - int off = data.ReadInt64(); - int count = data.ReadInt64(); - // put fileInfo into reply - errCode = ListFile(type, path, off, count, reply); - break; - } - case Operation::CREATE_FILE: { - string name = data.ReadString(); - string path = data.ReadString(); - errCode = CreateFile(name, path, reply); - break; - } - default: { - DEBUG_LOG("not valid code %{public}u.", code); - break; - } - } - return errCode; -} - -int MediaFileOper::CreateFile(const std::string &name, const std::string &path, MessageParcel &reply) const -{ - string type = "file"; - std::string uri; - int ret = MediaFileUtils::DoInsert(name, path, type, uri); - CmdResponse cmdResponse; - cmdResponse.SetErr(ret); - cmdResponse.SetUri(uri); - if (!reply.WriteParcelable(&cmdResponse)) { - ERR_LOG("reply write err parcel capacity:%{public}zu", reply.GetDataCapacity()); - } - return ret; -} - -int MediaFileOper::GetRoot(const std::string &name, const std::string &path, MessageParcel &reply) const -{ - std::vector> fileList; - int ret = MediaFileUtils::DoGetRoot(name, path, fileList); - CmdResponse cmdResponse; - cmdResponse.SetErr(ret); - cmdResponse.SetFileInfoList(fileList); - if (!reply.WriteParcelable(&cmdResponse)) { - ERR_LOG("reply write err parcel capacity%{public}zu", reply.GetDataCapacity()); - } - return ret; -} - -int MediaFileOper::ListFile(const string &type, const string &path, int offset, int count, MessageParcel &reply) const -{ - shared_ptr result; - int res = MediaFileUtils::DoListFile(type, path, offset, count, result); - if (res != SUCCESS) { - return res; - } - - std::vector> fileList; - res = MediaFileUtils::GetFileInfoFromResult(result, fileList); - CmdResponse cmdResponse; - cmdResponse.SetErr(res); - cmdResponse.SetFileInfoList(fileList); - if (!reply.WriteParcelable(&cmdResponse)) { - ERR_LOG("reply write err parcel capacity:%{public}zu", reply.GetDataCapacity()); - } - return res; -} - -int MediaFileOper::Mkdir(const string &name, const string &path) const -{ - (void)name; - DEBUG_LOG("MediaFileOper::mkdir path %{public}s.", path.c_str()); - return SUCCESS; -} -} // namespace FileManagerService -} // namespace OHOS diff --git a/services/src/fileoper/media_file_utils.cpp b/services/src/fileoper/media_file_utils.cpp deleted file mode 100644 index dcdd31e4407108f83d212b6098f2b3440a90a9c7..0000000000000000000000000000000000000000 --- a/services/src/fileoper/media_file_utils.cpp +++ /dev/null @@ -1,444 +0,0 @@ -/* - * Copyright (C) 2021-2022 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. - */ - -#include "media_file_utils.h" - -#include - -#include "data_ability_predicates.h" -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "log.h" -#include "media_asset.h" -#include "media_data_ability_const.h" -#include "rdb_errno.h" -#include "values_bucket.h" - -using namespace std; -namespace OHOS { -namespace FileManagerService { -bool GetPathFromResult(shared_ptr result, string &path) -{ - int count = 0; - result->GetRowCount(count); - if (count == RESULTSET_EMPTY) { - ERR_LOG("AbsSharedResultSet null"); - return false; - } - int32_t columnIndex = 0; - GET_COLUMN_INDEX_FROM_NAME(result, Media::MEDIA_DATA_DB_FILE_PATH, columnIndex); - result->GoToFirstRow(); - int ret = result->GetString(columnIndex, path); - if (ret != NativeRdb::E_OK) { - ERR_LOG("NativeRdb gets path index fail"); - return false; - } - GET_COLUMN_INDEX_FROM_NAME(result, Media::MEDIA_DATA_DB_RELATIVE_PATH, columnIndex); - string relativePath; - ret = result->GetString(columnIndex, relativePath); - if (ret != NativeRdb::E_OK) { - relativePath = ""; - DEBUG_LOG("NativeRdb gets relative path is null %{public}d", columnIndex); - } - // get relative path from absolute path - string::size_type pos = path.find_last_of('/'); - if (pos != string::npos) { - path = relativePath + path.substr(pos + 1) + "/"; - } - return true; -} - -bool IsNumber(const string &str) -{ - if (str.length() == 0) { - ERR_LOG("IsNumber input is empty "); - return false; - } - - for (char const &c : str) { - if (isdigit(c) == 0) { - ERR_LOG("Index is not a number"); - return false; - } - } - - return true; -} - -bool GetPathID(const string &uriPath, string &index) -{ - string::size_type pos = uriPath.find_last_of('/'); - if (pos == string::npos) { - ERR_LOG("invalid uri %{private}s", uriPath.c_str()); - return false; - } - index = uriPath.substr(pos + 1); - if (!IsNumber(index)) { - ERR_LOG("invalid uri %{private}s invalid id %{public}s", uriPath.c_str(), index.c_str()); - return false; - } - return true; -} - -int GetMediaType(const string &name) -{ - int mediaType = Media::MediaAsset::GetMediaType(name); - if (FILE_MIME_TYPE_MAPS.count(mediaType) == 0) { - ERR_LOG("invalid mediaType %{public}d", mediaType); - return FILE_MEDIA_TYPE; - } - return mediaType; -} - -string GetMimeType(const string &name) -{ - int mediaType = GetMediaType(name); - if (FILE_MIME_TYPE_MAPS.count(mediaType) == 0) { - ERR_LOG("invalid mediaType %{public}d", mediaType); - return FILE_MIME_TYPE; - } - return FILE_MIME_TYPE_MAPS.at(mediaType); -} - -bool GetPathFromAlbumPath(const string &albumUri, string &path) -{ - string id; - if (!GetPathID(albumUri, id)) { - ERR_LOG("GetPathID fails"); - return false; - } - string selection = Media::MEDIA_DATA_DB_ID + " LIKE ? "; - vector selectionArgs = {id}; - shared_ptr result = MediaFileUtils::DoQuery(selection, selectionArgs); - if (result == nullptr) { - ERR_LOG("AbsSharedResultSet null"); - return false; - } - return GetPathFromResult(result, path); -} - -string GetType(string type) -{ - unordered_map typeMap = { - {"image", Media::MediaType::MEDIA_TYPE_IMAGE}, - {"video", Media::MediaType::MEDIA_TYPE_VIDEO}, - {"audio", Media::MediaType::MEDIA_TYPE_AUDIO} - }; - if (typeMap.count(type) == 0) { - // type is wrong - ERR_LOG("Type %{public}s", type.c_str()); - return ""; - } - return ToString(typeMap[type]); -} - -bool IsFirstLevelUriPath(const string &path) -{ - // check whether path is first level uri - return path == FISRT_LEVEL_ALBUM; -} - -bool GetAlbumFromResult(shared_ptr &result, vector &album) -{ - int count = 0; - result->GetRowCount(count); - result->GoToFirstRow(); - int32_t columnIndex; - GET_COLUMN_INDEX_FROM_NAME(result, Media::MEDIA_DATA_DB_RELATIVE_PATH, columnIndex); - for (int i = 0; i < count; i++) { - string path; - if (result->GetString(columnIndex, path) != NativeRdb::E_OK) { - ERR_LOG("NativeRdb gets path columnIndex fail"); - return false; - } - path = MEDIA_ROOT_PATH + "/" + path.substr(0, path.size() - 1); - // add into ablum if not in album - if (find(album.begin(), album.end(), path) == album.end()) { - DEBUG_LOG(" // add into ablum path %{public}s", path.c_str()); - album.emplace_back(path); - } - result->GoToNextRow(); - } - return true; -} - -vector FindAlbumByType(string type) -{ - // find out the first level Album - // first find out file by type - // then get the album - string selection = Media::MEDIA_DATA_DB_MEDIA_TYPE + " LIKE ?"; - vector selectionArgs = {type}; - shared_ptr result = MediaFileUtils::DoQuery(selection, selectionArgs); - vector album; - if (result == nullptr) { - ERR_LOG("query album type returns fail"); - return album; - } - GetAlbumFromResult(result, album); - return album; -} - -/* listfile - * ----find "file" type - * --------first level view---- - * --------selection MEDIA_DATA_DB_RELATIVE_PATH == root_path && - * (MEDIA_DATA_DB_MEDIA_TYPE == "file" || MEDIA_DATA_DB_MEDIA_TYPE == "album") - * --------other level view ---- - * --------selection MEDIA_DATA_DB_RELATIVE_PATH == uri.MEDIA_DATA_DB_FILE_PATH && - * (MEDIA_DATA_DB_MEDIA_TYPE == "file" || MEDIA_DATA_DB_MEDIA_TYPE == "album") - * - * ----find "image"/"audio"/"video" type - * --------first level view---- - * --------find out all album with type file - * --------selection MEDIA_DATA_DB_MEDIA_TYPE == type - * --------Get the relative path ----> Album path - * --------selection MEDIA_DATA_DB_FILE_PATH == Album path1 || selection MEDIA_DATA_DB_FILE_PATH == Album path2 || ... - * --------second level view ---- - * --------selection MEDIA_DATA_DB_RELATIVE_PATH == uri.MEDIA_DATA_DB_FILE_PATH && MEDIA_DATA_DB_MEDIA_TYPE == type - */ -int CreateSelectionAndArgsFirstLevel(const string &type, string &selection, vector &selectionArgs) -{ - if (type == "file") { - selection = Media::MEDIA_DATA_DB_RELATIVE_PATH + " LIKE ? AND (" + Media::MEDIA_DATA_DB_MEDIA_TYPE; - selection += " LIKE ? OR " + Media::MEDIA_DATA_DB_MEDIA_TYPE + " LIKE ? )"; - selectionArgs = { - RELATIVE_ROOT_PATH, ToString(Media::MediaType::MEDIA_TYPE_FILE), - ToString(Media::MediaType::MEDIA_TYPE_ALBUM) - }; - } else { - selectionArgs = FindAlbumByType(GetType(type)); - selection = Media::MEDIA_DATA_DB_FILE_PATH + " LIKE ?"; - if (selectionArgs.size() > 1) { - for (uint32_t i = 1; i < selectionArgs.size(); i++) { - selection += " OR " + Media::MEDIA_DATA_DB_FILE_PATH + " LIKE ?"; - } - } - } - return SUCCESS; -} - -int CreateSelectionAndArgsOtherLevel(const string &type, const string &albumUri, string &selection, - vector &selectionArgs) -{ - // get the album path from the album uri - string albumPath; - if (!GetPathFromAlbumPath(albumUri, albumPath)) { - ERR_LOG("path not exsit"); - return E_NOEXIST; - } - if (type == "file") { - selection = Media::MEDIA_DATA_DB_RELATIVE_PATH + " LIKE ? AND (" + Media::MEDIA_DATA_DB_MEDIA_TYPE; - selection += " LIKE ? OR " + Media::MEDIA_DATA_DB_MEDIA_TYPE + " LIKE ? )"; - selectionArgs = { - albumPath, ToString(Media::MediaType::MEDIA_TYPE_FILE), - ToString(Media::MediaType::MEDIA_TYPE_ALBUM) - }; - } else { - selection = Media::MEDIA_DATA_DB_RELATIVE_PATH + " LIKE ? AND " + Media::MEDIA_DATA_DB_MEDIA_TYPE + " LIKE ?"; - selectionArgs = { albumPath, GetType(type) }; - } - return SUCCESS; -} - -bool GetAlbumPath(const string &name, const string &path, string &albumPath) -{ - if (IsFirstLevelUriPath(path)) { - int mediaType = GetMediaType(name); - albumPath = (MEDIA_TYPE_FOLDER_MAPS.count(mediaType) == 0) ? MEDIA_TYPE_FOLDER_MAPS.at(FILE_MEDIA_TYPE) : - MEDIA_TYPE_FOLDER_MAPS.at(mediaType); - return true; - } - return GetPathFromAlbumPath(path, albumPath); -} - -static void ShowSelecArgs(const string &selection, const vector &selectionArgs) -{ - DEBUG_LOG("selection %{public}s ", selection.c_str()); - for (auto s : selectionArgs) { - DEBUG_LOG("selectionArgs %{public}s", s.c_str()); - } -} - -int MediaFileUtils::DoListFile(const string &type, const string &path, int offset, int count, - shared_ptr &result) -{ - string selection; - vector selectionArgs; - if (IsFirstLevelUriPath(path)) { - DEBUG_LOG("IsFirstLevelUriPath"); - CreateSelectionAndArgsFirstLevel(type, selection, selectionArgs); - } else { - int err = CreateSelectionAndArgsOtherLevel(type, path, selection, selectionArgs); - if (err) { - ERR_LOG("CreateSelectionAndArgsOtherLevel returns fail"); - return err; - } - } - result = DoQuery(selection, selectionArgs, offset, count); - if (result == nullptr) { - ERR_LOG("ListFile folder is empty"); - return E_EMPTYFOLDER; - } - return SUCCESS; -} - -shared_ptr MediaFileUtils::DoQuery(const string &selection, - const vector &selectionArgs) -{ - return DoQuery(selection, selectionArgs, 0, MAX_NUM); -} - -shared_ptr MediaFileUtils::DoQuery(const string &selection, - const vector &selectionArgs, int offset, int count) -{ - ShowSelecArgs(selection, selectionArgs); - NativeRdb::DataAbilityPredicates predicates; - predicates.SetWhereClause(selection); - predicates.SetWhereArgs(selectionArgs); - predicates.SetOrder("date_taken DESC LIMIT " + ToString(offset) + "," + ToString(count)); - DEBUG_LOG("limit %{public}d, offset %{public}d", count, offset); - Uri uri = Uri(Media::MEDIALIBRARY_DATA_URI); - vector columns; - return abilityHelper->Query(uri, columns, predicates); -} - -int MediaFileUtils::DoInsert(const string &name, const string &path, const string &type, string &uri) -{ - NativeRdb::ValuesBucket values; - string albumPath; - if (!GetAlbumPath(name, path, albumPath)) { - ERR_LOG("path not exsit"); - return E_NOEXIST; - } - values.PutString(Media::MEDIA_DATA_DB_RELATIVE_PATH, albumPath); - values.PutString(Media::MEDIA_DATA_DB_NAME, name); - values.PutString(Media::MEDIA_DATA_DB_MIME_TYPE, GetMimeType(name)); - values.PutInt(Media::MEDIA_DATA_DB_MEDIA_TYPE, GetMediaType(name)); - Uri createAsset(Media::MEDIALIBRARY_DATA_URI + "/" + Media::MEDIA_FILEOPRN + "/" + - Media::MEDIA_FILEOPRN_CREATEASSET); - int index = abilityHelper->Insert(createAsset, values); - if (index < 0) { - ERR_LOG("Fail to create fail file %{public}s uri %{private}s album %{public}s", name.c_str(), - path.c_str(), albumPath.c_str()); - return E_CREATE_FAIL; - } - // use file id concatenate head as uri - uri = (MEDIA_TYPE_URI_MAPS.count(GetMediaType(name)) == 0) ? MEDIA_TYPE_URI_MAPS.at(FILE_MEDIA_TYPE) : - MEDIA_TYPE_URI_MAPS.at(GetMediaType(name)); - uri += "/" + to_string(index); - - return SUCCESS; -} - -bool MediaFileUtils::InitMediaTableColIndexMap(shared_ptr result) -{ - if (mediaTableMap.size() == 0) { - DEBUG_LOG("init mediaTableMap"); - vector> mediaData = { - {Media::MEDIA_DATA_DB_ID, "string"}, - {Media::MEDIA_DATA_DB_URI, "string"}, - {Media::MEDIA_DATA_DB_MEDIA_TYPE, "string"}, - {Media::MEDIA_DATA_DB_NAME, "string"}, - {Media::MEDIA_DATA_DB_SIZE, "int"}, - {Media::MEDIA_DATA_DB_DATE_ADDED, "int"}, - {Media::MEDIA_DATA_DB_DATE_MODIFIED, "int"} - }; - for (auto i : mediaData) { - int columnIndex = 0; - GET_COLUMN_INDEX_FROM_NAME(result, i.first, columnIndex); - mediaTableMap.emplace_back(columnIndex, i.second); - } - } - return true; -} - -bool MediaFileUtils::GetFileInfo(shared_ptr result, - shared_ptr &fileInfo) -{ - if (!InitMediaTableColIndexMap(result)) { - ERR_LOG("InitMediaTableColIndexMap returns fail"); - return false; - } - int index = 0; - string id; - result->GetString(mediaTableMap[index++].first, id); - string uri; - result->GetString(mediaTableMap[index++].first, uri); - - string path = uri + "/" + id; - fileInfo->SetPath(path); - string type; - result->GetString(mediaTableMap[index++].first, type); - fileInfo->SetType(type); - string name; - result->GetString(mediaTableMap[index++].first, name); - fileInfo->SetName(name); - int64_t value; - result->GetLong(mediaTableMap[index++].first, value); - fileInfo->SetSize(value); - result->GetLong(mediaTableMap[index++].first, value); - fileInfo->SetAddedTime(value); - result->GetLong(mediaTableMap[index++].first, value); - fileInfo->SetModifiedTime(value); - return true; -} - -int MediaFileUtils::GetFileInfoFromResult(shared_ptr result, - std::vector> &fileList) -{ - int count = 0; - result->GetRowCount(count); - if (count == 0) { - ERR_LOG("AbsSharedResultSet null"); - return E_EMPTYFOLDER; - } - result->GoToFirstRow(); - for (int i = 0; i < count; i++) { - shared_ptr fileInfo = make_shared(); - GetFileInfo(result, fileInfo); - fileList.push_back(fileInfo); - result->GoToNextRow(); - } - return SUCCESS; -} - -bool MediaFileUtils::InitHelper(sptr obj) -{ - if (abilityHelper == nullptr) { - abilityHelper = AppExecFwk::DataAbilityHelper::Creator(obj, make_shared(Media::MEDIALIBRARY_DATA_URI)); - if (abilityHelper == nullptr) { - DEBUG_LOG("get %{private}s helper fail", Media::MEDIALIBRARY_DATA_URI.c_str()); - return false; - } - } - return true; -} - -int MediaFileUtils::DoGetRoot(const std::string &name, const std::string &path, - std::vector> &fileList) -{ - shared_ptr image = make_shared(IMAGE_ROOT_NAME, FISRT_LEVEL_ALBUM, ALBUM_TYPE); - fileList.emplace_back(image); - shared_ptr video = make_shared(VIDEO_ROOT_NAME, FISRT_LEVEL_ALBUM, ALBUM_TYPE); - fileList.emplace_back(video); - shared_ptr audio = make_shared(AUDIO_ROOT_NAME, FISRT_LEVEL_ALBUM, ALBUM_TYPE); - fileList.emplace_back(audio); - shared_ptr file = make_shared(FILE_ROOT_NAME, FISRT_LEVEL_ALBUM, ALBUM_TYPE); - fileList.emplace_back(file); - return SUCCESS; -} -} // namespace FileManagerService -} // namespace OHOS \ No newline at end of file diff --git a/services/src/fileoper/media_file_utils.h b/services/src/fileoper/media_file_utils.h deleted file mode 100644 index 0a3b923f6893cae853c1434db00c6e863b27d508..0000000000000000000000000000000000000000 --- a/services/src/fileoper/media_file_utils.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2021 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 STORAGE_SERIVCES_MEDIA_FILE_UTILS_H -#define STORAGE_SERIVCES_MEDIA_FILE_UTILS_H - -#include -#include - -#include "abs_shared_result_set.h" -#include "file_info.h" -#include "file_oper.h" - -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" - -#include "data_ability_helper.h" - -namespace OHOS { -namespace FileManagerService { -class MediaFileUtils { -public: - MediaFileUtils(); - ~MediaFileUtils(); - static int DoGetRoot(const std::string &name, const std::string &path, - std::vector> &fileList); - static int DoListFile(const std::string &type, const std::string &path, int offset, int count, - std::shared_ptr &result); - static std::shared_ptr DoQuery(const std::string &selection, - const std::vector &selectionArgs); - static std::shared_ptr DoQuery(const std::string &selection, - const std::vector &selectionArgs, int offset, int count); - static int DoInsert(const std::string &name, const std::string &path, const std::string &type, std::string &uri); - static bool GetFileInfo(std::shared_ptr result, std::shared_ptr &fileInfo); - static int GetFileInfoFromResult(std::shared_ptr result, - std::vector> &fileList); - static bool InitMediaTableColIndexMap(std::shared_ptr result); - static bool InitHelper(sptr obj); -private: - inline static std::vector> mediaTableMap = {}; - inline static std::shared_ptr abilityHelper = nullptr; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_SERIVCES_MEDIA_FILE_UTILS_H \ No newline at end of file diff --git a/services/src/server/file_manager_service_stub.cpp b/services/src/server/file_manager_service_stub.cpp deleted file mode 100644 index 2cfc3d65519a5153eec5d3ff1da0257dfb05e608..0000000000000000000000000000000000000000 --- a/services/src/server/file_manager_service_stub.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2021 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. - */ - -#include "file_manager_service_stub.h" - -#include "accesstoken_kit.h" -#include "file_manager_service_def.h" -#include "file_manager_service_errno.h" -#include "file_manager_service.h" -#include "ipc_singleton.h" -#include "ipc_skeleton.h" -#include "log.h" -#include "media_file_utils.h" -#include "oper_factory.h" -#include "sa_mgr_client.h" -#include "string_ex.h" -#include "system_ability_definition.h" -using namespace std; -namespace OHOS { -namespace FileManagerService { -static int GetEquipmentCode(uint32_t code) -{ - return (code >> EQUIPMENT_SHIFT) & CODE_MASK; -} - -static int GetOperCode(uint32_t code) -{ - return code & CODE_MASK; -} - -int FileManagerServiceStub::OperProcess(uint32_t code, MessageParcel &data, - MessageParcel &reply) -{ - int equipmentId = GetEquipmentCode(code); - int operCode = GetOperCode(code); - OperFactory factory = OperFactory(); - auto fp = factory.GetFileOper(equipmentId); - if (fp == nullptr) { - ERR_LOG("OnRemoteRequest inner error %{public}d", code); - return FAIL; - } - int errCode = fp->OperProcess(operCode, data, reply); - return errCode; -} - -bool CheckClientPermission(const std::string& permissionStr) -{ - Security::AccessToken::AccessTokenID tokenCaller = IPCSkeleton::GetCallingTokenID(); - int res = Security::AccessToken::AccessTokenKit::VerifyAccessToken(tokenCaller, - permissionStr); - if (res != Security::AccessToken::PermissionState::PERMISSION_GRANTED) { - ERR_LOG("Have no media permission"); - return false; - } - ERR_LOG("permission check success"); - return true; -} - -int FileManagerServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, - MessageParcel &reply, MessageOption &option) -{ - // check whether request from fms proxy - if (data.ReadInterfaceToken() != GetDescriptor()) { - ERR_LOG("reject error remote request"); - reply.WriteInt32(FAIL); - return FAIL; - } - // change permission string after finishing accessToken - string permission = "ohos.permission.READ_MEDIA"; - if (!CheckClientPermission(permission)) { - ERR_LOG("checkpermission error FAIL"); - reply.WriteInt32(FAIL); - return FAIL; - } - if (!MediaFileUtils::InitHelper(AsObject())) { - ERR_LOG("Init MediaLibraryDataAbility Helper error"); - reply.WriteInt32(FAIL); - return FAIL; - } - // do request process - int32_t errCode = OperProcess(code, data, reply); - reply.WriteInt32(errCode); - return errCode; -} -} // namespace FileManagerService -} // namespace OHOS diff --git a/services/src/server/file_manager_service_stub.h b/services/src/server/file_manager_service_stub.h deleted file mode 100644 index e00697a98cf0b7bdda1cfd05700fc87ed0ee3143..0000000000000000000000000000000000000000 --- a/services/src/server/file_manager_service_stub.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2021 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 STORAGE_FILE_MANAGER_SERVICE_STUB_H -#define STORAGE_FILE_MANAGER_SERVICE_STUB_H - -#include "ipc_types.h" -#include "iremote_broker.h" -#include "iremote_proxy.h" -#include "iremote_stub.h" -#include "oper_factory.h" - -namespace OHOS { -namespace FileManagerService { -class IFileManagerService : public IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"IFileManagerService"); -}; - -class FileManagerServiceStub : public IRemoteStub { -public: - FileManagerServiceStub() = default; - virtual ~FileManagerServiceStub() = default; - int OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply); - virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, - MessageParcel &reply, MessageOption &option) override; -}; -} // namespace FileManagerService -} // namespace OHOS -#endif // STORAGE_FILE_MANAGER_SERVICE_STUB_H \ No newline at end of file diff --git a/services/test/BUILD.gn b/services/test/BUILD.gn deleted file mode 100644 index 92b1ac6cd93300407535c1396bdf659ad765e81f..0000000000000000000000000000000000000000 --- a/services/test/BUILD.gn +++ /dev/null @@ -1,125 +0,0 @@ -# Copyright (c) 2021 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/test.gni") -FMS_BASE_DIR = "//foundation/filemanagement/user_file_service/services" -ohos_unittest("file_manager_proxy_test") { - module_out_path = "filemanagement/user_file_service" - - sources = [ "client/file_manager_proxy_test.cpp" ] - - include_dirs = [ - "//third_party/json/include", - "//base/security/huks/interfaces/innerkits/huks_standard/main/include", - "$FMS_BASE_DIR/include", - "$FMS_BASE_DIR/src/client", - "$FMS_BASE_DIR/src/server", - "$FMS_BASE_DIR/src/fileoper", - "//third_party/googletest/googlemock/include/gmock", - "//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/rdb/include", - "//foundation/multimedia/medialibrary_standard/interfaces/inner_api/media_library_helper/include", - ] - - configs = [ "//build/config/compiler:exceptions" ] - - deps = [ - "$FMS_BASE_DIR:fms_server", - "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//third_party/googletest:gmock_main", - "//utils/native/base:utils", - ] - - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - ] -} - -ohos_unittest("oper_factory_test") { - module_out_path = "filemanagement/user_file_service" - - sources = [ "fileoper/oper_factory_test.cpp" ] - - include_dirs = [ - "//third_party/json/include", - "//base/security/huks/interfaces/innerkits/huks_standard/main/include", - "$FMS_BASE_DIR/include", - "$FMS_BASE_DIR/src/client", - "$FMS_BASE_DIR/src/server", - "$FMS_BASE_DIR/src/fileoper", - "//foundation/multimedia/medialibrary_standard/interfaces/inner_api/media_library_helper/include", - "//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/rdb/include", - ] - - configs = [ "//build/config/compiler:exceptions" ] - - deps = [ - "$FMS_BASE_DIR:fms_server", - "//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/appdatafwk:native_appdatafwk", - "//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/rdb:native_rdb", - "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//utils/native/base:utils", - ] - - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - ] -} - -ohos_unittest("file_manager_service_test") { - module_out_path = "filemanagement/user_file_service" - - sources = [ "server/file_manager_service_test.cpp" ] - - include_dirs = [ - "//third_party/json/include", - "//base/security/huks/interfaces/innerkits/huks_standard/main/include", - "$FMS_BASE_DIR/include", - "$FMS_BASE_DIR/src/client", - "$FMS_BASE_DIR/src/server", - "$FMS_BASE_DIR/src/fileoper", - "//foundation/multimedia/medialibrary_standard/interfaces/inner_api/media_library_helper/include", - "//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/rdb/include", - ] - - configs = [ "//build/config/compiler:exceptions" ] - deps = [ - "$FMS_BASE_DIR:fms_server", - "//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/appdatafwk:native_appdatafwk", - "//foundation/distributeddatamgr/appdatamgr/interfaces/inner_api/native/rdb:native_rdb", - "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", - "//utils/native/base:utils", - ] - - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - ] -} - -group("user_file_manager_test") { - testonly = true - - deps = [ - ":file_manager_proxy_test", - ":file_manager_service_test", - ":oper_factory_test", - ] -} diff --git a/services/test/client/file_manager_proxy_test.cpp b/services/test/client/file_manager_proxy_test.cpp deleted file mode 100644 index 501a1ec9002fbfd7598158dea1c18c7e87f6d9b3..0000000000000000000000000000000000000000 --- a/services/test/client/file_manager_proxy_test.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2021 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. - */ - -#include - -#include - -#include "ifms_client.h" -#include "file_manager_proxy.h" -#include "fms_manager_proxy_mock.h" - -namespace { -using namespace std; -using namespace OHOS; -using namespace FileManagerService; -class FileManagerProxyTest : public testing::Test { -public: - static void SetUpTestCase(void) - { - cout << "FileManagerProxyTest code test" << endl; - } - static void TearDownTestCase() {}; - void SetUp(); - void TearDown() {}; - std::shared_ptr proxy_ = nullptr; - sptr mock_ = nullptr; -}; - -void FileManagerProxyTest::SetUp() -{ - mock_ = new OHOS::FileManagerService::FmsManagerProxyMock(); - proxy_ = std::make_shared(mock_); -} - -/** - * @tc.number: SUB_STORAGE_File_Manager_Proxy_GetFmsInstance_0000 - * @tc.name: File_Manager_Proxy_GetFmsInstance_0000 - * @tc.desc: Test function of GetFmsInstance interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_GetFmsInstance_0000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "FileManagerProxyTest-begin File_Manager_Proxy_GetFmsInstance_0000"; - try { - IFmsClient* result = IFmsClient::GetFmsInstance(); - EXPECT_NE(result, nullptr); - } catch (...) { - GTEST_LOG_(INFO) << "FileManagerProxyTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_GetFmsInstance_0000"; -} - -/** - * @tc.number: SUB_STORAGE_File_Manager_Proxy_Mkdir_0000 - * @tc.name: File_Manager_Proxy_Mkdir_0000 - * @tc.desc: Test function of Mkdir interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(FileManagerProxyTest, File_Manager_Proxy_Mkdir_0000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "FileManagerProxyTest-begin File_Manager_Proxy_Mkdir_0000"; - std::string name = "File_Manager_Proxy_Mkdir_0000"; - std::string path = "dataability:///album"; - EXPECT_CALL(*mock_, SendRequest(testing::_, testing::_, testing::_, testing::_)) - .Times(1) - .WillOnce(testing::Invoke(mock_.GetRefPtr(), &FmsManagerProxyMock::InvokeSendRequest)); - int ret = proxy_->Mkdir(name, path); - EXPECT_EQ(ret, 1); - GTEST_LOG_(INFO) << "FileManagerProxyTest-end File_Manager_Proxy_Mkdir_0000"; -} -} // namespace \ No newline at end of file diff --git a/services/test/client/fms_manager_proxy_mock.h b/services/test/client/fms_manager_proxy_mock.h deleted file mode 100644 index 811807ed6f0d52ebdc692ea00dbe1545fb69ab72..0000000000000000000000000000000000000000 --- a/services/test/client/fms_manager_proxy_mock.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2021 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 FMS_MANAGER_PROXY_MOCK_H -#define FMS_MANAGER_PROXY_MOCK_H -#include -#include "gmock/gmock.h" -#include "iremote_stub.h" -#include "iremote_proxy.h" -#include "ifms_client.h" -#include "cmd_response.h" - -namespace OHOS { -namespace FileManagerService { -class FmsManagerProxyMock : public IRemoteStub, public IFmsClient { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"FmsManagerProxyMock"); - FmsManagerProxyMock() {} - virtual ~FmsManagerProxyMock() {} - MOCK_METHOD4(SendRequest, int(uint32_t, MessageParcel &, MessageParcel &, MessageOption &)); - int32_t InvokeSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) - { - sptr cmdResponse = new CmdResponse(); - reply.WriteParcelable(cmdResponse); - return ERR_NONE; - } - virtual int Mkdir(const std::string &name, const std::string &path) override - { - return ERR_NONE; - } - virtual int ListFile(const std::string &type, const std::string &path, const CmdOptions &option, - std::vector> &fileRes) override - { - return ERR_NONE; - } - virtual int GetRoot(const CmdOptions &option, std::vector> &fileRes) override - { - return ERR_NONE; - } - virtual int CreateFile(const std::string &path, const std::string &fileName, - const CmdOptions &option, std::string &uri) override - { - return ERR_NONE; - } -}; -} // namespace FileManagerService -} // namespace OHOS - -#endif // FMS_MANAGER_PROXY_MOCK_H \ No newline at end of file diff --git a/services/test/fileoper/oper_factory_test.cpp b/services/test/fileoper/oper_factory_test.cpp deleted file mode 100644 index 9a2eebbce6bbdc9445158c1d141e59c750724fbf..0000000000000000000000000000000000000000 --- a/services/test/fileoper/oper_factory_test.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2021 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. - */ - -#include -#include - -#include "file_manager_service_def.h" -#include "file_manager_service_stub.h" -#include "media_data_ability_const.h" -#include "abs_shared_result_set.h" - -namespace { -using namespace std; -using namespace OHOS; -using namespace FileManagerService; -class OperFactoryTest : public testing::Test { -public: - static void SetUpTestCase(void) - { - cout << "OperFactoryTest code test" << endl; - } - static void TearDownTestCase() {}; - void SetUp() {}; - void TearDown() {}; -}; - -/** - * @tc.number: SUB_STORAGE_oper_factory_GetFileOper_0000 - * @tc.name: oper_factory_GetFileOper_0000 - * @tc.desc: Test function of GetFileOper interface for SUCCESS which INTERNAL_STORAGE. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(OperFactoryTest, oper_factory_GetFileOper_0000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "OperFactoryTest-begin oper_factory_GetFileOper_0000"; - try { - OperFactory *oper = new OperFactory(); - std::unique_ptr result; - if (oper != nullptr) { - result = oper->GetFileOper(Equipment::INTERNAL_STORAGE); - } - EXPECT_NE(result, nullptr); - } catch (...) { - GTEST_LOG_(INFO) << "OperFactoryTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "OperFactoryTest-end oper_factory_GetFileOper_0000"; -} - -/** - * @tc.number: SUB_STORAGE_oper_factory_GetFileOper_0001 - * @tc.name: oper_factory_GetFileOper_0001 - * @tc.desc: Test function of GetFileOper for SUCCESS which EXTERNAL_STORAGE. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(OperFactoryTest, oper_factory_GetFileOper_0001, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "OperFactoryTest-begin oper_factory_GetFileOper_0001"; - try { - OperFactory *oper = new OperFactory(); - std::unique_ptr result; - if (oper != nullptr) { - result = oper->GetFileOper(Equipment::EXTERNAL_STORAGE); - } - EXPECT_NE(result, nullptr); - } catch (...) { - GTEST_LOG_(INFO) << "OperFactoryTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "OperFactoryTest-end oper_factory_GetFileOper_0001"; -} - -/** - * @tc.number: SUB_STORAGE_oper_factory_GetFileOper_0002 - * @tc.name: oper_factory_GetFileOper_0002 - * @tc.desc: Test function of GetFileOper interface for SUCCESS wich default. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(OperFactoryTest, oper_factory_GetFileOper_0002, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "OperFactoryTest-begin oper_factory_GetFileOper_0002"; - try { - OperFactory *oper = new OperFactory(); - std::unique_ptr result; - if (oper != nullptr) { - result = oper->GetFileOper(3); - } - EXPECT_EQ(result, nullptr); - } catch (...) { - GTEST_LOG_(INFO) << "OperFactoryTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "OperFactoryTest-end oper_factory_GetFileOper_0002"; -} -} // namespace \ No newline at end of file diff --git a/services/test/server/file_manager_service_test.cpp b/services/test/server/file_manager_service_test.cpp deleted file mode 100644 index 3d0ea852d1628e9046395799a6f8a525987bb1d0..0000000000000000000000000000000000000000 --- a/services/test/server/file_manager_service_test.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2021 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. - */ - -#include -#include - -#include "ifms_client.h" -#include "file_info.h" -#include "media_file_oper.h" -#include "file_manager_service_stub.h" -#include "media_data_ability_const.h" -#include "file_manager_service_def.h" -#include "abs_shared_result_set.h" -#include "file_manager_service.h" - -namespace { -using namespace std; -using namespace OHOS; -using namespace FileManagerService; -class FileManagerServiceTest : public testing::Test { -public: - static void SetUpTestCase(void) - { - cout << "FileManagerServiceTest code test" << endl; - } - static void TearDownTestCase() {}; - void SetUp() {}; - void TearDown() {}; -}; - -/** - * @tc.number: SUB_STORAGE_file_Manager_Service_OnDump_0000 - * @tc.name: file_Manager_Service_OnDump_0000 - * @tc.desc: Test function of OnDump interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(FileManagerServiceTest, file_Manager_Service_OnDump_0000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "FileManagerServiceTest-begin file_Manager_Service_OnDump_0000"; - try { - OHOS::FileManagerService::FileManagerService *service = new OHOS::FileManagerService::FileManagerService(0); - if (service != nullptr) { - service->OnDump(); - } - } catch (...) { - GTEST_LOG_(INFO) << "FileManagerServiceTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "FileManagerServiceTest-end file_Manager_Service_OnDump_0000"; -} - -/** - * @tc.number: SUB_STORAGE_file_Manager_Service_OnStart_0000 - * @tc.name: file_Manager_Service_OnStart_0000 - * @tc.desc: Test function of OnStart interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(FileManagerServiceTest, file_Manager_Service_OnStart_0000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "FileManagerServiceTest-begin file_Manager_Service_OnStart_0000"; - try { - OHOS::FileManagerService::FileManagerService *service = new OHOS::FileManagerService::FileManagerService(0); - if (service != nullptr) { - service->OnStart(); - } - } catch (...) { - GTEST_LOG_(INFO) << "FileManagerServiceTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "FileManagerServiceTest-end file_Manager_Service_OnStart_0000"; -} - -/** - * @tc.number: SUB_STORAGE_file_Manager_Service_OnStop_0000 - * @tc.name: file_Manager_Service_OnStop_0000 - * @tc.desc: Test function of OnStop interface for SUCCESS. - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: AR000GJ9T3 - */ -HWTEST_F(FileManagerServiceTest, Ffile_Manager_Service_OnStop_0000, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "FileManagerServiceTest-begin file_Manager_Service_OnStop_0000"; - try { - OHOS::FileManagerService::FileManagerService *service = new OHOS::FileManagerService::FileManagerService(0); - if (service != nullptr) { - service->OnStop(); - } - } catch (...) { - GTEST_LOG_(INFO) << "FileManagerServiceTest-an exception occurred."; - } - GTEST_LOG_(INFO) << "FileManagerServiceTest-end file_Manager_Service_OnStop_0000"; -} -} // namespace \ No newline at end of file diff --git a/utils/hilog_wrapper.h b/utils/hilog_wrapper.h new file mode 100644 index 0000000000000000000000000000000000000000..a070b12e42b608cc1d3b1e37a08ca5be599b899e --- /dev/null +++ b/utils/hilog_wrapper.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2022 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 HILOG_WRAPPER_H +#define HILOG_WRAPPER_H + +#define CONFIG_HILOG +#ifdef CONFIG_HILOG +#include "hilog/log.h" + +#ifdef HILOG_FATAL +#undef HILOG_FATAL +#endif + +#ifdef HILOG_ERROR +#undef HILOG_ERROR +#endif + +#ifdef HILOG_WARN +#undef HILOG_WARN +#endif + +#ifdef HILOG_INFO +#undef HILOG_INFO +#endif + +#ifdef HILOG_DEBUG +#undef HILOG_DEBUG +#endif + +#ifndef AMS_LOG_DOMAIN +#define AMS_LOG_DOMAIN 0xD00430A +#endif + +#ifndef AMS_LOG_TAG +#define AMS_LOG_TAG "FileAccessFrameworks" +#endif + +#ifdef LOG_LABEL +#undef LOG_LABEL +#endif + +static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = {LOG_CORE, AMS_LOG_DOMAIN, AMS_LOG_TAG}; + +#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) + +#define HILOG_FATAL(fmt, ...) \ + (void)OHOS::HiviewDFX::HiLog::Fatal( \ + LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, __FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define HILOG_ERROR(fmt, ...) \ + (void)OHOS::HiviewDFX::HiLog::Error( \ + LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, __FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define HILOG_WARN(fmt, ...) \ + (void)OHOS::HiviewDFX::HiLog::Warn( \ + LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, __FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define HILOG_INFO(fmt, ...) \ + (void)OHOS::HiviewDFX::HiLog::Info( \ + LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, __FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#define HILOG_DEBUG(fmt, ...) \ + (void)OHOS::HiviewDFX::HiLog::Debug( \ + LOG_LABEL, "[%{public}s(%{public}s:%{public}d)]" fmt, __FILENAME__, __FUNCTION__, __LINE__, ##__VA_ARGS__) +#else + +#define HILOG_FATAL(...) +#define HILOG_ERROR(...) +#define HILOG_WARN(...) +#define HILOG_INFO(...) +#define HILOG_DEBUG(...) +#endif // CONFIG_HILOG + +#endif // HILOG_WRAPPER_H \ No newline at end of file