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 SYS_INSTALLER_MODULE_FILE_REPOSITORY_H 17 #define SYS_INSTALLER_MODULE_FILE_REPOSITORY_H 18 19 #include <memory> 20 #include <unordered_map> 21 #include <unordered_set> 22 23 #include "module_file.h" 24 #include "singleton.h" 25 26 namespace OHOS { 27 namespace SysInstaller { 28 class ModuleFileRepository final { 29 public: 30 DISALLOW_COPY_AND_MOVE(ModuleFileRepository); 31 static ModuleFileRepository &GetInstance(); 32 void InitRepository(const std::unordered_set<int32_t> &saIdSet); 33 std::unique_ptr<ModuleFile> GetModuleFile(const std::string &pathPrefix, const int32_t saId) const; 34 bool IsPreInstalledModule(const ModuleFile &moduleFile) const; 35 std::string GetPublicKey(const int32_t saId) const; 36 void Clear(); 37 void SaveInstallerResult(const std::string &path, const std::string &hmpName, 38 int result, const std::string &resultInfo) const; 39 private: 40 ModuleFileRepository() = default; 41 ~ModuleFileRepository(); 42 void ProcessFile(const std::unordered_set<int32_t> &saIdSet, const std::string &path, const std::string &file, 43 std::unordered_map<int32_t, ModuleFile> &fileMap) const; 44 bool CheckFilePath(const ModuleFile &moduleFile, const std::string &prefix) const; 45 46 std::unordered_map<std::string, std::unordered_map<int32_t, ModuleFile>> moduleFileMap_; 47 }; 48 } // SysInstaller 49 } // namespace OHOS 50 #endif // SYS_INSTALLER_MODULE_FILE_REPOSITORY_H