From e3dea1c82f0229c68fa2c5ad9eab720f9ac87c7e Mon Sep 17 00:00:00 2001 From: yang-jingbo1985 Date: Sat, 30 Mar 2024 16:44:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96GetLocalcapability=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E9=9C=80=E8=A6=81=E5=8C=85=E5=90=ABallowBackup=3Dfals?= =?UTF-8?q?e=E7=9A=84=E5=BA=94=E7=94=A8=20Signed-off-by:=20yangjingbo10=20?= =?UTF-8?q??= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I9d0e80714556611f73da3eef45939186f4297f5f --- .../b_incremental_session_restore_async.cpp | 4 +- .../include/module_external/bms_adapter.h | 7 ---- .../src/module_external/bms_adapter.cpp | 39 +++++-------------- .../mock/module_external/bms_adapter_mock.cpp | 8 ---- 4 files changed, 12 insertions(+), 46 deletions(-) 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 c531d37d9..248726f22 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 @@ -27,7 +27,7 @@ using namespace std; BIncrementalSessionRestoreAsync::~BIncrementalSessionRestoreAsync() { if (!deathRecipient_) { - HILOGI("Death Recipient is nullptr"); + HILOGE("Death Recipient is nullptr"); return; } auto proxy = ServiceProxy::GetInstance(); @@ -49,7 +49,7 @@ shared_ptr BIncrementalSessionRestoreAsync::Ini ServiceProxy::InvaildInstance(); auto proxy = ServiceProxy::GetInstance(); if (proxy == nullptr) { - HILOGI("Failed to get backup service"); + HILOGE("Failed to get backup service"); return nullptr; } BIncrementalRestoreSession::Callbacks callbacksTmp {.onFileReady = callbacks.onFileReady, diff --git a/services/backup_sa/include/module_external/bms_adapter.h b/services/backup_sa/include/module_external/bms_adapter.h index 9903ec498..4603c38fd 100644 --- a/services/backup_sa/include/module_external/bms_adapter.h +++ b/services/backup_sa/include/module_external/bms_adapter.h @@ -29,13 +29,6 @@ class InnerReceiverImpl; class BundleMgrAdapter { public: - /** - * @brief Get the Bundle Infos object - * - * @param userId User ID - * @return std::vector - */ - static std::vector GetBundleInfos(int32_t userId); /** * @brief Get the bundle infos object diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index bb12e6627..1ae0c15db 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -106,32 +106,6 @@ static int64_t GetBundleStats(const string &bundleName, int32_t userId) return dataSize_; } -vector BundleMgrAdapter::GetBundleInfos(int32_t userId) -{ - 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) { - dataSize = GetBundleStats(installedBundle.name, userId); - } - bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo {installedBundle.name, installedBundle.versionCode, - installedBundle.versionName, dataSize, allToBackup, - extName, restoreDeps, supportScene}); - } - return bundleInfos; -} - vector BundleMgrAdapter::GetBundleInfos(const vector &bundleNames, int32_t userId) { vector bundleInfos; @@ -317,12 +291,14 @@ vector BundleMgrAdapter::GetBundleInfosForIncrement vector BundleMgrAdapter::GetBundleInfosForIncremental(int32_t userId) { - vector bundleNames; 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"); } + + vector bundleNames; + vector bundleInfos; for (auto const &installedBundle : installedBundles) { if (installedBundle.applicationInfo.codePath == HMOS_HAP_CODE_PATH || installedBundle.applicationInfo.codePath == LINUX_HAP_CODE_PATH) { @@ -330,10 +306,15 @@ vector BundleMgrAdapter::GetBundleInfosForIncrement continue; } auto [allToBackup, extName, restoreDeps, supportScene] = GetAllowAndExtName(installedBundle.extensionInfos); - if (allToBackup) { + if (!allToBackup) { + bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo {installedBundle.name, installedBundle.versionCode, + installedBundle.versionName, 0, allToBackup, extName, restoreDeps, supportScene}); + } else { bundleNames.emplace_back(BIncrementalData {installedBundle.name, 0}); } } - return BundleMgrAdapter::GetBundleInfosForIncremental(bundleNames, userId); + auto bundleInfosNew = BundleMgrAdapter::GetBundleInfosForIncremental(bundleNames, userId); + copy(bundleInfosNew.begin(), bundleInfosNew.end(), back_inserter(bundleInfos)); + return bundleInfos; } } // namespace OHOS::FileManagement::Backup diff --git a/tests/mock/module_external/bms_adapter_mock.cpp b/tests/mock/module_external/bms_adapter_mock.cpp index afff66e3e..602c4f45a 100644 --- a/tests/mock/module_external/bms_adapter_mock.cpp +++ b/tests/mock/module_external/bms_adapter_mock.cpp @@ -28,14 +28,6 @@ namespace OHOS::FileManagement::Backup { using namespace std; -vector BundleMgrAdapter::GetBundleInfos(int32_t userId) -{ - vector bundleInfos; - bundleInfos.emplace_back( - BJsonEntityCaps::BundleInfo {"com.example.app2backup", {}, {}, 0, true, "com.example.app2backup"}); - return bundleInfos; -} - vector BundleMgrAdapter::GetBundleInfos(const vector &bundleNames, int32_t userId) { vector bundleInfos; -- Gitee