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_UPDATE_H
17 #define SYS_INSTALLER_MODULE_UPDATE_H
18 
19 #include <memory>
20 #include <list>
21 #include <unordered_set>
22 
23 #include "module_file.h"
24 #include "module_file_repository.h"
25 #include "module_ipc_helper.h"
26 
27 namespace OHOS {
28 namespace SysInstaller {
29 class ModuleUpdate {
30 public:
31     static ModuleUpdate &GetInstance();
32     virtual ~ModuleUpdate() = default;
33     void CheckModuleUpdate();
34     bool DoModuleUpdate(ModuleUpdateStatus &status);
35     bool RemoveMountPoint(const std::string &hmpName);
36 
37 private:
38     void PrepareModuleFileList(const ModuleUpdateStatus &status);
39     bool ActivateModules(ModuleUpdateStatus &status, const Timer &timer);
40     bool MountModulePackage(const ModuleFile &moduleFile, const bool mountOnVerity) const;
41     void ReportModuleUpdateStatus(const ModuleUpdateStatus &status) const;
42     void WaitDevice(const std::string &blockDevice) const;
43     bool CheckMountComplete(const std::string &hmpName) const;
44     void ProcessHmpFile(const std::string &hmpFile, const ModuleUpdateStatus &status, const Timer &timer);
45     std::unique_ptr<ModuleFile> GetLatestUpdateModulePackage(const std::string &hmpName);
46 
47     std::list<ModuleFile> moduleFileList_;
48     ModuleFileRepository repository_;
49 };
50 } // SysInstaller
51 } // namespace OHOS
52 #endif // SYS_INSTALLER_MODULE_UPDATE_H