From e0fbfff362be2d8c82137baa2a4dc660f5b42730 Mon Sep 17 00:00:00 2001 From: zhuruigan Date: Mon, 15 Jan 2024 11:36:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9F=A5=E8=AF=A2=E5=8C=85?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A4=A7=E5=B0=8F=E7=9A=84=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhuruigan Change-Id: Iacfa5ea88ab3757c349a1e1622921fcab1eb6b06 --- .../backup_sa/src/module_external/bms_adapter.cpp | 12 +++++++++--- .../backup_sa/src/module_external/sms_adapter.cpp | 13 +++++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/services/backup_sa/src/module_external/bms_adapter.cpp b/services/backup_sa/src/module_external/bms_adapter.cpp index fbc7e4526..a8038634b 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 e6613ed2c..0d1c80600 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; -- Gitee