• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "module_external/sms_adapter.h"
17 
18 #include <refbase.h>
19 
20 #include "b_error/b_error.h"
21 #include "b_resources/b_constants.h"
22 #include "filemgmt_libhilog.h"
23 #include "iservice_registry.h"
24 #include "system_ability_definition.h"
25 #include "module_external/storage_manager_service.h"
26 
27 namespace OHOS::FileManagement::Backup {
28 using namespace std;
29 
30 namespace {
31 const string MEDIA_LIBRARY_HAP = "com.ohos.medialibrary.medialibrarydata";
32 const string EXTERNAL_FILE_HAP = "com.ohos.UserFile.ExternalFileManager";
33 const int64_t ERR_SIZE = -1;
34 } // namespace
35 
GetBundleStats(const string & bundleName)36 StorageManager::BundleStats StorageMgrAdapter::GetBundleStats(const string &bundleName)
37 {
38     StorageManager::BundleStats bundleStats;
39     if (!StorageManagerService::GetInstance().GetBundleStats(bundleName, bundleStats)) {
40         HILOGE("An error occured StorageMgrAdapter GetBundleStats");
41     }
42     return bundleStats;
43 }
44 
GetUserStorageStats(const std::string & bundleName,int32_t userId)45 int64_t StorageMgrAdapter::GetUserStorageStats(const std::string &bundleName, int32_t userId)
46 {
47     StorageManager::StorageStats bundleStats;
48     if (bundleName == MEDIA_LIBRARY_HAP) {
49         if (StorageManagerService::GetInstance().GetUserStorageStatsByType(userId, bundleStats, MEDIA_TYPE) != E_OK) {
50             HILOGE("Failed to get user media storage stats");
51             return ERR_SIZE;
52         }
53         return bundleStats.image_ + bundleStats.video_;
54     } else if (bundleName == EXTERNAL_FILE_HAP) {
55         if (StorageManagerService::GetInstance().GetUserStorageStatsByType(userId, bundleStats, FILE_TYPE) != E_OK) {
56             HILOGE("Failed to get user file storage stats");
57             return ERR_SIZE;
58         }
59         return bundleStats.file_;
60     }
61     return 0;
62 }
63 
UpdateMemPara(int32_t size)64 int32_t StorageMgrAdapter::UpdateMemPara(int32_t size)
65 {
66     int32_t oldSize = BConstants::DEFAULT_VFS_CACHE_PRESSURE;
67     if (StorageManagerService::GetInstance().UpdateMemoryPara(size, oldSize) != E_OK) {
68         HILOGE("An error occured StorageMgrAdapter UpdateMemPara");
69         return BConstants::DEFAULT_VFS_CACHE_PRESSURE;
70     }
71     return oldSize;
72 }
73 
GetBundleStatsForIncrease(uint32_t userId,const std::vector<std::string> & bundleNames,const std::vector<int64_t> & incrementalBackTimes,std::vector<int64_t> & pkgFileSizes,std::vector<int64_t> & incPkgFileSizes)74 int32_t StorageMgrAdapter::GetBundleStatsForIncrease(uint32_t userId, const std::vector<std::string> &bundleNames,
75     const std::vector<int64_t> &incrementalBackTimes, std::vector<int64_t> &pkgFileSizes,
76     std::vector<int64_t> &incPkgFileSizes)
77 {
78     if (StorageManagerService::GetInstance().GetBundleStatsForIncrease(userId, bundleNames, incrementalBackTimes,
79         pkgFileSizes, incPkgFileSizes) != E_OK) {
80         HILOGE("An error occured StorageManagerService GetBundleStatsForIncrease");
81         return E_ERR;
82     }
83     return E_OK;
84 }
85 } // namespace OHOS::FileManagement::Backup