diff --git a/bundle.json b/bundle.json index 22d8e9aa36e1a4bdfe1dc3b257e90e6d1df3b53e..ad8744a25fe5d27e869921f6bb080b277f2e0748 100644 --- a/bundle.json +++ b/bundle.json @@ -26,6 +26,7 @@ "bundle_framework", "build_framework", "common_event_service", + "cJSON", "c_utils", "data_share", "device_manager", @@ -44,8 +45,7 @@ "third_party": [ "bounds_checking_function", "jsoncpp", - "openssl", - "cJSON" + "openssl" ] }, "adapted_system_type": [ diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp index 56913f216d893b47e6ef3badf34e57671e6a6dd4..b8a8781a76040c2a8359d93a4a1903c8a230bfda 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_restore_session.cpp @@ -90,10 +90,19 @@ ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vectorAppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos); } +ErrCode BIncrementalRestoreSession::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore) +{ + auto proxy = ServiceProxy::GetInstance(); + if (proxy == nullptr) { + return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); + } + + return proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore); +} + ErrCode BIncrementalRestoreSession::Release() { auto proxy = ServiceProxy::GetInstance(); diff --git a/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp b/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp index ef87967e0fa6974f5d91584b0d2ac9e3580a9d28..27b76dad6bcfb4d539bea6f3976705ac7be5ddf7 100644 --- a/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp +++ b/frameworks/native/backup_kit_inner/src/b_incremental_session_restore_async.cpp @@ -90,9 +90,20 @@ ErrCode BIncrementalSessionRestoreAsync::GetFileHandle(const string &bundleName, return proxy->GetIncrementalFileHandle(bundleName, fileName); } +ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore, + std::vector detailInfos, RestoreTypeEnum restoreType, int32_t userId) +{ + auto proxy = ServiceProxy::GetInstance(); + if (proxy == nullptr) { + return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); + } + + return proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos, restoreType, + userId); +} + ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore, - std::vector detailInfos, RestoreTypeEnum restoreType, int32_t userId) { @@ -101,7 +112,7 @@ ErrCode BIncrementalSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos, restoreType, userId); + return proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, restoreType, userId); } ErrCode BIncrementalSessionRestoreAsync::Release() diff --git a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp index b98fb8f75267a73d87938e11da7552c5ea6cf67a..0f1fc3368c15eaa235fe7f30db27664081040e1b 100644 --- a/frameworks/native/backup_kit_inner/src/b_session_restore.cpp +++ b/frameworks/native/backup_kit_inner/src/b_session_restore.cpp @@ -104,6 +104,16 @@ ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bu return proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos); } +ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore) +{ + auto proxy = ServiceProxy::GetInstance(); + if (proxy == nullptr) { + return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); + } + + return proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore); +} + ErrCode BSessionRestore::Finish() { auto proxy = ServiceProxy::GetInstance(); 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 5920551ed18cf139827c522a4e174e1a2736568e..ead31fb7967731b97e8a36189edcf9ef15e6f33a 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 @@ -103,7 +103,21 @@ ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); } - return proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos, restoreType, userId); + return proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, detailInfos, restoreType, + userId); +} + +ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, + vector bundlesToRestore, + RestoreTypeEnum restoreType, + int32_t userId) +{ + auto proxy = ServiceProxy::GetInstance(); + if (proxy == nullptr) { + return BError(BError::Codes::SDK_BROKEN_IPC, "Failed to get backup service").GetCode(); + } + + return proxy->AppendBundlesRestoreSession(move(remoteCap), bundlesToRestore, restoreType, userId); } ErrCode BSessionRestoreAsync::Release() diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp index 3382c1bd448bccf703dcd94f94d8b789aceba0bc..a890b92a9c81ecb116a05f99814062c159d7e728 100644 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ b/frameworks/native/backup_kit_inner/src/service_proxy.cpp @@ -261,9 +261,48 @@ ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &file return ret; } +ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, + const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("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(); + } + MessageParcel reply; + MessageOption option; + option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); + + if (!data.WriteFileDescriptor(fd)) { + return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send the fd").GetCode(); + } + if (!data.WriteStringVector(bundleNames)) { + return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); + } + if (!data.WriteStringVector(detailInfos)) { + return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send detailInfos").GetCode(); + } + if (!data.WriteInt32(static_cast(restoreType))) { + return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send restoreType").GetCode(); + } + if (!data.WriteInt32(userId)) { + return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send userId").GetCode(); + } + + int32_t ret = Remote()->SendRequest( + static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION_DETAILS), + 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(); + } + return reply.ReadInt32(); +} + ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, - const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) { @@ -284,9 +323,6 @@ ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, if (!data.WriteStringVector(bundleNames)) { return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send bundleNames").GetCode(); } - if (!detailInfos.empty() && !data.WriteStringVector(detailInfos)) { - return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send detailInfos").GetCode(); - } if (!data.WriteInt32(static_cast(restoreType))) { return BError(BError::Codes::SDK_INVAL_ARG, "Failed to send restoreType").GetCode(); } 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 d2c2d4d6d4ba76e566d73f37ff7fccca1eae44d1..7dd4fe84719564551b5ffdedb115f83f5a1196e2 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 @@ -75,6 +75,15 @@ public: ErrCode AppendBundles(UniqueFd remoteCap, std::vector bundlesToRestore, std::vector detailInfos); + /** + * @brief 用于追加应用,现阶段仅支持在Start之前调用 + * + * @param remoteCap 已打开的保存远端设备能力的Json文件。可使用GetLocalCapabilities方法获取 + * @param bundlesToRestore 待恢复的应用清单 + * @return ErrCode 规范错误码 + */ + ErrCode AppendBundles(UniqueFd remoteCap, std::vector bundlesToRestore); + /** * @brief 用于结束服务 * diff --git a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h index 03d8d2c3d59580362b24b50ed8632d7543261963..ef198582a2e29a348920ff2bec2fcf64d6532372 100644 --- a/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h +++ b/interfaces/inner_api/native/backup_kit_inner/impl/b_incremental_session_restore_async.h @@ -78,13 +78,23 @@ public: * * @param remoteCap 已打开的保存远端设备能力的Json文件。可使用GetLocalCapabilities方法获取 * @param bundlesToRestore 待恢复的应用清单 - * @param detailInfos bundle的单双映射关系json串 + * @param userId 用户ID + * @return ErrCode 规范错误码 + */ + ErrCode AppendBundles(UniqueFd remoteCap, std::vector bundlesToRestore, + std::vector detailInfos, RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, + int32_t userId = DEFAULT_INVAL_VALUE); + + /** + * @brief 用于追加待恢复应用 + * + * @param remoteCap 已打开的保存远端设备能力的Json文件。可使用GetLocalCapabilities方法获取 + * @param bundlesToRestore 待恢复的应用清单 * @param userId 用户ID * @return ErrCode 规范错误码 */ ErrCode AppendBundles(UniqueFd remoteCap, std::vector bundlesToRestore, - std::vector detailInfos, RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, int32_t userId = DEFAULT_INVAL_VALUE); 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 403e802e17c7134a68fc9e9d11b70d9a01ef67bf..3cbc4efae1885db77abe96739d532bc05c03c8df 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 @@ -74,6 +74,15 @@ public: ErrCode AppendBundles(UniqueFd remoteCap, std::vector bundlesToRestore, std::vector detailInfos); + /** + * @brief 用于追加应用,现阶段仅支持在Start之前调用 + * + * @param remoteCap 已打开的保存远端设备能力的Json文件。可使用GetLocalCapabilities方法获取 + * @param bundlesToRestore 待恢复的应用清单 + * @return ErrCode 规范错误码 + */ + ErrCode AppendBundles(UniqueFd remoteCap, std::vector bundlesToRestore); + /** * @brief 用于结束追加应用,结束后不可在调用AppendBundles * 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 d91e3b033924937b96cc4e10760730d3b8bd5fde..6474810ef8c50bf5be6eb0feedbbaaae792b2afa 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 @@ -82,13 +82,26 @@ public: * @param detailInfos bundle对应的单双映射的json串 * @param userId 用户ID * @return ErrCode 规范错误码 - */ + */ ErrCode AppendBundles(UniqueFd remoteCap, std::vector bundlesToRestore, std::vector detailInfos, RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, int32_t userId = DEFAULT_INVAL_VALUE); + /** + * @brief 用于追加待恢复应用 + * + * @param remoteCap 已打开的保存远端设备能力的Json文件。可使用GetLocalCapabilities方法获取 + * @param bundlesToRestore 待恢复的应用清单 + * @param userId 用户ID + * @return ErrCode 规范错误码 + */ + ErrCode AppendBundles(UniqueFd remoteCap, + std::vector bundlesToRestore, + RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, + int32_t userId = DEFAULT_INVAL_VALUE); + /** * @brief 用于结束服务 * 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 51c274e74542f590344b83cd30d2bb346e3fd904..8c8a7138aa85fdd85f19b9de2aa4b4da7707b038 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 @@ -51,6 +51,10 @@ public: const std::vector &detailInfos, RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, int32_t userId = DEFAULT_INVAL_VALUE) = 0; + virtual ErrCode AppendBundlesRestoreSession(UniqueFd fd, + const std::vector &bundleNames, + RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, + int32_t userId = DEFAULT_INVAL_VALUE) = 0; virtual ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) = 0; virtual ErrCode Finish() = 0; virtual ErrCode Release() = 0; 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 459b134f06f5b6677e1b20aa09501af686317387..fcfc42cf641fd7f61e6fa0bcc94f302c52e825e7 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 @@ -29,6 +29,7 @@ enum class IServiceInterfaceCode { SERVICE_CMD_START, SERVICE_CMD_GET_FILE_NAME, SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION, + SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION_DETAILS, SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION, SERVICE_CMD_FINISH, SERVICE_CMD_RELSEASE_SESSION, 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 b088a981b11b395b925784fccacccabfce7e2a03..d93b68e969f7087b3bf2199c25be0651f60bcdfc 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 @@ -42,6 +42,10 @@ public: const std::vector &detailInfos, RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, int32_t userId = DEFAULT_INVAL_VALUE) override; + ErrCode AppendBundlesRestoreSession(UniqueFd fd, + const std::vector &bundleNames, + RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, + int32_t userId = DEFAULT_INVAL_VALUE) override; ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) override; ErrCode Finish() override; ErrCode Release() override; diff --git a/interfaces/kits/js/backup/session_restore_n_exporter.cpp b/interfaces/kits/js/backup/session_restore_n_exporter.cpp index eeafe3a11f97a39bff48e48f734e83de3eeb66d1..d69919d4dc1b09e1ba7c04f4d063d8008fe68435 100644 --- a/interfaces/kits/js/backup/session_restore_n_exporter.cpp +++ b/interfaces/kits/js/backup/session_restore_n_exporter.cpp @@ -394,9 +394,15 @@ napi_value SessionRestoreNExporter::AppendBundles(napi_env env, napi_callback_in return NError(BError(BError::Codes::SDK_INVAL_ARG, "restore session is nullptr").GetCode()); } if (entity->sessionWhole) { - return NError(entity->sessionWhole->AppendBundles(UniqueFd(fd), bundles, bundleDetails)); + if (!bundleDetails.empty()) { + return NError(entity->sessionWhole->AppendBundles(UniqueFd(fd), bundles, bundleDetails)); + } + return NError(entity->sessionWhole->AppendBundles(UniqueFd(fd), bundles)); } - return NError(entity->sessionSheet->AppendBundles(UniqueFd(fd), bundles, bundleDetails)); + if (!bundleDetails.empty()) { + return NError(entity->sessionSheet->AppendBundles(UniqueFd(fd), bundles, bundleDetails)); + } + return NError(entity->sessionSheet->AppendBundles(UniqueFd(fd), bundles)); }; auto cbCompl = [](napi_env env, NError err) -> NVal { return err ? NVal {env, err.GetNapiErr(env)} : NVal::CreateUndefined(env); diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 5222f0b7bbf31bf14ccbd35fd34ac34ffb926299..21b65a93272703abc7773ced32ef0f1799ee8010 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -48,6 +48,10 @@ public: const std::vector &detailInfos, RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, int32_t userId = DEFAULT_INVAL_VALUE) override; + ErrCode AppendBundlesRestoreSession(UniqueFd fd, + const std::vector &bundleNames, + RestoreTypeEnum restoreType = RestoreTypeEnum::RESTORE_DATA_WAIT_SEND, + int32_t userId = DEFAULT_INVAL_VALUE) override; ErrCode AppendBundlesBackupSession(const std::vector &bundleNames) override; ErrCode Finish() override; ErrCode Release() override; diff --git a/services/backup_sa/include/module_ipc/service_stub.h b/services/backup_sa/include/module_ipc/service_stub.h index 696c1ab84694bb6a72533778d00c73a169a47730..7fedba320c23f26a4c22148cfb2842377c3bf6a2 100644 --- a/services/backup_sa/include/module_ipc/service_stub.h +++ b/services/backup_sa/include/module_ipc/service_stub.h @@ -44,6 +44,7 @@ private: int32_t CmdResultReport(MessageParcel &data, MessageParcel &reply); int32_t CmdGetFileHandle(MessageParcel &data, MessageParcel &reply); int32_t CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply); + int32_t CmdAppendBundlesDetailsRestoreSession(MessageParcel &data, MessageParcel &reply); int32_t CmdAppendBundlesBackupSession(MessageParcel &data, MessageParcel &reply); int32_t CmdFinish(MessageParcel &data, MessageParcel &reply); int32_t CmdRelease(MessageParcel &data, MessageParcel &reply); diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 669282bd994781917a50cd8764e98366f76d696a..8442b27592f1bd5b0796fb26638b5f31f0cfc2e9 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -311,11 +311,8 @@ static vector GetRestoreBundleNames(UniqueFd fd, return restoreBundleInfos; } -ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, - const vector &bundleNames, - const std::vector &detailInfos, - RestoreTypeEnum restoreType, - int32_t userId) +ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, + const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { @@ -351,6 +348,41 @@ ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, } } +ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, + const vector &bundleNames, + RestoreTypeEnum restoreType, + int32_t userId) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + HILOGI("Begin"); + session_->IncreaseSessionCnt(); + if (userId != DEFAULT_INVAL_VALUE) { /* multi user scenario */ + session_->SetSessionUserId(userId); + } + VerifyCaller(IServiceReverse::Scenario::RESTORE); + auto restoreInfos = GetRestoreBundleNames(move(fd), session_, bundleNames); + auto restoreBundleNames = SvcRestoreDepsManager::GetInstance().GetRestoreBundleNames(restoreInfos, restoreType); + if (restoreBundleNames.empty()) { + session_->DecreaseSessionCnt(); + return BError(BError::Codes::OK); + } + session_->AppendBundles(restoreBundleNames); + std::map bundleNameDetailMap; + SetCurrentSessProperties(restoreInfos, restoreBundleNames, bundleNameDetailMap, restoreType); + OnStartSched(); + session_->DecreaseSessionCnt(); + return BError(BError::Codes::OK); + } catch (const BError &e) { + session_->DecreaseSessionCnt(); + return e.GetCode(); + } catch (...) { + session_->DecreaseSessionCnt(); + HILOGI("Unexpected exception"); + return EPERM; + } +} + void Service::SetCurrentSessProperties(std::vector &restoreBundleInfos, std::vector &restoreBundleNames, std::map &bundleNameDetailMap, RestoreTypeEnum restoreType) @@ -375,6 +407,9 @@ void Service::SetCurrentSessProperties(std::vector session_->SetBundleVersionName(restoreInfo.name, restoreInfo.versionName); session_->SetBundleDataSize(restoreInfo.name, restoreInfo.spaceOccupied); session_->SetBackupExtName(restoreInfo.name, restoreInfo.extensionName); + if (bundleNameDetailMap.empty()) { + continue; + } NotifyBundleInfos(bundleNameDetailMap, restoreInfo, restoreType); } HILOGI("End"); @@ -387,7 +422,7 @@ void Service::NotifyBundleInfos(std::mapsecond; + BJsonUtil::BundleDetailInfo bundleDetailInfo = iter->second; if (bundleDetailInfo.type == COMMON_EVENT_TYPE) { DelayedSingleton::GetInstance()->NotifyBundleDetail(bundleDetailInfo); } diff --git a/services/backup_sa/src/module_ipc/service_stub.cpp b/services/backup_sa/src/module_ipc/service_stub.cpp index 65c477772d711f1f9071f6e73c5c3bf768d41a7c..1810b62f108ab973c663f7be8276d620bc84b4bd 100644 --- a/services/backup_sa/src/module_ipc/service_stub.cpp +++ b/services/backup_sa/src/module_ipc/service_stub.cpp @@ -52,6 +52,8 @@ ServiceStub::ServiceStub() &ServiceStub::CmdGetFileHandle; opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION)] = &ServiceStub::CmdAppendBundlesRestoreSession; + opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION_DETAILS)] + = &ServiceStub::CmdAppendBundlesDetailsRestoreSession; opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION)] = &ServiceStub::CmdAppendBundlesBackupSession; opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_FINISH)] = &ServiceStub::CmdFinish; @@ -242,7 +244,7 @@ int32_t ServiceStub::CmdGetFileHandle(MessageParcel &data, MessageParcel &reply) return GetFileHandle(bundleName, fileName); } -int32_t ServiceStub::CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply) +int32_t ServiceStub::CmdAppendBundlesDetailsRestoreSession(MessageParcel &data, MessageParcel &reply) { HILOGI("Begin"); UniqueFd fd(data.ReadFileDescriptor()); @@ -276,6 +278,35 @@ int32_t ServiceStub::CmdAppendBundlesRestoreSession(MessageParcel &data, Message return BError(BError::Codes::OK); } +int32_t ServiceStub::CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply) +{ + HILOGI("Begin"); + UniqueFd fd(data.ReadFileDescriptor()); + if (fd < 0) { + return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive fd"); + } + + vector bundleNames; + if (!data.ReadStringVector(&bundleNames)) { + return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive bundleNames"); + } + int32_t type; + if (!data.ReadInt32(type)) { + return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive restoreType"); + } + RestoreTypeEnum restoreType = static_cast(type); + int32_t userId; + if (!data.ReadInt32(userId)) { + return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive userId"); + } + + int res = AppendBundlesRestoreSession(move(fd), bundleNames, restoreType, userId); + if (!reply.WriteInt32(res)) { + return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to send the result ") + to_string(res)); + } + return BError(BError::Codes::OK); +} + int32_t ServiceStub::CmdAppendBundlesBackupSession(MessageParcel &data, MessageParcel &reply) { HILOGI("Begin"); 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 d3765aa2d1be8a016d2ef179715783e0098cac5e..4b77fba4c4a53b73613f3bc94578f3244ab0c430 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 @@ -58,9 +58,42 @@ ErrCode BSessionRestoreAsync::GetFileHandle(const string &bundleName, const stri return BError(BError::Codes::OK); } +ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore, + vector detailInfos, RestoreTypeEnum restoreType, int32_t userId) +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsync::AppendBundles"; + if (restoreType == RestoreTypeEnum::RESTORE_DATA_READDY) { + callbacks_.onBackupServiceDied(); + return BError(BError::Codes::OK); + } + callbacks_.onBundleStarted(0, "com.example.app2backup"); + + BFileInfo bFileInfo("com.example.app2backup", "1.tar", 0); + TestManager tm("BSessionRestoreAsyncMock_GetFd_0100"); + string filePath = tm.GetRootDirCurTest().append("1.tar"); + UniqueFd fd(open(filePath.data(), O_RDWR | O_CREAT, S_IRWXU)); + GTEST_LOG_(INFO) << "callbacks_::onFileReady 1.tar"; + callbacks_.onFileReady(bFileInfo, move(fd)); + + string fileManagePath = tm.GetRootDirCurTest().append("manage.json"); + UniqueFd fdManage(open(fileManagePath.data(), O_RDWR | O_CREAT, S_IRWXU)); + bFileInfo.fileName = "manage.json"; + GTEST_LOG_(INFO) << "File ready callback for manage.json"; + callbacks_.onFileReady(bFileInfo, move(fdManage)); + + callbacks_.onBundleFinished(0, "com.example.app2backup"); + + callbacks_.onAllBundlesFinished(0); + callbacks_.onBundleStarted(1, "com.example.app2backup"); + callbacks_.onBundleFinished(1, "com.example.app2backup"); + callbacks_.onAllBundlesFinished(1); + callbacks_.onResultReport("com.example.app2backup"); + callbacks_.onBackupServiceDied(); + return BError(BError::Codes::OK); +} + ErrCode BSessionRestoreAsync::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore, - vector detailInfos, RestoreTypeEnum restoreType, int32_t userId) { diff --git a/tests/mock/backup_kit_inner/b_session_restore_mock.cpp b/tests/mock/backup_kit_inner/b_session_restore_mock.cpp index 6707975bcbd41042cf55eba30bad68199653dee3..225f62e1d1a8fbdd66f37dc6beb212468c69d5c8 100644 --- a/tests/mock/backup_kit_inner/b_session_restore_mock.cpp +++ b/tests/mock/backup_kit_inner/b_session_restore_mock.cpp @@ -92,6 +92,12 @@ ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bu return BError(BError::Codes::OK); } +ErrCode BSessionRestore::AppendBundles(UniqueFd remoteCap, vector bundlesToRestore) +{ + Start(); + return BError(BError::Codes::OK); +} + ErrCode BSessionRestore::Finish() { 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 9a3104023e2b439c217626b6476609de60002054..76a6a9897150e0ee5e94d2ec7c6b09c61edc6562 100644 --- a/tests/mock/backup_kit_inner/service_proxy_mock.cpp +++ b/tests/mock/backup_kit_inner/service_proxy_mock.cpp @@ -85,9 +85,14 @@ ErrCode ServiceProxy::GetFileHandle(const string &bundleName, const string &file return BError(BError::Codes::OK); } +ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, + const vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) +{ + return BError(BError::Codes::OK); +} + ErrCode ServiceProxy::AppendBundlesRestoreSession(UniqueFd fd, const vector &bundleNames, - const vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) { diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index 68bf610abaa12220cc11db7f394bf90f6bacf46a..50511c6023828ba61b87ee4e0fbd4e4ba9efdf55 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -77,9 +77,14 @@ ErrCode Service::ServiceResultReport(const std::string &restoreRetInfo) return BError(BError::Codes::OK); } +ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, + const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) +{ + return BError(BError::Codes::OK); +} + ErrCode Service::AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, - const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId) { diff --git a/tests/mock/module_ipc/service_stub_mock.cpp b/tests/mock/module_ipc/service_stub_mock.cpp index 4a658453d9904a0bed32a1796125f03c41d3b639..a703f0c08637dc15d24f5e4bdb465bac7892c98e 100644 --- a/tests/mock/module_ipc/service_stub_mock.cpp +++ b/tests/mock/module_ipc/service_stub_mock.cpp @@ -46,6 +46,8 @@ ServiceStub::ServiceStub() &ServiceStub::CmdGetFileHandle; opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION)] = &ServiceStub::CmdAppendBundlesRestoreSession; + opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION_DETAILS)] + = &ServiceStub::CmdAppendBundlesDetailsRestoreSession; opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_BACKUP_SESSION)] = &ServiceStub::CmdAppendBundlesBackupSession; opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_LOCAL_CAPABILITIES_INCREMENTAL)] = @@ -161,6 +163,16 @@ int32_t ServiceStub::CmdGetFileHandle(MessageParcel &data, MessageParcel &reply) } int32_t ServiceStub::CmdAppendBundlesRestoreSession(MessageParcel &data, MessageParcel &reply) +{ + UniqueFd fd(data.ReadFileDescriptor()); + std::vector bundleNames; + data.ReadStringVector(&bundleNames); + int res = AppendBundlesRestoreSession(move(fd), bundleNames); + reply.WriteInt32(res); + return BError(BError::Codes::OK); +} + +int32_t ServiceStub::CmdAppendBundlesDetailsRestoreSession(MessageParcel &data, MessageParcel &reply) { UniqueFd fd(data.ReadFileDescriptor()); std::vector bundleNames; 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 ddc68738605cf4e50065cf2791663811130c1427..7a2df76cc4225a77eb05ced7392211abb0e80e02 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 @@ -214,6 +214,34 @@ HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_0400, test * @tc.require: I7L7A6 */ HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_0500, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-begin SUB_backup_b_session_restore_async_0500"; + try { + SetMockGetInstance(true); + SetMockLoadSystemAbility(true); + vector bundleNames; + ErrCode ret = restorePtr_->AppendBundles(UniqueFd(-1), bundleNames); + EXPECT_EQ(ret, ErrCode(BError::Codes::OK)); + ret = restorePtr_->AppendBundles(UniqueFd(-1), bundleNames); + EXPECT_EQ(ret, ErrCode(BError::Codes::OK)); + restorePtr_ = nullptr; + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-an exception occurred by ~BSessionRestoreAsync."; + } + GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-end SUB_backup_b_session_restore_async_0500"; +} + +/** + * @tc.number: SUB_backup_b_session_restore_async_0501 + * @tc.name: SUB_backup_b_session_restore_async_0501 + * @tc.desc: 测试AppendBundles接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I7L7A6 + */ +HWTEST_F(BSessionRestoreAsyncTest, SUB_backup_b_session_restore_async_0501, testing::ext::TestSize.Level1) { GTEST_LOG_(INFO) << "BSessionRestoreAsyncTest-begin SUB_backup_b_session_restore_async_0500"; try { 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 e11db00c2dcf91e127b32d176cf4e38b4e2afc39..27bc3476fa4077d39d701fde66f44e27fbd8b357 100644 --- a/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp +++ b/tests/moduletests/backup_kit_inner/b_session_restore_test.cpp @@ -283,6 +283,41 @@ HWTEST_F(BSessionRestoreTest, SUB_backup_b_session_restore_0600, testing::ext::T GTEST_LOG_(INFO) << "BSessionRestoreTest-end SUB_backup_b_session_restore_0600"; } +/** + * @tc.number: SUB_backup_b_session_restore_0601 + * @tc.name: SUB_backup_b_session_restore_0601 + * @tc.desc: 测试AppendBundles接口 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6F3GV + */ +HWTEST_F(BSessionRestoreTest, SUB_backup_b_session_restore_0601, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "BSessionRestoreTest-begin SUB_backup_b_session_restore_0600"; + try { + const string fileName = "1.tar"; + TestManager tm("SUB_backup_b_session_restore_0600"); + string filePath = tm.GetRootDirCurTest().append(fileName); + UniqueFd remoteCap(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); + string bundleName = ""; + vector bundlesToRestore; + bundlesToRestore.emplace_back(bundleName); + GTEST_LOG_(INFO) << "GetInstance is false"; + SetMockGetInstance(false); + auto ret = restorePtr_->AppendBundles(move(remoteCap), bundlesToRestore); + EXPECT_NE(ret, ErrCode(BError::Codes::OK)); + GTEST_LOG_(INFO) << "GetInstance is true"; + SetMockGetInstance(true); + ret = restorePtr_->AppendBundles(move(remoteCap), bundlesToRestore); + EXPECT_EQ(ret, ErrCode(BError::Codes::OK)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "BSessionRestoreTest-an exception occurred by AppendBundles."; + } + GTEST_LOG_(INFO) << "BSessionRestoreTest-end SUB_backup_b_session_restore_0600"; +} + /** * @tc.number: SUB_backup_b_session_restore_0700 * @tc.name: SUB_backup_b_session_restore_0700 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 1289f0466d5a17a4c7e111fb26d4aff27ed7cc20..5dae931be363d439416bb2522c0575868b7c7f4f 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 @@ -98,6 +98,14 @@ public: return BError(BError::Codes::OK); } + ErrCode AppendBundlesRestoreSession(UniqueFd fd, + const std::vector &bundleNames, + RestoreTypeEnum restoreType, + int32_t userId) override + { + return BError(BError::Codes::OK); + } + ErrCode AppendBundlesRestoreSession(UniqueFd fd, const std::vector &bundleNames, const std::vector &detailInfos, 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 d4f69ab572adde85ba44d8d2f7b4a00a0240bc45..a5c69cfe7b14eb8fbfff18c25808ffde7ace6a84 100644 --- a/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp +++ b/tests/unittests/backup_api/backup_impl/service_proxy_test.cpp @@ -285,6 +285,33 @@ HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesRestoreSession_0100, t .Times(1) .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); + std::vector bundleNames; + TestManager tm("BackupSession_GetFd_0100"); + std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); + UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); + int32_t result = proxy_->AppendBundlesRestoreSession(move(fd), bundleNames); + EXPECT_EQ(result, BError(BError::Codes::OK)); + result = proxy_->AppendBundlesRestoreSession(UniqueFd(-1), bundleNames); + EXPECT_NE(result, BError(BError::Codes::OK)); + GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesRestoreSession_0100"; +} + +/** + * @tc.number: SUB_Service_proxy_AppendBundlesRestoreSession_0101 + * @tc.name: SUB_Service_proxy_AppendBundlesRestoreSession_0101 + * @tc.desc: 测试 AppendBundlesRestoreSession 获取真实文件调用成功和失败 + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: I6URNZ + */ +HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesRestoreSession_0101, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "ServiceProxyTest-begin SUB_Service_proxy_AppendBundlesRestoreSession_0101"; + EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mock_.GetRefPtr(), &IServiceMock::InvokeSendRequest)); + std::vector bundleNames; TestManager tm("BackupSession_GetFd_0100"); std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); @@ -294,7 +321,7 @@ HWTEST_F(ServiceProxyTest, SUB_Service_proxy_AppendBundlesRestoreSession_0100, t EXPECT_EQ(result, BError(BError::Codes::OK)); result = proxy_->AppendBundlesRestoreSession(UniqueFd(-1), bundleNames, detailInfos); EXPECT_NE(result, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesRestoreSession_0100"; + GTEST_LOG_(INFO) << "ServiceProxyTest-end SUB_Service_proxy_AppendBundlesRestoreSession_0101"; } /** 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 53e4c800d84c203e4d132451e788beb5e2874573..78300691abe89c7f7cd7a35b730466641b5623b1 100644 --- a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp @@ -53,6 +53,9 @@ public: AppendBundlesRestoreSession, ErrCode(UniqueFd fd, const std::vector &bundleNames, const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId)); + MOCK_METHOD4( + AppendBundlesRestoreSession, + ErrCode(UniqueFd fd, const std::vector &bundleNames, RestoreTypeEnum restoreType, int32_t userId)); MOCK_METHOD1(AppendBundlesBackupSession, ErrCode(const std::vector &bundleNames)); MOCK_METHOD0(Finish, ErrCode()); MOCK_METHOD0(Release, ErrCode()); @@ -414,6 +417,48 @@ HWTEST_F(ServiceStubTest, SUB_backup_sa_ServiceStub_AppendBundlesRestoreSession_ GTEST_LOG_(INFO) << "ServiceStubTest-end SUB_backup_sa_ServiceStub_AppendBundlesRestoreSession_0100"; } + +/** + * @tc.number: SUB_backup_sa_ServiceStub_AppendBundlesRestoreSession_0101 + * @tc.name: SUB_backup_sa_ServiceStub_AppendBundlesRestoreSession_0101 + * @tc.desc: Test function of AppendBundlesRestoreSession interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 0 + * @tc.require: I6URNZ + */ +HWTEST_F(ServiceStubTest, SUB_backup_sa_ServiceStub_AppendBundlesRestoreSession_0101, testing::ext::TestSize.Level0) +{ + GTEST_LOG_(INFO) << "ServiceStubTest-begin SUB_backup_sa_ServiceStub_AppendBundlesRestoreSession_0100"; + try { + MockService service; + EXPECT_CALL(service, AppendBundlesRestoreSession(_, _, _, _, _)).WillOnce(Return(BError(BError::Codes::OK))); + MessageParcel data; + MessageParcel reply; + MessageOption option; + + vector bundleNames; + bundleNames.push_back(BUNDLE_NAME); + TestManager tm("ServiceStub_GetFd_0300"); + std::string filePath = tm.GetRootDirCurTest().append(FILE_NAME); + UniqueFd fd(open(filePath.data(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR)); + + EXPECT_TRUE(data.WriteInterfaceToken(IService::GetDescriptor())); + EXPECT_TRUE(data.WriteFileDescriptor(fd)); + EXPECT_TRUE(data.WriteStringVector(bundleNames)); + EXPECT_TRUE(data.WriteInt32(0)); + EXPECT_TRUE(data.WriteInt32(-1)); + EXPECT_EQ(BError(BError::Codes::OK), + service.OnRemoteRequest( + static_cast(IServiceInterfaceCode::SERVICE_CMD_APPEND_BUNDLES_RESTORE_SESSION), data, + reply, option)); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << "ServiceStubTest-an exception occurred by AppendBundlesRestoreSession."; + } + GTEST_LOG_(INFO) << "ServiceStubTest-end SUB_backup_sa_ServiceStub_AppendBundlesRestoreSession_0100"; +} + /** * @tc.number: SUB_backup_sa_ServiceStub_AppendBundlesBackupSession_0100 * @tc.name: SUB_backup_sa_ServiceStub_AppendBundlesBackupSession_0100 diff --git a/tests/unittests/backup_utils/BUILD.gn b/tests/unittests/backup_utils/BUILD.gn index e71ece84872a92e67fed733ab5f63dbe708c3a86..b67e7a51ed27b84558634b3b19128f96fce3209b 100644 --- a/tests/unittests/backup_utils/BUILD.gn +++ b/tests/unittests/backup_utils/BUILD.gn @@ -85,10 +85,10 @@ ohos_unittest("b_jsonutil_test") { "${path_backup}/tests/utils:backup_test_utils", "${path_backup}/utils/:backup_utils", "${path_jsoncpp}:jsoncpp", - "//third_party/cJSON:cjson", ] external_deps = [ + "cJSON:cjson", "c_utils:utils", "hilog:libhilog", ] diff --git a/tools/backup_tool/src/tools_op_incremental_restore.cpp b/tools/backup_tool/src/tools_op_incremental_restore.cpp index e921186b8f9ed320e41d497c5d4c404eb4fcd8f4..703a922ed9533df8164ebf3fde12275128e5ed44 100644 --- a/tools/backup_tool/src/tools_op_incremental_restore.cpp +++ b/tools/backup_tool/src/tools_op_incremental_restore.cpp @@ -294,16 +294,14 @@ static int32_t Init(const string &pathCapFile, vector bundleNames, bool FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return -errno; } - std::string detailInfo = ""; - int result = ctx->session_->AppendBundles(move(fileFd), {bundleName}, {detailInfo}); + int result = ctx->session_->AppendBundles(move(fileFd), {bundleName}); if (result != 0) { printf("restore append bundles error: %d\n", result); return -result; } } } else { - vector detailInfos; - ret = ctx->session_->AppendBundles(move(fd), bundleNames, detailInfos); + ret = ctx->session_->AppendBundles(move(fd), bundleNames); if (ret != 0) { printf("restore append bundles error: %d\n", ret); return -ret; diff --git a/tools/backup_tool/src/tools_op_incremental_restore_async.cpp b/tools/backup_tool/src/tools_op_incremental_restore_async.cpp index ac74f5e186320c7a6ccf83fdffbbd84c30533247..8b52144b8c86c6ee7f85fd7da860050c07238da0 100644 --- a/tools/backup_tool/src/tools_op_incremental_restore_async.cpp +++ b/tools/backup_tool/src/tools_op_incremental_restore_async.cpp @@ -316,9 +316,7 @@ static int32_t AppendBundles(shared_ptr restore, restoreType = RestoreTypeEnum::RESTORE_DATA_READDY; } try { - std::vector detailInfos; - int ret = restore->session_->AppendBundles(move(fd), bundleNames, detailInfos, restoreType, - atoi(userId.data())); + int ret = restore->session_->AppendBundles(move(fd), bundleNames, restoreType, atoi(userId.data())); if (ret != 0) { printf("restore append bundles error: %d\n", ret); return -ret; diff --git a/tools/backup_tool/src/tools_op_restore.cpp b/tools/backup_tool/src/tools_op_restore.cpp index 8f56941950cd85e1e78e296839a4f219f6264809..dbf3e372526abcbb1bcd03b11c6ad99ad268b81b 100644 --- a/tools/backup_tool/src/tools_op_restore.cpp +++ b/tools/backup_tool/src/tools_op_restore.cpp @@ -242,7 +242,7 @@ static int32_t InitRestoreSession(shared_ptr ctx) .onBundleStarted = bind(OnBundleStarted, ctx, placeholders::_1, placeholders::_2), .onBundleFinished = bind(OnBundleFinished, ctx, placeholders::_1, placeholders::_2), .onAllBundlesFinished = bind(OnAllBundlesFinished, ctx, placeholders::_1), - .onResultReport = bind(OnResultReport, ctx, placeholders::_1); + .onResultReport = bind(OnResultReport, ctx, placeholders::_1), .onBackupServiceDied = bind(OnBackupServiceDied, ctx)}); if (ctx->session_ == nullptr) { printf("Failed to init restore\n"); @@ -278,16 +278,14 @@ static int32_t InitPathCapFile(const string &pathCapFile, vector bundleN FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return -errno; } - std::string bundleDetail = ""; - int result = ctx->session_->AppendBundles(move(fileFd), {bundleName}, {bundleDetail}); + int result = ctx->session_->AppendBundles(move(fileFd), {bundleName}); if (result != 0) { printf("restore append bundles error: %d\n", result); return -result; } } } else { - std::vector detailInfos; - ret = ctx->session_->AppendBundles(move(fd), bundleNames, detailInfos); + ret = ctx->session_->AppendBundles(move(fd), bundleNames); if (ret != 0) { printf("restore append bundles error: %d\n", ret); return -ret; diff --git a/tools/backup_tool/src/tools_op_restore_async.cpp b/tools/backup_tool/src/tools_op_restore_async.cpp index d8dd57b452890c25fbb176a049390fa3f7b06b04..0be93a066383b655c31726264baec291e3063fcc 100644 --- a/tools/backup_tool/src/tools_op_restore_async.cpp +++ b/tools/backup_tool/src/tools_op_restore_async.cpp @@ -300,9 +300,7 @@ static int32_t AppendBundles(shared_ptr restore, restoreType = RestoreTypeEnum::RESTORE_DATA_READDY; } try { - std::vector detailInfos; - int ret = restore->session_->AppendBundles(move(fd), bundleNames, detailInfos, - restoreType, atoi(userId.data())); + int ret = restore->session_->AppendBundles(move(fd), bundleNames, restoreType, atoi(userId.data())); if (ret != 0) { printf("restore append bundles error: %d\n", ret); return -ret; diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 50b6d300f3cd07f63df590aff9897505db236c89..5893b725e7cc772056751d724999d3d651a32bdf 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -101,6 +101,7 @@ ohos_shared_library("backup_utils") { public_configs = [ ":utils_public_config" ] external_deps = [ + "cJSON:cjson", "c_utils:utils", "faultloggerd:libdfx_dumpcatcher", "hilog:libhilog", @@ -113,7 +114,6 @@ ohos_shared_library("backup_utils") { "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", "${path_rust}/crates/cxx/include", "${target_gen_dir}/rust/src", - "//third_party/cJSON:cjson", ] deps = [ @@ -121,7 +121,6 @@ ohos_shared_library("backup_utils") { ":backup_cxx_gen", ":backup_cxx_rust", "${path_jsoncpp}:jsoncpp", - "//third_party/cJSON:cjson", "//third_party/openssl:libcrypto_shared", ]