diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index 018ac64de651692e8e481a552e387a35b64a5844..cf83b816cf85a2382cecccf14fa15754b5845a78 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -119,7 +119,10 @@ vector BundleMgrAdapter::GetBundleInfos(int32_t use continue; } auto [allToBackup, extName, restoreDeps, supportScene] = 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, supportScene}); @@ -143,7 +146,10 @@ vector BundleMgrAdapter::GetBundleInfos(const vecto continue; } auto [allToBackup, extName, restoreDeps, supportScene] = 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, supportScene}); 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;