From e521d685b3d4c0798d3f3793fd845cc0d2c0c131 Mon Sep 17 00:00:00 2001 From: yang-jingbo1985 Date: Mon, 20 Nov 2023 22:57:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=8E=B7=E5=8F=96StorageStat?= =?UTF-8?q?us=E6=80=A7=E8=83=BD=20Signed-off-by:=20yangjingbo10=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I9e0cb2693b4476588339ee8806cff00980fa0e7e --- .../include/module_external/bms_adapter.h | 1 + .../include/module_external/sms_adapter.h | 2 +- .../src/module_external/bms_adapter.cpp | 21 ++++++++++++++++++- .../src/module_external/sms_adapter.cpp | 9 ++------ 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/services/backup_sa/include/module_external/bms_adapter.h b/services/backup_sa/include/module_external/bms_adapter.h index e96aab688..8ef64c3b4 100644 --- a/services/backup_sa/include/module_external/bms_adapter.h +++ b/services/backup_sa/include/module_external/bms_adapter.h @@ -21,6 +21,7 @@ #include "b_json/b_json_entity_caps.h" #include "bundlemgr/bundle_mgr_interface.h" +#include "istorage_manager.h" namespace OHOS::FileManagement::Backup { class InnerReceiverImpl; diff --git a/services/backup_sa/include/module_external/sms_adapter.h b/services/backup_sa/include/module_external/sms_adapter.h index 5dd16545b..725826d74 100644 --- a/services/backup_sa/include/module_external/sms_adapter.h +++ b/services/backup_sa/include/module_external/sms_adapter.h @@ -36,7 +36,7 @@ public: * @param bundleName bundle name * @param userId user id */ - static int64_t GetUserStorageStats(const std::string &bundleName, int32_t userId); + static StorageManager::StorageStats GetUserStorageStats(const std::string &bundleName, int32_t userId); }; } // namespace OHOS::FileManagement::Backup #endif // OHOS_FILEMGMT_BACKUP_STORAGE_MGR_ADAPTER_H \ No newline at end of file diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index 2e2a25e94..e1de01143 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -46,6 +46,8 @@ const int E_ERR = -1; const vector dataDir = {"app", "local", "distributed", "database", "cache"}; } // namespace +static vector bundlesStatsVec; + static sptr GetBundleManager() { auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -84,7 +86,18 @@ static int64_t GetBundleStats(const string &bundleName, int32_t userId) { HILOGI("Begin bundleName:%{public}s", bundleName.c_str()); if (bundleName == MEDIA_LIBRARY_HAP || bundleName == EXTERNAL_FILE_HAP) { - return StorageMgrAdapter::GetUserStorageStats(bundleName, userId); + StorageManager::StorageStats bundleStats; + if (bundlesStatsVec.size() > 0) { + bundleStats = bundlesStatsVec.front(); + } else { + bundleStats = StorageMgrAdapter::GetUserStorageStats(bundleName, userId); + bundlesStatsVec.emplace_back(bundleStats); + } + if (bundleName == MEDIA_LIBRARY_HAP) { + return bundleStats.image_ + bundleStats.video_; + } else { + return bundleStats.file_; + } } auto bms = GetBundleManager(); vector bundleStats; @@ -118,6 +131,9 @@ vector BundleMgrAdapter::GetBundleInfos(int32_t use continue; } auto [allToBackup, extName, restoreDeps] = GetAllowAndExtName(installedBundle.extensionInfos); + if (!allToBackup) { + continue; + } auto dataSize = GetBundleStats(installedBundle.name, userId); bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo {installedBundle.name, installedBundle.versionCode, installedBundle.versionName, dataSize, allToBackup, @@ -142,6 +158,9 @@ vector BundleMgrAdapter::GetBundleInfos(const vecto continue; } auto [allToBackup, extName, restoreDeps] = GetAllowAndExtName(installedBundle.extensionInfos); + if (!allToBackup) { + continue; + } auto dataSize = GetBundleStats(installedBundle.name, userId); bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo {installedBundle.name, installedBundle.versionCode, installedBundle.versionName, dataSize, allToBackup, diff --git a/services/backup_sa/src/module_external/sms_adapter.cpp b/services/backup_sa/src/module_external/sms_adapter.cpp index e6613ed2c..e76231b44 100644 --- a/services/backup_sa/src/module_external/sms_adapter.cpp +++ b/services/backup_sa/src/module_external/sms_adapter.cpp @@ -55,18 +55,13 @@ StorageManager::BundleStats StorageMgrAdapter::GetBundleStats(const string &bund return bundleStats; } -int64_t StorageMgrAdapter::GetUserStorageStats(const std::string &bundleName, int32_t userId) +StorageManager::StorageStats StorageMgrAdapter::GetUserStorageStats(const std::string &bundleName, int32_t userId) { StorageManager::StorageStats bundleStats; auto storageMgr = GetStorageManager(); if (storageMgr->GetUserStorageStats(userId, bundleStats)) { throw BError(BError::Codes::SA_BROKEN_IPC, "Failed to get user storage stats"); } - if (bundleName == MEDIA_LIBRARY_HAP) { - return bundleStats.image_ + bundleStats.video_; - } else if (bundleName == EXTERNAL_FILE_HAP) { - return bundleStats.file_; - } - return 0; + return bundleStats; } } // namespace OHOS::FileManagement::Backup -- Gitee