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 #ifndef OHOS_FILEMGMT_BACKUP_SVC_RESTORE_DEPS_MANAGER_H 17 #define OHOS_FILEMGMT_BACKUP_SVC_RESTORE_DEPS_MANAGER_H 18 19 #include <set> 20 #include <shared_mutex> 21 #include <string> 22 #include <vector> 23 24 #include "b_json/b_json_entity_caps.h" 25 #include "i_service.h" 26 27 namespace OHOS::FileManagement::Backup { 28 29 class SvcRestoreDepsManager { 30 public: GetInstance()31 static SvcRestoreDepsManager &GetInstance() 32 { 33 static SvcRestoreDepsManager manager; 34 return manager; 35 } 36 struct RestoreInfo { 37 RestoreTypeEnum restoreType_ {RESTORE_DATA_WAIT_SEND}; 38 set<string> fileNames_ {}; 39 }; 40 41 vector<string> GetRestoreBundleNames(const vector<BJsonEntityCaps::BundleInfo> &infos, RestoreTypeEnum restoreType); 42 map<string, SvcRestoreDepsManager::RestoreInfo> GetRestoreBundleMap(); 43 void AddRestoredBundles(const string &bundleName); 44 vector<BJsonEntityCaps::BundleInfo> GetAllBundles() const; 45 bool IsAllBundlesRestored() const; 46 bool UpdateToRestoreBundleMap(const string &bundleName, const string &fileName); 47 48 private: SvcRestoreDepsManager()49 SvcRestoreDepsManager() {} 50 ~SvcRestoreDepsManager() = default; 51 SvcRestoreDepsManager(const SvcRestoreDepsManager &manager) = delete; 52 SvcRestoreDepsManager &operator=(const SvcRestoreDepsManager &manager) = delete; 53 54 void BuildDepsMap(const vector<BJsonEntityCaps::BundleInfo> &infos); 55 vector<string> SplitString(const string &srcStr, const string &separator); 56 bool IsAllDepsRestored(const string &bundleName); 57 58 mutable std::shared_mutex lock_; 59 map<string, vector<string>> depsMap_ {}; 60 vector<BJsonEntityCaps::BundleInfo> allBundles_ {}; // 所有的应用 61 map<string, RestoreInfo> toRestoreBundleMap_ {}; // 有依赖的应用 62 set<string> restoredBundles_ {}; // 已经恢复完成的应用 63 }; 64 65 } // namespace OHOS::FileManagement::Backup 66 67 #endif // OHOS_FILEMGMT_BACKUP_SVC_RESTORE_DEPS_MANAGER_H 68