• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_MAIN_H
16 #define SYS_INSTALLER_MODULE_UPDATE_MAIN_H
17 
18 #include <unordered_map>
19 #include <unordered_set>
20 
21 #include "imodule_update.h"
22 #include "iservice_registry.h"
23 #include "isys_installer_callback.h"
24 #include "module_ipc_helper.h"
25 #include "module_utils.h"
26 #include "singleton.h"
27 
28 namespace OHOS {
29 namespace SysInstaller {
30 class ModuleUpdateMain final : public Singleton<ModuleUpdateMain> {
31     DECLARE_SINGLETON(ModuleUpdateMain);
32 public:
33     int32_t CheckHmpName(const std::string &hmpName);
34     int32_t UninstallModulePackage(const std::string &hmpName);
35     int32_t GetModulePackageInfo(const std::string &hmpName,
36         std::list<ModulePackageInfo> &modulePackageInfos);
37     int32_t ReportModuleUpdateStatus(const ModuleUpdateStatus &status);
38     std::vector<HmpVersionInfo> GetHmpVersionInfo();
39     void ExitModuleUpdate();
40     int32_t InstallModuleFile(const std::string &hmpName, const std::string &file);
41     void CollectModulePackageInfo(const std::string &hmpName, std::list<ModulePackageInfo> &modulePackageInfos) const;
42     bool BackupActiveModules(const std::string &hmpName) const;
43     bool GetHmpVersion(const std::string &hmpPath, HmpVersionInfo &versionInfo);
44     void SaveInstallerResult(const std::string &hmpPath, int result,
45         const std::string &resultInfo, const Timer &timer);
46     int32_t ReallyInstallModulePackage(const std::string &pkgPath, const sptr<ISysInstallerCallback> &updateCallback);
47     void ParseHmpVersionInfo(std::vector<HmpVersionInfo> &versionInfos, const HmpVersionInfo &preInfo,
48         const HmpVersionInfo &actInfo);
49     std::string GetWorkHmpImagePath(const std::string &hmpName);
50 
51     void ScanPreInstalledHmp();
52     void Start();
53     void Stop();
54 
55 private:
56     int32_t ValidateVersion(ModuleFile &installFile, const std::string &hmpName) const;
57     int32_t PrepareResourceForReboot(const std::string &hmpName) const;
58     sptr<ISystemAbilityManager> &GetSystemAbilityManager();
59 
60     sptr<ISystemAbilityManager> samgr_ = nullptr;
61     std::unordered_set<std::string> hmpSet_;
62     std::unordered_set<std::string> moduleSet_;
63     std::unordered_map<int32_t, std::string> saIdHmpMap_;
64     std::mutex mlock_;
65     std::unordered_map<std::string, std::string> hmpWorkDirMap_;
66     std::unique_ptr<ModuleFile> installModule_ = nullptr;
67 };
68 } // namespace SysInstaller
69 } // namespace OHOS
70 #endif // SYS_INSTALLER_MODULE_UPDATE_MAIN_H