From 1db40f7eb00aa7d444ca648fc80076afc57f603f Mon Sep 17 00:00:00 2001 From: wangpggg Date: Mon, 3 Apr 2023 12:45:27 +0800 Subject: [PATCH] add backup Js api interface and make it available Signed-off-by: wangpeng --- backup.gni | 3 + bundle.json | 3 +- interfaces/kits/js/BUILD.gn | 26 ++++++++ .../kits/js/backup/local_capabilities.cpp | 65 +++++++++++++++++++ .../kits/js/backup/local_capabilities.h | 29 +++++++++ 5 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 interfaces/kits/js/backup/local_capabilities.cpp create mode 100644 interfaces/kits/js/backup/local_capabilities.h diff --git a/backup.gni b/backup.gni index 7dc5c0e87..b907a5cd4 100644 --- a/backup.gni +++ b/backup.gni @@ -16,9 +16,12 @@ path_module_out_tests = "filemanagement/app_file_service/backup" path_ability_runtime = "//foundation/ability/ability_runtime" path_access_token = "//base/security/access_token" +path_backup_js = + "//foundation/filemanagement/app_file_service/interfaces/kits/js" path_base = "//commonlibrary/c_utils/base" path_distributedfile = "//foundation/distributeddatamgr/distributedfile" path_faultloggerd = "//base/hiviewdfx/faultloggerd" +path_file_api = "//foundation/filemanagement/file_api" path_googletest = "//third_party/googletest" path_ipc = "//foundation/communication/ipc" path_jsoncpp = "//third_party/jsoncpp" diff --git a/bundle.json b/bundle.json index fc02fdb76..4f1a1d4c8 100644 --- a/bundle.json +++ b/bundle.json @@ -28,7 +28,8 @@ "fwk_group": [ "//foundation/filemanagement/app_file_service:libremotefileshare", "//foundation/filemanagement/app_file_service/interfaces/kits/js:fileshare", - "//foundation/filemanagement/app_file_service/interfaces/kits/js:fileuri" + "//foundation/filemanagement/app_file_service/interfaces/kits/js:fileuri", + "//foundation/filemanagement/app_file_service/interfaces/kits/js:backup" ], "service_group": [ "//foundation/filemanagement/app_file_service:tgt_backup_extension", diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index fbdd483cf..b39590199 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -13,6 +13,7 @@ import("//build/ohos.gni") import("//foundation/filemanagement/app_file_service/app_file_service.gni") +import("//foundation/filemanagement/app_file_service/backup.gni") ohos_shared_library("remotefileshare") { include_dirs = [ @@ -93,3 +94,28 @@ ohos_shared_library("fileuri") { part_name = "app_file_service" subsystem_name = "filemanagement" } + +ohos_shared_library("backup") { + relative_install_dir = "module" + subsystem_name = "filemanagement" + part_name = "app_file_service" + + include_dirs = [ "${path_napi}/interfaces/kits" ] + + sources = [ + "${path_backup_js}/backup/local_capabilities.cpp", + "${path_backup_js}/backup/module.cpp", + "${path_backup_js}/backup/prop_n_exporter.cpp", + "${path_backup_js}/backup/session_backup_n_exporter.cpp", + "${path_backup_js}/backup/session_restore_n_exporter.cpp", + ] + + deps = [ + "${path_file_api}/utils/filemgmt_libn:filemgmt_libn", + "${path_napi}:ace_napi", + ] + + external_deps = [ "app_file_service:backup_kit_inner" ] + + public_deps = [ "${path_file_api}/utils/filemgmt_libhilog:filemgmt_libhilog" ] +} diff --git a/interfaces/kits/js/backup/local_capabilities.cpp b/interfaces/kits/js/backup/local_capabilities.cpp new file mode 100644 index 000000000..9c8ea23e6 --- /dev/null +++ b/interfaces/kits/js/backup/local_capabilities.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023 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 "local_capabilities.h" + +#include "filemgmt_libhilog.h" +#include "filemgmt_libn.h" +#include "service_proxy.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; +using namespace LibN; + +napi_value LocalCapabilities::Async(napi_env env, napi_callback_info info) +{ + HILOGI("called LocalCapabilities::Async begin"); + NFuncArg funcArg(env, info); + if (!funcArg.InitArgs(NARG_CNT::ZERO, NARG_CNT::ONE)) { + HILOGE("Number of arguments unmatched"); + NError(EINVAL).ThrowErr(env); + return nullptr; + } + + auto fd = make_shared(); + auto cbExec = [fd]() -> NError { + HILOGI("called LocalCapabilities::Async cbExec"); + auto proxy = ServiceProxy::GetInstance(); + if (!proxy) { + HILOGI("called LocalCapabilities::Async cbExec, failed to get proxy"); + return NError(errno); + } + *fd = proxy->GetLocalCapabilities(); + return NError(ERRNO_NOERR); + }; + auto cbCompl = [fd](napi_env env, NError err) -> NVal { + if (err) { + return {env, err.GetNapiErr(env)}; + } + NVal obj = NVal::CreateObject(env); + obj.AddProp({NVal::DeclareNapiProperty("fd", NVal::CreateInt32(env, fd->Release()).val_)}); + return {obj}; + }; + + NVal thisVar(env, funcArg.GetThisVar()); + if (funcArg.GetArgc() == NARG_CNT::ZERO) { + HILOGI("called LocalCapabilities::Async::promise"); + return NAsyncWorkPromise(env, thisVar).Schedule(PROCEDURE_LOCALCAPABILITIES_NAME, cbExec, cbCompl).val_; + } else { + HILOGI("called LocalCapabilities::Async::callback"); + NVal cb(env, funcArg[NARG_POS::FIRST]); + return NAsyncWorkCallback(env, thisVar, cb).Schedule(PROCEDURE_LOCALCAPABILITIES_NAME, cbExec, cbCompl).val_; + } +} +} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/interfaces/kits/js/backup/local_capabilities.h b/interfaces/kits/js/backup/local_capabilities.h new file mode 100644 index 000000000..716b5d3df --- /dev/null +++ b/interfaces/kits/js/backup/local_capabilities.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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 INTERFACES_KITS_JS_SRC_MOD_BACKUP_PROPERTIES_LOCAL_CAPABILITIES_H +#define INTERFACES_KITS_JS_SRC_MOD_BACKUP_PROPERTIES_LOCAL_CAPABILITIES_H + +#include +#include + +namespace OHOS::FileManagement::Backup { +class LocalCapabilities final { +public: + static napi_value Async(napi_env env, napi_callback_info info); +}; + +const std::string PROCEDURE_LOCALCAPABILITIES_NAME = "getLocalCapalities"; +} // namespace OHOS::FileManagement::Backup +#endif // INTERFACES_KITS_JS_SRC_MOD_BACKUP_PROPERTIES_LOCAL_CAPABILITIES_H \ No newline at end of file -- Gitee