• 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 
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 using ImageVerifyFunc = std::function<bool(ModuleFile &, std::string &)>;
30 
31 class ModuleUpdate {
32 public:
33     static ModuleUpdate &GetInstance();
34     virtual ~ModuleUpdate() = default;
35     void CheckModuleUpdate();
36     bool DoModuleUpdate(ModuleUpdateStatus &status);
37     void RegisterImageVerifyFunc(ImageVerifyFunc ptr, int32_t level);
38     void HandleExtraArgs(int argc, char **argv) const;
39 
40 private:
41     void PrepareModuleFileList(const ModuleUpdateStatus &status);
42     bool ActivateModules(ModuleUpdateStatus &status, const Timer &timer);
43     bool MountModulePackage(ModuleFile &moduleFile, const bool mountOnVerity);
44     void ReportModuleUpdateStatus(const ModuleUpdateStatus &status) const;
45     void WaitDevice(const std::string &blockDevice) const;
46     bool CheckMountComplete(const std::string &hmpName) const;
47     void ProcessHmpFile(const std::string &hmpFile, const ModuleUpdateStatus &status, const Timer &timer);
48     std::unique_ptr<ModuleFile> GetLatestUpdateModulePackage(const std::string &hmpName);
49     bool CheckRevert(const std::string &hmpName);
50     std::string CreateMountPoint(const ModuleFile &moduleFile) const;
51     bool VerifyImageAndCreateDm(ModuleFile &moduleFile, bool mountOnVerity, std::string &blockDevice);
52     void SetParameterFromFile(void) const;
53 
54     std::list<ModuleFile> moduleFileList_;
55     ModuleFileRepository repository_;
56     ImageVerifyFunc ImageVerifyFunc_ = nullptr;
57     int32_t registeredLevel_ = 0;
58 };
59 } // SysInstaller
60 } // namespace OHOS
61 #endif // SYS_INSTALLER_MODULE_UPDATE_H