diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index 2e2a25e94a0e13a645f6bdd624195bf356434acb..a83683619cc87a9c31abafce7cc6194c5c5f0760 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -118,7 +118,10 @@ vector BundleMgrAdapter::GetBundleInfos(int32_t use continue; } auto [allToBackup, extName, restoreDeps] = GetAllowAndExtName(installedBundle.extensionInfos); - auto dataSize = GetBundleStats(installedBundle.name, userId); + 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, false, restoreDeps}); @@ -142,7 +145,10 @@ vector BundleMgrAdapter::GetBundleInfos(const vecto continue; } auto [allToBackup, extName, restoreDeps] = GetAllowAndExtName(installedBundle.extensionInfos); - auto dataSize = GetBundleStats(installedBundle.name, userId); + 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, false, restoreDeps}); diff --git a/services/backup_sa/src/module_external/sms_adapter.cpp b/services/backup_sa/src/module_external/sms_adapter.cpp index e6613ed2cb8cdd575d5e52129d938f80a1d5cb15..75cd654ee2f206fb99470edcc44a55964b7ec8cc 100644 --- a/services/backup_sa/src/module_external/sms_adapter.cpp +++ b/services/backup_sa/src/module_external/sms_adapter.cpp @@ -28,6 +28,8 @@ using namespace std; namespace { const string MEDIA_LIBRARY_HAP = "com.ohos.medialibrary.medialibrarydata"; const string EXTERNAL_FILE_HAP = "com.ohos.UserFile.ExternalFileManager"; +const string MEDIA_TYPE = "media"; +const string FILE_TYPE = "file"; } // namespace static sptr GetStorageManager() @@ -59,12 +61,15 @@ int64_t StorageMgrAdapter::GetUserStorageStats(const std::string &bundleName, in { 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) { + if (storageMgr->GetUserStorageStatsByType(userId, bundleStats, MEDIA_TYPE)) { + throw BError(BError::Codes::SA_BROKEN_IPC, "Failed to get user storage stats"); + } return bundleStats.image_ + bundleStats.video_; } else if (bundleName == EXTERNAL_FILE_HAP) { + if (storageMgr->GetUserStorageStatsByType(userId, bundleStats, FILE_TYPE)) { + throw BError(BError::Codes::SA_BROKEN_IPC, "Failed to get user storage stats"); + } return bundleStats.file_; } return 0;