From a269bdafb7c4745e2182683d152c40c009e3b5eb Mon Sep 17 00:00:00 2001 From: huaqingsimeng Date: Wed, 21 Feb 2024 15:29:42 +0800 Subject: [PATCH] =?UTF-8?q?GetLocalCapabilities=20=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E6=95=B0=E6=8D=AE=E5=A4=A7=E5=B0=8F=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huaqingsimeng --- .../include/module_external/bms_adapter.h | 2 ++ .../src/module_external/bms_adapter.cpp | 32 +++++++++++++++++++ services/backup_sa/src/module_ipc/service.cpp | 2 +- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/services/backup_sa/include/module_external/bms_adapter.h b/services/backup_sa/include/module_external/bms_adapter.h index af1c849e4..9903ec498 100644 --- a/services/backup_sa/include/module_external/bms_adapter.h +++ b/services/backup_sa/include/module_external/bms_adapter.h @@ -61,6 +61,8 @@ public: */ static std::vector GetBundleInfosForIncremental( const std::vector &incrementalDataList, int32_t userId); + + static std::vector GetBundleInfosForIncremental(int32_t userId); }; } // namespace OHOS::FileManagement::Backup #endif // OHOS_FILEMGMT_BACKUP_BUNDLE_MGR_ADAPTER_H diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index d0753183d..d42fa0698 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -314,4 +314,36 @@ vector BundleMgrAdapter::GetBundleInfosForIncrement HILOGI("BundleMgrAdapter GetBundleInfosForIncremental end "); return newBundleInfos; } + +vector BundleMgrAdapter::GetBundleInfosForIncremental(int32_t userId) +{ + vector bundleNames; + vector bundleInfos; + vector installedBundles; + auto bms = GetBundleManager(); + if (!bms->GetBundleInfos(AppExecFwk::GET_BUNDLE_WITH_EXTENSION_INFO, installedBundles, userId)) { + throw BError(BError::Codes::SA_BROKEN_IPC, "Failed to get bundle infos"); + } + for (auto const &installedBundle : installedBundles) { + if (installedBundle.applicationInfo.codePath == HMOS_HAP_CODE_PATH || + installedBundle.applicationInfo.codePath == LINUX_HAP_CODE_PATH) { + HILOGI("Unsupported applications, name : %{public}s", installedBundle.name.data()); + continue; + } + auto [allToBackup, extName, restoreDeps, supportScene] = GetAllowAndExtName(installedBundle.extensionInfos); + int64_t dataSize = 0; + if (!allToBackup) { + bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo {installedBundle.name, installedBundle.versionCode, + installedBundle.versionName, dataSize, allToBackup, + extName, restoreDeps, supportScene}); + } else { + bundleNames.emplace_back(BIncrementalData {installedBundle.name, 0}); + } + } + auto bundleInfosNew = BundleMgrAdapter::GetBundleInfosForIncremental(bundleNames, userId); + for(auto &bundleInfo : bundleInfosNew) { + bundleInfos.emplace_back(bundleInfo); + } + return bundleInfos; +} } // namespace OHOS::FileManagement::Backup diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index 18a2f76d3..339c2a917 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -121,7 +121,7 @@ UniqueFd Service::GetLocalCapabilities() cache.SetSystemFullName(GetOSFullName()); cache.SetDeviceType(GetDeviceType()); - auto bundleInfos = BundleMgrAdapter::GetBundleInfos(session_->GetSessionUserId()); + auto bundleInfos = BundleMgrAdapter::GetBundleInfosForIncremental(session_->GetSessionUserId()); cache.SetBundleInfos(bundleInfos); cachedEntity.Persist(); session_->DecreaseSessionCnt(); -- Gitee