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 std::vector<HmpVersionInfo> GetHmpVersionInfo() override; 41 int32_t StartUpdateHmpPackage(const std::string &path, 42 const sptr<ISysInstallerCallback> &updateCallback) override; 43 std::vector<HmpUpdateInfo> GetHmpUpdateResult() override; 44 45 void ScanPreInstalledHmp(); 46 void OnProcessCrash(const std::string &processName); 47 void OnBootCompleted(); 48 49 #ifndef UPDATER_UT 50 protected: 51 #endif 52 void OnStart() override; 53 void OnStop() override; 54 55 private: 56 int32_t InstallModuleFile(const std::string &hmpName, const std::string &file) const; 57 void CollectModulePackageInfo(const std::string &hmpName, std::list<ModulePackageInfo> &modulePackageInfos) const; 58 bool BackupActiveModules() const; 59 bool RevertAndReboot() const; 60 void OnHmpError(const std::string &hmpName); 61 void ProcessSaStatus(const SaStatus &status, std::unordered_set<std::string> &hmpSet); 62 bool GetHmpVersion(const std::string &hmpPath, HmpVersionInfo &versionInfo); 63 void SaveInstallerResult(const std::string &hmpPath, int result, const std::string &resultInfo); 64 int32_t ReallyInstallModulePackage(const std::string &pkgPath, const sptr<ISysInstallerCallback> &updateCallback); 65 void ParseHmpVersionInfo(std::vector<HmpVersionInfo> &versionInfos, const HmpVersionInfo &preInfo, 66 const HmpVersionInfo &actInfo); 67 68 std::unordered_set<std::string> hmpSet_; 69 std::unordered_map<int32_t, std::string> saIdHmpMap_; 70 std::unordered_map<std::string, std::unordered_set<std::string>> processHmpMap_; 71 }; 72 } // namespace SysInstaller 73 } // namespace OHOS 74 #endif // SYS_INSTALLER_MODULE_UPDATE_SERVICE_H 75