From ff8eaa5a7f131766c58503b2f97c157aa58b816d Mon Sep 17 00:00:00 2001 From: libuyan <1014734367@qq.com> Date: Sat, 23 Mar 2024 15:38:08 +0800 Subject: [PATCH 01/15] support get info from app Signed-off-by: libuyan <1014734367@qq.com> --- .../native/backup_ext/include/ext_backup.h | 5 ++ .../native/backup_ext/include/ext_backup_js.h | 4 + .../native/backup_ext/include/ext_extension.h | 4 + .../backup_ext/include/ext_extension_stub.h | 1 + .../native/backup_ext/src/ext_backup.cpp | 6 ++ .../native/backup_ext/src/ext_backup_js.cpp | 30 +++++++ .../native/backup_ext/src/ext_extension.cpp | 31 ++++++++ .../backup_ext/src/ext_extension_stub.cpp | 16 ++++ .../include/service_reverse.h | 1 + .../include/service_reverse_stub.h | 1 + .../src/b_session_restore_async.cpp | 1 + .../backup_kit_inner/src/service_proxy.cpp | 28 +++++++ .../backup_kit_inner/src/service_reverse.cpp | 6 ++ .../src/service_reverse_stub.cpp | 12 +++ .../backup_ext/backup_extension_ability.js | 4 + .../impl/b_incremental_restore_session.h | 1 + .../backup_kit_inner/impl/b_session_backup.h | 1 + .../backup_kit_inner/impl/b_session_restore.h | 1 + .../impl/b_session_restore_async.h | 1 + .../backup_kit_inner/impl/i_extension.h | 1 + .../impl/i_extension_ipc_interface_code.h | 1 + .../native/backup_kit_inner/impl/i_service.h | 1 + .../impl/i_service_ipc_interface_code.h | 1 + .../backup_kit_inner/impl/i_service_reverse.h | 1 + .../i_service_reverse_ipc_interface_code.h | 1 + .../backup_kit_inner/impl/service_proxy.h | 1 + interfaces/kits/js/backup/general_callbacks.h | 4 +- .../kits/js/backup/local_capabilities.cpp | 45 +++++++++++ .../kits/js/backup/local_capabilities.h | 1 + interfaces/kits/js/backup/prop_n_exporter.cpp | 1 + .../js/backup/session_backup_n_exporter.cpp | 41 ++++++++++ .../js/backup/session_restore_n_exporter.cpp | 41 ++++++++++ .../backup_sa/include/module_ipc/service.h | 3 + .../module_ipc/service_reverse_proxy.h | 1 + .../include/module_ipc/service_stub.h | 1 + .../include/module_ipc/svc_extension_proxy.h | 1 + .../include/module_ipc/svc_session_manager.h | 7 ++ services/backup_sa/src/module_ipc/service.cpp | 78 +++++++++++++++++++ .../src/module_ipc/service_reverse_proxy.cpp | 19 +++++ .../backup_sa/src/module_ipc/service_stub.cpp | 25 ++++++ .../src/module_ipc/svc_extension_proxy.cpp | 31 ++++++++ .../src/module_ipc/svc_session_manager.cpp | 14 ++++ 42 files changed, 473 insertions(+), 1 deletion(-) diff --git a/frameworks/native/backup_ext/include/ext_backup.h b/frameworks/native/backup_ext/include/ext_backup.h index a7a015f3a..c8ab0d602 100644 --- a/frameworks/native/backup_ext/include/ext_backup.h +++ b/frameworks/native/backup_ext/include/ext_backup.h @@ -132,6 +132,11 @@ public: */ virtual ErrCode OnRestore(std::function callback); + /** + * @brief Called do GetBackupInfo. + */ + virtual ErrCode GetBackupInfo(std::function callback); + /** * @brief 数据迁移判断 * diff --git a/frameworks/native/backup_ext/include/ext_backup_js.h b/frameworks/native/backup_ext/include/ext_backup_js.h index b1e9d89d4..ed9ce3bdb 100644 --- a/frameworks/native/backup_ext/include/ext_backup_js.h +++ b/frameworks/native/backup_ext/include/ext_backup_js.h @@ -55,8 +55,10 @@ struct CallJsParam { struct CallBackInfo { std::function callback; + std::function callbackParam; CallBackInfo(std::function callbackIn) : callback(callbackIn) {} + CallBackInfo(std::function callbackIn) : callbackParam(callbackIn) {} }; class ExtBackupJs : public ExtBackup { @@ -96,6 +98,7 @@ public: * @param callback The callback. */ ErrCode OnRestore(std::function callback) override; + ErrCode GetBackupInfo(std::function callback) override; public: explicit ExtBackupJs(AbilityRuntime::JsRuntime &jsRuntime) : jsRuntime_(jsRuntime) {} @@ -117,6 +120,7 @@ private: AbilityRuntime::JsRuntime &jsRuntime_; std::unique_ptr jsObj_; std::shared_ptr callbackInfo_; + std::shared_ptr CallBackInfoEx_; }; } // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index da4aa29cd..3d6501d27 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -43,6 +43,7 @@ public: ErrCode PublishIncrementalFile(const std::string &fileName) override; ErrCode HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) override; std::tuple GetIncrementalBackupFileHandle() override; + ErrCode GetBackupInfo(std::string &result) override; void AsyncTaskRestoreForUpgrade(void); void ExtClear(void); @@ -145,6 +146,9 @@ private: std::shared_mutex lock_; std::shared_ptr extension_; std::vector tars_; + std::mutex getEtsInfoMtx_; + std::condition_veriable getEtsInfoCondition_; + std::string backupInfo_; OHOS::ThreadPool threadPool_; }; } // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_ext/include/ext_extension_stub.h b/frameworks/native/backup_ext/include/ext_extension_stub.h index 97dabc07c..67705e003 100644 --- a/frameworks/native/backup_ext/include/ext_extension_stub.h +++ b/frameworks/native/backup_ext/include/ext_extension_stub.h @@ -40,6 +40,7 @@ private: ErrCode CmdPublishIncrementalFile(MessageParcel &data, MessageParcel &reply); ErrCode CmdHandleIncrementalBackup(MessageParcel &data, MessageParcel &reply); ErrCode CmdGetIncrementalBackupFileHandle(MessageParcel &data, MessageParcel &reply); + ErrCode CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply); private: using ExtensionInterface = int32_t (ExtExtensionStub::*)(MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/native/backup_ext/src/ext_backup.cpp b/frameworks/native/backup_ext/src/ext_backup.cpp index 298df3f9c..9db3d2006 100644 --- a/frameworks/native/backup_ext/src/ext_backup.cpp +++ b/frameworks/native/backup_ext/src/ext_backup.cpp @@ -256,4 +256,10 @@ ErrCode ExtBackup::OnRestore(function callback) return ERR_OK; } +ErrCode ExtBackup::GetBackupInfo(function callback) +{ + HILOGI("BackupExtensionAbility(base) GetBackupInfo."); + return ERR_OK; +} + } // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_ext/src/ext_backup_js.cpp b/frameworks/native/backup_ext/src/ext_backup_js.cpp index edccf655b..8adf2be9e 100644 --- a/frameworks/native/backup_ext/src/ext_backup_js.cpp +++ b/frameworks/native/backup_ext/src/ext_backup_js.cpp @@ -291,6 +291,36 @@ ErrCode ExtBackupJs::OnRestore(function callback) return errCode; } +ErrCode ExtBackupJs::GetBackupInfo(std::function callback) +{ + HILOGI("BackupExtensionAbulity(JS) GetBackupInfo begin."); + BExcepUltils::BAssert(jsObj_, BError::Codes::EXT_BROKEN_FRAMEWORK, + "The app does not provide the GetBackupInfo interface."); + callbackInfo_ = std::make_share(callbcak); + auto retParser = [jsRuntime {&jsRuntime_}, callBackInfo {callbackInfo_}](napi_env env, + napi_value result) -> bool { + if (!CheckPromise(env, result)) { + size_t strLen = 0; + napi_status = napi_get_value_string_utf8(env, result, nullptr, -1, &strLen); + if (status != napi_ok) { + return false; + } + size_t bufLen = strLen + 1; + unique_ptr str = make_unique(buflen); + status = napi_get_value_string_utf8(env, result, str.get(), bufLen, &strLen); + callBackInfo->callbackParam(str.get()); + return true; + } + HILOGI("BackupExtensionAbulity(JS) GetBackupInfo ok."); + } + + auto errCode = CallJsMethod("getBackupInfo", jsRuntime_, jsObj_.get(), {}, retParser); + if (errCode != ERR_OK) { + HILOGE("CallJsMethod error, code:%{public}d.", errCode); + } + HILOGI("BackupExtensionAbulity(JS) GetBackupInfo end."); +} + static int DoCallJsMethod(CallJsParam *param) { AbilityRuntime::JsRuntime *jsRuntime = param->jsRuntime; diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index d44fc6e41..6edec334d 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -69,6 +69,7 @@ using namespace std; namespace { const int64_t DEFAULT_SLICE_SIZE = 100 * 1024 * 1024; // 分片文件大小为100M const uint32_t MAX_FILE_COUNT = 6000; // 单个tar包最多包含6000个文件 +const int32_t CONNECT_WAIT_TIME = 5; } // namespace void BackupExtExtension::VerifyCaller() @@ -1578,4 +1579,34 @@ void BackupExtExtension::AppIncrementalDone(ErrCode errCode) HILOGE("Failed to notify the app done. err = %{public}d", ret); } } + +ErrCode GetBackupInfo(std::string &result) +{ + try { + auto obj = wptr(this); + auto ptr = obj.promote(); + auto callbackup = [ptr](std::string result) { + HILOGI("GetBackupInfo callbackup start. result = %s", result); + ptr->backupInfo_ = result; + ptr->getEtsInfoCondition_.notify_one(); + } + auto ret = ptr->extension_->GetBackupInfo(callBackup); + if (ret != ERR_OK) { + HILOGE("Failed to notify the app done. err = %{public}d", ret); + BError(BError::Codes::EXT_INVAL_ARG, "extension getBackupInfo exception").GetCode(); + } + HILOGD("GetBackupInfo getEtsInfoMtx_ lock."); + std::unique_lock lock(getEtsInfoMtx_); + getEtsInfoCondition_.wait_for(lock, std::chrono::seconds(CONNECT_WAIT_TIME)); + HILOGD("GetBackupInfo getEtsInfoMtx_ unlock."); + + result = backupInfo_; + backupInfo.clear(); + + return ERR_OK; + } catch (const Errpr &e) { + HILOGE("Catched an unexpected low-level exception %{public}s", e.what()); + return BError(BError::Codes::EXT_INVAL_ARG, "extension getBackupInfo exception").GetCode(); + } +} } // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_ext/src/ext_extension_stub.cpp b/frameworks/native/backup_ext/src/ext_extension_stub.cpp index 888099411..804013fe9 100644 --- a/frameworks/native/backup_ext/src/ext_extension_stub.cpp +++ b/frameworks/native/backup_ext/src/ext_extension_stub.cpp @@ -45,6 +45,8 @@ ExtExtensionStub::ExtExtensionStub() &ExtExtensionStub::CmdHandleIncrementalBackup; opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_GET_INCREMENTAL_BACKUP_FILE_HANDLE)] = &ExtExtensionStub::CmdGetIncrementalBackupFileHandle; + opToInterfaceMap_[static_cast(IExtensionInterfaceCode::CMD_GET_BACKUP_INFO)] = + &ExtExtensionStub::CmdGetBackupInfo; } int32_t ExtExtensionStub::OnRemoteRequest(uint32_t code, @@ -195,4 +197,18 @@ ErrCode ExtExtensionStub::CmdGetIncrementalBackupFileHandle(MessageParcel &data, } return BError(BError::Codes::OK); } + +ErrCode ExtExtensionStub::CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply) +{ + HILOGI("CmdGetBackupInfo Begin"); + std::string result; + int ret = GetBackupInfo(result); + if (!reply.WriteInt32(ret)) { + return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the ret").GetCode(); + } + if (!reply.WriteString(result)) { + return BError(BError::Codes::EXT_BROKEN_IPC, "Failed to send out the result").GetCode(); + } + return BError(BError::Codes::OK); +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/frameworks/native/backup_kit_inner/include/service_reverse.h b/frameworks/native/backup_kit_inner/include/service_reverse.h index 81707f8b2..4dbf43273 100644 --- a/frameworks/native/backup_kit_inner/include/service_reverse.h +++ b/frameworks/native/backup_kit_inner/include/service_reverse.h @@ -34,6 +34,7 @@ public: void RestoreOnBundleFinished(int32_t errCode, std::string bundleName) override; void RestoreOnAllBundlesFinished(int32_t errCode) override; void RestoreOnFileReady(std::string bundleName, std::string fileName, int fd) override; + void RestoreOnResultReport(std::string result) override; void IncrementalBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd) override; void IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) override; diff --git a/frameworks/native/backup_kit_inner/include/service_reverse_stub.h b/frameworks/native/backup_kit_inner/include/service_reverse_stub.h index 650a7e784..b58400ec9 100644 --- a/frameworks/native/backup_kit_inner/include/service_reverse_stub.h +++ b/frameworks/native/backup_kit_inner/include/service_reverse_stub.h @@ -43,6 +43,7 @@ private: int32_t CmdRestoreOnBundleFinished(MessageParcel &data, MessageParcel &reply); int32_t CmdRestoreOnAllBundlesFinished(MessageParcel &data, MessageParcel &reply); int32_t CmdRestoreOnFileReady(MessageParcel &data, MessageParcel &reply); + int32_t CmdRestoreOnResultReport(MessageParcel &data, MessageParcel &reply); int32_t CmdIncrementalBackupOnFileReady(MessageParcel &data, MessageParcel &reply); int32_t CmdIncrementalBackupOnBundleStarted(MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp index 9336f3d95..5e1b8b18a 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore_async.cpp @@ -57,6 +57,7 @@ shared_ptr BSessionRestoreAsync::Init(Callbacks callbacks) .onBundleStarted = callbacks.onBundleStarted, .onBundleFinished = callbacks.onBundleFinished, .onAllBundlesFinished = callbacks.onAllBundlesFinished, + .onResultReport = callbacks.onResultReport, .onBackupServiceDied = callbacks.onBackupServiceDied}; int32_t res = proxy->InitRestoreSession(new ServiceReverse(callbacksTmp)); if (res != 0) { diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp index 0e03d48ef..e1dd4ab28 100644 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ b/frameworks/native/backup_kit_inner/src/service_proxy.cpp @@ -406,4 +406,32 @@ void ServiceProxy::ServiceProxyLoadCallback::OnLoadSystemAbilityFail(int32_t sys isLoadSuccess_.store(false); proxyConVar_.notify_one(); } + +ErrCode ServiceProxy::GetBackupInfo(BundleName &bundleName, std::string &result) +{ + HILOGI("ServiceProxy GetBackupInfo Begin."); + BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); + MessageParcel data; + if (!data.WriteInterfaceToken(GetDescriptor())) { + return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); + } + if (!remote) { + return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); + } + if (!data.WriteString(bundleName)) { + return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName").GetCode(); + } + MessageParcel reply; + MessageOption option; + option.SetWaitTime(BContants::IPC_MAX_WAIT_TIME); + int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_INFO), + data, reply, option); + if (ret != NO_ERROR) { + string str = "Failed to send out the request because of " + to_string(ret); + return BError(BError::Codes::SDK_INVAL_ARG, str.data()).GetCode(); + } + reply.ReadString(result); + HILOGI("ServiceProxy GetBackupInfo end. result = %s", result.c_str()); + return BError(BError::Codes::OK, "success"); +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/frameworks/native/backup_kit_inner/src/service_reverse.cpp b/frameworks/native/backup_kit_inner/src/service_reverse.cpp index 6564af51a..5d8d9a030 100644 --- a/frameworks/native/backup_kit_inner/src/service_reverse.cpp +++ b/frameworks/native/backup_kit_inner/src/service_reverse.cpp @@ -103,6 +103,12 @@ void ServiceReverse::RestoreOnFileReady(string bundleName, string fileName, int callbacksRestore_.onFileReady(bFileInfo, UniqueFd(fd)); } +void ServiceReverse::RestoreOnResultReport(string result) +{ + HILOGI("ServiceReverse RestoreOnResultReport begin with result: %s", result.c_str()); + callbacksRestore_.onResultReport(BError(BError::Codes::OK), result); +} + ServiceReverse::ServiceReverse(BSessionBackup::Callbacks callbacks) : scenario_(Scenario::BACKUP), callbacksBackup_(callbacks) { diff --git a/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp b/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp index 082a2a24c..61f786f33 100644 --- a/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp +++ b/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp @@ -63,6 +63,8 @@ ServiceReverseStub::ServiceReverseStub() &ServiceReverseStub::CmdRestoreOnAllBundlesFinished; opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_FILE_READY)] = &ServiceReverseStub::CmdRestoreOnFileReady; + opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_RESULT_REPORT)] = + &ServiceReverseStub::CmdRestoreOnResultReport; opToInterfaceMap_[static_cast(IServiceReverseInterfaceCode::SERVICER_INCREMENTAL_BACKUP_ON_FILE_READY)] = &ServiceReverseStub::CmdIncrementalBackupOnFileReady; @@ -153,6 +155,16 @@ int32_t ServiceReverseStub::CmdRestoreOnFileReady(MessageParcel &data, MessagePa return BError(BError::Codes::OK); } +int32_t ServiceReverseStub::CmdRestoreOnResultReport(MessageParcel &data, MessageParcel &reply) +{ + std::string result; + if (!data.ReadString(result)) { + return BError(BError::Codes::SDK_INVAL_ARG, "Failed to read result").GetCode(); + } + RestoreOnResultReport(result); + return BError(BError::Codes::OK); +} + int32_t ServiceReverseStub::CmdIncrementalBackupOnFileReady(MessageParcel &data, MessageParcel &reply) { auto bundleName = data.ReadString(); diff --git a/interfaces/api/js/napi/backup_ext/backup_extension_ability.js b/interfaces/api/js/napi/backup_ext/backup_extension_ability.js index 1e21a35d2..6f73f6363 100644 --- a/interfaces/api/js/napi/backup_ext/backup_extension_ability.js +++ b/interfaces/api/js/napi/backup_ext/backup_extension_ability.js @@ -21,6 +21,10 @@ class BackupExtensionAbility { onRestore(versionBackupedBundle) { console.log(versionBackupedBundle) } + + getBackupInfo() { + console.log() + } } export default BackupExtensionAbility \ No newline at end of file diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h index 020b80db2..fcd926e10 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h @@ -35,6 +35,7 @@ public: std::function onBundleFinished; // 当某个应用的恢复流程结束或意外中止时执行的回调函数 std::function onAllBundlesFinished; // 当整个恢复流程结束或意外中止时执行的回调函数 + std::function onResultReport; std::function onBackupServiceDied; // 当备份服务意外死亡时执行的回调函数 }; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h index c662a5844..f8b8c23d0 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h @@ -33,6 +33,7 @@ public: std::function onBundleStarted; // 当启动某个应用的备份流程结束时执行的回调函数 std::function onBundleFinished; // 当某个应用的备份流程结束或意外中止时执行的回调函数 std::function onAllBundlesFinished; // 当整个备份流程结束或意外中止时执行的回调函数 + std::function onResultReport; std::function onBackupServiceDied; // 当备份服务意外死亡时执行的回调函数 }; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h index 59fe34360..10ac8aa95 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h @@ -33,6 +33,7 @@ public: std::function onBundleStarted; // 当启动某个应用的恢复流程结束时执行的回调函数 std::function onBundleFinished; // 当某个应用的恢复流程结束或意外中止时执行的回调函数 std::function onAllBundlesFinished; // 当整个恢复流程结束或意外中止时执行的回调函数 + std::function onResultReport; std::function onBackupServiceDied; // 当备份服务意外死亡时执行的回调函数 }; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h index 9b7853706..d2d173e8f 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h @@ -37,6 +37,7 @@ public: std::function onBundleFinished; // 当某个应用的恢复流程结束或意外中止时执行的回调函数 std::function onAllBundlesFinished; // 当整个恢复流程结束或意外中止时执行的回调函数 + std::function onResultReport; std::function onBackupServiceDied; // 当备份服务意外死亡时执行的回调函数 }; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h index d5c0d7b35..3641d6a4a 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/i_extension.h @@ -36,6 +36,7 @@ public: virtual ErrCode PublishIncrementalFile(const std::string &fileName) = 0; virtual ErrCode HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) = 0; virtual std::tuple GetIncrementalBackupFileHandle() = 0; + virtual ErrCode GetBackupInfo(std::string &result) = 0; }; } // namespace OHOS::FileManagement::Backup diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_extension_ipc_interface_code.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_extension_ipc_interface_code.h index 81eaf29f5..595690825 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_extension_ipc_interface_code.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/i_extension_ipc_interface_code.h @@ -28,6 +28,7 @@ enum class IExtensionInterfaceCode { CMD_PUBLISH_INCREMENTAL_FILE, CMD_HANDLE_INCREMENTAL_BACKUP, CMD_GET_INCREMENTAL_BACKUP_FILE_HANDLE, + CMD_GET_BACKUP_INFO, }; } // namespace OHOS::FileManagement::Backup diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h index 4e58bbd5e..ca78c738f 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h @@ -60,6 +60,7 @@ public: virtual ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd) = 0; virtual ErrCode AppIncrementalDone(ErrCode errCode) = 0; virtual ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) = 0; + virtual Errcode GetBackupInfo(BundleName &BundleName, std::string &result) = 0; DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Filemanagement.Backup.IService") }; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_ipc_interface_code.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_service_ipc_interface_code.h index 1de726cf2..a1e4d4ba6 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_ipc_interface_code.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/i_service_ipc_interface_code.h @@ -38,6 +38,7 @@ enum class IServiceInterfaceCode { SERVICE_CMD_APP_INCREMENTAL_FILE_READY, SERVICE_CMD_APP_INCREMENTAL_DONE, SERVICE_CMD_GET_INCREMENTAL_FILE_NAME, + SERVICE_CMD_GET_BACKUP_INFO, }; } // namespace OHOS::FileManagement::Backup diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse.h index fbdf2408b..3fe6b51f9 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse.h @@ -40,6 +40,7 @@ public: virtual void RestoreOnBundleFinished(int32_t errCode, std::string bundleName) = 0; virtual void RestoreOnAllBundlesFinished(int32_t errCode) = 0; virtual void RestoreOnFileReady(std::string bundleName, std::string fileName, int fd) = 0; + virtual void RestoreOnResultReport(std::string result) = 0; virtual void IncrementalBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd) = 0; virtual void IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) = 0; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse_ipc_interface_code.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse_ipc_interface_code.h index b3300a21b..1c3bfecbd 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse_ipc_interface_code.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/i_service_reverse_ipc_interface_code.h @@ -27,6 +27,7 @@ enum class IServiceReverseInterfaceCode { SERVICER_RESTORE_ON_SUB_TASK_FINISHED, SERVICER_RESTORE_ON_TASK_FINISHED, SERVICER_RESTORE_ON_FILE_READY, + SERVICER_RESTORE_ON_RESULT_REPORT, SERVICER_INCREMENTAL_BACKUP_ON_FILE_READY, SERVICER_INCREMENTAL_BACKUP_ON_SUB_TASK_STARTED, SERVICER_INCREMENTAL_BACKUP_ON_SUB_TASK_FINISHED, diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h b/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h index 6204832a8..9131738cc 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h @@ -51,6 +51,7 @@ public: ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd) override; ErrCode AppIncrementalDone(ErrCode errCode) override; ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) override; + Errcode GetBackupInfo(BundleName &BundleName, std::string &result) override; public: explicit ServiceProxy(const sptr &impl) : IRemoteProxy(impl) {} diff --git a/interfaces/kits/js/backup/general_callbacks.h b/interfaces/kits/js/backup/general_callbacks.h index 6bde169b8..ceb8c5301 100644 --- a/interfaces/kits/js/backup/general_callbacks.h +++ b/interfaces/kits/js/backup/general_callbacks.h @@ -29,7 +29,8 @@ public: onBundleBegin(env, thisPtr, jsCallbacks.GetProp("onBundleBegin")), onBundleEnd(env, thisPtr, jsCallbacks.GetProp("onBundleEnd")), onAllBundlesEnd(env, thisPtr, jsCallbacks.GetProp("onAllBundlesEnd")), - onBackupServiceDied(env, thisPtr, jsCallbacks.GetProp("onBackupServiceDied")) {}; + onBackupServiceDied(env, thisPtr, jsCallbacks.GetProp("onBackupServiceDied"), + onResultReport(env, thisPtr, jsCallbacks.GetProp("onResultReport"))) {}; public: LibN::NAsyncWorkCallback onFileReady; @@ -37,6 +38,7 @@ public: LibN::NAsyncWorkCallback onBundleEnd; LibN::NAsyncWorkCallback onAllBundlesEnd; LibN::NAsyncWorkCallback onBackupServiceDied; + LibN::NAsyncWorkCallback onResultReport; }; } // namespace OHOS::FileManagement::Backup #endif // INTERFACES_KITS_JS_SRC_MOD_BACKUP_PROPERTIES_GENERAL_CALLBACKS_H \ No newline at end of file diff --git a/interfaces/kits/js/backup/local_capabilities.cpp b/interfaces/kits/js/backup/local_capabilities.cpp index 10570a91e..e8dcdcefb 100644 --- a/interfaces/kits/js/backup/local_capabilities.cpp +++ b/interfaces/kits/js/backup/local_capabilities.cpp @@ -178,4 +178,49 @@ napi_value LocalCapabilities::Async(napi_env env, napi_callback_info info) return AsyncCallback(env, funcArg); } + +napi_value LocalCapabilities::DoGetBackupInfo(napi_env env, napi_callback_info info) +{ + HILOGI("called DoGetBackupInfo begin"); + std::string result; + NFuncArg funcArg(env, info); + if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) { + HILOGE("Number of arguments unmatched."); + NError(BError(BError::Codes::SDK_INVAL_ARG, "Number of arguments unmatched.").GetCode()).ThrowErr(env); + return nullptr; + } + NVal jsBundle(env, funcArg[NARG_POS::FIRST]); + auto [succ, bundle, size] = jsBundle.ToUTF8String(); + if (succ) { + HILOGE(First argument is not string.); + NError(EINVAL).ThrowErr(env); + return nullptr; + } + + ServiceProxy::InvaildInstance(); + auto proxy = ServiceProxy::GetInstance(); + if (!proxy) { + HILOGE("called DoGetBackupInfo,failed to get proxy"); + return nullptr; + } + std::string bundleName = bundle.get(); + ErrCode errcode = proxy->GetBackupInfo(bundelName, result); + if (errcode != 0) { + HILOGE("proxy->GetBackupInfo faild."); + return nullptr; + } + if (result.size() == 0) { + HILOGE("proxy->GetBackupInfo result is empty."); + return nullptr; + } + + napi_value nResult; + napi_status status = napi_create_string_utf8(env, result.c_str(), result.size(), &nResult); + if (status != napi_ok) { + HILOGE("napi_create_string_utf8 faild."); + return nullptr; + } + HILOGI("DoGetBackupInfo success with result: %s", result.c_str()); + return nResult; +} } // 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 index 716b5d3df..7870aec63 100644 --- a/interfaces/kits/js/backup/local_capabilities.h +++ b/interfaces/kits/js/backup/local_capabilities.h @@ -22,6 +22,7 @@ namespace OHOS::FileManagement::Backup { class LocalCapabilities final { public: static napi_value Async(napi_env env, napi_callback_info info); + static napi_value DoGetBackupInfo(napi_env env, napi_callback_info info); }; const std::string PROCEDURE_LOCALCAPABILITIES_NAME = "getLocalCapalities"; diff --git a/interfaces/kits/js/backup/prop_n_exporter.cpp b/interfaces/kits/js/backup/prop_n_exporter.cpp index 572a46db4..f2bb79ad0 100644 --- a/interfaces/kits/js/backup/prop_n_exporter.cpp +++ b/interfaces/kits/js/backup/prop_n_exporter.cpp @@ -24,6 +24,7 @@ bool PropNExporter::Export() { return exports_.AddProp({ NVal::DeclareNapiFunction("getLocalCapabilities", LocalCapabilities::Async), + NVal::DeclareNapiFunction("getBackupInfo", LocalCapabilities::DoGetBackupInfo), }); } diff --git a/interfaces/kits/js/backup/session_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_backup_n_exporter.cpp index d3252402c..b7b918bd9 100644 --- a/interfaces/kits/js/backup/session_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_backup_n_exporter.cpp @@ -204,6 +204,46 @@ static void OnBackupServiceDied(weak_ptr pCallbacks) callbacks->onBackupServiceDied.ThreadSafeSchedule(cbCompl); } +static void onResultReport(weak_ptr pCallbacks, ErrCode err, const std::string result) +{ + HILOGI("callback function onResultReport begin."); + if (pCallbacks.expired()) { + HILOGI("callbacks is unbound"); + return; + } + auto callbacks = pCallbacks.lock(); + if (!callbacks) { + HILOGI("callback function onResultReport has already been released"); + return; + } + if (!bool(callbacks->onResultReport)) { + HILOGI("callback function onResultReport is undefined"); + return; + } + + auto cbCompl = [result {result}, errCode {err}](napi_env env, NError err) -> NVal { + NVal resultStr = NVal::CreateUTF8String(env, result); + if (!err && errCode == 0) { + return resultStr; + } + + NVal res; + if (err) { + res = NVal {env, err.GetNapiErr(env)}; + } else { + res = NVal {env, NError(errCode).GetNapiErr(env)}; + } + napi_status status = napi_set_named_property(env, res.val_, FILEIO_TAG_ERR_DATA.c_str(), resultStr.val_); + if (status != napi_ok) { + HILOGE("Failed to set data property, status %{public}d, bundleName %{public}s", status, result.c_str()); + } + + return res; + }; + + callbacks->onResultReport.ThreadSafeSchedule(cbCompl); +} + napi_value SessionBackupNExporter::Constructor(napi_env env, napi_callback_info cbinfo) { HILOGI("called SessionBackup::Constructor begin"); @@ -229,6 +269,7 @@ napi_value SessionBackupNExporter::Constructor(napi_env env, napi_callback_info .onBundleStarted = bind(onBundleBegin, backupEntity->callbacks, placeholders::_1, placeholders::_2), .onBundleFinished = bind(onBundleEnd, backupEntity->callbacks, placeholders::_1, placeholders::_2), .onAllBundlesFinished = bind(onAllBundlesEnd, backupEntity->callbacks, placeholders::_1), + .onResultReport = bind(onResultReport, backupEntity->callbacks, placeholders::_1, placeholders::_2), .onBackupServiceDied = bind(OnBackupServiceDied, backupEntity->callbacks)}); if (!backupEntity->session) { NError(BError(BError::Codes::SDK_INVAL_ARG, "Failed to init backup").GetCode()).ThrowErr(env); diff --git a/interfaces/kits/js/backup/session_restore_n_exporter.cpp b/interfaces/kits/js/backup/session_restore_n_exporter.cpp index 34afc9697..45753cc9b 100644 --- a/interfaces/kits/js/backup/session_restore_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_restore_n_exporter.cpp @@ -247,6 +247,46 @@ static void OnBackupServiceDied(weak_ptr pCallbacks) callbacks->onBackupServiceDied.ThreadSafeSchedule(cbCompl); } +static void onResultReport(weak_ptr pCallbacks, ErrCode err, const std::string result) +{ + HILOGI("callback function onResultReport begin."); + if (pCallbacks.expired()) { + HILOGI("callbacks is unbound"); + return; + } + auto callbacks = pCallbacks.lock(); + if (!callbacks) { + HILOGI("callback function onResultReport has already been released"); + return; + } + if (!bool(callbacks->onResultReport)) { + HILOGI("callback function onResultReport is undefined"); + return; + } + + auto cbCompl = [result {result}, errCode {err}](napi_env env, NError err) -> NVal { + NVal resultStr = NVal::CreateUTF8String(env, result); + if (!err && errCode == 0) { + return resultStr; + } + + NVal res; + if (err) { + res = NVal {env, err.GetNapiErr(env)}; + } else { + res = NVal {env, NError(errCode).GetNapiErr(env)}; + } + napi_status status = napi_set_named_property(env, res.val_, FILEIO_TAG_ERR_DATA.c_str(), resultStr.val_); + if (status != napi_ok) { + HILOGE("Failed to set data property, status %{public}d, bundleName %{public}s", status, result.c_str()); + } + + return res; + }; + + callbacks->onResultReport.ThreadSafeSchedule(cbCompl); +} + napi_value SessionRestoreNExporter::Constructor(napi_env env, napi_callback_info cbinfo) { HILOGI("called SessionRestore::Constructor begin"); @@ -284,6 +324,7 @@ napi_value SessionRestoreNExporter::Constructor(napi_env env, napi_callback_info .onBundleStarted = bind(onBundleBegin, restoreEntity->callbacks, placeholders::_1, placeholders::_2), .onBundleFinished = bind(onBundleEnd, restoreEntity->callbacks, placeholders::_1, placeholders::_2), .onAllBundlesFinished = bind(onAllBundlesEnd, restoreEntity->callbacks, placeholders::_1), + .onResultReport = bind(onResultReport, backupEntity->callbacks, placeholders::_1, placeholders::_2), .onBackupServiceDied = bind(OnBackupServiceDied, restoreEntity->callbacks)}); } if (!restoreEntity->sessionWhole && !restoreEntity->sessionSheet) { diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 66dc61a54..f17cbe086 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -56,6 +56,7 @@ public: ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd) override; ErrCode AppIncrementalDone(ErrCode errCode) override; ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) override; + ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) override; // 以下都是非IPC接口 public: @@ -197,6 +198,8 @@ private: private: static sptr instance_; static std::mutex instanceLock_; + std::mutex getBackupInfoMutx_; + std::condition_variable getBackupInfoCondition_; static inline std::atomic seed {1}; sptr session_; diff --git a/services/backup_sa/include/module_ipc/service_reverse_proxy.h b/services/backup_sa/include/module_ipc/service_reverse_proxy.h index 401644b79..14923ee45 100644 --- a/services/backup_sa/include/module_ipc/service_reverse_proxy.h +++ b/services/backup_sa/include/module_ipc/service_reverse_proxy.h @@ -31,6 +31,7 @@ public: void RestoreOnBundleFinished(int32_t errCode, std::string bundleName) override; void RestoreOnAllBundlesFinished(int32_t errCode) override; void RestoreOnFileReady(std::string bundleName, std::string fileName, int fd) override; + void RestoreOnResultReport(std::string result) override; void IncrementalBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd) override; void IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) override; diff --git a/services/backup_sa/include/module_ipc/service_stub.h b/services/backup_sa/include/module_ipc/service_stub.h index 066c0f878..2367f5016 100644 --- a/services/backup_sa/include/module_ipc/service_stub.h +++ b/services/backup_sa/include/module_ipc/service_stub.h @@ -53,6 +53,7 @@ private: int32_t CmdAppIncrementalFileReady(MessageParcel &data, MessageParcel &reply); int32_t CmdAppIncrementalDone(MessageParcel &data, MessageParcel &reply); int32_t CmdGetIncrementalFileHandle(MessageParcel &data, MessageParcel &reply); + int32_t CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply); public: template diff --git a/services/backup_sa/include/module_ipc/svc_extension_proxy.h b/services/backup_sa/include/module_ipc/svc_extension_proxy.h index f208cb2d4..a63a781aa 100644 --- a/services/backup_sa/include/module_ipc/svc_extension_proxy.h +++ b/services/backup_sa/include/module_ipc/svc_extension_proxy.h @@ -32,6 +32,7 @@ public: ErrCode PublishIncrementalFile(const std::string &fileName) override; ErrCode HandleIncrementalBackup(UniqueFd incrementalFd, UniqueFd manifestFd) override; std::tuple GetIncrementalBackupFileHandle() override; + ErrCode GetBackupInfo(std::string &result) override; public: explicit SvcExtensionProxy(const sptr &remote) : IRemoteProxy(remote) {} diff --git a/services/backup_sa/include/module_ipc/svc_session_manager.h b/services/backup_sa/include/module_ipc/svc_session_manager.h index 777765d1c..ca5dd8bdd 100644 --- a/services/backup_sa/include/module_ipc/svc_session_manager.h +++ b/services/backup_sa/include/module_ipc/svc_session_manager.h @@ -253,6 +253,13 @@ public: */ void AppendBundles(const std::vector &bundleNames); + /** + * @brief 添加指定应用 + * + * @param bundleName 应用名称 + */ + void CreateBackupConnection(const std::string &bundleName); + /** * @brief 开始备份 * diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 7043f60e7..b32d24d45 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -64,6 +64,7 @@ REGISTER_SYSTEM_ABILITY_BY_ID(Service, FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, fals namespace { constexpr int32_t DEBUG_ID = 100; +const int32_t CONNECT_WAIT_TIME = 5; } // namespace /* Shell/Xts user id equal to 0/1, we need set default 100 */ @@ -931,4 +932,81 @@ void Service::SessionDeactive() return; } } + +ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) +{ + try { + HILOGI("Service::GetBackupInfo begin."); + session_->IncreaseSessionCnt(); + session->CreateBackupConnection(bundleName); + auto backupConnection = session_->GetExtConnection(bundleName); + auto callConnDone = [ptr {wptr(this)}](const string &&bundleName) { + HILOGI(callConnDone begin.); + auto thisPtr = ptr.promote(); + if (!thisPtr) { + HILOGW("this pointer is null."); + return; + } + thisPtr->getBackupInfoCondition_.notify_one(); + }; + backupConnection->setCallback(callConnDone); + + IServiceReverse::Scenario scenario = session_->GetScenario(); + BConstants::ExtensionAction action; + if (scenario == IServiceReverse::Scenario::BACKUP) { + action = BConstants::ExtensionAction::BACKUP; + } else if (scenario == IServiceReverse::Scenario::RESTORE) { + action = BConstants::ExtensionAction::RESTORE; + } else { + throw BError(BError::Codes::SA_INVAL_ARG, "Failed to scenario"); + } + + AAFwk::Want want; + string backupExtName = session_->GetBackupExtName(bundleName); /* new device app ext name */ + HILOGD("backupExtName: %{public}s, bundleName: %{public}s", backupExtName.data(), bundleName.data()); + string versionName = session_->GetBundleVersionName(bundleName); /* old device app version name */ + uint32_t versionCode = session_->GetBundleVersionCode(bundleName); /* old device app version code */ + RestoreTypeEnum restoreType = session_->GetBundleRestoreType(bundleName); /* app restore type */ + + want.SetElementName(bundleName, backupExtName); + want.SetParam(BConstants::EXTENSION_ACTION_PARA, static_cast(action)); + want.SetParam(BConstants::EXTENSION_VERSION_CODE_PARA, static_cast(versionCode)); + want.SetParam(BConstants::EXTENSION_RESTORE_TYPE_PARA, static_cast(restoreType)); + want.SetParam(BConstants::EXTENSION_VERSION_NAME_PARA, versionName); + + backUpConnection->ConnectBackupExtAbility(want, session_->GetSessionUserId()); + + HILOGD("GetBackupInfo getBackupInfoMtx_ lock."); + std::unique_lock lock(getBackupInfoMtx_); + getBackupInfoCondition_.wait_for(lock, std::chrono::seconds(CONNECT_WAIT_TIME)); + HILOGD("GetBackupInfo getBackupInfoMtx_ unlock."); + auto proxy = backupConnection->GetBackupExtProxy(); + if (!proxy) { + throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); + } + auto ret = proxy->GetBackupInfo(result); + + backUpConnection->DisconnectBackupExtAbility(); + if (ret != ERR_OK) { + HILOGE("Call Ext GetBackupInfo faild."); + return BError(BError::Codes::SA_INVAL_ARG); + } + + HILOGI("Service::GetBackupInfo end. result: %s", result.c_str()); + session_->DeceaseSessionCnt(); + return BError(BError::Codes::OK); + } catch (const BError &e) { + session_->DecreaseSessionCnt(); + HILOGE("GetBackupInfo failed, errCode = %{public}d", e.GetCode()); + return UniqueFd(-e.GetCode()); + } catch (const exception &e) { + session_->DecreaseSessionCnt(); + HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); + return UniqueFd(-EPERM); + } catch (...) { + session_->DecreaseSessionCnt(); + HILOGI("Unexpected exception"); + return UniqueFd(-EPERM); + } +} } // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp b/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp index dc6d5fb89..cb2776723 100644 --- a/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp +++ b/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp @@ -177,4 +177,23 @@ void ServiceReverseProxy::RestoreOnFileReady(string bundleName, string fileName, throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); } } + +void ServiceReverseProxy::RestoreOnResultReport(string result) +{ + HILOGI("ServiceReverseProxy::RestoreOnResultReport Begin with result: %s", result.c_str()); + BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); + MessageParcel data; + if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(result)) { + throw BError(BError::Codes::SA_BROKEN_IPC); + } + + MessageParcel reply; + MessageOption option; + if (int err = Remote()->SendRequest( + static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_RESULT_REPORT), data, reply, + option); + err != ERR_OK) { + throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); + } +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/services/backup_sa/src/module_ipc/service_stub.cpp b/services/backup_sa/src/module_ipc/service_stub.cpp index d55334d30..29b4709e2 100644 --- a/services/backup_sa/src/module_ipc/service_stub.cpp +++ b/services/backup_sa/src/module_ipc/service_stub.cpp @@ -70,6 +70,8 @@ ServiceStub::ServiceStub() &ServiceStub::CmdAppIncrementalDone; opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_INCREMENTAL_FILE_NAME)] = &ServiceStub::CmdGetIncrementalFileHandle; + opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_INFO)] = + &ServiceStub::CmdGetBackupInfo; } int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) @@ -276,6 +278,29 @@ int32_t ServiceStub::CmdFinish(MessageParcel &data, MessageParcel &reply) return BError(BError::Codes::OK); } +int32_t ServiceStub::CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply) +{ + HILOGI("ServiceStub::CmdGetBackupInfo Begin."); + int ret = ERR_OK; + string bundleName; + if (!data.ReadString(bundleName)) { + return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); + } + string result; + ret = GetBackupInfo(bundleName, result); + if (ret != ERR_OK) { + return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call GetBackupInfo")); + } + if (!data.ReadString(bundleName)) { + return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); + } + if (!reply.WriteString(result)) { + return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); + } + HILOGI("ServiceStub::CmdGetBackupInfo end."); + return BError(BError::Codes::OK); +} + int32_t ServiceStub::CmdRelease(MessageParcel &data, MessageParcel &reply) { HILOGI("Begin"); diff --git a/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp b/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp index 9479d43da..574e8ed18 100644 --- a/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp +++ b/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp @@ -140,4 +140,35 @@ ErrCode SvcExtensionProxy::HandleRestore() HILOGI("Successful"); return reply.ReadInt32(); } + +ErrCode SvcExtensionProxy::GetBackupInfo(std::string &result) +{ + HILOGD("SvcExtensionProxy::GetBackupInfo begin."); + BExcepUltils::BAssert(Remote(), BError::Codes::SDK_INVAL_ARG, "Remote is nullptr"); + MessageParcel data; + data.WriteInterfaceToken(GetDescriptor()); + + MessageParcel reply; + MessageOption option; + int32_t ret = + Remote()->SendRequest(static_cast(IExtensionInterfaceCode::CMD_GET_BACKUP_INFO), data, reply, option); + if (ret != NO_ERROR) { + HILOGE("Received error %{public}d when doing IPC", ret); + return ErrCode(ret); + } + if (!reply.ReadInt32(ret)) { + HILOGE("fail to ReadInt32 ret"); + return ErrCode(ret); + } + if (ret != NO_ERROR) { + HILOGE("ret is not NO_ERROR. ret = %d", ret); + return ErrCode(ret); + } + if (!reply.ReadString(result)) { + HILOGE("fail to ReadInt32 ret"); + return ErrCode(ret); + } + HILOGI("SvcExtensionProxy::GetBackupInfo end. result: %s", result.c_str()); + return ret; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/services/backup_sa/src/module_ipc/svc_session_manager.cpp b/services/backup_sa/src/module_ipc/svc_session_manager.cpp index 0622b7040..34c3b55b1 100644 --- a/services/backup_sa/src/module_ipc/svc_session_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_session_manager.cpp @@ -404,6 +404,20 @@ void SvcSessionManager::AppendBundles(const vector &bundleNames) impl_.isAppendFinish = true; } +void SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +{ + HILOGI("SvcSessionManager::CreateBackupConnection begin."); + unique_lock lock(lock_); + if (!impl_.clientToken) { + throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + } + HILOGD("bundleName: %{public}s", bundleName.c_str()); + BackupExtInfo info {}; + info.backUpConnection = GetBackupExtAbility(bundleName); + info.backupExtName = bundleName; + impl_.backupExtNameMap.insert(make_pair(bundleName, info)); +} + void SvcSessionManager::Start() { HILOGI("Begin"); -- Gitee From e7e958c2d658341498c4bd4c953157d4a03ba503 Mon Sep 17 00:00:00 2001 From: libuyan <1014734367@qq.com> Date: Sat, 23 Mar 2024 17:12:12 +0800 Subject: [PATCH 02/15] add target Signed-off-by: libuyan <1014734367@qq.com> --- frameworks/native/backup_ext/include/ext_extension.h | 2 +- frameworks/native/backup_kit_inner/src/service_proxy.cpp | 5 +---- .../native/backup_kit_inner/src/service_reverse_stub.cpp | 2 +- .../inner_api/native/backup_kit_inner/impl/i_service.h | 2 +- .../inner_api/native/backup_kit_inner/impl/service_proxy.h | 2 +- interfaces/kits/js/backup/general_callbacks.h | 4 ++-- interfaces/kits/js/backup/local_capabilities.cpp | 4 ++-- services/backup_sa/src/module_ipc/service.cpp | 4 ++-- services/backup_sa/src/module_ipc/service_stub.cpp | 3 --- 9 files changed, 11 insertions(+), 17 deletions(-) diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index 3d6501d27..c19e8434c 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -147,7 +147,7 @@ private: std::shared_ptr extension_; std::vector tars_; std::mutex getEtsInfoMtx_; - std::condition_veriable getEtsInfoCondition_; + std::condition_variable getEtsInfoCondition_; std::string backupInfo_; OHOS::ThreadPool threadPool_; }; diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp index e1dd4ab28..611004100 100644 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ b/frameworks/native/backup_kit_inner/src/service_proxy.cpp @@ -415,15 +415,12 @@ ErrCode ServiceProxy::GetBackupInfo(BundleName &bundleName, std::string &result) if (!data.WriteInterfaceToken(GetDescriptor())) { return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write descriptor").GetCode(); } - if (!remote) { - return BError(BError::Codes::SDK_INVAL_ARG, "Empty reverse stub").GetCode(); - } if (!data.WriteString(bundleName)) { return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleName").GetCode(); } MessageParcel reply; MessageOption option; - option.SetWaitTime(BContants::IPC_MAX_WAIT_TIME); + option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_INFO), data, reply, option); if (ret != NO_ERROR) { diff --git a/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp b/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp index 61f786f33..942b91fa0 100644 --- a/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp +++ b/frameworks/native/backup_kit_inner/src/service_reverse_stub.cpp @@ -159,7 +159,7 @@ int32_t ServiceReverseStub::CmdRestoreOnResultReport(MessageParcel &data, Messag { std::string result; if (!data.ReadString(result)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to read result").GetCode(); + return BError(BError::Codes::EXT_INVAL_ARG, "Failed to read result").GetCode(); } RestoreOnResultReport(result); return BError(BError::Codes::OK); diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h b/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h index ca78c738f..ef588233b 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/i_service.h @@ -60,7 +60,7 @@ public: virtual ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd) = 0; virtual ErrCode AppIncrementalDone(ErrCode errCode) = 0; virtual ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) = 0; - virtual Errcode GetBackupInfo(BundleName &BundleName, std::string &result) = 0; + virtual ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) = 0; DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.Filemanagement.Backup.IService") }; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h b/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h index 9131738cc..3fc047e7d 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/service_proxy.h @@ -51,7 +51,7 @@ public: ErrCode AppIncrementalFileReady(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd) override; ErrCode AppIncrementalDone(ErrCode errCode) override; ErrCode GetIncrementalFileHandle(const std::string &bundleName, const std::string &fileName) override; - Errcode GetBackupInfo(BundleName &BundleName, std::string &result) override; + ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) override; public: explicit ServiceProxy(const sptr &impl) : IRemoteProxy(impl) {} diff --git a/interfaces/kits/js/backup/general_callbacks.h b/interfaces/kits/js/backup/general_callbacks.h index ceb8c5301..51b70f05d 100644 --- a/interfaces/kits/js/backup/general_callbacks.h +++ b/interfaces/kits/js/backup/general_callbacks.h @@ -29,8 +29,8 @@ public: onBundleBegin(env, thisPtr, jsCallbacks.GetProp("onBundleBegin")), onBundleEnd(env, thisPtr, jsCallbacks.GetProp("onBundleEnd")), onAllBundlesEnd(env, thisPtr, jsCallbacks.GetProp("onAllBundlesEnd")), - onBackupServiceDied(env, thisPtr, jsCallbacks.GetProp("onBackupServiceDied"), - onResultReport(env, thisPtr, jsCallbacks.GetProp("onResultReport"))) {}; + onBackupServiceDied(env, thisPtr, jsCallbacks.GetProp("onBackupServiceDied")), + onResultReport(env, thisPtr, jsCallbacks.GetProp("onResultReport")) {}; public: LibN::NAsyncWorkCallback onFileReady; diff --git a/interfaces/kits/js/backup/local_capabilities.cpp b/interfaces/kits/js/backup/local_capabilities.cpp index e8dcdcefb..7f148af77 100644 --- a/interfaces/kits/js/backup/local_capabilities.cpp +++ b/interfaces/kits/js/backup/local_capabilities.cpp @@ -191,7 +191,7 @@ napi_value LocalCapabilities::DoGetBackupInfo(napi_env env, napi_callback_info i } NVal jsBundle(env, funcArg[NARG_POS::FIRST]); auto [succ, bundle, size] = jsBundle.ToUTF8String(); - if (succ) { + if (!succ) { HILOGE(First argument is not string.); NError(EINVAL).ThrowErr(env); return nullptr; @@ -204,7 +204,7 @@ napi_value LocalCapabilities::DoGetBackupInfo(napi_env env, napi_callback_info i return nullptr; } std::string bundleName = bundle.get(); - ErrCode errcode = proxy->GetBackupInfo(bundelName, result); + ErrCode errcode = proxy->GetBackupInfo(bundleName, result); if (errcode != 0) { HILOGE("proxy->GetBackupInfo faild."); return nullptr; diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index b32d24d45..c5f9b5059 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -949,7 +949,7 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) } thisPtr->getBackupInfoCondition_.notify_one(); }; - backupConnection->setCallback(callConnDone); + backupConnection->SetCallback(callConnDone); IServiceReverse::Scenario scenario = session_->GetScenario(); BConstants::ExtensionAction action; @@ -977,7 +977,7 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) backUpConnection->ConnectBackupExtAbility(want, session_->GetSessionUserId()); HILOGD("GetBackupInfo getBackupInfoMtx_ lock."); - std::unique_lock lock(getBackupInfoMtx_); + std::unique_lock lock(getBackupInfoMutx_); getBackupInfoCondition_.wait_for(lock, std::chrono::seconds(CONNECT_WAIT_TIME)); HILOGD("GetBackupInfo getBackupInfoMtx_ unlock."); auto proxy = backupConnection->GetBackupExtProxy(); diff --git a/services/backup_sa/src/module_ipc/service_stub.cpp b/services/backup_sa/src/module_ipc/service_stub.cpp index 29b4709e2..83aa61450 100644 --- a/services/backup_sa/src/module_ipc/service_stub.cpp +++ b/services/backup_sa/src/module_ipc/service_stub.cpp @@ -291,9 +291,6 @@ int32_t ServiceStub::CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply) if (ret != ERR_OK) { return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call GetBackupInfo")); } - if (!data.ReadString(bundleName)) { - return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); - } if (!reply.WriteString(result)) { return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); } -- Gitee From 3e707313cde0b5098b7946f8066953e952aadeea Mon Sep 17 00:00:00 2001 From: libuyan <1014734367@qq.com> Date: Sun, 24 Mar 2024 17:01:13 +0800 Subject: [PATCH 03/15] add target Signed-off-by: libuyan <1014734367@qq.com> --- frameworks/native/backup_ext/src/ext_backup_js.cpp | 12 +++++++----- frameworks/native/backup_ext/src/ext_extension.cpp | 8 ++++---- interfaces/kits/js/backup/local_capabilities.cpp | 2 +- .../kits/js/backup/session_restore_n_exporter.cpp | 2 +- .../include/module_ipc/svc_session_manager.h | 2 +- services/backup_sa/src/module_ipc/service.cpp | 10 +++++----- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/frameworks/native/backup_ext/src/ext_backup_js.cpp b/frameworks/native/backup_ext/src/ext_backup_js.cpp index 8adf2be9e..8faa8fcfe 100644 --- a/frameworks/native/backup_ext/src/ext_backup_js.cpp +++ b/frameworks/native/backup_ext/src/ext_backup_js.cpp @@ -293,32 +293,34 @@ ErrCode ExtBackupJs::OnRestore(function callback) ErrCode ExtBackupJs::GetBackupInfo(std::function callback) { - HILOGI("BackupExtensionAbulity(JS) GetBackupInfo begin."); + HILOGI("BackupExtensionAbility(JS) GetBackupInfo begin."); BExcepUltils::BAssert(jsObj_, BError::Codes::EXT_BROKEN_FRAMEWORK, "The app does not provide the GetBackupInfo interface."); - callbackInfo_ = std::make_share(callbcak); + callbackInfo_ = std::make_shared(callback); auto retParser = [jsRuntime {&jsRuntime_}, callBackInfo {callbackInfo_}](napi_env env, napi_value result) -> bool { if (!CheckPromise(env, result)) { size_t strLen = 0; - napi_status = napi_get_value_string_utf8(env, result, nullptr, -1, &strLen); + napi_status status = napi_get_value_string_utf8(env, result, nullptr, -1, &strLen); if (status != napi_ok) { return false; } size_t bufLen = strLen + 1; - unique_ptr str = make_unique(buflen); + unique_ptr str = make_unique(bufLen); status = napi_get_value_string_utf8(env, result, str.get(), bufLen, &strLen); callBackInfo->callbackParam(str.get()); return true; } HILOGI("BackupExtensionAbulity(JS) GetBackupInfo ok."); - } + return CallPromise(*jsRuntime, result, callBackInfo.get()); + }; auto errCode = CallJsMethod("getBackupInfo", jsRuntime_, jsObj_.get(), {}, retParser); if (errCode != ERR_OK) { HILOGE("CallJsMethod error, code:%{public}d.", errCode); } HILOGI("BackupExtensionAbulity(JS) GetBackupInfo end."); + return errCode; } static int DoCallJsMethod(CallJsParam *param) diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 6edec334d..06b1d4e8d 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -1585,8 +1585,8 @@ ErrCode GetBackupInfo(std::string &result) try { auto obj = wptr(this); auto ptr = obj.promote(); - auto callbackup = [ptr](std::string result) { - HILOGI("GetBackupInfo callbackup start. result = %s", result); + auto callBackup = [ptr](std::string result) { + HILOGI("GetBackupInfo callBackup start. result = %s", result.c_str()); ptr->backupInfo_ = result; ptr->getEtsInfoCondition_.notify_one(); } @@ -1601,10 +1601,10 @@ ErrCode GetBackupInfo(std::string &result) HILOGD("GetBackupInfo getEtsInfoMtx_ unlock."); result = backupInfo_; - backupInfo.clear(); + backupInfo_.clear(); return ERR_OK; - } catch (const Errpr &e) { + } catch (const BError &e) { HILOGE("Catched an unexpected low-level exception %{public}s", e.what()); return BError(BError::Codes::EXT_INVAL_ARG, "extension getBackupInfo exception").GetCode(); } diff --git a/interfaces/kits/js/backup/local_capabilities.cpp b/interfaces/kits/js/backup/local_capabilities.cpp index 7f148af77..50a233922 100644 --- a/interfaces/kits/js/backup/local_capabilities.cpp +++ b/interfaces/kits/js/backup/local_capabilities.cpp @@ -192,7 +192,7 @@ napi_value LocalCapabilities::DoGetBackupInfo(napi_env env, napi_callback_info i NVal jsBundle(env, funcArg[NARG_POS::FIRST]); auto [succ, bundle, size] = jsBundle.ToUTF8String(); if (!succ) { - HILOGE(First argument is not string.); + HILOGE("First argument is not string."); NError(EINVAL).ThrowErr(env); return nullptr; } diff --git a/interfaces/kits/js/backup/session_restore_n_exporter.cpp b/interfaces/kits/js/backup/session_restore_n_exporter.cpp index 45753cc9b..706602119 100644 --- a/interfaces/kits/js/backup/session_restore_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_restore_n_exporter.cpp @@ -324,7 +324,7 @@ napi_value SessionRestoreNExporter::Constructor(napi_env env, napi_callback_info .onBundleStarted = bind(onBundleBegin, restoreEntity->callbacks, placeholders::_1, placeholders::_2), .onBundleFinished = bind(onBundleEnd, restoreEntity->callbacks, placeholders::_1, placeholders::_2), .onAllBundlesFinished = bind(onAllBundlesEnd, restoreEntity->callbacks, placeholders::_1), - .onResultReport = bind(onResultReport, backupEntity->callbacks, placeholders::_1, placeholders::_2), + .onResultReport = bind(onResultReport, restoreEntity->callbacks, placeholders::_1, placeholders::_2), .onBackupServiceDied = bind(OnBackupServiceDied, restoreEntity->callbacks)}); } if (!restoreEntity->sessionWhole && !restoreEntity->sessionSheet) { diff --git a/services/backup_sa/include/module_ipc/svc_session_manager.h b/services/backup_sa/include/module_ipc/svc_session_manager.h index ca5dd8bdd..12c647180 100644 --- a/services/backup_sa/include/module_ipc/svc_session_manager.h +++ b/services/backup_sa/include/module_ipc/svc_session_manager.h @@ -258,7 +258,7 @@ public: * * @param bundleName 应用名称 */ - void CreateBackupConnection(const std::string &bundleName); + void CreateBackupConnection(BundleName &bundleName); /** * @brief 开始备份 diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index c5f9b5059..70b645946 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -938,10 +938,10 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) try { HILOGI("Service::GetBackupInfo begin."); session_->IncreaseSessionCnt(); - session->CreateBackupConnection(bundleName); + session_->CreateBackupConnection(bundleName); auto backupConnection = session_->GetExtConnection(bundleName); auto callConnDone = [ptr {wptr(this)}](const string &&bundleName) { - HILOGI(callConnDone begin.); + HILOGI("callConnDone begin."); auto thisPtr = ptr.promote(); if (!thisPtr) { HILOGW("this pointer is null."); @@ -974,7 +974,7 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) want.SetParam(BConstants::EXTENSION_RESTORE_TYPE_PARA, static_cast(restoreType)); want.SetParam(BConstants::EXTENSION_VERSION_NAME_PARA, versionName); - backUpConnection->ConnectBackupExtAbility(want, session_->GetSessionUserId()); + backupConnection->ConnectBackupExtAbility(want, session_->GetSessionUserId()); HILOGD("GetBackupInfo getBackupInfoMtx_ lock."); std::unique_lock lock(getBackupInfoMutx_); @@ -986,14 +986,14 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) } auto ret = proxy->GetBackupInfo(result); - backUpConnection->DisconnectBackupExtAbility(); + backupConnection->DisconnectBackupExtAbility(); if (ret != ERR_OK) { HILOGE("Call Ext GetBackupInfo faild."); return BError(BError::Codes::SA_INVAL_ARG); } HILOGI("Service::GetBackupInfo end. result: %s", result.c_str()); - session_->DeceaseSessionCnt(); + session_->DecreaseSessionCnt(); return BError(BError::Codes::OK); } catch (const BError &e) { session_->DecreaseSessionCnt(); -- Gitee From d3bc9f73f58ac5ad8438e6cf742ee90ea6992dcf Mon Sep 17 00:00:00 2001 From: libuyan <1014734367@qq.com> Date: Sun, 24 Mar 2024 17:03:10 +0800 Subject: [PATCH 04/15] add target Signed-off-by: libuyan <1014734367@qq.com> --- services/backup_sa/src/module_ipc/service.cpp | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 70b645946..2a445b7cd 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -950,7 +950,6 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) thisPtr->getBackupInfoCondition_.notify_one(); }; backupConnection->SetCallback(callConnDone); - IServiceReverse::Scenario scenario = session_->GetScenario(); BConstants::ExtensionAction action; if (scenario == IServiceReverse::Scenario::BACKUP) { @@ -960,26 +959,19 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) } else { throw BError(BError::Codes::SA_INVAL_ARG, "Failed to scenario"); } - AAFwk::Want want; string backupExtName = session_->GetBackupExtName(bundleName); /* new device app ext name */ - HILOGD("backupExtName: %{public}s, bundleName: %{public}s", backupExtName.data(), bundleName.data()); string versionName = session_->GetBundleVersionName(bundleName); /* old device app version name */ uint32_t versionCode = session_->GetBundleVersionCode(bundleName); /* old device app version code */ RestoreTypeEnum restoreType = session_->GetBundleRestoreType(bundleName); /* app restore type */ - want.SetElementName(bundleName, backupExtName); want.SetParam(BConstants::EXTENSION_ACTION_PARA, static_cast(action)); want.SetParam(BConstants::EXTENSION_VERSION_CODE_PARA, static_cast(versionCode)); want.SetParam(BConstants::EXTENSION_RESTORE_TYPE_PARA, static_cast(restoreType)); want.SetParam(BConstants::EXTENSION_VERSION_NAME_PARA, versionName); - backupConnection->ConnectBackupExtAbility(want, session_->GetSessionUserId()); - - HILOGD("GetBackupInfo getBackupInfoMtx_ lock."); std::unique_lock lock(getBackupInfoMutx_); getBackupInfoCondition_.wait_for(lock, std::chrono::seconds(CONNECT_WAIT_TIME)); - HILOGD("GetBackupInfo getBackupInfoMtx_ unlock."); auto proxy = backupConnection->GetBackupExtProxy(); if (!proxy) { throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); @@ -991,18 +983,9 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) HILOGE("Call Ext GetBackupInfo faild."); return BError(BError::Codes::SA_INVAL_ARG); } - HILOGI("Service::GetBackupInfo end. result: %s", result.c_str()); session_->DecreaseSessionCnt(); return BError(BError::Codes::OK); - } catch (const BError &e) { - session_->DecreaseSessionCnt(); - HILOGE("GetBackupInfo failed, errCode = %{public}d", e.GetCode()); - return UniqueFd(-e.GetCode()); - } catch (const exception &e) { - session_->DecreaseSessionCnt(); - HILOGI("Catched an unexpected low-level exception %{public}s", e.what()); - return UniqueFd(-EPERM); } catch (...) { session_->DecreaseSessionCnt(); HILOGI("Unexpected exception"); -- Gitee From 1a65101d1aa3811bcda9d213f743d6a3087f1616 Mon Sep 17 00:00:00 2001 From: libuyan <1014734367@qq.com> Date: Sun, 24 Mar 2024 17:03:50 +0800 Subject: [PATCH 05/15] add target Signed-off-by: libuyan <1014734367@qq.com> --- services/backup_sa/src/module_ipc/service.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 2a445b7cd..e43bd663d 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -977,7 +977,6 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); } auto ret = proxy->GetBackupInfo(result); - backupConnection->DisconnectBackupExtAbility(); if (ret != ERR_OK) { HILOGE("Call Ext GetBackupInfo faild."); -- Gitee From 042c6e70ff386d852622fac3cfa74e2c30bcfa44 Mon Sep 17 00:00:00 2001 From: libuyan <1014734367@qq.com> Date: Mon, 25 Mar 2024 15:06:28 +0800 Subject: [PATCH 06/15] add target Signed-off-by: libuyan <1014734367@qq.com> --- frameworks/native/backup_ext/include/ext_backup_js.h | 2 +- frameworks/native/backup_ext/src/ext_extension.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/native/backup_ext/include/ext_backup_js.h b/frameworks/native/backup_ext/include/ext_backup_js.h index ed9ce3bdb..5c76b2df4 100644 --- a/frameworks/native/backup_ext/include/ext_backup_js.h +++ b/frameworks/native/backup_ext/include/ext_backup_js.h @@ -120,7 +120,7 @@ private: AbilityRuntime::JsRuntime &jsRuntime_; std::unique_ptr jsObj_; std::shared_ptr callbackInfo_; - std::shared_ptr CallBackInfoEx_; + std::shared_ptr callbackInfoEx_; }; } // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 06b1d4e8d..47cf3cb3b 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -1580,7 +1580,7 @@ void BackupExtExtension::AppIncrementalDone(ErrCode errCode) } } -ErrCode GetBackupInfo(std::string &result) +ErrCode BackupExtExtension::GetBackupInfo(std::string &result) { try { auto obj = wptr(this); @@ -1589,7 +1589,7 @@ ErrCode GetBackupInfo(std::string &result) HILOGI("GetBackupInfo callBackup start. result = %s", result.c_str()); ptr->backupInfo_ = result; ptr->getEtsInfoCondition_.notify_one(); - } + }; auto ret = ptr->extension_->GetBackupInfo(callBackup); if (ret != ERR_OK) { HILOGE("Failed to notify the app done. err = %{public}d", ret); -- Gitee From 4f6feb0740b5c0c466a5359ac1bc44d86b35d1c0 Mon Sep 17 00:00:00 2001 From: libuyan <1014734367@qq.com> Date: Mon, 25 Mar 2024 15:19:18 +0800 Subject: [PATCH 07/15] add target Signed-off-by: libuyan <1014734367@qq.com> --- .../native/backup_ext/src/ext_extension.cpp | 2 +- .../backup_sa/include/module_ipc/service.h | 7 +++ services/backup_sa/src/module_ipc/service.cpp | 44 +++++++++++-------- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 47cf3cb3b..5cdf006e1 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -1608,5 +1608,5 @@ ErrCode BackupExtExtension::GetBackupInfo(std::string &result) HILOGE("Catched an unexpected low-level exception %{public}s", e.what()); return BError(BError::Codes::EXT_INVAL_ARG, "extension getBackupInfo exception").GetCode(); } -} +} } // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index f17cbe086..6aaa3e7d1 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -114,6 +114,13 @@ public: * */ void SessionDeactive(); + /** + * @brief 构造拉起应用所需的want + * + * @param bundleName 应用名称 + * + */ + AAFwk::Want CreateConnectWant (BundleName &bundleName); public: explicit Service(int32_t saID, bool runOnCreate = false) : SystemAbility(saID, runOnCreate) diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index e43bd663d..fe44a5ee9 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -950,25 +950,7 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) thisPtr->getBackupInfoCondition_.notify_one(); }; backupConnection->SetCallback(callConnDone); - IServiceReverse::Scenario scenario = session_->GetScenario(); - BConstants::ExtensionAction action; - if (scenario == IServiceReverse::Scenario::BACKUP) { - action = BConstants::ExtensionAction::BACKUP; - } else if (scenario == IServiceReverse::Scenario::RESTORE) { - action = BConstants::ExtensionAction::RESTORE; - } else { - throw BError(BError::Codes::SA_INVAL_ARG, "Failed to scenario"); - } - AAFwk::Want want; - string backupExtName = session_->GetBackupExtName(bundleName); /* new device app ext name */ - string versionName = session_->GetBundleVersionName(bundleName); /* old device app version name */ - uint32_t versionCode = session_->GetBundleVersionCode(bundleName); /* old device app version code */ - RestoreTypeEnum restoreType = session_->GetBundleRestoreType(bundleName); /* app restore type */ - want.SetElementName(bundleName, backupExtName); - want.SetParam(BConstants::EXTENSION_ACTION_PARA, static_cast(action)); - want.SetParam(BConstants::EXTENSION_VERSION_CODE_PARA, static_cast(versionCode)); - want.SetParam(BConstants::EXTENSION_RESTORE_TYPE_PARA, static_cast(restoreType)); - want.SetParam(BConstants::EXTENSION_VERSION_NAME_PARA, versionName); + AAFwk::Want want = CreateConnectWant(bundleName); backupConnection->ConnectBackupExtAbility(want, session_->GetSessionUserId()); std::unique_lock lock(getBackupInfoMutx_); getBackupInfoCondition_.wait_for(lock, std::chrono::seconds(CONNECT_WAIT_TIME)); @@ -991,4 +973,28 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) return UniqueFd(-EPERM); } } + +AAFwk::Want Service::CreateConnectWant (BundleName &bundleName) +{ + IServiceReverse::Scenario scenario = session_->GetScenario(); + BConstants::ExtensionAction action; + if (scenario == IServiceReverse::Scenario::BACKUP) { + action = BConstants::ExtensionAction::BACKUP; + } else if (scenario == IServiceReverse::Scenario::RESTORE) { + action = BConstants::ExtensionAction::RESTORE; + } else { + throw BError(BError::Codes::SA_INVAL_ARG, "Failed to scenario"); + } + AAFwk::Want want; + string backupExtName = session_->GetBackupExtName(bundleName); /* new device app ext name */ + string versionName = session_->GetBundleVersionName(bundleName); /* old device app version name */ + uint32_t versionCode = session_->GetBundleVersionCode(bundleName); /* old device app version code */ + RestoreTypeEnum restoreType = session_->GetBundleRestoreType(bundleName); /* app restore type */ + want.SetElementName(bundleName, backupExtName); + want.SetParam(BConstants::EXTENSION_ACTION_PARA, static_cast(action)); + want.SetParam(BConstants::EXTENSION_VERSION_CODE_PARA, static_cast(versionCode)); + want.SetParam(BConstants::EXTENSION_RESTORE_TYPE_PARA, static_cast(restoreType)); + want.SetParam(BConstants::EXTENSION_VERSION_NAME_PARA, versionName); + return want; +} } // namespace OHOS::FileManagement::Backup -- Gitee From 8e63018cdde12fd6e46b12456bc8046160acf050 Mon Sep 17 00:00:00 2001 From: libuyan <1014734367@qq.com> Date: Tue, 26 Mar 2024 08:24:56 +0800 Subject: [PATCH 08/15] add UT Signed-off-by: libuyan <1014734367@qq.com> --- .../b_session_restore_async_mock.cpp | 2 +- .../backup_kit_inner/service_proxy_mock.cpp | 5 +++ tests/mock/module_ipc/service_mock.cpp | 5 +++ .../module_ipc/service_reverse_proxy_mock.cpp | 2 + tests/mock/module_ipc/service_stub_mock.cpp | 14 +++++++ .../module_ipc/svc_extension_proxy_mock.cpp | 5 +++ .../module_ipc/svc_session_manager_mock.cpp | 9 +++++ .../b_session_restore_async_test.cpp | 7 ++++ .../b_session_restore_test.cpp | 6 +++ .../backup_impl/include/ext_extension_mock.h | 5 +++ .../backup_impl/include/i_service_mock.h | 5 +++ .../include/service_reverse_mock.h | 1 + .../backup_impl/service_proxy_test.cpp | 24 ++++++++++++ .../backup_impl/service_reverse_stub_test.cpp | 39 +++++++++++++++++++ .../backup_impl/service_reverse_test.cpp | 26 ++++++++++++- .../module_ipc/service_reverse_proxy_test.cpp | 25 ++++++++++++ .../module_ipc/service_stub_test.cpp | 33 ++++++++++++++++ .../backup_sa/module_ipc/service_test.cpp | 23 +++++++++++ .../module_ipc/svc_extension_proxy_test.cpp | 25 ++++++++++++ 19 files changed, 259 insertions(+), 2 deletions(-) diff --git a/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp b/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp index a80632f9b..d61a41388 100644 --- a/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp +++ b/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp @@ -89,7 +89,7 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, callbacks_.onBundleStarted(1, "com.example.app2backup"); callbacks_.onBundleFinished(1, "com.example.app2backup"); callbacks_.onAllBundlesFinished(1); - + callbacks_.onResultReport(0, "com.example.app2backup"); callbacks_.onBackupServiceDied(); return BError(BError::Codes::OK); } diff --git a/tests/mock/backup_kit_inner/service_proxy_mock.cpp b/tests/mock/backup_kit_inner/service_proxy_mock.cpp index 1d9217548..25cbe64e7 100644 --- a/tests/mock/backup_kit_inner/service_proxy_mock.cpp +++ b/tests/mock/backup_kit_inner/service_proxy_mock.cpp @@ -138,6 +138,11 @@ ErrCode ServiceProxy::GetIncrementalFileHandle(const std::string &bundleName, co return BError(BError::Codes::OK); } +ErrCode ServiceProxy::GetBackupInfo(std::string &bundleName, std::string &result) +{ + return BError(BError::Codes::OK); +} + sptr ServiceProxy::GetInstance() { if (!GetMockGetInstance()) { diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index cb41e78f0..38648a1ad 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -171,4 +171,9 @@ ErrCode Service::GetIncrementalFileHandle(const string &bundleName, const string { return BError(BError::Codes::OK); } + +ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) +{ + return BError(BError::Codes::OK); +} } // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_ipc/service_reverse_proxy_mock.cpp b/tests/mock/module_ipc/service_reverse_proxy_mock.cpp index 3123ee3d7..c52642c43 100644 --- a/tests/mock/module_ipc/service_reverse_proxy_mock.cpp +++ b/tests/mock/module_ipc/service_reverse_proxy_mock.cpp @@ -36,6 +36,8 @@ void ServiceReverseProxy::RestoreOnAllBundlesFinished(int32_t errCode) {} void ServiceReverseProxy::RestoreOnFileReady(string bundleName, string fileName, int fd) {} +void ServiceReverseProxy::RestoreOnResultReport(string result) {} + void ServiceReverseProxy::IncrementalBackupOnFileReady(string bundleName, string fileName, int fd, int manifestFd) {} void ServiceReverseProxy::IncrementalBackupOnBundleStarted(int32_t errCode, string bundleName) {} diff --git a/tests/mock/module_ipc/service_stub_mock.cpp b/tests/mock/module_ipc/service_stub_mock.cpp index 7ae9cced2..bcc3e4e40 100644 --- a/tests/mock/module_ipc/service_stub_mock.cpp +++ b/tests/mock/module_ipc/service_stub_mock.cpp @@ -59,6 +59,8 @@ ServiceStub::ServiceStub() &ServiceStub::CmdAppIncrementalFileReady; opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_INCREMENTAL_FILE_NAME)] = &ServiceStub::CmdGetIncrementalFileHandle; + opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_INFO)] = + &ServiceStub::CmdGetBackupInfo; } int32_t ServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) @@ -175,6 +177,18 @@ int32_t ServiceStub::CmdFinish(MessageParcel &data, MessageParcel &reply) return BError(BError::Codes::OK); } +int32_t ServiceStub::CmdGetBackupInfo(MessageParcel &data, MessageParcel &reply) +{ + int ret = ERR_OK; + string bundleName; + if (!data.ReadString(bundleName)) { + return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to recive bundleName")); + } + std::string result; + ret = GetBackupInfo(bundleName, result); + return BError(BError::Codes::OK); +} + int32_t ServiceStub::CmdRelease(MessageParcel &data, MessageParcel &reply) { int res = Release(); diff --git a/tests/mock/module_ipc/svc_extension_proxy_mock.cpp b/tests/mock/module_ipc/svc_extension_proxy_mock.cpp index a973df624..577db8a21 100644 --- a/tests/mock/module_ipc/svc_extension_proxy_mock.cpp +++ b/tests/mock/module_ipc/svc_extension_proxy_mock.cpp @@ -43,6 +43,11 @@ ErrCode SvcExtensionProxy::HandleRestore() return 0; } +ErrCode SvcExtensionProxy::GetBackupInfo(std::string &result) +{ + return 0; +} + ErrCode SvcExtensionProxy::GetIncrementalFileHandle(const string &fileName) { return 0; diff --git a/tests/mock/module_ipc/svc_session_manager_mock.cpp b/tests/mock/module_ipc/svc_session_manager_mock.cpp index 386bc4a52..69f45fd8d 100644 --- a/tests/mock/module_ipc/svc_session_manager_mock.cpp +++ b/tests/mock/module_ipc/svc_session_manager_mock.cpp @@ -202,6 +202,15 @@ void SvcSessionManager::AppendBundles(const vector &bundleNames) impl_.backupExtNameMap.insert(make_pair("com.example.app2backup", info)); } +void SvcSessionManager::CreateBackupConnection(BundleName &bundleName) +{ + GTEST_LOG_(INFO) << "CreateBackupConnection"; + BackupExtInfo info {}; + info.backUpConnection = GetBackupExtAbility("com.example.app2backup"); + info.backupExtName = "com.example.app2backup"; + impl_.backupExtNameMap.insert(make_pair("com.example.app2backup", info)); +} + void SvcSessionManager::Start() {} void SvcSessionManager::Finish() {} diff --git a/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp b/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp index e9badac6b..063e54607 100644 --- a/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp +++ b/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp @@ -54,6 +54,11 @@ static void OnBackupServiceDied() GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest OnBackupServiceDied OK"; } +static void OnResultReport(ErrCode err, std::string result) +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest OnResultReport OK"; +} + class BSessionRestoreAsyncTest : public testing::Test { public: static void SetUpTestCase(void) {}; @@ -87,6 +92,7 @@ void BSessionRestoreAsyncTest::Init() callbacks_.onBundleFinished = OnBundleFinished; callbacks_.onAllBundlesFinished = OnAllBundlesFinished; callbacks_.onBackupServiceDied = OnBackupServiceDied; + callbacks_.onResultReport = OnResultReport; } /** @@ -109,6 +115,7 @@ HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_0100, test callbacks_.onBundleFinished(ErrCode(BError::Codes::OK), ""); callbacks_.onAllBundlesFinished(ErrCode(BError::Codes::OK)); callbacks_.onBackupServiceDied(); + callbacks_.onResultReport(ErrCode(BError::Codes::OK), ""); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-an exception occurred by Callbacks."; diff --git a/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp b/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp index 77bded075..8afe29786 100644 --- a/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp +++ b/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp @@ -55,6 +55,11 @@ static void OnBackupServiceDied() GTEST_LOG_(INFO) << "BSessionRestoreTest OnBackupServiceDied OK"; } +static void OnResultReport(ErrCode err, const std::string result) +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest OnResultReport OK"; +} + class BSessionRestoreTest : public testing::Test { public: static void SetUpTestCase(void) {}; @@ -88,6 +93,7 @@ void BSessionRestoreTest::Init() callbacks_.onBundleFinished = OnBundleFinished; callbacks_.onAllBundlesFinished = OnAllBundlesFinished; callbacks_.onBackupServiceDied = OnBackupServiceDied; + callbacks_.onResultReport = OnResultReport; } /** diff --git a/tests/unittests/backup_api/backup_impl/include/ext_extension_mock.h b/tests/unittests/backup_api/backup_impl/include/ext_extension_mock.h index b24f09103..963051d78 100644 --- a/tests/unittests/backup_api/backup_impl/include/ext_extension_mock.h +++ b/tests/unittests/backup_api/backup_impl/include/ext_extension_mock.h @@ -117,6 +117,11 @@ public: return {UniqueFd(-1), UniqueFd(-1)}; }; + ErrCode GetBackupInfo(std::string &result) override + { + return BError(BError::Codes::OK); + }; + private: int32_t nHandleBackupNum_ = 0; }; diff --git a/tests/unittests/backup_api/backup_impl/include/i_service_mock.h b/tests/unittests/backup_api/backup_impl/include/i_service_mock.h index 9c4a84cc7..e3e79cab4 100644 --- a/tests/unittests/backup_api/backup_impl/include/i_service_mock.h +++ b/tests/unittests/backup_api/backup_impl/include/i_service_mock.h @@ -111,6 +111,11 @@ public: return BError(BError::Codes::OK); } + ErrCode GetBackupInfo(BundleName &bundleName, std::string &result) override + { + return BError(BError::Codes::OK); + } + ErrCode Release() override { return BError(BError::Codes::OK); diff --git a/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h b/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h index bd08b8ce5..a9a0539ad 100644 --- a/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h +++ b/tests/unittests/backup_api/backup_impl/include/service_reverse_mock.h @@ -45,6 +45,7 @@ public: void RestoreOnBundleFinished(int32_t errCode, std::string bundleName) override {} void RestoreOnAllBundlesFinished(int32_t errCode) override {} void RestoreOnFileReady(std::string bundleName, std::string fileName, int fd) override {} + void RestoreOnResultReport(std::string result) override {} void IncrementalBackupOnFileReady(std::string bundleName, std::string fileName, int fd, int manifestFd) override {} void IncrementalBackupOnBundleStarted(int32_t errCode, std::string bundleName) override {} diff --git a/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp b/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp index 72f7167a7..bbb9ed6ac 100644 --- a/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp +++ b/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp @@ -32,6 +32,7 @@ using namespace std; using namespace testing; namespace { +const string BUNDLE_NAME = "com.example.app2backup"; const string FILE_NAME = "1.tar"; constexpr int32_t SERVICE_ID = 5203; } // namespace @@ -686,4 +687,27 @@ HWTEST_F(ServiceProxyTest, SUB_Service_proxy_InvaildInstance_0100, testing::ext: ServiceProxy::InvaildInstance(); GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_InvaildInstance_0100"; } + +/** + * @tc.number: SUB_Service_proxy_GetBackupInfo_0100 + * @tc.name: SUB_Service_proxy_GetBackupInfo_0100 + * @tc.desc: 测试 GetBackupInfo 获取应用信息接口调用成功和失败 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetBackupInfo_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetBackupInfo_0100"; + EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) + .Times(2) + .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeGetLocalSendRequest)) + .WillOnce(Return(EPERM)); + std::string result; + std::string bundleName = "com.example.app2backup"; + int32_t ret = proxy_->GetBackupInfo(bundleName, result); + EXPECT_EQ(ret, BError(BError::Codes::OK)); + GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_GetBackupInfo_0100"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp b/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp index 4af64cdb4..08e9f171e 100644 --- a/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp +++ b/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp @@ -48,6 +48,7 @@ public: MOCK_METHOD2(RestoreOnBundleFinished, void(int32_t errCode, string bundleName)); MOCK_METHOD1(RestoreOnAllBundlesFinished, void(int32_t errCode)); MOCK_METHOD3(RestoreOnFileReady, void(string bundleName, string fileName, int fd)); + MOCK_METHOD1(RestoreOnResultReport, void(string result)); MOCK_METHOD4(IncrementalBackupOnFileReady, void(string bundleName, string fileName, int fd, int manifestFd)); MOCK_METHOD2(IncrementalBackupOnBundleStarted, void(int32_t errCode, string bundleName)); MOCK_METHOD2(IncrementalBackupOnBundleFinished, void(int32_t errCode, string bundleName)); @@ -707,4 +708,42 @@ HWTEST_F(ServiceReverseStubTest, } GTEST_LOG_(INFO) << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_IncrementalRestoreOnFileReady_0100"; } + +/** + * @tc.number: SUB_backup_ServiceReverseStub_RestoreOnResultReport_0100 + * @tc.name: SUB_backup_ServiceReverseStub_RestoreOnResultReport_0100 + * @tc.desc: Test function of RestoreOnResultReport interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I90ZZX + */ +HWTEST_F(ServiceReverseStubTest, + SUB_backup_ServiceReverseStub_RestoreOnResultReport_0100, + testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) + << "ServiceReverseStubTest-begin SUB_backup_ServiceReverseStub_RestoreOnResultReport_0100"; + try { + MockServiceReverse service; + EXPECT_CALL(service, RestoreOnResultReport(_)).WillOnce(Return()); + MessageParcel data; + MessageParcel reply; + MessageOption option; + std::string resultReport = "resultReport"; + EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); + EXPECT_TRUE(data.WriteString(resultReport)); + + EXPECT_EQ( + BError(BError::Codes::OK), + service.OnRemoteRequest( + static_cast(IServiceReverseInterfaceCode::SERVICER_RESTORE_ON_RESULT_REPORT), + data, reply, option)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseStubTest-an exception occurred by RestoreOnResultReport."; + } + GTEST_LOG_(INFO) + << "ServiceReverseStubTest-end SUB_backup_ServiceReverseStub_RestoreOnResultReport_0100"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp b/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp index 5c663ff2f..87a1c9d3b 100644 --- a/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp +++ b/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp @@ -112,7 +112,8 @@ void ServiceReverseTest::Init(IServiceReverse::Scenario scenario, int nType) .onBundleStarted = bind(OnBundleStartedTest, placeholders::_1, placeholders::_2), .onBundleFinished = bind(OnBundleFinishedTest, placeholders::_1, placeholders::_2), .onAllBundlesFinished = bind(OnAllBundlesFinishedTest, placeholders::_1), - .onBackupServiceDied = bind(OnBackupServiceDiedTest)}); + .onBackupServiceDied = bind(OnBackupServiceDiedTest), + .onResultReport = bind(OnBundleFinishedTest, placeholders::_1, placeholders::_2)}); } } } @@ -1201,4 +1202,27 @@ HWTEST_F(ServiceReverseTest, } GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_IncrementalRestoreOnAllBundlesFinished_0101"; } + +/** + * @tc.number: SUB_backup_ServiceReverse_RestoreOnResultReport_0100 + * @tc.name: SUB_backup_ServiceReverse_RestoreOnResultReport_0100 + * @tc.desc: 测试 RestoreOnResultReport 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseTest, SUB_backup_ServiceReverse_RestoreOnResultReport_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseTest-begin SUB_backup_ServiceReverse_RestoreOnResultReport_0100"; + try { + Init(IServiceReverse::Scenario::BACKUP); + std::string resultReport = "result_report"; + service_->RestoreOnResultReport(resultReport); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseTest-an exception occurred by RestoreOnResultReport."; + } + GTEST_LOG_(INFO) << "ServiceReverseTest-end SUB_backup_ServiceReverse_RestoreOnResultReport_0100"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp b/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp index 4b23b74fb..edc7f4e47 100644 --- a/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp @@ -35,6 +35,7 @@ namespace { const string BUNDLE_NAME = "com.example.app2backup"; const string FILE_NAME = "1.tar"; const string FILE_NAME_MANIFEST = "manifest.rp"; +const string RESULT_REPORT = "result report"; } // namespace class ServiceReverseProxyTest : public testing::Test { @@ -488,4 +489,28 @@ HWTEST_F(ServiceReverseProxyTest, } GTEST_LOG_(INFO) << "ServiceReverseProxyTest-end SUB_ServiceReverse_proxy_IncrementalRestoreOnFileReady_0100"; } + +/** + * @tc.number: SUB_ServiceReverse_proxy_RestoreOnResultReport_0100 + * @tc.name: SUB_ServiceReverse_proxy_RestoreOnResultReport_0100 + * @tc.desc: Test function of RestoreOnResultReport interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(ServiceReverseProxyTest, SUB_ServiceReverse_proxy_RestoreOnResultReport_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceReverseProxyTest-begin SUB_ServiceReverse_proxy_RestoreOnResultReport_0100"; + try { + EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mock_.GetRefPtr(), &ServiceReverseMock::InvokeSendRequest)); + proxy_->RestoreOnResultReport(RESULT_REPORT); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceReverseProxyTest-an exception occurred by RestoreOnResultReport."; + } + GTEST_LOG_(INFO) << "ServiceReverseProxyTest-end SUB_ServiceReverse_proxy_RestoreOnResultReport_0100"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp index 00723373e..6b630e27d 100644 --- a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp @@ -62,6 +62,7 @@ public: MOCK_METHOD3(AppIncrementalFileReady, ErrCode(const std::string &fileName, UniqueFd fd, UniqueFd manifestFd)); MOCK_METHOD1(AppIncrementalDone, ErrCode(ErrCode errCode)); MOCK_METHOD2(GetIncrementalFileHandle, ErrCode(const std::string &bundleName, const std::string &fileName)); + MOCK_METHOD2(GetBackupInfo, ErrCode(string &bundleName, string &result)); UniqueFd InvokeGetLocalCapabilities() { if (bCapabilities_) { @@ -505,4 +506,36 @@ HWTEST_F(ServiceStubTest, SUB_backup_sa_ServiceStub_Release_0100, testing::ext:: } GTEST_LOG_(INFO) << "ServiceStubTest-end SUB_backup_sa_ServiceStub_Release_0100"; } + +/** + * @tc.number: SUB_backup_sa_ServiceStub_GetBackupInfo_0100 + * @tc.name: SUB_backup_sa_ServiceStub_GetBackupInfo_0100 + * @tc.desc: Test function of GetBackupInfo interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6URNZ + */ +HWTEST_F(ServiceStubTest, SUB_backup_sa_ServiceStub_GetBackupInfo_0100, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "ServiceStubTest-begin SUB_backup_sa_ServiceStub_GetBackupInfo_0100"; + try { + MockService service; + EXPECT_CALL(service, GetBackupInfo(_, _)).WillOnce(Return(BError(BError::Codes::OK))); + MessageParcel data; + MessageParcel reply; + MessageOption option; + std::string bundleName = "com.example.app2backup"; + EXPECT_TRUE(data.WriteInterfaceToken(IService::GetDescriptor())); + EXPECT_TRUE(data.WriteString(bundleName)); + EXPECT_EQ(BError(BError::Codes::OK), + service.OnRemoteRequest( + static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_INFO), data, + reply, option)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceStubTest-an exception occurred by GetBackupInfo."; + } + GTEST_LOG_(INFO) << "ServiceStubTest-end SUB_backup_sa_ServiceStub_GetBackupInfo_0100"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_sa/module_ipc/service_test.cpp b/tests/unittests/backup_sa/module_ipc/service_test.cpp index 7189421ef..39be801ba 100644 --- a/tests/unittests/backup_sa/module_ipc/service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_test.cpp @@ -852,4 +852,27 @@ HWTEST_F(ServiceTest, SUB_Service_SessionDeactive_0100, testing::ext::TestSize.L } GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_SessionDeactive_0100"; } + +/** + * @tc.number: SUB_Service_GetBackupInfo_0100 + * @tc.name: SUB_Service_GetBackupInfo_0100 + * @tc.desc: 测试 SessionDeactive 接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I8ZIMJ + */ +HWTEST_F(ServiceTest, SUB_Service_GetBackupInfo_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceTest-begin SUB_Service_GetBackupInfo_0100"; + try { + std::string bundleName = "com.example.app2backup"; + std::string backupInfo = "backup info"; + servicePtr_->GetBackupInfo(bundleName, backupInfo); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceTest-an exception occurred by GetBackupInfo."; + } + GTEST_LOG_(INFO) << "ServiceTest-end SUB_Service_GetBackupInfo_0100"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_sa/module_ipc/svc_extension_proxy_test.cpp b/tests/unittests/backup_sa/module_ipc/svc_extension_proxy_test.cpp index 708699d79..00305c8c8 100644 --- a/tests/unittests/backup_sa/module_ipc/svc_extension_proxy_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/svc_extension_proxy_test.cpp @@ -144,4 +144,29 @@ HWTEST_F(SvcExtensionProxyTest, SUB_Ext_Extension_proxy_PublishFile_0100, testin EXPECT_NE(BError(BError::Codes::OK), ret); GTEST_LOG_(INFO) << "SvcExtensionProxyTest-end SUB_Ext_Extension_proxy_PublishFile_0100"; } + +/** + * @tc.number: SUB_Ext_Extension_proxy_GetBackupInfo_0100 + * @tc.name: SUB_Ext_Extension_proxy_GetBackupInfo_0100 + * @tc.desc: 测试 GetBackupInfo 接口调用成功和失败 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(SvcExtensionProxyTest, SUB_Ext_Extension_proxy_GetBackupInfo_0100, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SvcExtensionProxyTest-begin SUB_Ext_Extension_proxy_GetBackupInfo_0100"; + EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) + .Times(2) + .WillOnce(Invoke(mock_.GetRefPtr(), &BackupExtExtensionMock::InvokeSendRequest)) + .WillOnce(Return(EPERM)); + string result = "result report"; + ErrCode ret = proxy_->GetBackupInfo(result); + EXPECT_EQ(BError(BError::Codes::OK), ret); + + ret = proxy_->GetBackupInfo(result); + EXPECT_NE(BError(BError::Codes::OK), ret); + GTEST_LOG_(INFO) << "SvcExtensionProxyTest-end SUB_Ext_Extension_proxy_GetBackupInfo_0100"; +} } // namespace OHOS::FileManagement::Backup \ No newline at end of file -- Gitee From 0df3d0cec41698c05a22844098fcb5fc010a1d68 Mon Sep 17 00:00:00 2001 From: libuyan <1014734367@qq.com> Date: Tue, 26 Mar 2024 18:44:11 +0800 Subject: [PATCH 09/15] add target Signed-off-by: libuyan <1014734367@qq.com> --- .../unittests/backup_api/backup_impl/service_proxy_test.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp b/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp index bbb9ed6ac..9ecb14e66 100644 --- a/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp +++ b/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp @@ -701,9 +701,8 @@ HWTEST_F(ServiceProxyTest, SUB_Service_proxy_GetBackupInfo_0100, testing::ext::T { GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_GetBackupInfo_0100"; EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeGetLocalSendRequest)) - .WillOnce(Return(EPERM)); + .Times(1) + .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); std::string result; std::string bundleName = "com.example.app2backup"; int32_t ret = proxy_->GetBackupInfo(bundleName, result); -- Gitee From bec4d61ee078f9c5328b9f6096e7c2615a1db246 Mon Sep 17 00:00:00 2001 From: libuyan <1014734367@qq.com> Date: Thu, 28 Mar 2024 15:44:06 +0800 Subject: [PATCH 10/15] add target Signed-off-by: libuyan <1014734367@qq.com> --- .../native/backup_ext/include/ext_extension.h | 4 +- .../native/backup_ext/src/ext_extension.cpp | 45 +++++++++---------- .../backup_kit_inner/src/service_reverse.cpp | 2 +- .../impl/b_incremental_restore_session.h | 1 - .../backup_kit_inner/impl/b_session_backup.h | 1 - .../backup_kit_inner/impl/b_session_restore.h | 2 +- .../impl/b_session_restore_async.h | 2 +- .../js/backup/session_backup_n_exporter.cpp | 41 ----------------- .../js/backup/session_restore_n_exporter.cpp | 10 ++--- services/backup_sa/src/module_ipc/service.cpp | 4 +- .../b_session_restore_async_mock.cpp | 2 +- .../b_session_restore_async_test.cpp | 4 +- .../b_session_restore_test.cpp | 2 +- 13 files changed, 35 insertions(+), 85 deletions(-) diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index c19e8434c..bf47f8744 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -146,8 +146,8 @@ private: std::shared_mutex lock_; std::shared_ptr extension_; std::vector tars_; - std::mutex getEtsInfoMtx_; - std::condition_variable getEtsInfoCondition_; + std::mutex getExtInfoMtx_; + std::condition_variable getExtInfoCondition_; std::string backupInfo_; OHOS::ThreadPool threadPool_; }; diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 5cdf006e1..98e54a135 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -69,7 +69,7 @@ using namespace std; namespace { const int64_t DEFAULT_SLICE_SIZE = 100 * 1024 * 1024; // 分片文件大小为100M const uint32_t MAX_FILE_COUNT = 6000; // 单个tar包最多包含6000个文件 -const int32_t CONNECT_WAIT_TIME = 5; +const int32_t CONNECT_WAIT_TIME_S = 15; } // namespace void BackupExtExtension::VerifyCaller() @@ -1582,31 +1582,26 @@ void BackupExtExtension::AppIncrementalDone(ErrCode errCode) ErrCode BackupExtExtension::GetBackupInfo(std::string &result) { - try { - auto obj = wptr(this); - auto ptr = obj.promote(); - auto callBackup = [ptr](std::string result) { - HILOGI("GetBackupInfo callBackup start. result = %s", result.c_str()); - ptr->backupInfo_ = result; - ptr->getEtsInfoCondition_.notify_one(); - }; - auto ret = ptr->extension_->GetBackupInfo(callBackup); - if (ret != ERR_OK) { - HILOGE("Failed to notify the app done. err = %{public}d", ret); - BError(BError::Codes::EXT_INVAL_ARG, "extension getBackupInfo exception").GetCode(); - } - HILOGD("GetBackupInfo getEtsInfoMtx_ lock."); - std::unique_lock lock(getEtsInfoMtx_); - getEtsInfoCondition_.wait_for(lock, std::chrono::seconds(CONNECT_WAIT_TIME)); - HILOGD("GetBackupInfo getEtsInfoMtx_ unlock."); - - result = backupInfo_; - backupInfo_.clear(); - - return ERR_OK; - } catch (const BError &e) { - HILOGE("Catched an unexpected low-level exception %{public}s", e.what()); + auto obj = wptr(this); + auto ptr = obj.promote(); + auto callBackup = [ptr](std::string result) { + HILOGI("GetBackupInfo callBackup start. result = %{public}s", result.c_str()); + ptr->backupInfo_ = result; + ptr->getExtInfoCondition_.notify_one(); + }; + auto ret = ptr->extension_->GetBackupInfo(callBackup); + if (ret != ERR_OK) { + HILOGE("Failed to notify the app done. err = %{public}d", ret); return BError(BError::Codes::EXT_INVAL_ARG, "extension getBackupInfo exception").GetCode(); } + HILOGD("GetBackupInfo getExtInfoMtx_ lock."); + std::unique_lock lock(getExtInfoMtx_); + getExtInfoCondition_.wait_for(lock, std::chrono::seconds(CONNECT_WAIT_TIME_S)); + HILOGD("GetBackupInfo getExtInfoMtx_ unlock."); + + result = backupInfo_; + backupInfo_.clear(); + + return ERR_OK; } } // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_kit_inner/src/service_reverse.cpp b/frameworks/native/backup_kit_inner/src/service_reverse.cpp index 5d8d9a030..6df10a366 100644 --- a/frameworks/native/backup_kit_inner/src/service_reverse.cpp +++ b/frameworks/native/backup_kit_inner/src/service_reverse.cpp @@ -106,7 +106,7 @@ void ServiceReverse::RestoreOnFileReady(string bundleName, string fileName, int void ServiceReverse::RestoreOnResultReport(string result) { HILOGI("ServiceReverse RestoreOnResultReport begin with result: %s", result.c_str()); - callbacksRestore_.onResultReport(BError(BError::Codes::OK), result); + callbacksRestore_.onResultReport(result); } ServiceReverse::ServiceReverse(BSessionBackup::Callbacks callbacks) diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h index fcd926e10..020b80db2 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_restore_session.h @@ -35,7 +35,6 @@ public: std::function onBundleFinished; // 当某个应用的恢复流程结束或意外中止时执行的回调函数 std::function onAllBundlesFinished; // 当整个恢复流程结束或意外中止时执行的回调函数 - std::function onResultReport; std::function onBackupServiceDied; // 当备份服务意外死亡时执行的回调函数 }; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h index f8b8c23d0..c662a5844 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_backup.h @@ -33,7 +33,6 @@ public: std::function onBundleStarted; // 当启动某个应用的备份流程结束时执行的回调函数 std::function onBundleFinished; // 当某个应用的备份流程结束或意外中止时执行的回调函数 std::function onAllBundlesFinished; // 当整个备份流程结束或意外中止时执行的回调函数 - std::function onResultReport; std::function onBackupServiceDied; // 当备份服务意外死亡时执行的回调函数 }; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h index 10ac8aa95..d97763fa0 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore.h @@ -33,7 +33,7 @@ public: std::function onBundleStarted; // 当启动某个应用的恢复流程结束时执行的回调函数 std::function onBundleFinished; // 当某个应用的恢复流程结束或意外中止时执行的回调函数 std::function onAllBundlesFinished; // 当整个恢复流程结束或意外中止时执行的回调函数 - std::function onResultReport; + std::function onResultReport; std::function onBackupServiceDied; // 当备份服务意外死亡时执行的回调函数 }; diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h index d2d173e8f..6e7a4df6f 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_session_restore_async.h @@ -37,7 +37,7 @@ public: std::function onBundleFinished; // 当某个应用的恢复流程结束或意外中止时执行的回调函数 std::function onAllBundlesFinished; // 当整个恢复流程结束或意外中止时执行的回调函数 - std::function onResultReport; + std::function onResultReport; std::function onBackupServiceDied; // 当备份服务意外死亡时执行的回调函数 }; diff --git a/interfaces/kits/js/backup/session_backup_n_exporter.cpp b/interfaces/kits/js/backup/session_backup_n_exporter.cpp index b7b918bd9..d3252402c 100644 --- a/interfaces/kits/js/backup/session_backup_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_backup_n_exporter.cpp @@ -204,46 +204,6 @@ static void OnBackupServiceDied(weak_ptr pCallbacks) callbacks->onBackupServiceDied.ThreadSafeSchedule(cbCompl); } -static void onResultReport(weak_ptr pCallbacks, ErrCode err, const std::string result) -{ - HILOGI("callback function onResultReport begin."); - if (pCallbacks.expired()) { - HILOGI("callbacks is unbound"); - return; - } - auto callbacks = pCallbacks.lock(); - if (!callbacks) { - HILOGI("callback function onResultReport has already been released"); - return; - } - if (!bool(callbacks->onResultReport)) { - HILOGI("callback function onResultReport is undefined"); - return; - } - - auto cbCompl = [result {result}, errCode {err}](napi_env env, NError err) -> NVal { - NVal resultStr = NVal::CreateUTF8String(env, result); - if (!err && errCode == 0) { - return resultStr; - } - - NVal res; - if (err) { - res = NVal {env, err.GetNapiErr(env)}; - } else { - res = NVal {env, NError(errCode).GetNapiErr(env)}; - } - napi_status status = napi_set_named_property(env, res.val_, FILEIO_TAG_ERR_DATA.c_str(), resultStr.val_); - if (status != napi_ok) { - HILOGE("Failed to set data property, status %{public}d, bundleName %{public}s", status, result.c_str()); - } - - return res; - }; - - callbacks->onResultReport.ThreadSafeSchedule(cbCompl); -} - napi_value SessionBackupNExporter::Constructor(napi_env env, napi_callback_info cbinfo) { HILOGI("called SessionBackup::Constructor begin"); @@ -269,7 +229,6 @@ napi_value SessionBackupNExporter::Constructor(napi_env env, napi_callback_info .onBundleStarted = bind(onBundleBegin, backupEntity->callbacks, placeholders::_1, placeholders::_2), .onBundleFinished = bind(onBundleEnd, backupEntity->callbacks, placeholders::_1, placeholders::_2), .onAllBundlesFinished = bind(onAllBundlesEnd, backupEntity->callbacks, placeholders::_1), - .onResultReport = bind(onResultReport, backupEntity->callbacks, placeholders::_1, placeholders::_2), .onBackupServiceDied = bind(OnBackupServiceDied, backupEntity->callbacks)}); if (!backupEntity->session) { NError(BError(BError::Codes::SDK_INVAL_ARG, "Failed to init backup").GetCode()).ThrowErr(env); diff --git a/interfaces/kits/js/backup/session_restore_n_exporter.cpp b/interfaces/kits/js/backup/session_restore_n_exporter.cpp index 706602119..77709c593 100644 --- a/interfaces/kits/js/backup/session_restore_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_restore_n_exporter.cpp @@ -247,7 +247,7 @@ static void OnBackupServiceDied(weak_ptr pCallbacks) callbacks->onBackupServiceDied.ThreadSafeSchedule(cbCompl); } -static void onResultReport(weak_ptr pCallbacks, ErrCode err, const std::string result) +static void onResultReport(weak_ptr pCallbacks, const std::string result) { HILOGI("callback function onResultReport begin."); if (pCallbacks.expired()) { @@ -264,17 +264,15 @@ static void onResultReport(weak_ptr pCallbacks, ErrCode err, c return; } - auto cbCompl = [result {result}, errCode {err}](napi_env env, NError err) -> NVal { + auto cbCompl = [result {result}](napi_env env, NError err) -> NVal { NVal resultStr = NVal::CreateUTF8String(env, result); - if (!err && errCode == 0) { + if (!err) { return resultStr; } NVal res; if (err) { res = NVal {env, err.GetNapiErr(env)}; - } else { - res = NVal {env, NError(errCode).GetNapiErr(env)}; } napi_status status = napi_set_named_property(env, res.val_, FILEIO_TAG_ERR_DATA.c_str(), resultStr.val_); if (status != napi_ok) { @@ -324,7 +322,7 @@ napi_value SessionRestoreNExporter::Constructor(napi_env env, napi_callback_info .onBundleStarted = bind(onBundleBegin, restoreEntity->callbacks, placeholders::_1, placeholders::_2), .onBundleFinished = bind(onBundleEnd, restoreEntity->callbacks, placeholders::_1, placeholders::_2), .onAllBundlesFinished = bind(onAllBundlesEnd, restoreEntity->callbacks, placeholders::_1), - .onResultReport = bind(onResultReport, restoreEntity->callbacks, placeholders::_1, placeholders::_2), + .onResultReport = bind(onResultReport, restoreEntity->callbacks, placeholders::_1), .onBackupServiceDied = bind(OnBackupServiceDied, restoreEntity->callbacks)}); } if (!restoreEntity->sessionWhole && !restoreEntity->sessionSheet) { diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index fe44a5ee9..0844f9e8d 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -64,7 +64,7 @@ REGISTER_SYSTEM_ABILITY_BY_ID(Service, FILEMANAGEMENT_BACKUP_SERVICE_SA_ID, fals namespace { constexpr int32_t DEBUG_ID = 100; -const int32_t CONNECT_WAIT_TIME = 5; +const int32_t CONNECT_WAIT_TIME_S = 15; } // namespace /* Shell/Xts user id equal to 0/1, we need set default 100 */ @@ -953,7 +953,7 @@ ErrCode Service::GetBackupInfo(BundleName &bundleName, std::string &result) AAFwk::Want want = CreateConnectWant(bundleName); backupConnection->ConnectBackupExtAbility(want, session_->GetSessionUserId()); std::unique_lock lock(getBackupInfoMutx_); - getBackupInfoCondition_.wait_for(lock, std::chrono::seconds(CONNECT_WAIT_TIME)); + getBackupInfoCondition_.wait_for(lock, std::chrono::seconds(CONNECT_WAIT_TIME_S)); auto proxy = backupConnection->GetBackupExtProxy(); if (!proxy) { throw BError(BError::Codes::SA_INVAL_ARG, "Extension backup Proxy is empty"); diff --git a/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp b/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp index d61a41388..e76e4dbbb 100644 --- a/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp +++ b/tests/mock/backup_kit_inner/b_session_restore_async_mock.cpp @@ -89,7 +89,7 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, callbacks_.onBundleStarted(1, "com.example.app2backup"); callbacks_.onBundleFinished(1, "com.example.app2backup"); callbacks_.onAllBundlesFinished(1); - callbacks_.onResultReport(0, "com.example.app2backup"); + callbacks_.onResultReport("com.example.app2backup"); callbacks_.onBackupServiceDied(); return BError(BError::Codes::OK); } diff --git a/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp b/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp index 063e54607..02efd1058 100644 --- a/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp +++ b/tests/moduletests/backup_kit_inner/b_session_restore_async_test.cpp @@ -54,7 +54,7 @@ static void OnBackupServiceDied() GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest OnBackupServiceDied OK"; } -static void OnResultReport(ErrCode err, std::string result) +static void OnResultReport(std::string result) { GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest OnResultReport OK"; } @@ -115,7 +115,7 @@ HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_0100, test callbacks_.onBundleFinished(ErrCode(BError::Codes::OK), ""); callbacks_.onAllBundlesFinished(ErrCode(BError::Codes::OK)); callbacks_.onBackupServiceDied(); - callbacks_.onResultReport(ErrCode(BError::Codes::OK), ""); + callbacks_.onResultReport(""); } catch (...) { EXPECT_TRUE(false); GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-an exception occurred by Callbacks."; diff --git a/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp b/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp index 8afe29786..882708cf6 100644 --- a/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp +++ b/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp @@ -55,7 +55,7 @@ static void OnBackupServiceDied() GTEST_LOG_(INFO) << "BSessionRestoreTest OnBackupServiceDied OK"; } -static void OnResultReport(ErrCode err, const std::string result) +static void OnResultReport(const std::string result) { GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest OnResultReport OK"; } -- Gitee From c6633d51176b122a4ad2050278b496ea56ab5521 Mon Sep 17 00:00:00 2001 From: libuyan <1014734367@qq.com> Date: Thu, 28 Mar 2024 17:04:10 +0800 Subject: [PATCH 11/15] add target Signed-off-by: libuyan <1014734367@qq.com> --- interfaces/kits/js/BUILD.gn | 2 +- interfaces/kits/js/backup/prop_n_exporter.cpp | 6 +++--- interfaces/kits/js/backup/prop_n_exporter.h | 2 +- .../{local_capabilities.cpp => prop_n_operation.cpp} | 6 +++--- .../backup/{local_capabilities.h => prop_n_operation.h} | 2 +- .../backup_api/backup_impl/service_reverse_stub_test.cpp | 2 +- .../backup_api/backup_impl/service_reverse_test.cpp | 8 +++++++- .../backup_sa/module_ipc/service_reverse_proxy_test.cpp | 2 +- .../backup_sa/module_ipc/svc_extension_proxy_test.cpp | 2 +- 9 files changed, 19 insertions(+), 13 deletions(-) rename interfaces/kits/js/backup/{local_capabilities.cpp => prop_n_operation.cpp} (97%) rename interfaces/kits/js/backup/{local_capabilities.h => prop_n_operation.h} (97%) diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index 283085c87..e0431d22a 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -116,7 +116,7 @@ ohos_shared_library("backup") { ] sources = [ - "${path_backup_js}/backup/local_capabilities.cpp", + "${path_backup_js}/backup/prop_n_operation.cpp", "${path_backup_js}/backup/module.cpp", "${path_backup_js}/backup/prop_n_exporter.cpp", "${path_backup_js}/backup/session_backup_n_exporter.cpp", diff --git a/interfaces/kits/js/backup/prop_n_exporter.cpp b/interfaces/kits/js/backup/prop_n_exporter.cpp index f2bb79ad0..d615542c2 100644 --- a/interfaces/kits/js/backup/prop_n_exporter.cpp +++ b/interfaces/kits/js/backup/prop_n_exporter.cpp @@ -14,7 +14,7 @@ */ #include "prop_n_exporter.h" -#include "local_capabilities.h" +#include "prop_n_operation.h" namespace OHOS::FileManagement::Backup { using namespace std; @@ -23,8 +23,8 @@ using namespace LibN; bool PropNExporter::Export() { return exports_.AddProp({ - NVal::DeclareNapiFunction("getLocalCapabilities", LocalCapabilities::Async), - NVal::DeclareNapiFunction("getBackupInfo", LocalCapabilities::DoGetBackupInfo), + NVal::DeclareNapiFunction("getLocalCapabilities", PropNOperation::Async), + NVal::DeclareNapiFunction("getBackupInfo", PropNOperation::DoGetBackupInfo), }); } diff --git a/interfaces/kits/js/backup/prop_n_exporter.h b/interfaces/kits/js/backup/prop_n_exporter.h index defb4c78a..78f96caff 100644 --- a/interfaces/kits/js/backup/prop_n_exporter.h +++ b/interfaces/kits/js/backup/prop_n_exporter.h @@ -22,7 +22,7 @@ namespace OHOS::FileManagement::Backup { class PropNExporter final : public LibN::NExporter { public: - inline static const std::string className = "LocalCapabilities"; + inline static const std::string className = "propNOperation"; bool Export() override; std::string GetClassName() override; diff --git a/interfaces/kits/js/backup/local_capabilities.cpp b/interfaces/kits/js/backup/prop_n_operation.cpp similarity index 97% rename from interfaces/kits/js/backup/local_capabilities.cpp rename to interfaces/kits/js/backup/prop_n_operation.cpp index 50a233922..f09636d52 100644 --- a/interfaces/kits/js/backup/local_capabilities.cpp +++ b/interfaces/kits/js/backup/prop_n_operation.cpp @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "local_capabilities.h" +#include "prop_n_operation.h" #include "b_error/b_error.h" #include "b_incremental_data.h" @@ -158,7 +158,7 @@ static napi_value AsyncDataList(napi_env env, const NFuncArg& funcArg) return NAsyncWorkPromise(env, thisVar).Schedule(PROCEDURE_LOCALCAPABILITIES_NAME, cbExec, cbCompl).val_; } -napi_value LocalCapabilities::Async(napi_env env, napi_callback_info info) +napi_value PropNOperation::Async(napi_env env, napi_callback_info info) { HILOGI("called LocalCapabilities::Async begin"); NFuncArg funcArg(env, info); @@ -179,7 +179,7 @@ napi_value LocalCapabilities::Async(napi_env env, napi_callback_info info) return AsyncCallback(env, funcArg); } -napi_value LocalCapabilities::DoGetBackupInfo(napi_env env, napi_callback_info info) +napi_value PropNOperation::DoGetBackupInfo(napi_env env, napi_callback_info info) { HILOGI("called DoGetBackupInfo begin"); std::string result; diff --git a/interfaces/kits/js/backup/local_capabilities.h b/interfaces/kits/js/backup/prop_n_operation.h similarity index 97% rename from interfaces/kits/js/backup/local_capabilities.h rename to interfaces/kits/js/backup/prop_n_operation.h index 7870aec63..192d70b76 100644 --- a/interfaces/kits/js/backup/local_capabilities.h +++ b/interfaces/kits/js/backup/prop_n_operation.h @@ -19,7 +19,7 @@ #include namespace OHOS::FileManagement::Backup { -class LocalCapabilities final { +class PropNOperation final { public: static napi_value Async(napi_env env, napi_callback_info info); static napi_value DoGetBackupInfo(napi_env env, napi_callback_info info); diff --git a/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp b/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp index 08e9f171e..10cf595c8 100644 --- a/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp +++ b/tests/unittests/backup_api/backup_impl/service_reverse_stub_test.cpp @@ -730,7 +730,7 @@ HWTEST_F(ServiceReverseStubTest, MessageParcel data; MessageParcel reply; MessageOption option; - std::string resultReport = "resultReport"; + std::string resultReport = "result_report"; EXPECT_TRUE(data.WriteInterfaceToken(IServiceReverse::GetDescriptor())); EXPECT_TRUE(data.WriteString(resultReport)); diff --git a/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp b/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp index 87a1c9d3b..e07040799 100644 --- a/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp +++ b/tests/unittests/backup_api/backup_impl/service_reverse_test.cpp @@ -77,6 +77,12 @@ static void OnAllBundlesFinishedTest(ErrCode err) static void OnBackupServiceDiedTest() {} +static void OnResultReportTest(std::string result) +{ + EXPECT_EQ(result, "result_report"); + GTEST_LOG_(INFO) << "ServiceReverseTest-OnResultReportTest SUCCESS"; +} + void ServiceReverseTest::TearDown() { service_ = nullptr; @@ -113,7 +119,7 @@ void ServiceReverseTest::Init(IServiceReverse::Scenario scenario, int nType) .onBundleFinished = bind(OnBundleFinishedTest, placeholders::_1, placeholders::_2), .onAllBundlesFinished = bind(OnAllBundlesFinishedTest, placeholders::_1), .onBackupServiceDied = bind(OnBackupServiceDiedTest), - .onResultReport = bind(OnBundleFinishedTest, placeholders::_1, placeholders::_2)}); + .onResultReport = bind(OnResultReportTest, placeholders::_1)}); } } } diff --git a/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp b/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp index edc7f4e47..e41f1c445 100644 --- a/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_reverse_proxy_test.cpp @@ -35,7 +35,7 @@ namespace { const string BUNDLE_NAME = "com.example.app2backup"; const string FILE_NAME = "1.tar"; const string FILE_NAME_MANIFEST = "manifest.rp"; -const string RESULT_REPORT = "result report"; +const string RESULT_REPORT = "result_report"; } // namespace class ServiceReverseProxyTest : public testing::Test { diff --git a/tests/unittests/backup_sa/module_ipc/svc_extension_proxy_test.cpp b/tests/unittests/backup_sa/module_ipc/svc_extension_proxy_test.cpp index 00305c8c8..ebf0fdd7c 100644 --- a/tests/unittests/backup_sa/module_ipc/svc_extension_proxy_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/svc_extension_proxy_test.cpp @@ -161,7 +161,7 @@ HWTEST_F(SvcExtensionProxyTest, SUB_Ext_Extension_proxy_GetBackupInfo_0100, test .Times(2) .WillOnce(Invoke(mock_.GetRefPtr(), &BackupExtExtensionMock::InvokeSendRequest)) .WillOnce(Return(EPERM)); - string result = "result report"; + string result = "result_report"; ErrCode ret = proxy_->GetBackupInfo(result); EXPECT_EQ(BError(BError::Codes::OK), ret); -- Gitee From 0845e8ec489dc5eeb198c1637842e68f89e4ffb9 Mon Sep 17 00:00:00 2001 From: libuyan <1014734367@qq.com> Date: Thu, 28 Mar 2024 17:50:38 +0800 Subject: [PATCH 12/15] add target Signed-off-by: libuyan <1014734367@qq.com> --- interfaces/kits/js/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index e0431d22a..2573f0e06 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -116,9 +116,9 @@ ohos_shared_library("backup") { ] sources = [ - "${path_backup_js}/backup/prop_n_operation.cpp", "${path_backup_js}/backup/module.cpp", "${path_backup_js}/backup/prop_n_exporter.cpp", + "${path_backup_js}/backup/prop_n_operation.cpp", "${path_backup_js}/backup/session_backup_n_exporter.cpp", "${path_backup_js}/backup/session_incremental_backup_n_exporter.cpp", "${path_backup_js}/backup/session_restore_n_exporter.cpp", -- Gitee From 95ec305a8d9acbeeeeb69c818a34cd779adc0d60 Mon Sep 17 00:00:00 2001 From: libuyan <1014734367@qq.com> Date: Fri, 29 Mar 2024 10:10:38 +0800 Subject: [PATCH 13/15] add Target Signed-off-by: libuyan <1014734367@qq.com> --- interfaces/kits/js/backup/prop_n_operation.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/interfaces/kits/js/backup/prop_n_operation.cpp b/interfaces/kits/js/backup/prop_n_operation.cpp index f09636d52..878d70787 100644 --- a/interfaces/kits/js/backup/prop_n_operation.cpp +++ b/interfaces/kits/js/backup/prop_n_operation.cpp @@ -209,10 +209,6 @@ napi_value PropNOperation::DoGetBackupInfo(napi_env env, napi_callback_info info HILOGE("proxy->GetBackupInfo faild."); return nullptr; } - if (result.size() == 0) { - HILOGE("proxy->GetBackupInfo result is empty."); - return nullptr; - } napi_value nResult; napi_status status = napi_create_string_utf8(env, result.c_str(), result.size(), &nResult); @@ -220,7 +216,7 @@ napi_value PropNOperation::DoGetBackupInfo(napi_env env, napi_callback_info info HILOGE("napi_create_string_utf8 faild."); return nullptr; } - HILOGI("DoGetBackupInfo success with result: %s", result.c_str()); + HILOGI("DoGetBackupInfo success with result: %{public}s", result.c_str()); return nResult; } } // namespace OHOS::FileManagement::Backup \ No newline at end of file -- Gitee From 4e5efe38c5721e6632b038107c57ebec8be98a5f Mon Sep 17 00:00:00 2001 From: libuyan <1014734367@qq.com> Date: Fri, 29 Mar 2024 15:12:16 +0800 Subject: [PATCH 14/15] add target Signed-off-by: libuyan <1014734367@qq.com> --- interfaces/kits/js/backup/session_restore_n_exporter.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/interfaces/kits/js/backup/session_restore_n_exporter.cpp b/interfaces/kits/js/backup/session_restore_n_exporter.cpp index 77709c593..a950ca206 100644 --- a/interfaces/kits/js/backup/session_restore_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_restore_n_exporter.cpp @@ -266,14 +266,7 @@ static void onResultReport(weak_ptr pCallbacks, const std::str auto cbCompl = [result {result}](napi_env env, NError err) -> NVal { NVal resultStr = NVal::CreateUTF8String(env, result); - if (!err) { - return resultStr; - } - NVal res; - if (err) { - res = NVal {env, err.GetNapiErr(env)}; - } napi_status status = napi_set_named_property(env, res.val_, FILEIO_TAG_ERR_DATA.c_str(), resultStr.val_); if (status != napi_ok) { HILOGE("Failed to set data property, status %{public}d, bundleName %{public}s", status, result.c_str()); -- Gitee From fdc3e328b083ac23d56763dc2238a4cdb9f8eff0 Mon Sep 17 00:00:00 2001 From: libuyan <1014734367@qq.com> Date: Fri, 29 Mar 2024 15:20:15 +0800 Subject: [PATCH 15/15] change copyright Signed-off-by: libuyan <1014734367@qq.com> --- frameworks/native/backup_ext/include/ext_backup.h | 2 +- frameworks/native/backup_ext/include/ext_extension_stub.h | 2 +- frameworks/native/backup_ext/src/ext_backup.cpp | 2 +- frameworks/native/backup_ext/src/ext_backup_js.cpp | 2 +- frameworks/native/backup_kit_inner/src/service_proxy.cpp | 2 +- frameworks/native/backup_kit_inner/src/service_reverse.cpp | 2 +- interfaces/kits/js/backup/general_callbacks.h | 2 +- interfaces/kits/js/backup/prop_n_exporter.cpp | 2 +- interfaces/kits/js/backup/prop_n_exporter.h | 2 +- interfaces/kits/js/backup/prop_n_operation.cpp | 2 +- interfaces/kits/js/backup/prop_n_operation.h | 2 +- services/backup_sa/src/module_ipc/service_reverse_proxy.cpp | 2 +- services/backup_sa/src/module_ipc/svc_extension_proxy.cpp | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/frameworks/native/backup_ext/include/ext_backup.h b/frameworks/native/backup_ext/include/ext_backup.h index c8ab0d602..317175732 100644 --- a/frameworks/native/backup_ext/include/ext_backup.h +++ b/frameworks/native/backup_ext/include/ext_backup.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/frameworks/native/backup_ext/include/ext_extension_stub.h b/frameworks/native/backup_ext/include/ext_extension_stub.h index 67705e003..2f5f015b6 100644 --- a/frameworks/native/backup_ext/include/ext_extension_stub.h +++ b/frameworks/native/backup_ext/include/ext_extension_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/frameworks/native/backup_ext/src/ext_backup.cpp b/frameworks/native/backup_ext/src/ext_backup.cpp index 9db3d2006..0ffd1dd00 100644 --- a/frameworks/native/backup_ext/src/ext_backup.cpp +++ b/frameworks/native/backup_ext/src/ext_backup.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/frameworks/native/backup_ext/src/ext_backup_js.cpp b/frameworks/native/backup_ext/src/ext_backup_js.cpp index 8faa8fcfe..f0308a6e6 100644 --- a/frameworks/native/backup_ext/src/ext_backup_js.cpp +++ b/frameworks/native/backup_ext/src/ext_backup_js.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp index 611004100..f7a63ade9 100644 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ b/frameworks/native/backup_kit_inner/src/service_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/frameworks/native/backup_kit_inner/src/service_reverse.cpp b/frameworks/native/backup_kit_inner/src/service_reverse.cpp index 6df10a366..1fb6d5b41 100644 --- a/frameworks/native/backup_kit_inner/src/service_reverse.cpp +++ b/frameworks/native/backup_kit_inner/src/service_reverse.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/interfaces/kits/js/backup/general_callbacks.h b/interfaces/kits/js/backup/general_callbacks.h index 51b70f05d..d5d0e1a2e 100644 --- a/interfaces/kits/js/backup/general_callbacks.h +++ b/interfaces/kits/js/backup/general_callbacks.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/interfaces/kits/js/backup/prop_n_exporter.cpp b/interfaces/kits/js/backup/prop_n_exporter.cpp index d615542c2..15d901d62 100644 --- a/interfaces/kits/js/backup/prop_n_exporter.cpp +++ b/interfaces/kits/js/backup/prop_n_exporter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/interfaces/kits/js/backup/prop_n_exporter.h b/interfaces/kits/js/backup/prop_n_exporter.h index 78f96caff..ca48be1e0 100644 --- a/interfaces/kits/js/backup/prop_n_exporter.h +++ b/interfaces/kits/js/backup/prop_n_exporter.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/interfaces/kits/js/backup/prop_n_operation.cpp b/interfaces/kits/js/backup/prop_n_operation.cpp index 878d70787..3055a56a8 100644 --- a/interfaces/kits/js/backup/prop_n_operation.cpp +++ b/interfaces/kits/js/backup/prop_n_operation.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/interfaces/kits/js/backup/prop_n_operation.h b/interfaces/kits/js/backup/prop_n_operation.h index 192d70b76..76ffb2ff5 100644 --- a/interfaces/kits/js/backup/prop_n_operation.h +++ b/interfaces/kits/js/backup/prop_n_operation.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp b/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp index cb2776723..a0f5a510c 100644 --- a/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp +++ b/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp b/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp index 574e8ed18..18c792821 100644 --- a/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp +++ b/services/backup_sa/src/module_ipc/svc_extension_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at -- Gitee