From 701431e6cdee3ea047a9d4215e7fa4f5ce1d6593 Mon Sep 17 00:00:00 2001 From: "yaoruozi1@huawei.com" Date: Thu, 7 Nov 2024 15:08:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8B=89=E8=B5=B7ability?= =?UTF-8?q?=E6=97=B6=E4=BF=A1=E6=81=AF=E6=9C=AA=E8=AE=BE=E7=BD=AE=E5=AE=8C?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yaoruozi1@huawei.com --- .../include/module_ipc/svc_session_manager.h | 5 ++++- .../backup_sa/src/module_external/bms_adapter.cpp | 2 +- services/backup_sa/src/module_ipc/service.cpp | 12 +++++++++++- .../src/module_ipc/service_incremental.cpp | 3 +++ services/backup_sa/src/module_ipc/sub_service.cpp | 2 +- .../src/module_ipc/svc_session_manager.cpp | 15 +++++++++++++-- .../src/module_sched/sched_scheduler.cpp | 1 - .../module_ipc/svc_session_manager_test.cpp | 3 +++ 8 files changed, 36 insertions(+), 7 deletions(-) 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 fd8aaf4d3..d8ecb2d95 100644 --- a/services/backup_sa/include/module_ipc/svc_session_manager.h +++ b/services/backup_sa/include/module_ipc/svc_session_manager.h @@ -71,6 +71,7 @@ struct BackupExtInfo { int32_t appendNum {1}; bool isClearData {true}; bool isInPublishFile {false}; + bool isSetBackupExtInfoDone {false}; }; class Service; @@ -293,7 +294,7 @@ public: * @param bundleName 应用名称 */ sptr CreateBackupConnection(BundleName &bundleName); - + /** * @brief 开始备份 * @@ -512,6 +513,8 @@ public: void SetImplRestoreType(const RestoreTypeEnum restoreType); + void SetBackupExtInfoDone(const std::string &bundleName); + private: /** * @brief 获取backup extension ability diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index 571ca389f..26af6e970 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -127,7 +127,7 @@ vector BundleMgrAdapter::GetBundleInfos(const vecto std::vector extensionInfos; bool getBundleSuccess = GetCurBundleExtenionInfo(installedBundle, bundleName, extensionInfos, bms, userId); if (!getBundleSuccess) { - HILOGE("Get current extension failed"); + HILOGE("Get current extension failed, bundleName:%{public}s", bundleName.c_str()); continue; } auto [allToBackup, fullBackupOnly, extName, restoreDeps, supportScene, extraInfo] = diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index caa9bd9c3..71e966696 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -679,6 +679,7 @@ void Service::SetCurrentSessProperties(std::vector SendUserIdToApp(bundleNameIndexInfo, session_->GetSessionUserId()); } session_->SetBackupExtName(bundleNameIndexInfo, restoreInfo.extensionName); + session_->SetBackupExtInfoDone(bundleNameIndexInfo); } HILOGI("End"); } @@ -777,6 +778,7 @@ void Service::SetCurrentSessProperties(std::vector session_->SetBackupExtInfo(bundleNameIndexInfo, uniCastInfo.detail); } session_->SetBackupExtName(bundleNameIndexInfo, restoreInfo.extensionName); + session_->SetBackupExtInfoDone(bundleNameIndexInfo); } HILOGI("End"); } @@ -870,6 +872,7 @@ void Service::HandleCurGroupBackupInfos(std::vector session_->SetBackupExtInfo(bundleNameIndexInfo, uniCastInfo.detail); } session_->SetBackupExtName(bundleNameIndexInfo, info.extensionName); + session_->SetBackupExtInfoDone(bundleNameIndexInfo); } } @@ -1333,6 +1336,7 @@ void Service::HandleRestoreDepsBundle(const string &bundleName) session_->SetExtFileNameRequest(bundleInfo.name, fileName); } session_->SetBackupExtName(bundleInfo.name, bundleInfo.extensionName); + session_->SetBackupExtInfoDone(bundleInfo.name); } } HILOGI("End"); @@ -1726,10 +1730,16 @@ ErrCode Service::AppendBundlesClearSession(const std::vector &bundle } session_->IncreaseSessionCnt(__PRETTY_FUNCTION__); // BundleMgrAdapter::GetBundleInfos可能耗时 auto backupInfos = BundleMgrAdapter::GetBundleInfos(bundleNames, session_->GetSessionUserId()); - session_->AppendBundles(bundleNames); + std::vector supportBundleNames; + for (auto info : backupInfos) { + std::string bundleNameIndexStr = BJsonUtil::BuildBundleNameIndexInfo(info.name, info.appIndex); + supportBundleNames.emplace_back(bundleNameIndexStr); + } + session_->AppendBundles(supportBundleNames); for (auto info : backupInfos) { std::string bundleNameIndexInfo = BJsonUtil::BuildBundleNameIndexInfo(info.name, info.appIndex); session_->SetBackupExtName(bundleNameIndexInfo, info.extensionName); + session_->SetBackupExtInfoDone(bundleNameIndexInfo); } OnStartSched(); session_->DecreaseSessionCnt(__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 2b089f179..6b4293a90 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -398,6 +398,7 @@ void Service::HandleCurGroupIncBackupInfos(vector & session_->SetBackupExtInfo(bundleNameIndexInfo, uniCastInfo.detail); } session_->SetBackupExtName(bundleNameIndexInfo, info.extensionName); + session_->SetBackupExtInfoDone(bundleNameIndexInfo); } } @@ -700,6 +701,7 @@ void Service::SetCurrentBackupSessProperties(const vector &bundleNames, auto it = bundleNameIndexBundleInfoMap.find(bundleName); if (it == bundleNameIndexBundleInfoMap.end()) { HILOGE("Current bundleName can not find bundleInfo, bundleName:%{public}s", bundleName.c_str()); + session_->RemoveExtInfo(bundleName); continue; } auto bundleInfo = it->second; @@ -709,6 +711,7 @@ void Service::SetCurrentBackupSessProperties(const vector &bundleNames, session_->SetBundleDataSize(bundleName, bundleInfo.spaceOccupied); } session_->SetBackupExtName(bundleName, bundleInfo.extensionName); + session_->SetBackupExtInfoDone(bundleName); } HILOGI("end SetCurrentBackupSessProperties"); } diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index 484c89a24..b269ace2a 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -313,7 +313,7 @@ std::vector Service::GetSupportBackupBundleNames(vector lock(lock_); + if (!impl_.clientToken) { + throw BError(BError::Codes::SA_INVAL_ARG, "No caller token was specified"); + } + auto it = GetBackupExtNameMap(bundleName); + it->second.isSetBackupExtInfoDone = true; + HILOGE("isSetBackupExtInfoDone success, bundleName = %{public}s", bundleName.c_str()); +} } // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/src/module_sched/sched_scheduler.cpp b/services/backup_sa/src/module_sched/sched_scheduler.cpp index 09b743314..ca7e528f8 100644 --- a/services/backup_sa/src/module_sched/sched_scheduler.cpp +++ b/services/backup_sa/src/module_sched/sched_scheduler.cpp @@ -63,7 +63,6 @@ void SchedScheduler::Sched(string bundleName) return; } if (!sessionPtr_->GetSchedBundleName(bundleName)) { - HILOGE("Current bundle can not execute sched, bundleName:%{public}s", bundleName.c_str()); return; } } diff --git a/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp b/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp index b7c34633a..f79c8acf1 100644 --- a/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/svc_session_manager_test.cpp @@ -860,6 +860,9 @@ HWTEST_F(SvcSessionManagerTest, SUB_backup_sa_session_GetSchedBundleName_0100, t try { string bundleName; EXPECT_TRUE(sessionManagerPtr_ != nullptr); + BackupExtInfo backupExtInfo; + backupExtInfo.isSetBackupExtInfoDone = true; + sessionManagerPtr_->impl_.backupExtNameMap[bundleName] = backupExtInfo; bool condition = sessionManagerPtr_->GetSchedBundleName(bundleName); EXPECT_EQ(bundleName, BUNDLE_NAME); EXPECT_TRUE(condition); -- Gitee