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 #ifndef SYS_INSTALLER_MODULE_UPDATE_SERVICE_H 16 #define SYS_INSTALLER_MODULE_UPDATE_SERVICE_H 17 18 #include <unordered_map> 19 #include <unordered_set> 20 21 #include "module_update_stub.h" 22 #include "system_ability.h" 23 24 namespace OHOS { 25 namespace SysInstaller { 26 class ModuleUpdateService : public SystemAbility, public ModuleUpdateStub { 27 DECLARE_SYSTEM_ABILITY(ModuleUpdateService); 28 29 public: 30 ModuleUpdateService(); 31 ~ModuleUpdateService(); 32 33 int32_t InstallModulePackage(const std::string &pkgPath) override; 34 int32_t UninstallModulePackage(const std::string &hmpName) override; 35 int32_t GetModulePackageInfo(const std::string &hmpName, 36 std::list<ModulePackageInfo> &modulePackageInfos) override; 37 int32_t ReportModuleUpdateStatus(const ModuleUpdateStatus &status) override; 38 int32_t ExitModuleUpdate() override; 39 40 void ScanPreInstalledHmp(); 41 void OnProcessCrash(const std::string &processName); 42 void OnBootCompleted(); 43 44 #ifndef UPDATER_UT 45 protected: 46 #endif 47 void OnStart() override; 48 void OnStop() override; 49 50 private: 51 int32_t InstallModuleFile(const std::string &hmpName, const std::string &file) const; 52 void CollectModulePackageInfo(const std::string &hmpName, std::list<ModulePackageInfo> &modulePackageInfos) const; 53 bool BackupActiveModules() const; 54 bool RevertAndReboot() const; 55 void OnHmpError(const std::string &hmpName); 56 void ProcessSaStatus(const SaStatus &status, std::unordered_set<std::string> &hmpSet); 57 58 std::unordered_set<std::string> hmpSet_; 59 std::unordered_map<int32_t, std::string> saIdHmpMap_; 60 std::unordered_map<std::string, std::unordered_set<std::string>> processHmpMap_; 61 }; 62 } // namespace SysInstaller 63 } // namespace OHOS 64 #endif // SYS_INSTALLER_MODULE_UPDATE_SERVICE_H 65