From 72cecbdc928559c2d5001e0aa9d8c64d71d93ec2 Mon Sep 17 00:00:00 2001 From: linjun9528 Date: Fri, 13 May 2022 15:55:03 +0800 Subject: [PATCH 1/2] add file extension code Signed-off-by: linjun9528 --- bundle.json | 5 +- frameworks/innerkits/BUILD.gn | 58 + frameworks/innerkits/file_extension/BUILD.gn | 116 ++ .../include/file_access_helper.h | 81 + .../file_extension/include/file_ext_ability.h | 46 + .../include/file_ext_ability_module_loader.h | 36 + .../include/file_ext_connection.h | 61 + .../file_extension/include/file_ext_proxy.h | 43 + .../file_extension/include/file_ext_stub.h | 45 + .../include/file_ext_stub_impl.h | 54 + .../file_extension/include/ifile_ext_base.h | 85 + .../include/js_file_ext_ability.h | 62 + .../file_extension/src/file_access_helper.cpp | 318 ++++ .../file_extension/src/file_ext_ability.cpp | 107 ++ .../src/file_ext_ability_module_loader.cpp | 34 + .../src/file_ext_connection.cpp | 96 + .../file_extension/src/file_ext_proxy.cpp | 342 ++++ .../file_extension/src/file_ext_stub.cpp | 298 +++ .../file_extension/src/file_ext_stub_impl.cpp | 124 ++ .../src/js_file_ext_ability.cpp | 398 ++++ .../innerkits/file_extension_hap/.gitignore | 4 + .../file_extension_hap/AppScope/app.json | 13 + .../resources/base/element/string.json | 8 + .../resources/base/media/app_icon.png | Bin 0 -> 6790 bytes .../file_extension_hap/build-profile.json5 | 26 + .../file_extension_hap/entry/.gitignore | 3 + .../entry/build-profile.json5 | 13 + .../file_extension_hap/entry/hvigorfile.js | 2 + .../entry/package-lock.json | 5 + .../file_extension_hap/entry/package.json | 14 + .../src/main/ets/Application/AbilityStage.ts | 21 + .../FileExtensionAbility.ts | 57 + .../src/main/ets/MainAbility/MainAbility.ts | 48 + .../entry/src/main/ets/pages/index.ets | 31 + .../entry/src/main/module.json | 37 + .../main/resources/base/element/string.json | 20 + .../src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../resources/base/profile/main_pages.json | 5 + .../ohosTest/ets/TestAbility/TestAbility.ts | 39 + .../ohosTest/ets/TestAbility/pages/index.ets | 34 + .../ets/TestRunner/OpenHarmonyTestRunner.ts | 58 + .../src/ohosTest/ets/test/Ability.test.ets | 13 + .../entry/src/ohosTest/ets/test/List.test.ets | 5 + .../entry/src/ohosTest/module.json5 | 37 + .../resources/base/element/string.json | 16 + .../ohosTest/resources/base/media/icon.png | Bin 0 -> 6790 bytes .../resources/base/profile/test_pages.json | 5 + .../file_extension_hap/hvigorfile.js | 2 + .../file_extension_hap/package-lock.json | 1652 +++++++++++++++++ .../innerkits/file_extension_hap/package.json | 18 + .../innerkits/signature/fileextension.p7b | Bin 0 -> 3400 bytes .../kits/napi/file_access_module/BUILD.gn | 48 + .../file_access_module/file_access_common.h | 112 ++ .../napi_fileaccess_helper.cpp | 1503 +++++++++++++++ .../napi_fileaccess_helper.h | 83 + .../native_fileaccess_module.cpp | 62 + .../kits/napi/file_ext_ability/BUILD.gn | 50 + .../napi/file_ext_ability/file_ext_ability.js | 52 + .../file_ext_ability_module.cpp | 57 + utils/hilog_wrapper.h | 83 + 60 files changed, 6644 insertions(+), 1 deletion(-) create mode 100644 frameworks/innerkits/BUILD.gn create mode 100644 frameworks/innerkits/file_extension/BUILD.gn create mode 100644 frameworks/innerkits/file_extension/include/file_access_helper.h create mode 100644 frameworks/innerkits/file_extension/include/file_ext_ability.h create mode 100644 frameworks/innerkits/file_extension/include/file_ext_ability_module_loader.h create mode 100644 frameworks/innerkits/file_extension/include/file_ext_connection.h create mode 100644 frameworks/innerkits/file_extension/include/file_ext_proxy.h create mode 100644 frameworks/innerkits/file_extension/include/file_ext_stub.h create mode 100644 frameworks/innerkits/file_extension/include/file_ext_stub_impl.h create mode 100644 frameworks/innerkits/file_extension/include/ifile_ext_base.h create mode 100644 frameworks/innerkits/file_extension/include/js_file_ext_ability.h create mode 100644 frameworks/innerkits/file_extension/src/file_access_helper.cpp create mode 100644 frameworks/innerkits/file_extension/src/file_ext_ability.cpp create mode 100644 frameworks/innerkits/file_extension/src/file_ext_ability_module_loader.cpp create mode 100644 frameworks/innerkits/file_extension/src/file_ext_connection.cpp create mode 100644 frameworks/innerkits/file_extension/src/file_ext_proxy.cpp create mode 100644 frameworks/innerkits/file_extension/src/file_ext_stub.cpp create mode 100644 frameworks/innerkits/file_extension/src/file_ext_stub_impl.cpp create mode 100644 frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp create mode 100644 frameworks/innerkits/file_extension_hap/.gitignore create mode 100644 frameworks/innerkits/file_extension_hap/AppScope/app.json create mode 100644 frameworks/innerkits/file_extension_hap/AppScope/resources/base/element/string.json create mode 100644 frameworks/innerkits/file_extension_hap/AppScope/resources/base/media/app_icon.png create mode 100644 frameworks/innerkits/file_extension_hap/build-profile.json5 create mode 100644 frameworks/innerkits/file_extension_hap/entry/.gitignore create mode 100644 frameworks/innerkits/file_extension_hap/entry/build-profile.json5 create mode 100644 frameworks/innerkits/file_extension_hap/entry/hvigorfile.js create mode 100644 frameworks/innerkits/file_extension_hap/entry/package-lock.json create mode 100644 frameworks/innerkits/file_extension_hap/entry/package.json create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/main/ets/Application/AbilityStage.ts create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/main/ets/FileExtensionAbility/FileExtensionAbility.ts create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/main/ets/MainAbility/MainAbility.ts create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/main/ets/pages/index.ets create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/main/module.json create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/main/resources/base/element/string.json create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/main/resources/base/media/icon.png create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/main/resources/base/profile/main_pages.json create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestAbility/TestAbility.ts create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestAbility/pages/index.ets create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/Ability.test.ets create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/List.test.ets create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/module.json5 create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/element/string.json create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/media/icon.png create mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/profile/test_pages.json create mode 100644 frameworks/innerkits/file_extension_hap/hvigorfile.js create mode 100644 frameworks/innerkits/file_extension_hap/package-lock.json create mode 100644 frameworks/innerkits/file_extension_hap/package.json create mode 100644 frameworks/innerkits/signature/fileextension.p7b create mode 100644 interfaces/kits/napi/file_access_module/BUILD.gn create mode 100644 interfaces/kits/napi/file_access_module/file_access_common.h create mode 100644 interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp create mode 100644 interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h create mode 100644 interfaces/kits/napi/file_access_module/native_fileaccess_module.cpp create mode 100644 interfaces/kits/napi/file_ext_ability/BUILD.gn create mode 100644 interfaces/kits/napi/file_ext_ability/file_ext_ability.js create mode 100644 interfaces/kits/napi/file_ext_ability/file_ext_ability_module.cpp create mode 100644 utils/hilog_wrapper.h diff --git a/bundle.json b/bundle.json index 95dbc537..5fab9ad8 100644 --- a/bundle.json +++ b/bundle.json @@ -35,7 +35,10 @@ "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/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/frameworks/innerkits/BUILD.gn b/frameworks/innerkits/BUILD.gn new file mode 100644 index 00000000..0c10968c --- /dev/null +++ b/frameworks/innerkits/BUILD.gn @@ -0,0 +1,58 @@ +# 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("//build/ohos.gni") + +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" +} + +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" +} + +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 = [ + "file_extension_hap/entry/src/main/resources", + ] + deps = [ + ":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/frameworks/innerkits/file_extension/BUILD.gn b/frameworks/innerkits/file_extension/BUILD.gn new file mode 100644 index 00000000..aba44d06 --- /dev/null +++ b/frameworks/innerkits/file_extension/BUILD.gn @@ -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. + +import("//build/ohos.gni") + +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", + ] + + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } +} + +config("ability_public_config") { + visibility = [ ":*" ] + include_dirs = [ + "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 = [ + "${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 = [ + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", + "//foundation/aafwk/standard/frameworks/kits/appkit:app_context", + ] + + 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", + "bytrace_standard:bytrace_core", + "ipc:ipc_core", + "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 00000000..9cdfc593 --- /dev/null +++ b/frameworks/innerkits/file_extension/include/file_access_helper.h @@ -0,0 +1,81 @@ +/* + * 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 "context.h" +#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; + static std::mutex oplock_; + 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 00000000..c98a352a --- /dev/null +++ b/frameworks/innerkits/file_extension/include/file_ext_ability.h @@ -0,0 +1,46 @@ +/* + * 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 : 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); +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // FOUNDATION_ABILITYRUNTIME_OHOS_FILE_EXT_ABILITY_H \ No newline at end of file diff --git a/frameworks/innerkits/file_extension/include/file_ext_ability_module_loader.h b/frameworks/innerkits/file_extension/include/file_ext_ability_module_loader.h new file mode 100644 index 00000000..81cd27ac --- /dev/null +++ b/frameworks/innerkits/file_extension/include/file_ext_ability_module_loader.h @@ -0,0 +1,36 @@ +/* + * 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/frameworks/innerkits/file_extension/include/file_ext_connection.h b/frameworks/innerkits/file_extension/include/file_ext_connection.h new file mode 100644 index 00000000..292a9130 --- /dev/null +++ b/frameworks/innerkits/file_extension/include/file_ext_connection.h @@ -0,0 +1,61 @@ +/* + * 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_FILEEXT_CONNECTION_H +#define FOUNDATION_APPEXECFWK_OHOS_FILEEXT_CONNECTION_H + +#include + +#include "ability_connect_callback_stub.h" +#include "event_handler.h" +#include "ifile_ext_base.h" +#include "want.h" + +namespace OHOS { +namespace AppExecFwk { +class FileExtConnection : public AAFwk::AbilityConnectionStub { +public: + 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 AppExecFwk +} // namespace OHOS +#endif // FOUNDATION_APPEXECFWK_OHOS_DATASHARE_CONNECTION_H diff --git a/frameworks/innerkits/file_extension/include/file_ext_proxy.h b/frameworks/innerkits/file_extension/include/file_ext_proxy.h new file mode 100644 index 00000000..1a3d2126 --- /dev/null +++ b/frameworks/innerkits/file_extension/include/file_ext_proxy.h @@ -0,0 +1,43 @@ +/* + * 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_FILEEXT_PROXY_H +#define OHOS_APPEXECFWK_FILEEXT_PROXY_H + +#include +#include "ifile_ext_base.h" + +namespace OHOS { +namespace AppExecFwk { +class FileExtProxy : public IRemoteProxy { +public: + 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: + static inline BrokerDelegator delegator_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_APPEXECFWK_DATASHARE_PROXY_H + diff --git a/frameworks/innerkits/file_extension/include/file_ext_stub.h b/frameworks/innerkits/file_extension/include/file_ext_stub.h new file mode 100644 index 00000000..356e4cff --- /dev/null +++ b/frameworks/innerkits/file_extension/include/file_ext_stub.h @@ -0,0 +1,45 @@ +/* + * 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_FILEEXT_STUB_H +#define OHOS_APPEXECFWK_FILEEXT_STUB_H + +#include +#include + +#include "ifile_ext_base.h" + +namespace OHOS { +namespace AppExecFwk { +class FileExtStub : public IRemoteStub { +public: + FileExtStub(); + ~FileExtStub(); + int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override; +private: + 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 AppExecFwk +} // namespace OHOS +#endif // OHOS_APPEXECFWK_FILEEXT_STUB_H + diff --git a/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h b/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h new file mode 100644 index 00000000..3caf1ca0 --- /dev/null +++ b/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h @@ -0,0 +1,54 @@ +/* + * 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_FILEEXT_STUB_IMPL_H +#define OHOS_APPEXECFWK_FILEEXT_STUB_IMPL_H + +#include +#include "file_ext_stub.h" +#include "js_file_ext_ability.h" +#include "native_engine/native_value.h" + +namespace OHOS { +namespace AppExecFwk { +using AbilityRuntime::JsFileExtAbility; +class FileExtStubImpl : public FileExtStub { +public: + explicit FileExtStubImpl(const std::shared_ptr& extension, napi_env env) + : extension_(extension) + { + //uvQueue_ = std::make_shared(env); + } + + 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_; + //std::shared_ptr uvQueue_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_APPEXECFWK_DATASHARE_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 00000000..ad7399cf --- /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 00000000..ae17d3e4 --- /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 00000000..eababd69 --- /dev/null +++ b/frameworks/innerkits/file_extension/src/file_access_helper.cpp @@ -0,0 +1,318 @@ +/* + * 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 + +std::mutex FileAccessHelper::oplock_; + +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_->Mkdir."); + index = fileExtProxy_->CreateFile(parentUri, displayName, newFileUri); + HILOG_INFO("tag dsa FileAccessHelper::CreateFile end. index = %{public}d", index); + HILOG_INFO("tag dsa FileAccessHelper::Mkdir 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::OpenFile before fileExtProxy_->OpenFile."); + 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::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::OpenFile before fileExtProxy_->OpenFile."); + 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 00000000..f5fcdb9a --- /dev/null +++ b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp @@ -0,0 +1,107 @@ +/* + * 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; +FileExtAbility* FileExtAbility::Create(const std::unique_ptr& runtime) +{ + HILOG_INFO("tag dsa %{public}s begin.", __func__); + if (!runtime) { + return new FileExtAbility(); + } + 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); + 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/frameworks/innerkits/file_extension/src/file_ext_ability_module_loader.cpp b/frameworks/innerkits/file_extension/src/file_ext_ability_module_loader.cpp new file mode 100644 index 00000000..96ae5c4a --- /dev/null +++ b/frameworks/innerkits/file_extension/src/file_ext_ability_module_loader.cpp @@ -0,0 +1,34 @@ +/* + * 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(); +} +} // 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 00000000..08893233 --- /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 00000000..3224b86f --- /dev/null +++ b/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp @@ -0,0 +1,342 @@ +/* + * 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.WriteInt32(fd)) { + HILOG_ERROR("tag dsa fail to WriteParcelable sourceFileUri"); + 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."); + 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 00000000..336cbad5 --- /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.ReadInt32(); + 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 WriteFileDescriptor 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 00000000..ced9fe21 --- /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 00000000..6c7942c7 --- /dev/null +++ b/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp @@ -0,0 +1,398 @@ +/* + * 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_); + //auto& engine = jsRuntime_.GetNativeEngine(); + + 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; + } + + /* + auto context = GetContext(); + if (context == nullptr) { + HILOG_ERROR("tag dsa Failed to get context"); + return; + } + + HILOG_INFO("tag dsa JsFileExtAbility::Init CreateJsDataShareExtAbilityContext."); + NativeValue* contextObj = CreateJsDataShareExtAbilityContext(engine, context); + auto contextRef = jsRuntime_.LoadSystemModule("application.DataShareExtensionAbilityContext", + &contextObj, ARGC_ONE); + contextObj = contextRef->Get(); + HILOG_INFO("tag dsa JsFileExtAbility::Init Bind."); + context->Bind(jsRuntime_, contextRef.release()); + HILOG_INFO("tag dsa JsFileExtAbility::SetProperty."); + obj->SetProperty("context", contextObj); + + auto nativeObj = ConvertNativeValueTo(contextObj); + if (nativeObj == nullptr) { + HILOG_ERROR("tag dsa Failed to get datashare extension ability native object"); + return; + } + + HILOG_INFO("tag dsa Set datashare extension ability context"); + + nativeObj->SetNativePointer(new std::weak_ptr(context), + [](NativeEngine*, void* data, void*) { + HILOG_INFO("tag dsa Finalizer for weak_ptr datashare extension ability context is called"); + delete static_cast*>(data); + }, nullptr); + */ + 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 = 0; + } + 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 = 0; + } + 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 = 0; + } + 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 = 0; + } + 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/.gitignore b/frameworks/innerkits/file_extension_hap/.gitignore new file mode 100644 index 00000000..39187ebe --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/.gitignore @@ -0,0 +1,4 @@ +/node_modules +/local.properties +/.idea +**/build \ 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 00000000..f86c4521 --- /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 00000000..7863972b --- /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 GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O18 zbsbSmKN=aaq8k3NFYZfDWpKmM!coBU0(XnL8R{4=i|wi{!uWYM2je{U{B*K2PVdu&=E zTq*-XsEsJ$u5H4g6DIm2Y!DN`>^v|AqlwuCD;w45K0@eqauiqWf7l&o)+YLHm~|L~ z7$0v5mkobriU!H<@mVJHLlmQqzQ3d6Rh_-|%Yy2li*tHO>_vcnuZ7OR_xkAIuIU&x z-|8Y0wj|6|a6_I(v91y%k_kNw6pnkNdxjqG8!%Vz_d%c_!X+6-;1`GC9_Fpj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?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 00000000..7a0024d4 --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,58 @@ +import TestRunner from '@ohos.application.testRunner' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}` + } + } + return targetParams.trim() +} + +async function onAbilityCreateCallback() { + console.log("onAbilityCreateCallback"); +} + +async function addAbilityMonitorCallback(err: any) { + console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info("OpenHarmonyTestRunner OnPrepare ") + } + + async onRun() { + console.log('OpenHarmonyTestRunner onRun run') + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }) + console.info('OpenHarmonyTestRunner onRun end') + } +}; \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/Ability.test.ets b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 00000000..1236e0ce --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,13 @@ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'hypium/index' + +export default function abilityTest() { + describe('ActsAbilityTest', function () { + it('assertContain',0, function () { + console.info("it begin") + let a = 'abc' + let b = 'b' + expect(a).assertContain(b) + expect(a).assertEqual(a) + }) + }) +} \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/List.test.ets b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 00000000..d766fe24 --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,5 @@ +import abilityTest from './Ability.test' + +export default function testsuite() { + abilityTest() +} \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/module.json5 b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/module.json5 new file mode 100644 index 00000000..5d696c10 --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/module.json5 @@ -0,0 +1,37 @@ +{ + "module": { + "name": "entry_test", + "type": "feature", + "srcEntrance": "./ets/TestAbility/TestAbility.ts", + "description": "$string:entry_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "phone", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "TestAbility", + "srcEntrance": "./ets/TestAbility/TestAbility.ts", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/element/string.json b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/element/string.json new file mode 100644 index 00000000..84078007 --- /dev/null +++ b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_test_desc", + "value": "i am an entry for tv" + }, + { + "name": "TestAbility_desc", + "value": "the tv entry test ability" + }, + { + "name": "TestAbility_label", + "value": "tvBase" + } + ] +} \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/media/icon.png b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c GIT binary patch literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+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L{wsdrmPvf#a9OHyYLcwQD4Kcm)`LLwMh4WT~p29f7M!iafJSU`IV}QY5Wa z(n44-9oA}?J{a+ah*@31WTs#&J#o1`H98#6IQf;Wv0N_!);f&9g7o-k(lW5rWnDUR zQBFIRG+X=6NnsI@mxnwm;tf5;_Uxg?jZ8m-m0}&6+DA!qam(p$mN5R})yA_7m$q@| zFEd|dpS595rxQr-n#GjI5i-AhnUE>Cr;jpCqSrD~EwK_DqI^7%3#p5)%T_od!t3SOmH9MyXeeGO2(UQL;ax|x?Ncixmeo1=$ z{-);Au{*tfzOG?KQ~K|ak8-HQ?`Pekhe2WM(8s{xv-p>Zmu_6{G!-oE$7$mY`MOJorI=+mMx?H;`pr!;fVYz?5~yXBACruWB`Ph zZM}90_<^OBxIhyZ9BW$`>6JvO;%VFpqVr8|7t3~AmxYak6?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y= 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 00000000..15be3afb --- /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 GIT binary patch literal 3400 zcmcgvZB!Fi8YUk=5hExH>Z(Ar;);Pg`GU|@JCm7w5GElZ0YY(cl1#ociOGZzT&)|n zY}Kmk_Eg#WQB*|TqV7>!WY1B%-BoM5>S`^grz=`&Ia{q;+tpfEkM7POi_q$iJw3<# z$mD(Q``&rxzR!Jb1|$S%O4{63P3w08PAa!OA&`ND0OE2uPzDgBq%CgMa7Z4X%SlcG z34Z^hR8D(>f1aP23|H#IK&`K z`bi=}GLzY&l*3PoJd`uY&gUQ-Nq;azhDC#ng6?2s7-F(VJ&m0V(;lbCPSET_iP#T< zskQn%C1x^fRazx%#s<-P3fF3t7^+mlbyY4nrbS?v7BiM>}b+k&YirZ=wQPPan;fP%g zLl#Wggd5Eg#BcMt-Sz;~Xrp|tYIU`{p0b%SFRsJ}v*0G2_ zE+fEV8n<1Kd$A_mt8HdDpe_h+#w9f@+B}Fh4P#zJg&Tb_BsR!Vjm6+5r5V;dd1f;93t_zbIF|5D{qtxJt(}-MOg{$D0#%M+BscI82Acz%HVTf7p zqG)}wuNb$NhLz=25F)WT!U}}IVJXYrfyOYTIA+9{u4`N<>}1!Yp3+p|m>Pv^T!`7` z4%XN7vQ#lDOZEF6ZHej)f(T7FJtfUcjcy$rHs#@%G$o-|HJff|O zsvPBHl_3r)gN^oDdWlJFY?k36ToFNa)w(4rCn~d4cn!cRX7o@<#FV(IJW!=AG)T2# ztsyGYN_53?o0n4AbWjB_Nz@jFyso080wz$aQzN#x{BD(6tSu&MAd*=JL}#T`uKDxp zsX>`zdh{{Uf3(Mj?7|)l6tVlNNagX9SQAZBteK3CP=Y3yLe@Z>Btb{n?JZ<#8Y1xs zO$Hj60U@)SnSC1YMA-5OyLrPT>osyX0Hm`EO28+(Prh z++**x8`r00|M^wv86LIz#N^j^m_Q}SW#~+w$)60eS4{kSYqv1_qx5aM?!IT2_I#7P zY`aJe#<2+*9L|6Ed>%J-1(?ppd8U36Z(oaTz>FUv3fcrx! zdNrf*CFPW5ZhLdeF9wnfUFX^g4z$(9#+@GBJ)SEG zIJh8I7b}2He;3=mVB?nF+C%I16?BeSb9U_EvYr_)t(YrouHU(BnrQ2V<3avRkF|i_ z#09h7ob~JAqOO^#rimSEZneJx$`{7be@C%_P)FmI&9}hDC5H9!-d#Bt3OmoJC$}au zIwBYy4GigM2KmnX(M+CV_ePizB$J3o>WB@Wjw3!nLit<2I=N+kj%@F$_d6Q?aTR{H zfPZD`8#h0sTa^2Dr`+CqqhRU>y{`)Xc(|lvd8l^f$>l!@9cb))`>!TYbLf+ebL5q8 zb?<+7)6~s7Z?0UKdGlOb{>nQqE zYrW$cvpVriFt(>Gyv@`-TXgTO+OFdpHe|l*f37b(G41}#m-K7G18a#ZAuGMc^}h6t z=RPTd5*#HXvW3h)e&Bm5Z5%pLN55ROd%)!3my0wWls+7!a=^6VAT1fnV2(vGkO2jN zWF?TS4irBcQC?PIEE{`s+8g4_vU`um+xQD{be*aZ+gpwq%Ruc(5m8F b8(RNXcJEm4@?+zVTqBG6Hv8%Y{^S1zJ!C?= literal 0 HcmV?d00001 diff --git a/interfaces/kits/napi/file_access_module/BUILD.gn b/interfaces/kits/napi/file_access_module/BUILD.gn new file mode 100644 index 00000000..cb6a0605 --- /dev/null +++ b/interfaces/kits/napi/file_access_module/BUILD.gn @@ -0,0 +1,48 @@ +# 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("//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 00000000..163e6caf --- /dev/null +++ b/interfaces/kits/napi/file_access_module/file_access_common.h @@ -0,0 +1,112 @@ +/* + * 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; +}; +} +} +#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 00000000..3b7f7826 --- /dev/null +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.cpp @@ -0,0 +1,1503 @@ +/* + * 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); +} +/* +bool NapiValueToArrayStringUtf8(napi_env env, napi_value param, std::vector &result) +{ + return UnwrapArrayStringFromJS(env, param, 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), + }; + 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,DataShareHelper 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, openFileCB == 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,uri=%{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,mode=%{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_create_int32(env, CreateFileCB->result, &result[PARAM1]); + 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_create_int32(env, CreateFileCB->result, &result); + 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,uri=%{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,mode=%{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 uri 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,uri=%{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) { + HILOG_INFO("tag dsa DeleteWrap_DeleteAsync start"); + ret = DeleteAsync(env, args, ARGS_ONE, deleteCB); + HILOG_INFO("tag dsa DeleteWrap_DeleteAsync ,end"); + } else { + HILOG_INFO("tag dsa DeleteWrap_DeletePromise start"); + ret = DeletePromise(env, deleteCB); + HILOG_INFO("tag dsa DeleteWrap_DeletePromise,end"); + } + 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 uri 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,uri=%{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,mode=%{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 uri 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,uri=%{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,mode=%{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 uri 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 uri is empty"); + } + } 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."); +} + +} // 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 00000000..404808ff --- /dev/null +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.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 FILE_ACCESS_NAPI_H +#define FILE_ACCESS_NAPI_H + +//#include "n_exporter.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); +} +} +#endif \ No newline at end of file diff --git a/interfaces/kits/napi/file_access_module/native_fileaccess_module.cpp b/interfaces/kits/napi/file_access_module/native_fileaccess_module.cpp new file mode 100644 index 00000000..22d41c96 --- /dev/null +++ b/interfaces/kits/napi/file_access_module/native_fileaccess_module.cpp @@ -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. + */ + +#include +#include + +#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 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 + +/* + * 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/interfaces/kits/napi/file_ext_ability/BUILD.gn b/interfaces/kits/napi/file_ext_ability/BUILD.gn new file mode 100644 index 00000000..b0e794e8 --- /dev/null +++ b/interfaces/kits/napi/file_ext_ability/BUILD.gn @@ -0,0 +1,50 @@ +# 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("//ark/ts2abc/ts2panda/ts2abc_config.gni") +import("//build/ohos.gni") + +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 00000000..7ecdc1bc --- /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 00000000..6dca96b5 --- /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/utils/hilog_wrapper.h b/utils/hilog_wrapper.h new file mode 100644 index 00000000..a070b12e --- /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 -- Gitee From f18b5b65df4c4eb855298be6a0f3b673f609c769 Mon Sep 17 00:00:00 2001 From: linjun9528 Date: Tue, 17 May 2022 10:37:00 +0800 Subject: [PATCH 2/2] add napi release code & clear useless code of hap Signed-off-by: linjun9528 --- .../include/file_access_helper.h | 2 - .../include/file_ext_stub_impl.h | 8 +- .../file_extension/src/file_access_helper.cpp | 13 +- .../file_extension/src/file_ext_ability.cpp | 1 - .../file_extension/src/file_ext_proxy.cpp | 5 +- .../file_extension/src/file_ext_stub.cpp | 4 +- .../src/js_file_ext_ability.cpp | 41 +--- .../innerkits/file_extension_hap/.gitignore | 4 - .../file_extension_hap/entry/.gitignore | 3 - .../FileExtensionAbility.ts | 4 +- .../ohosTest/ets/TestAbility/TestAbility.ts | 39 ---- .../ohosTest/ets/TestAbility/pages/index.ets | 34 --- .../ets/TestRunner/OpenHarmonyTestRunner.ts | 58 ----- .../src/ohosTest/ets/test/Ability.test.ets | 13 -- .../entry/src/ohosTest/ets/test/List.test.ets | 5 - .../entry/src/ohosTest/module.json5 | 37 ---- .../resources/base/element/string.json | 16 -- .../ohosTest/resources/base/media/icon.png | Bin 6790 -> 0 bytes .../resources/base/profile/test_pages.json | 5 - .../file_access_module/file_access_common.h | 6 + .../napi_fileaccess_helper.cpp | 204 +++++++++++++++--- .../napi_fileaccess_helper.h | 9 +- 22 files changed, 209 insertions(+), 302 deletions(-) delete mode 100644 frameworks/innerkits/file_extension_hap/.gitignore delete mode 100644 frameworks/innerkits/file_extension_hap/entry/.gitignore delete mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestAbility/TestAbility.ts delete mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestAbility/pages/index.ets delete mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts delete mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/Ability.test.ets delete mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/List.test.ets delete mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/module.json5 delete mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/element/string.json delete mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/media/icon.png delete mode 100644 frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/profile/test_pages.json diff --git a/frameworks/innerkits/file_extension/include/file_access_helper.h b/frameworks/innerkits/file_extension/include/file_access_helper.h index 9cdfc593..a3f7e3ca 100644 --- a/frameworks/innerkits/file_extension/include/file_access_helper.h +++ b/frameworks/innerkits/file_extension/include/file_access_helper.h @@ -20,7 +20,6 @@ #include #include -#include "context.h" #include "file_ext_connection.h" #include "foundation/aafwk/standard/frameworks/kits/appkit/native/ability_runtime/context/context.h" #include "ifile_ext_base.h" @@ -57,7 +56,6 @@ private: sptr token_ = {}; AAFwk::Want want_ = {}; sptr fileExtProxy_ = nullptr; - static std::mutex oplock_; bool isSystemCaller_ = false; sptr callerDeathRecipient_ = nullptr; sptr fileExtConnection_ = nullptr; diff --git a/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h b/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h index 3caf1ca0..9f964953 100644 --- a/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h +++ b/frameworks/innerkits/file_extension/include/file_ext_stub_impl.h @@ -27,10 +27,7 @@ using AbilityRuntime::JsFileExtAbility; class FileExtStubImpl : public FileExtStub { public: explicit FileExtStubImpl(const std::shared_ptr& extension, napi_env env) - : extension_(extension) - { - //uvQueue_ = std::make_shared(env); - } + : extension_(extension) {} virtual ~FileExtStubImpl() {} @@ -46,9 +43,8 @@ private: private: std::shared_ptr extension_; - //std::shared_ptr uvQueue_; }; } // namespace AppExecFwk } // namespace OHOS -#endif // OHOS_APPEXECFWK_DATASHARE_STUB_IMPL_H +#endif // OHOS_APPEXECFWK_FILEEXT_STUB_IMPL_H diff --git a/frameworks/innerkits/file_extension/src/file_access_helper.cpp b/frameworks/innerkits/file_extension/src/file_access_helper.cpp index eababd69..6a62e048 100644 --- a/frameworks/innerkits/file_extension/src/file_access_helper.cpp +++ b/frameworks/innerkits/file_extension/src/file_access_helper.cpp @@ -24,7 +24,6 @@ namespace { constexpr int INVALID_VALUE = -1; } // namespace -std::mutex FileAccessHelper::oplock_; FileAccessHelper::FileAccessHelper(const std::shared_ptr &context, const AAFwk::Want &want, const sptr &fileExtProxy) @@ -156,10 +155,10 @@ int FileAccessHelper::CreateFile(Uri &parentUri, const std::string &displayName, return index; } - HILOG_INFO("tag dsa FileAccessHelper::CreateFile before fileExtProxy_->Mkdir."); + 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::Mkdir end. newDirUri = %{public}s", newFileUri.ToString().c_str()); + HILOG_INFO("tag dsa FileAccessHelper::CreateFile end. newDirUri = %{public}s", newFileUri.ToString().c_str()); return index; } @@ -210,7 +209,7 @@ int FileAccessHelper::Delete(Uri &selectFileUri) return index; } - HILOG_INFO("tag dsa FileAccessHelper::OpenFile before fileExtProxy_->OpenFile."); + HILOG_INFO("tag dsa FileAccessHelper::Delete before fileExtProxy_->Delete."); index = fileExtProxy_->Delete(selectFileUri); HILOG_INFO("tag dsa %{public}s begin.", __func__); return index; @@ -275,12 +274,12 @@ 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::Delete before ConnectFileExtAbility."); + HILOG_INFO("tag dsa FileAccessHelper::CloseFile before ConnectFileExtAbility."); if (!fileExtConnection_->IsExtAbilityConnected()) { fileExtConnection_->ConnectFileExtAbility(want_, token_); } fileExtProxy_ = fileExtConnection_->GetFileExtProxy(); - HILOG_INFO("tag dsa FileAccessHelper::Delete after ConnectFileExtAbility."); + HILOG_INFO("tag dsa FileAccessHelper::CloseFile after ConnectFileExtAbility."); if (isSystemCaller_ && fileExtProxy_) { AddFileAccessDeathRecipient(fileExtProxy_->AsObject()); } @@ -290,7 +289,7 @@ int FileAccessHelper::CloseFile(int fd, const std::string &uri) return index; } - HILOG_INFO("tag dsa FileAccessHelper::OpenFile before fileExtProxy_->OpenFile."); + HILOG_INFO("tag dsa FileAccessHelper::CloseFile before fileExtProxy_->CloseFile."); index = fileExtProxy_->CloseFile(fd, uri); HILOG_INFO("tag dsa %{public}s begin.", __func__); return index; diff --git a/frameworks/innerkits/file_extension/src/file_ext_ability.cpp b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp index f5fcdb9a..e137a15f 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_ability.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_ability.cpp @@ -50,7 +50,6 @@ void FileExtAbility::Init(const std::shared_ptr &record, const sptr &token) { HILOG_INFO("tag dsa %{public}s begin.", __func__); - //ExtensionBase::Init(record, application, handler, token); ExtensionBase<>::Init(record, application, handler, token); HILOG_INFO("tag dsa %{public}s end.", __func__); } diff --git a/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp b/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp index 3224b86f..085c7b41 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_proxy.cpp @@ -67,8 +67,8 @@ int FileExtProxy::CloseFile(int fd, const std::string &uri) return ret; } - if (!data.WriteInt32(fd)) { - HILOG_ERROR("tag dsa fail to WriteParcelable sourceFileUri"); + if (!data.WriteFileDescriptor(fd)) { + HILOG_ERROR("tag dsa fail to WriteFileDescriptor fd"); return ret; } @@ -329,6 +329,7 @@ int FileExtProxy::Rename(const Uri &sourceFileUri, const std::string &displayNam std::unique_ptr tempUri(reply.ReadParcelable()); if (!tempUri) { HILOG_ERROR("ReadParcelable value is nullptr."); + ret = -1; return ret; } diff --git a/frameworks/innerkits/file_extension/src/file_ext_stub.cpp b/frameworks/innerkits/file_extension/src/file_ext_stub.cpp index 336cbad5..e81ddb29 100644 --- a/frameworks/innerkits/file_extension/src/file_ext_stub.cpp +++ b/frameworks/innerkits/file_extension/src/file_ext_stub.cpp @@ -88,7 +88,7 @@ ErrCode FileExtStub::CmdOpenFile(MessageParcel &data, MessageParcel &reply) ErrCode FileExtStub::CmdCloseFile(MessageParcel &data, MessageParcel &reply) { HILOG_INFO("tag dsa %{public}s begin.", __func__); - int fd = data.ReadInt32(); + int fd = data.ReadFileDescriptor(); if (fd < 0) { HILOG_ERROR("tag dsa FileExtStub fd is invalid"); return ERR_INVALID_VALUE; @@ -106,7 +106,7 @@ ErrCode FileExtStub::CmdCloseFile(MessageParcel &data, MessageParcel &reply) } if (!reply.WriteInt32(ret)) { - HILOG_ERROR("tag dsa fail to WriteFileDescriptor ret"); + HILOG_ERROR("tag dsa fail to WriteInt32 ret"); return ERR_INVALID_VALUE; } HILOG_INFO("tag dsa %{public}s end.", __func__); diff --git a/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp b/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp index 6c7942c7..cc650974 100644 --- a/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp +++ b/frameworks/innerkits/file_extension/src/js_file_ext_ability.cpp @@ -66,7 +66,6 @@ void JsFileExtAbility::Init(const std::shared_ptr &record, 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_); - //auto& engine = jsRuntime_.GetNativeEngine(); jsObj_ = jsRuntime_.LoadModule(moduleName, srcPath); if (jsObj_ == nullptr) { @@ -79,38 +78,6 @@ void JsFileExtAbility::Init(const std::shared_ptr &record, HILOG_ERROR("tag dsa Failed to get JsFileExtAbility object"); return; } - - /* - auto context = GetContext(); - if (context == nullptr) { - HILOG_ERROR("tag dsa Failed to get context"); - return; - } - - HILOG_INFO("tag dsa JsFileExtAbility::Init CreateJsDataShareExtAbilityContext."); - NativeValue* contextObj = CreateJsDataShareExtAbilityContext(engine, context); - auto contextRef = jsRuntime_.LoadSystemModule("application.DataShareExtensionAbilityContext", - &contextObj, ARGC_ONE); - contextObj = contextRef->Get(); - HILOG_INFO("tag dsa JsFileExtAbility::Init Bind."); - context->Bind(jsRuntime_, contextRef.release()); - HILOG_INFO("tag dsa JsFileExtAbility::SetProperty."); - obj->SetProperty("context", contextObj); - - auto nativeObj = ConvertNativeValueTo(contextObj); - if (nativeObj == nullptr) { - HILOG_ERROR("tag dsa Failed to get datashare extension ability native object"); - return; - } - - HILOG_INFO("tag dsa Set datashare extension ability context"); - - nativeObj->SetNativePointer(new std::weak_ptr(context), - [](NativeEngine*, void* data, void*) { - HILOG_INFO("tag dsa Finalizer for weak_ptr datashare extension ability context is called"); - delete static_cast*>(data); - }, nullptr); - */ HILOG_INFO("tag dsa JsFileExtAbility::Init end."); } @@ -270,7 +237,7 @@ int JsFileExtAbility::CreateFile(const Uri &parentUri, const std::string &displa HILOG_ERROR("tag dsa %{public}s call Mkdir with return empty.", __func__); return ret; } else { - ret = 0; + 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()); @@ -302,7 +269,7 @@ int JsFileExtAbility::Mkdir(const Uri &parentUri, const std::string &displayName HILOG_ERROR("tag dsa %{public}s call Mkdir with return empty.", __func__); return ret; } else { - ret = 0; + 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()); @@ -356,7 +323,7 @@ int JsFileExtAbility::Move(const Uri &sourceFileUri, const Uri &targetParentUri, HILOG_ERROR("tag dsa %{public}s call move with return empty.", __func__); return ret; } else { - ret = 0; + 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()); @@ -388,7 +355,7 @@ int JsFileExtAbility::Rename(const Uri &sourceFileUri, const std::string &displa HILOG_ERROR("tag dsa %{public}s call rename with return empty.", __func__); return ret; } else { - ret = 0; + 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()); diff --git a/frameworks/innerkits/file_extension_hap/.gitignore b/frameworks/innerkits/file_extension_hap/.gitignore deleted file mode 100644 index 39187ebe..00000000 --- a/frameworks/innerkits/file_extension_hap/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/node_modules -/local.properties -/.idea -**/build \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/.gitignore b/frameworks/innerkits/file_extension_hap/entry/.gitignore deleted file mode 100644 index 4f9a9738..00000000 --- a/frameworks/innerkits/file_extension_hap/entry/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/node_modules -/.preview -/build \ 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 index 486f83fb..ef8d617a 100644 --- 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 @@ -27,7 +27,7 @@ export default class FileExtAbility extends Extension { closeFile(fd, uri) { console.log('js server tag dsa delete, fd:' + fd + ",uri: " + uri); - return 268; + return 0; } createFile(parentUri, displayName) { @@ -42,7 +42,7 @@ export default class FileExtAbility extends Extension { delete(sourceFileUri) { console.log('js server tag dsa delete, sourceFileUri:' + sourceFileUri); - return 132; + return 0; } move(sourceFileUri, targetParentUri) { diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestAbility/TestAbility.ts b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestAbility/TestAbility.ts deleted file mode 100644 index d5e778f1..00000000 --- a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestAbility/TestAbility.ts +++ /dev/null @@ -1,39 +0,0 @@ -import Ability from '@ohos.application.Ability' -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' -import { Hypium } from 'hypium/index' -import testsuite from '../test/List.test' - -export default class TestAbility extends Ability { - onCreate(want, launchParam) { - console.log('TestAbility onCreate') - var abilityDelegator: any - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - var abilityDelegatorArguments: any - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - console.info('start run testcase!!!') - Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) - } - - onDestroy() { - console.log('TestAbility onDestroy') - } - - onWindowStageCreate(windowStage) { - console.log('TestAbility onWindowStageCreate') - windowStage.setUIContent(this.context, 'TestAbility/pages/index', null) - - globalThis.abilityContext = this.context; - } - - onWindowStageDestroy() { - console.log('TestAbility onWindowStageDestroy') - } - - onForeground() { - console.log('TestAbility onForeground') - } - - onBackground() { - console.log('TestAbility onBackground') - } -}; \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestAbility/pages/index.ets b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestAbility/pages/index.ets deleted file mode 100644 index 733600ab..00000000 --- a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestAbility/pages/index.ets +++ /dev/null @@ -1,34 +0,0 @@ -import router from '@ohos.router'; - -@Entry -@Component -struct Index { - aboutToAppear() { - console.info('TestAbility index aboutToAppear') - } - @State message: string = 'Hello World' - build() { - Row() { - Column() { - Text(this.message) - .fontSize(50) - .fontWeight(FontWeight.Bold) - Button() { - Text('next page') - .fontSize(20) - .fontWeight(FontWeight.Bold) - }.type(ButtonType.Capsule) - .margin({ - top: 20 - }) - .backgroundColor('#0D9FFB') - .width('35%') - .height('5%') - .onClick(()=>{ - }) - } - .width('100%') - } - .height('100%') - } - } \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts deleted file mode 100644 index 7a0024d4..00000000 --- a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts +++ /dev/null @@ -1,58 +0,0 @@ -import TestRunner from '@ohos.application.testRunner' -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' - -var abilityDelegator = undefined -var abilityDelegatorArguments = undefined - -function translateParamsToString(parameters) { - const keySet = new Set([ - '-s class', '-s notClass', '-s suite', '-s it', - '-s level', '-s testType', '-s size', '-s timeout' - ]) - let targetParams = ''; - for (const key in parameters) { - if (keySet.has(key)) { - targetParams = `${targetParams} ${key} ${parameters[key]}` - } - } - return targetParams.trim() -} - -async function onAbilityCreateCallback() { - console.log("onAbilityCreateCallback"); -} - -async function addAbilityMonitorCallback(err: any) { - console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) -} - -export default class OpenHarmonyTestRunner implements TestRunner { - constructor() { - } - - onPrepare() { - console.info("OpenHarmonyTestRunner OnPrepare ") - } - - async onRun() { - console.log('OpenHarmonyTestRunner onRun run') - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' - let lMonitor = { - abilityName: testAbilityName, - onAbilityCreate: onAbilityCreateCallback, - }; - abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) - var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName - cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) - console.info('cmd : '+cmd) - abilityDelegator.executeShellCommand(cmd, - (err: any, d: any) => { - console.info('executeShellCommand : err : ' + JSON.stringify(err)); - console.info('executeShellCommand : data : ' + d.stdResult); - console.info('executeShellCommand : data : ' + d.exitCode); - }) - console.info('OpenHarmonyTestRunner onRun end') - } -}; \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/Ability.test.ets b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/Ability.test.ets deleted file mode 100644 index 1236e0ce..00000000 --- a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/Ability.test.ets +++ /dev/null @@ -1,13 +0,0 @@ -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'hypium/index' - -export default function abilityTest() { - describe('ActsAbilityTest', function () { - it('assertContain',0, function () { - console.info("it begin") - let a = 'abc' - let b = 'b' - expect(a).assertContain(b) - expect(a).assertEqual(a) - }) - }) -} \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/List.test.ets b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/List.test.ets deleted file mode 100644 index d766fe24..00000000 --- a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,5 +0,0 @@ -import abilityTest from './Ability.test' - -export default function testsuite() { - abilityTest() -} \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/module.json5 b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/module.json5 deleted file mode 100644 index 5d696c10..00000000 --- a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/module.json5 +++ /dev/null @@ -1,37 +0,0 @@ -{ - "module": { - "name": "entry_test", - "type": "feature", - "srcEntrance": "./ets/TestAbility/TestAbility.ts", - "description": "$string:entry_test_desc", - "mainElement": "TestAbility", - "deviceTypes": [ - "phone", - "tablet" - ], - "deliveryWithInstall": true, - "installationFree": false, - "pages": "$profile:test_pages", - "uiSyntax": "ets", - "abilities": [ - { - "name": "TestAbility", - "srcEntrance": "./ets/TestAbility/TestAbility.ts", - "description": "$string:TestAbility_desc", - "icon": "$media:icon", - "label": "$string:TestAbility_label", - "visible": true, - "skills": [ - { - "actions": [ - "action.system.home" - ], - "entities": [ - "entity.system.home" - ] - } - ] - } - ] - } -} diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/element/string.json b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/element/string.json deleted file mode 100644 index 84078007..00000000 --- a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/element/string.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "string": [ - { - "name": "entry_test_desc", - "value": "i am an entry for tv" - }, - { - "name": "TestAbility_desc", - "value": "the tv entry test ability" - }, - { - "name": "TestAbility_label", - "value": "tvBase" - } - ] -} \ No newline at end of file diff --git a/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/media/icon.png b/frameworks/innerkits/file_extension_hap/entry/src/ohosTest/resources/base/media/icon.png deleted file mode 100644 index ce307a8827bd75456441ceb57d530e4c8d45d36c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6790 zcmX|G1ymHk)?T_}Vd;>R?p|tHQo6fg38|$UVM!6BLrPFWk?s;$LOP{GmJpBl$qoSA!PUg~PA65-S00{{S`XKG6NkG0RgjEntPrmV+?0|00mu7;+5 zrdpa{2QLqPJ4Y{j7=Mrl{BaxrkdY69+c~(w{Fv-v&aR%aEI&JYSeRTLWm!zbv;?)_ ziZB;fwGbbeL5Q}YLx`J$lp~A09KK8t_z}PZ=4ZzgdeKtgoc+o5EvN9A1K1_<>M?MBqb#!ASf&# zEX?<)!RH(7>1P+j=jqG(58}TVN-$psA6K}atCuI!KTJD&FMmH-78ZejBm)0qc{ESp z|LuG1{QnBUJRg_E=h1#XMWt2%fcoN@l7eAS!Es?Q+;XsRNPhiiE=@AqlLkJzF`O18 zbsbSmKN=aaq8k3NFYZfDWpKmM!coBU0(XnL8R{4=i|wi{!uWYM2je{U{B*K2PVdu&=E zTq*-XsEsJ$u5H4g6DIm2Y!DN`>^v|AqlwuCD;w45K0@eqauiqWf7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;tf5;_Uxg?jZ8m-m0}&6+DA!qam(p$mN5R})yA_7m$q@| zFEd|dpS595rxQr-n#GjI5i-AhnUE>Cr;jpCqSrD~EwK_DqI^7%3#p5)%T_od!t3SOmH9MyXeeGO2(UQL;ax|x?Ncixmeo1=$ z{-);Au{*tfzOG?KQ~K|ak8-HQ?`Pekhe2WM(8s{xv-p>Zmu_6{G!-oE$7$mY`MOJorI=+mMx?H;`pr!;fVYz?5~yXBACruWB`Ph zZM}90_<^OBxIhyZ9BW$`>6JvO;%VFpqVr8|7t3~AmxYak6?`Pp#c;**_SYmi`&z23 z`p6_~ePvH)C6x-G9$hgL=eVALq`-AiamN>!3~Lxw&{H(b{B(7xSRm6<3<{%{yXiH# zos5Rv1L+8fUKJLo%P>4I&$}y &result) -{ - return UnwrapArrayStringFromJS(env, param, result); -} -*/ } std::list> g_fileAccessHelperList; @@ -145,6 +139,7 @@ napi_value FileAccessHelperInit(napi_env env, napi_value exports) 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, @@ -259,7 +254,7 @@ napi_value OpenFileWrap(napi_env env, napi_callback_info info, FileAccessHelperO FileAccessHelper *objectInfo = nullptr; napi_unwrap(env, thisVar, (void **)&objectInfo); - HILOG_INFO("tag dsa %{public}s,DataShareHelper objectInfo", __func__); + HILOG_INFO("tag dsa %{public}s,FileAccessHelper objectInfo", __func__); openFileCB->fileAccessHelper = objectInfo; if (argcAsync > argcPromise) { @@ -390,7 +385,7 @@ 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, openFileCB == nullptr.", __func__); + HILOG_ERROR("tag dsa %{public}s, createFileCB == nullptr.", __func__); return WrapVoidToJS(env); } createFileCB->cbBase.cbInfo.env = env; @@ -431,13 +426,13 @@ napi_value CreateFileWrap(napi_env env, napi_callback_info info, FileAccessHelpe 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,uri=%{public}s", __func__, createFileCB->parentUri.c_str()); + 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,mode=%{public}s", __func__, createFileCB->name.c_str()); + HILOG_INFO("tag dsa %{public}s,name=%{public}s", __func__, createFileCB->name.c_str()); } FileAccessHelper *objectInfo = nullptr; @@ -546,7 +541,6 @@ void CreateFileAsyncCompleteCB(napi_env env, napi_status status, void *data) NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, CreateFileCB->cbBase.cbInfo.callback, &callback)); result[PARAM0] = GetCallbackErrorValue(env, CreateFileCB->execResult); - // napi_create_int32(env, CreateFileCB->result, &result[PARAM1]); 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)); @@ -565,7 +559,6 @@ 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_create_int32(env, CreateFileCB->result, &result); 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)); @@ -620,13 +613,13 @@ napi_value MkdirWrap(napi_env env, napi_callback_info info, FileAccessHelperMkdi 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,uri=%{public}s", __func__, mkdirCB->parentUri.c_str()); + 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,mode=%{public}s", __func__, mkdirCB->name.c_str()); + HILOG_INFO("tag dsa%{public}s,name=%{public}s", __func__, mkdirCB->name.c_str()); } FileAccessHelper *objectInfo = nullptr; @@ -715,7 +708,7 @@ void MkdirExecuteCB(napi_env env, void *data) MkdirCB->result = newDirUri.ToString(); MkdirCB->execResult = err; } else { - HILOG_ERROR("tag dsaNAPI_Mkdir, fileAccessHelper uri is empty"); + HILOG_ERROR("tag dsaNAPI_Mkdir, fileAccessHelper parentUri is empty"); } } else { HILOG_ERROR("tag dsaNAPI_Mkdir, fileAccessHelper == nullptr"); @@ -807,7 +800,7 @@ napi_value DeleteWrap(napi_env env, napi_callback_info info, FileAccessHelperDel 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,uri=%{public}s", __func__, deleteCB->selectFileUri.c_str()); + HILOG_INFO("tag dsa %{public}s,selectFileUri=%{public}s", __func__, deleteCB->selectFileUri.c_str()); } FileAccessHelper *objectInfo = nullptr; @@ -816,13 +809,9 @@ napi_value DeleteWrap(napi_env env, napi_callback_info info, FileAccessHelperDel deleteCB->fileAccessHelper = objectInfo; if (argcAsync > argcPromise) { - HILOG_INFO("tag dsa DeleteWrap_DeleteAsync start"); ret = DeleteAsync(env, args, ARGS_ONE, deleteCB); - HILOG_INFO("tag dsa DeleteWrap_DeleteAsync ,end"); } else { - HILOG_INFO("tag dsa DeleteWrap_DeletePromise start"); ret = DeletePromise(env, deleteCB); - HILOG_INFO("tag dsa DeleteWrap_DeletePromise,end"); } HILOG_INFO("tag dsa %{public}s,end", __func__); return ret; @@ -897,7 +886,7 @@ void DeleteExecuteCB(napi_env env, void *data) DeleteCB->result = DeleteCB->fileAccessHelper->Delete(selectFileUri); DeleteCB->execResult = NO_ERROR; } else { - HILOG_ERROR("tag dsa NAPI_Delete, fileAccessHelper uri is empty"); + HILOG_ERROR("tag dsa NAPI_Delete, fileAccessHelper selectFileUri is empty"); } } else { HILOG_ERROR("tag dsa NAPI_Delete, fileAccessHelper == nullptr"); @@ -988,13 +977,13 @@ napi_value MoveWrap(napi_env env, napi_callback_info info, FileAccessHelperMoveC 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,uri=%{public}s", __func__, moveCB->sourceFileUri.c_str()); + 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,mode=%{public}s", __func__, moveCB->targetParentUri.c_str()); + HILOG_INFO("tag dsa %{public}s,targetParentUri=%{public}s", __func__, moveCB->targetParentUri.c_str()); } FileAccessHelper *objectInfo = nullptr; @@ -1084,7 +1073,7 @@ void MoveExecuteCB(napi_env env, void *data) MoveCB->result = newFileUri.ToString(); MoveCB->execResult = err; } else { - HILOG_ERROR("tag dsa NAPI_Move, fileAccessHelper uri is empty"); + HILOG_ERROR("tag dsa NAPI_Move, fileAccessHelper sourceFileUri is empty"); } } else { HILOG_ERROR("tag dsa NAPI_Move, fileAccessHelper == nullptr"); @@ -1176,13 +1165,13 @@ napi_value RenameWrap(napi_env env, napi_callback_info info, FileAccessHelperRen 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,uri=%{public}s", __func__, renameCB->sourceFileUri.c_str()); + 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,mode=%{public}s", __func__, renameCB->displayName.c_str()); + HILOG_INFO("tag dsa %{public}s,displayName=%{public}s", __func__, renameCB->displayName.c_str()); } FileAccessHelper *objectInfo = nullptr; @@ -1271,7 +1260,7 @@ void RenameExecuteCB(napi_env env, void *data) renameCB->result = newFileUri.ToString(); renameCB->execResult = err; } else { - HILOG_ERROR("tag dsa NAPI_Rename, fileAccessHelper uri is empty"); + HILOG_ERROR("tag dsa NAPI_Rename, fileAccessHelper sourceFileUri is empty"); } } else { HILOG_ERROR("tag dsa NAPI_Rename, fileAccessHelper == nullptr"); @@ -1454,7 +1443,7 @@ void CloseFileExecuteCB(napi_env env, void *data) CloseFileCB->result = CloseFileCB->fileAccessHelper->CloseFile(CloseFileCB->fd, CloseFileCB->uri); CloseFileCB->execResult = NO_ERROR; } else { - HILOG_ERROR("tag dsa NAPI_CloseFile, fileAccessHelper uri is empty"); + HILOG_ERROR("tag dsa NAPI_CloseFile, fileAccessHelper fd != NO_ERROR"); } } else { HILOG_ERROR("tag dsa NAPI_CloseFile, fileAccessHelper == nullptr"); @@ -1499,5 +1488,164 @@ void CloseFilePromiseCompleteCB(napi_env env, napi_status status, void *data) 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 index 404808ff..aa9348d7 100644 --- a/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h +++ b/interfaces/kits/napi/file_access_module/napi_fileaccess_helper.h @@ -16,7 +16,6 @@ #ifndef FILE_ACCESS_NAPI_H #define FILE_ACCESS_NAPI_H -//#include "n_exporter.h" #include "file_access_common.h" namespace OHOS { @@ -78,6 +77,14 @@ namespace AppExecFwk { 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 -- Gitee