1 /* 2 * Copyright (c) 2023 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 "filemgmt_libhilog.h" 22 #include "iservice_registry.h" 23 #include "system_ability_definition.h" 24 25 namespace OHOS::FileManagement::Backup { 26 using namespace std; 27 GetStorageManager()28static sptr<StorageManager::IStorageManager> GetStorageManager() 29 { 30 auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 31 if (saMgr == nullptr) { 32 throw BError(BError::Codes::SA_BROKEN_IPC, "Failed to get system ability manager"); 33 } 34 35 auto storageObj = saMgr->GetSystemAbility(STORAGE_MANAGER_MANAGER_ID); 36 if (storageObj == nullptr) { 37 throw BError(BError::Codes::SA_BROKEN_IPC, "Failed to get storage manager service"); 38 } 39 40 return iface_cast<StorageManager::IStorageManager>(storageObj); 41 } 42 GetBundleStats(const string & bundleName)43StorageManager::BundleStats StorageMgrAdapter::GetBundleStats(const string &bundleName) 44 { 45 StorageManager::BundleStats bundleStats; 46 auto storageMgr = GetStorageManager(); 47 if (storageMgr->GetBundleStats(bundleName, bundleStats)) { 48 throw BError(BError::Codes::SA_BROKEN_IPC, "Failed to get bundle stats"); 49 } 50 return bundleStats; 51 } 52 } // namespace OHOS::FileManagement::Backup 53