From 047173933a1411dc92d1170da0dd6186485a6443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=99=9F=E9=92=B0?= Date: Sat, 23 Nov 2024 14:28:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E5=99=A8=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E5=89=8D=E5=88=B7=E6=96=B0=E6=95=B0=E6=8D=AE=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张晟钰 --- .../native/backup_ext/include/ext_extension.h | 31 ++++- .../native/backup_ext/src/ext_extension.cpp | 123 +++++++++++++----- .../backup_kit_inner/src/service_proxy.cpp | 51 ++++++++ .../native/backup_kit_inner/impl/i_service.h | 2 + .../impl/i_service_ipc_interface_code.h | 2 + .../backup_kit_inner/impl/service_proxy.h | 2 + .../backup_sa/include/module_ipc/service.h | 2 + .../include/module_ipc/service_stub.h | 2 + services/backup_sa/src/module_ipc/service.cpp | 22 ++++ .../src/module_ipc/service_incremental.cpp | 11 +- .../backup_sa/src/module_ipc/service_stub.cpp | 38 ++++++ .../backup_sa/src/module_ipc/sub_service.cpp | 19 +++ .../backup_kit_inner/service_proxy_mock.cpp | 11 ++ .../module_ipc/include/service_stub_mock.h | 4 + tests/mock/module_ipc/service_mock.cpp | 10 ++ tests/mock/module_ipc/service_stub_mock.cpp | 14 ++ .../mock/module_ipc/src/service_stub_mock.cpp | 10 ++ .../backup_impl/include/i_service_mock.h | 10 ++ .../module_ipc/service_incremental_test.cpp | 15 +++ .../module_ipc/service_stub_test.cpp | 2 + .../backup_sa/session/service_proxy_mock.cpp | 10 ++ .../backup_sa/session/service_proxy_mock.h | 2 + utils/include/b_error/b_error.h | 1 + utils/include/b_radar/b_radar.h | 4 +- 24 files changed, 358 insertions(+), 40 deletions(-) diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index 7315efd2a..eaeb37439 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -94,9 +94,12 @@ private: /** * @brief backup * - * @param usrConfig user configure + * @param bigFileInfo bigfiles to be backup + * @param smallFiles smallfiles to be backup + * @param includes sizeof includes + * @param excludes sizeof excludes */ - int DoBackup(const BJsonEntityExtensionConfig &usrConfig); + int DoBackup(TarMap &bigFileInfo, map &smallFiles, int32_t includes, int32_t excludes); /** * @brief restore @@ -218,6 +221,30 @@ private: */ void StartFwkTimer(bool &isFwkStart); + /** + * @brief stop ext timer by ipc + * + */ + bool StopExtTimer(); + + /** + * @brief refresh datasize + * + * @param totalSize backup totalSize + */ + void RefreshDataSize(int64_t totalSize); + + /** + * @brief scanning files and calculate datasize + * + * @param usrConfig usrConfig + * @param totalSize totalSize + * @param bigFileInfo bigFileInfo + * @param smallFiles smallFiles info + */ + tuple CalculateDataSize(const BJsonEntityExtensionConfig &usrConfig, + int64_t &totalSize, TarMap &bigFileInfo, map &smallFiles); + /** * @brief get increCallbackEx for execute onRestore with string param * diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 7f5a72508..e5e3303b6 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -92,7 +92,7 @@ static void RecordDoRestoreRes(const std::string &bundleName, const std::string static void RecordDoBackupRes(const std::string &bundleName, const ErrCode errCode, AppRadar::DoBackupInfo &backupInfo) { - uint32_t inExcludeNum = backupInfo.includeNum + backupInfo.excludeNum; + int32_t inExcludeNum = backupInfo.includeNum + backupInfo.excludeNum; if (inExcludeNum >= BConstants::MAX_INEXCLUDE_SIZE) { AppRadar::Info infoInExclude(bundleName, "", string("\"total inExclude\":").append(to_string(inExcludeNum))); AppRadar::GetInstance().RecordBackupFuncRes(infoInExclude, "BackupExtExtension::DoBackup", @@ -765,7 +765,8 @@ void BackupExtExtension::DoPacket(const map &srcFiles, TarMap &t } } -int BackupExtExtension::DoBackup(const BJsonEntityExtensionConfig &usrConfig) +int BackupExtExtension::DoBackup(TarMap &bigFileInfo, map &smallFiles, + int32_t includes, int32_t excludes) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); HILOGI("Start Do backup"); @@ -778,28 +779,11 @@ int BackupExtExtension::DoBackup(const BJsonEntityExtensionConfig &usrConfig) return EPERM; } - string path = string(BConstants::PATH_BUNDLE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_BACKUP); - if (mkdir(path.data(), S_IRWXU) && errno != EEXIST) { - throw BError(errno); - } - - vector includes = usrConfig.GetIncludes(); - vector excludes = usrConfig.GetExcludes(); auto proxy = ServiceProxy::GetInstance(); if (proxy == nullptr) { throw BError(BError::Codes::EXT_BROKEN_BACKUP_SA, std::generic_category().message(errno)); } - // 大文件处理 - HILOGI("Start packet bigfiles and small files"); - auto [bigFileInfo, smallFiles] = GetFileInfos(includes, excludes); - for (const auto &item : bigFileInfo) { - auto filePath = std::get<0>(item.second); - if (!filePath.empty()) { - excludes.push_back(filePath); - } - } - // 回传大文件 HILOGI("Will notify BigFileReady"); auto res = BigFileReady(bigFileInfo, proxy); @@ -820,11 +804,59 @@ int BackupExtExtension::DoBackup(const BJsonEntityExtensionConfig &usrConfig) auto end = std::chrono::system_clock::now(); auto cost = std::chrono::duration_cast(end - start).count(); AppRadar::DoBackupInfo doBackupInfo = {cost, bigFileInfo.size(), smallFiles.size(), tarMap.size(), - includes.size(), excludes.size()}; + includes, excludes}; RecordDoBackupRes(bundleName_, res, doBackupInfo); return res; } +tuple BackupExtExtension::CalculateDataSize(const BJsonEntityExtensionConfig &usrConfig, + int64_t &totalSize, TarMap &bigFileInfo, map &smallFiles) +{ + HILOGI("Start scanning files and calculate datasize"); + string path = string(BConstants::PATH_BUNDLE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_BACKUP); + if (mkdir(path.data(), S_IRWXU) && errno != EEXIST) { + HILOGE("mkdir failed path :%{public}s, err = %{public}d", path.c_str(), errno); + return {-errno, -1}; + } + + vector includes = usrConfig.GetIncludes(); + vector excludes = usrConfig.GetExcludes(); + + // 扫描文件计算数据量 + tie(bigFileInfo, smallFiles) = GetFileInfos(includes, excludes); + for (const auto &item : bigFileInfo) { + int64_t fileSize = static_cast(std::get<1>(item.second).st_size); + HILOGD("bigfile size = %{public}" PRId64 "", fileSize); + totalSize += fileSize; + } + HILOGI("bigfile size = %{public}" PRId64 "", totalSize); + for (const auto &item : smallFiles) { + totalSize += static_cast(item.second); + } + HILOGI("scanning end, Datasize = %{public}" PRId64 "", totalSize); + return {static_cast(includes.size()), static_cast(excludes.size())}; +} + +void BackupExtExtension::RefreshDataSize(int64_t totalSize) +{ + HILOGI("RefreshDataSize start"); + if (totalSize == 0) { + HILOGI("no backup datasize, don't need to refresh"); + return; + } + auto proxy = ServiceProxy::GetInstance(); + if (proxy == nullptr) { + HILOGE("Failed to obtain the ServiceProxy handle"); + return; + } + HILOGI("start RefreshDatasize by ipc"); + auto ret = proxy->RefreshDataSize(totalSize); + if (ret != ERR_OK) { + HILOGI("RefreshDataSize failed, ret = %{public}d", ret); + } + HILOGI("RefreshDataSize end"); +} + int BackupExtExtension::DoRestore(const string &fileName, const off_t fileSize) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); @@ -973,31 +1005,35 @@ void BackupExtExtension::AsyncTaskBackup(const string config) auto ptr = obj.promote(); BExcepUltils::BAssert(ptr, BError::Codes::EXT_BROKEN_FRAMEWORK, "Ext extension handle have been released"); try { - HILOGI("Do backup, start fwk timer begin."); + if (!ptr->StopExtTimer()) { + throw BError(BError::Codes::EXT_TIMER_ERROR, "Failed to stop exttimer"); + } + int64_t totalSize; + TarMap bigFileInfo; + map smallFiles; + BJsonCachedEntity cachedEntity(config); + auto cache = cachedEntity.Structuralize(); + auto [includeSize, excludeSize] = ptr->CalculateDataSize(cache, totalSize, bigFileInfo, smallFiles); + if (includeSize < 0 || excludeSize < 0) { + throw BError(BError::Codes::EXT_INVAL_ARG, "Failed to mkldir"); + } + ptr->RefreshDataSize(totalSize); bool isFwkStart; ptr->StartFwkTimer(isFwkStart); if (!isFwkStart) { HILOGE("Do backup, start fwk timer fail."); - return; + throw BError(BError::Codes::EXT_TIMER_ERROR, "Failed to start fwktimer"); } - HILOGI("Do backup, start fwk timer end."); - BJsonCachedEntity cachedEntity(config); - auto cache = cachedEntity.Structuralize(); - auto ret = ptr->DoBackup(cache); - // REM: 处理返回结果 ret + auto ret = ptr->DoBackup(bigFileInfo, smallFiles, includeSize, excludeSize); ptr->AppDone(ret); HILOGI("backup app done %{public}d", ret); } catch (const BError &e) { HILOGE("extension: AsyncTaskBackup error, err code:%{public}d", e.GetCode()); ptr->AppDone(e.GetCode()); - } catch (const exception &e) { - HILOGE("Catched an unexpected low-level exception %{public}s", e.what()); - ptr->AppDone(BError(BError::Codes::EXT_INVAL_ARG).GetCode()); } catch (...) { HILOGE("Failed to restore the ext bundle"); ptr->AppDone(BError(BError::Codes::EXT_INVAL_ARG).GetCode()); } - // 清空备份目录 ptr->DoClear(); }; @@ -1713,6 +1749,7 @@ void BackupExtExtension::StartExtTimer(bool &isExtStart) void BackupExtExtension::StartFwkTimer(bool &isFwkStart) { + HILOGI("Do backup, start fwk timer begin."); auto proxy = ServiceProxy::GetInstance(); BExcepUltils::BAssert(proxy, BError::Codes::EXT_BROKEN_IPC, "Failed to obtain the ServiceProxy handle"); HILOGI("Start fwk timer by ipc."); @@ -1720,6 +1757,30 @@ void BackupExtExtension::StartFwkTimer(bool &isFwkStart) if (ret != ERR_OK) { HILOGE("Start fwk timer failed, errCode: %{public}d", ret); } + HILOGI("Do backup, start fwk timer end."); +} + +bool BackupExtExtension::StopExtTimer() +{ + HILOGI("StopExtTimer start"); + bool isExtStop; + auto proxy = ServiceProxy::GetInstance(); + if (proxy == nullptr) { + HILOGE("Failed to obtain the ServiceProxy handle"); + return false; + } + HILOGI("StopExtTimer by ipc"); + auto ret = proxy->StopExtTimer(isExtStop); + if (ret != ERR_OK) { + HILOGE("StopExtTimer failed, errcode :%{public}d", ret); + return false; + } + if (!isExtStop) { + HILOGE("StopExtTimer failed"); + return false; + } + HILOGI("StopExtTimer end"); + return true; } void BackupExtExtension::UpdateOnStartTime() diff --git a/frameworks/native/backup_kit_inner/src/service_proxy.cpp b/frameworks/native/backup_kit_inner/src/service_proxy.cpp index 2e1ecb6bb..516d7ba8f 100644 --- a/frameworks/native/backup_kit_inner/src/service_proxy.cpp +++ b/frameworks/native/backup_kit_inner/src/service_proxy.cpp @@ -674,4 +674,55 @@ ErrCode ServiceProxy::StartFwkTimer(bool &isFwkStart) HILOGI("ServiceProxy StartFwkTimer end. isFwkStart = %d", isFwkStart); return BError(BError::Codes::OK, "success"); } + +ErrCode ServiceProxy::StopExtTimer(bool &isExtStop) +{ + HILOGI("ServiceProxy StopExtTimer 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); + int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_STOP_EXT_TIMER), + 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.ReadBool(isExtStop); + HILOGI("ServiceProxy StopExtTimer end. isFwkUpdate = %d", isExtStop); + return BError(BError::Codes::OK, "success"); +} + +ErrCode ServiceProxy::RefreshDataSize(int64_t totalSize) +{ + HILOGI("ServiceProxy RefreshDatasize 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 (!data.WriteInt64(totalSize)) { + return BError(BError::Codes::SDK_INVAL_ARG, "Failed to write totalSize").GetCode(); + } + MessageParcel reply; + MessageOption option; + option.SetWaitTime(BConstants::IPC_MAX_WAIT_TIME); + int32_t ret = Remote()->SendRequest(static_cast(IServiceInterfaceCode::SERVICE_CMD_REFRESH_DATA_SIZE), + 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(); + } + bool result = false; + reply.ReadBool(result); + if (!result) { + return BError(BError::Codes::SDK_INVAL_ARG, "Failed to Refresh Datasize").GetCode(); + } + return BError(BError::Codes::OK, "success"); +} + } // 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 6dee18fc3..16ddf4c62 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 @@ -88,6 +88,8 @@ public: virtual ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) = 0; virtual ErrCode StartExtTimer(bool &isExtStart) = 0; virtual ErrCode StartFwkTimer(bool &isFwkStart) = 0; + virtual ErrCode StopExtTimer(bool &isExtStop) = 0; + virtual ErrCode RefreshDataSize(int64_t totalSize) = 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 9175e2295..c4ab2d359 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 @@ -50,6 +50,8 @@ enum class IServiceInterfaceCode { SERVICE_CMD_UPDATE_SENDRATE, SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP, SERVICE_CMD_REPORT_APP_PROCESS_INFO, + SERVICE_CMD_STOP_EXT_TIMER, + SERVICE_CMD_REFRESH_DATA_SIZE, }; } // namespace OHOS::FileManagement::Backup 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 21c676d85..94271d4bc 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 @@ -71,6 +71,8 @@ public: ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) override; ErrCode StartExtTimer(bool &isExtStart) override; ErrCode StartFwkTimer(bool &isFwkStart) override; + ErrCode StopExtTimer(bool &isExtStop) override; + ErrCode RefreshDataSize(int64_t totalSize) override; public: explicit ServiceProxy(const sptr &impl) : IRemoteProxy(impl) {} diff --git a/services/backup_sa/include/module_ipc/service.h b/services/backup_sa/include/module_ipc/service.h index 1b92cc342..1dc6eaa1e 100644 --- a/services/backup_sa/include/module_ipc/service.h +++ b/services/backup_sa/include/module_ipc/service.h @@ -92,6 +92,8 @@ public: ErrCode ReportAppProcessInfo(const std::string processInfo, const BackupRestoreScenario sennario) override; ErrCode StartExtTimer(bool &isExtStart) override; ErrCode StartFwkTimer(bool &isFwkStart) override; + ErrCode StopExtTimer(bool &isExtStop) override; + ErrCode RefreshDataSize(int64_t totalDataSize) override; ErrCode SAResultReport(const std::string bundleName, const std::string resultInfo, const ErrCode errCode, const BackupRestoreScenario sennario); diff --git a/services/backup_sa/include/module_ipc/service_stub.h b/services/backup_sa/include/module_ipc/service_stub.h index 5aeba2752..09dc21490 100644 --- a/services/backup_sa/include/module_ipc/service_stub.h +++ b/services/backup_sa/include/module_ipc/service_stub.h @@ -65,6 +65,8 @@ private: int32_t CmdReportAppProcessInfo(MessageParcel &data, MessageParcel &reply); int32_t CmdStartExtTimer(MessageParcel &data, MessageParcel &reply); int32_t CmdStartFwkTimer(MessageParcel &data, MessageParcel &reply); + int32_t CmdStopExtTimer(MessageParcel &data, MessageParcel &reply); + int32_t CmdRefreshDataSize(MessageParcel &data, MessageParcel &reply); void ServiceStubSupplement(); void ServiceStubSuppAppendBundles(); diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 463df88a0..ca34bd2f7 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -1728,6 +1728,28 @@ ErrCode Service::StartFwkTimer(bool &isFwkStart) } } +ErrCode Service::StopExtTimer(bool &isExtStop) +{ + try { + HILOGI("Service::StopExtTimer begin."); + if (session_ == nullptr) { + HILOGE("StopExtTimer error, session_ is nullptr."); + isExtStop = false; + return BError(BError::Codes::SA_INVAL_ARG); + } + session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); + string bundleName = VerifyCallerAndGetCallerName(); + isExtStop = session_->StopExtTimer(bundleName); + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + return BError(BError::Codes::OK); + } catch (...) { + isExtStop = false; + session_->DecreaseSessionCnt(__PRETTY_FUNCTION__); + HILOGI("Unexpected exception"); + return EPERM; + } +} + ErrCode Service::AppendBundlesClearSession(const std::vector &bundleNames) { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 8583f06e2..41ffd2998 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -215,16 +215,16 @@ void Service::StartGetFdTask(std::string bundleName, wptr ptr) } return; } + if (!session->StopExtTimer(bundleName)) { + throw BError(BError::Codes::SA_INVAL_ARG, "StopExtTimer error"); + } int64_t lastTime = session->GetLastIncrementalTime(bundleName); std::vector bundleNames; bundleNames.emplace_back(BIncrementalData {bundleName, lastTime}); auto newBundleInfos = BundleMgrAdapter::GetBundleInfosForIncremental(bundleNames, session->GetSessionUserId()); RefreshBundleDataSize(newBundleInfos, bundleName, ptr); string path = BConstants::GetSaBundleBackupRootDir(session->GetSessionUserId()). - append(bundleName). - append("/"). - append(BConstants::BACKUP_STAT_SYMBOL). - append(to_string(lastTime)); + append(bundleName).append("/").append(BConstants::BACKUP_STAT_SYMBOL).append(to_string(lastTime)); HILOGD("path = %{public}s,bundleName = %{public}s", path.c_str(), bundleName.c_str()); UniqueFd fdLocal(open(path.data(), O_RDWR, S_IRGRP | S_IWGRP)); if (fdLocal < 0) { @@ -252,8 +252,9 @@ void Service::RefreshBundleDataSize(const vector &n HILOGE("session is nullptr"); return; } + BJsonUtil::BundleDetailInfo bundleInfo = BJsonUtil::ParseBundleNameIndexStr(bundleName); for (auto &info : newBundleInfos) { - if (info.name == bundleName) { + if (info.name == bundleInfo.bundleName && info.appIndex == bundleInfo.bundleIndex) { session->SetBundleDataSize(bundleName, info.increSpaceOccupied); HILOGI("RefreshBundleDataSize, bundlename = %{public}s , datasize = %{public}" PRId64 "", bundleName.c_str(), info.increSpaceOccupied); diff --git a/services/backup_sa/src/module_ipc/service_stub.cpp b/services/backup_sa/src/module_ipc/service_stub.cpp index 20dedbbba..abf1a4563 100644 --- a/services/backup_sa/src/module_ipc/service_stub.cpp +++ b/services/backup_sa/src/module_ipc/service_stub.cpp @@ -50,6 +50,8 @@ void ServiceStub::ServiceStubSupplement() &ServiceStub::CmdStartExtTimer; opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_START_FWK_TIMER)] = &ServiceStub::CmdStartFwkTimer; + opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_STOP_EXT_TIMER)] = + &ServiceStub::CmdStopExtTimer; } void ServiceStub::ServiceStubSuppAppendBundles() @@ -108,6 +110,8 @@ ServiceStub::ServiceStub() &ServiceStub::CmdGetIncrementalFileHandle; opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_GET_BACKUP_INFO)] = &ServiceStub::CmdGetBackupInfo; + opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_REFRESH_DATA_SIZE)] = + &ServiceStub::CmdRefreshDataSize; ServiceStubSupplement(); } @@ -675,6 +679,40 @@ int32_t ServiceStub::CmdReportAppProcessInfo(MessageParcel &data, MessageParcel return ReportAppProcessInfo(processInfo, secenrioInfo); } +int32_t ServiceStub::CmdStopExtTimer(MessageParcel &data, MessageParcel &reply) +{ + HILOGI("ServiceStub::CmdStopExtTimer Begin."); + bool isExtStop; + auto ret = StopExtTimer(isExtStop); + if (ret != ERR_OK) { + return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to call StopExtTimer")); + } + if (!reply.WriteBool(isExtStop)) { + return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); + } + HILOGI("ServiceStub::CmdStopExtTimer end."); + return BError(BError::Codes::OK); +} + +int32_t ServiceStub::CmdRefreshDataSize(MessageParcel &data, MessageParcel &reply) +{ + HILOGI("ServiceStub::CmdRefreshDataSize Begin."); + int64_t totalDatasize = 0; + if (!data.ReadInt64(totalDatasize)) { + return BError(BError::Codes::SA_INVAL_ARG, "Failed to receive totalDatasize").GetCode(); + } + auto ret = RefreshDataSize(totalDatasize); + if (ret != ERR_OK) { + return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to receive totalDatasize")); + } + bool ifRefreshSuccess = true; + if (!reply.WriteBool(ifRefreshSuccess)) { + return BError(BError::Codes::SA_BROKEN_IPC, string("Failed to write result")); + } + HILOGI("ServiceStub::CmdRefreshDataSize end."); + return BError(BError::Codes::OK); +} + template bool ServiceStub::ReadParcelableVector(std::vector &parcelableInfos, MessageParcel &data) { diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index 8bbdf2482..8a359e3d4 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -346,6 +346,25 @@ void Service::SetCurrentSessProperties(BJsonEntityCaps::BundleInfo &info, HILOGI("End"); } +ErrCode Service::RefreshDataSize(int64_t totalDataSize) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + try { + if (session_ == nullptr) { + HILOGE("session id nullptr"); + return BError(BError::Codes::SA_INVAL_ARG); + } + std::string bundleName = VerifyCallerAndGetCallerName(); + session_->SetBundleDataSize(bundleName, totalDataSize); + HILOGI("RefreshDataSize, bundleName:%{public}s ,datasize = %{public}" PRId64 "", + bundleName.c_str(), totalDataSize); + return BError(BError::Codes::OK); + } catch (const BError &e) { + return e.GetCode(); + } +} + + void Service::HandleNotSupportBundleNames(const std::vector &srcBundleNames, std::vector &supportBundleNames, bool isIncBackup) { diff --git a/tests/mock/backup_kit_inner/service_proxy_mock.cpp b/tests/mock/backup_kit_inner/service_proxy_mock.cpp index 04c6afe8a..7b5340c0b 100644 --- a/tests/mock/backup_kit_inner/service_proxy_mock.cpp +++ b/tests/mock/backup_kit_inner/service_proxy_mock.cpp @@ -189,11 +189,22 @@ ErrCode ServiceProxy::StartExtTimer(bool &isExtStart) { return BError(BError::Codes::OK); } + ErrCode ServiceProxy::StartFwkTimer(bool &isFwkStart) { return BError(BError::Codes::OK); } +ErrCode ServiceProxy::StopExtTimer(bool &isExtStop) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceProxy::RefreshDataSize(int64_t totalSize) +{ + return BError(BError::Codes::OK); +} + ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) { return BError(BError::Codes::OK); diff --git a/tests/mock/module_ipc/include/service_stub_mock.h b/tests/mock/module_ipc/include/service_stub_mock.h index 85a71336f..0c3069b46 100644 --- a/tests/mock/module_ipc/include/service_stub_mock.h +++ b/tests/mock/module_ipc/include/service_stub_mock.h @@ -50,6 +50,8 @@ public: virtual int32_t CmdGetBackupInfo(MessageParcel&, MessageParcel&) = 0; virtual int32_t CmdUpdateTimer(MessageParcel&, MessageParcel&) = 0; virtual int32_t CmdUpdateSendRate(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdStopExtTimer(MessageParcel&, MessageParcel&) = 0; + virtual int32_t CmdRefreshDataSize(MessageParcel&, MessageParcel&) = 0; virtual void ServiceStubSupplement() = 0; virtual void ServiceStubSuppAppendBundles() = 0; @@ -91,6 +93,8 @@ public: MOCK_METHOD(int32_t, CmdGetBackupInfo, (MessageParcel&, MessageParcel&)); MOCK_METHOD(int32_t, CmdUpdateTimer, (MessageParcel&, MessageParcel&)); MOCK_METHOD(int32_t, CmdUpdateSendRate, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdStopExtTimer, (MessageParcel&, MessageParcel&)); + MOCK_METHOD(int32_t, CmdRefreshDataSize, (MessageParcel&, MessageParcel&)); MOCK_METHOD(void, ServiceStubSupplement, ()); MOCK_METHOD(void, ServiceStubSuppAppendBundles, ()); }; diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index 4f6a1d0d1..99bcabc99 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -226,6 +226,16 @@ ErrCode Service::StartFwkTimer(bool &isFwkStart) return BError(BError::Codes::OK); } +ErrCode Service::StopExtTimer(bool &isExtStop) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::RefreshDataSize(int64_t totalDatasize) +{ + return BError(BError::Codes::OK); +} + ErrCode Service::UpdateTimer(BundleName &bundleName, uint32_t timeout, bool &result) { return BError(BError::Codes::OK); diff --git a/tests/mock/module_ipc/service_stub_mock.cpp b/tests/mock/module_ipc/service_stub_mock.cpp index 101f2fdfb..cd36d6d44 100644 --- a/tests/mock/module_ipc/service_stub_mock.cpp +++ b/tests/mock/module_ipc/service_stub_mock.cpp @@ -69,6 +69,10 @@ ServiceStub::ServiceStub() opToInterfaceMap_[static_cast( IServiceInterfaceCode::SERVICE_CMD_GET_APP_LOCAL_LIST_AND_DO_INCREMENTAL_BACKUP)] = &ServiceStub::CmdGetAppLocalListAndDoIncrementalBackup; + opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_STOP_EXT_TIMER)] = + &ServiceStub::CmdStopExtTimer; + opToInterfaceMap_[static_cast(IServiceInterfaceCode::SERVICE_CMD_REFRESH_DATA_SIZE)] = + &ServiceStub::CmdRefreshDataSize; } void ServiceStub::ServiceStubSupplement() @@ -316,4 +320,14 @@ int32_t ServiceStub::CmdReportAppProcessInfo(MessageParcel &data, MessageParcel { return BError(BError::Codes::OK); } + +int32_t ServiceStub::CmdStopExtTimer(MessageParcel &data, MessageParcel &reply) +{ + return BError(BError::Codes::OK); +} + +int32_t ServiceStub::CmdRefreshDataSize(MessageParcel &data, MessageParcel &reply) +{ + return BError(BError::Codes::OK); +} } // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_ipc/src/service_stub_mock.cpp b/tests/mock/module_ipc/src/service_stub_mock.cpp index df67aac7d..59deec0f8 100644 --- a/tests/mock/module_ipc/src/service_stub_mock.cpp +++ b/tests/mock/module_ipc/src/service_stub_mock.cpp @@ -156,4 +156,14 @@ int32_t ServiceStub::CmdGetIncrementalFileHandle(MessageParcel &data, MessagePar { return BServiceStub::stub->CmdGetIncrementalFileHandle(data, reply); } + +int32_t ServiceStub::CmdStopExtTimer(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdStopExtTimer(data, reply); +} + +int32_t ServiceStub::CmdRefreshDataSize(MessageParcel &data, MessageParcel &reply) +{ + return BServiceStub::stub->CmdRefreshDataSize(data, reply); +} } // namespace OHOS::FileManagement::Backup 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 a0da61edc..20ebe6b6e 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 @@ -153,6 +153,16 @@ public: return BError(BError::Codes::OK); } + ErrCode StopExtTimer(bool &isExtStop) override + { + return BError(BError::Codes::OK); + } + + ErrCode RefreshDataSize(int64_t totalsize) override + { + return BError(BError::Codes::OK); + } + ErrCode UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) override { return BError(BError::Codes::OK); diff --git a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp index 9d43383b8..03756494b 100644 --- a/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_incremental_test.cpp @@ -207,6 +207,21 @@ ErrCode Service::StartFwkTimer(bool &isFwkStart) return BError(BError::Codes::OK); } +ErrCode Service::StopExtTimer(bool &isExtStop) +{ + return BError(BError::Codes::OK); +} + +ErrCode Service::RefreshDataSize(int64_t totalsize) +{ + return BError(BError::Codes::OK); +} + +std::function Service::TimeOutCallback(wptr ptr, std::string bundleName) +{ + return []() {}; +} + void Service::SetCurrentSessProperties(std::vector&, std::vector&, RestoreTypeEnum) {} 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 632d7def5..015a5c0b0 100644 --- a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp @@ -82,6 +82,8 @@ public: MOCK_METHOD3(UpdateTimer, ErrCode(BundleName &bundleName, uint32_t timeout, bool &result)); MOCK_METHOD1(StartExtTimer, ErrCode(bool &isExtStart)); MOCK_METHOD1(StartFwkTimer, ErrCode(bool &isFwkStart)); + MOCK_METHOD1(StopExtTimer, ErrCode(bool &isExtStop)); + MOCK_METHOD1(RefreshDataSize, ErrCode(int64_t totalsize)); MOCK_METHOD3(UpdateSendRate, ErrCode(std::string &bundleName, int32_t sendRate, bool &result)); MOCK_METHOD2(ReportAppProcessInfo, ErrCode(const std::string processInfo, BackupRestoreScenario sennario)); }; diff --git a/tests/unittests/backup_sa/session/service_proxy_mock.cpp b/tests/unittests/backup_sa/session/service_proxy_mock.cpp index ebcf680de..c27b68417 100644 --- a/tests/unittests/backup_sa/session/service_proxy_mock.cpp +++ b/tests/unittests/backup_sa/session/service_proxy_mock.cpp @@ -172,6 +172,16 @@ ErrCode ServiceProxy::StartFwkTimer(bool &isFwkStart) return BError(BError::Codes::OK); } +ErrCode ServiceProxy::StopExtTimer(bool &isExtStop) +{ + return BError(BError::Codes::OK); +} + +ErrCode ServiceProxy::RefreshDataSize(int64_t totalsize) +{ + return BError(BError::Codes::OK); +} + ErrCode ServiceProxy::UpdateSendRate(std::string &bundleName, int32_t sendRate, bool &result) { return BError(BError::Codes::OK); diff --git a/tests/unittests/backup_sa/session/service_proxy_mock.h b/tests/unittests/backup_sa/session/service_proxy_mock.h index 521d3904a..9d213bcd6 100644 --- a/tests/unittests/backup_sa/session/service_proxy_mock.h +++ b/tests/unittests/backup_sa/session/service_proxy_mock.h @@ -60,6 +60,8 @@ public: MOCK_METHOD2(GetBackupInfo, ErrCode(BundleName &bundleName, std::string &result)); MOCK_METHOD3(UpdateTimer, ErrCode(BundleName &bundleName, uint32_t timeout, bool &result)); MOCK_METHOD0(GetAppLocalListAndDoIncrementalBackup, ErrCode()); + MOCK_METHOD1(StopExtTimer, ErrCode(bool &isExtStop)); + MOCK_METHOD1(RefreshDataSize, ErrCode(int64_t totalsize)); }; } // End of namespace OHOS::FileManagement::Backup #endif // TEST_UNITTEST_SERVICE_PROXY_MOCK_H diff --git a/utils/include/b_error/b_error.h b/utils/include/b_error/b_error.h index 3863761c7..1cc4ee2d5 100644 --- a/utils/include/b_error/b_error.h +++ b/utils/include/b_error/b_error.h @@ -91,6 +91,7 @@ public: EXT_METHOD_NOT_EXIST = 0x5008, EXT_THROW_EXCEPTION = 0x5009, EXT_BACKUP_UNPACKET_ERROR = 0x5010, + EXT_TIMER_ERROR = 0X5011, // 0x6000~0x6999 sa_ext错误 SA_EXT_ERR_CALL = 0x6000, diff --git a/utils/include/b_radar/b_radar.h b/utils/include/b_radar/b_radar.h index 2ec80872e..0af5b385c 100644 --- a/utils/include/b_radar/b_radar.h +++ b/utils/include/b_radar/b_radar.h @@ -99,8 +99,8 @@ public: uint32_t allFileNum; uint32_t smallFileNum; uint32_t tarFileNum; - uint32_t includeNum; - uint32_t excludeNum; + int32_t includeNum; + int32_t excludeNum; }; struct StatInfo { -- Gitee