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 #ifndef OHOS_FILEMGMT_BACKUP_BUNDLE_MGR_ADAPTER_H 17 #define OHOS_FILEMGMT_BACKUP_BUNDLE_MGR_ADAPTER_H 18 19 #include <string> 20 #include <vector> 21 22 #include "b_radar/radar_const.h" 23 #include "b_json/b_json_entity_caps.h" 24 #include "bundlemgr/bundle_mgr_interface.h" 25 #include "b_incremental_data.h" 26 #include "istorage_manager.h" 27 28 namespace OHOS::FileManagement::Backup { 29 class InnerReceiverImpl; 30 31 struct BundleExtInfo { BundleExtInfoBundleExtInfo32 BundleExtInfo(const std::string& bundleName) : bundleName_(bundleName), 33 error_(RadarError(BError(BError::Codes::OK))) {} 34 AppExecFwk::BundleInfo bundleInfo_; 35 const std::string bundleName_; 36 std::vector<AppExecFwk::ExtensionAbilityInfo> extensionInfos_; 37 RadarError error_; 38 uint32_t getExtSpend_ = 0; 39 }; 40 41 class BundleMgrAdapter { 42 public: 43 44 /** 45 * @brief Get the bundle infos object 46 * 47 * @param bundleNames bundle names 48 * @param userId User ID 49 * @return std::vector<BJsonEntityCaps::BundleInfo> 50 */ 51 static std::vector<BJsonEntityCaps::BundleInfo> GetBundleInfos(const std::vector<std::string> &bundleNames, 52 int32_t userId); 53 54 /** 55 * @brief Get app gallery bundle name 56 */ 57 static std::string GetAppGalleryBundleName(); 58 59 /** 60 * @brief Get the bundle infos object for incremental backup 61 * 62 * @param incrementalDataList bundle Name and time list 63 * @param userId User ID 64 * @return std::vector<BJsonEntityCaps::BundleInfo> 65 */ 66 static std::vector<BJsonEntityCaps::BundleInfo> GetBundleInfosForIncremental( 67 const std::vector<BIncrementalData> &incrementalDataList, int32_t userId); 68 69 static std::vector<BJsonEntityCaps::BundleInfo> GetBundleInfosForIncremental(int32_t userId, 70 const std::vector<BIncrementalData> &extraIncreData = {}); 71 72 static std::vector<BJsonEntityCaps::BundleInfo> GetFullBundleInfos(int32_t userId); 73 74 static std::string GetExtName(string bundleName, int32_t userId); 75 76 static std::vector<BJsonEntityCaps::BundleInfo> GetBundleInfosForSA(); 77 78 static void GetBundleInfoForSA(std::string bundleName, std::vector<BJsonEntityCaps::BundleInfo> &bundleInfos); 79 80 static bool IsUser0BundleName(std::string bundleName, int32_t userId); 81 82 static std::vector<BJsonEntityCaps::BundleInfo> GetBundleInfosForAppend( 83 const std::vector<BIncrementalData> &incrementalDataList, int32_t userId); 84 85 static std::vector<BJsonEntityCaps::BundleInfo> GetBundleInfosForLocalCapabilities(int32_t userId); 86 87 static std::vector<BJsonEntityCaps::BundleInfo> GetBundleInfosForIndex( 88 const vector<string> &bundleNames, int32_t userId); 89 90 static int64_t GetBundleDataSize(const std::string &bundleName, int32_t userId); 91 92 static void CreatBackupEnv(const std::vector<BIncrementalData> &bundleNameList, int32_t userId); 93 94 static std::vector<BJsonEntityCaps::BundleInfo> GetBundleInfosForAppendBundles( 95 const std::vector<BIncrementalData> &incrementalDataList, int32_t userId); 96 private: 97 static bool GetCurBundleExtenionInfo(BundleExtInfo &bundleExtInfo, sptr<AppExecFwk::IBundleMgr> bms, 98 int32_t userId); 99 }; 100 } // namespace OHOS::FileManagement::Backup 101 #endif // OHOS_FILEMGMT_BACKUP_BUNDLE_MGR_ADAPTER_H 102