diff --git a/services/backup_sa/include/module_external/bms_adapter.h b/services/backup_sa/include/module_external/bms_adapter.h index e96aab688bf12a6f6d6ffa5a8b58f2d73deeaae8..8ef64c3b449b14ad8a39e4668f4fd629d5d63c3a 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 5dd16545bc8c2cde2bf7bb00d7e1574e2adaaf89..725826d745f02745184cbe037d4b9b1c69f32c0d 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 2e2a25e94a0e13a645f6bdd624195bf356434acb..e1de011435bc25769ab3f56a0989684a4aa298f3 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 e6613ed2cb8cdd575d5e52129d938f80a1d5cb15..e76231b44f325f7221ceeef050c34acac386186e 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