diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index fbc7e4526c68ae2485ba59072718bf3fe989a346..a8038634bc31e168ca7fee84c21de866e2fc28df 100644 --- a/services/backup_sa/src/module_external/bms_adapter.cpp +++ b/services/backup_sa/src/module_external/bms_adapter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -118,7 +118,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, restoreDeps, supportScene}); @@ -142,7 +145,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, 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..0d1c80600c7d3e12d444b1db7e3b208076de6673 100644 --- a/services/backup_sa/src/module_external/sms_adapter.cpp +++ b/services/backup_sa/src/module_external/sms_adapter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -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 media 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 file storage stats"); + } return bundleStats.file_; } return 0;