diff --git a/backup.gni b/backup.gni index 7dc5c0e8790cf156fdbdcfc131128191634fe5c5..b907a5cd452075a8a5d5954593552a6e4367cfae 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 fc02fdb7680ad45c54ac72ad65f516d9ce9774ed..4f1a1d4c862ec891de34e2f87879a272c1a0b70e 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 fbdd483cfcac2712124b9ed1791bfcfcda53d51b..b3959019917afd2aeb637df1868d053d3b71edea 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 0000000000000000000000000000000000000000..9c8ea23e693f730e3b9851f5ed0f70e0bd2bfec4 --- /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 0000000000000000000000000000000000000000..716b5d3dfb01a20ae323aa3e6e96604443b222ef --- /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