• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_MANAGER_H
17 #define SYS_INSTALLER_MANAGER_H
18 
19 #include "sys_installer_manager_helper.h"
20 #include "macros_updater.h"
21 #include "status_manager.h"
22 
23 namespace OHOS {
24 namespace SysInstaller {
25 class SysInstallerManager {
26     DISALLOW_COPY_MOVE(SysInstallerManager);
27 public:
28     void RegisterDump(std::unique_ptr<SysInstallerManagerHelper> ptr);
29     static SysInstallerManager &GetInstance();
30 
31     virtual int32_t SysInstallerInit(const std::string &taskId);
32     virtual int32_t StartUpdatePackageZip(const std::string &taskId, const std::string &pkgPath);
33     virtual int32_t SetUpdateCallback(const std::string &taskId, const sptr<ISysInstallerCallback> &updateCallback);
34     virtual int32_t GetUpdateStatus(const std::string &taskId);
35     virtual int32_t StartUpdateParaZip(const std::string &taskId, const std::string &pkgPath,
36         const std::string &location, const std::string &cfgDir);
37     virtual int32_t StartDeleteParaZip(const std::string &taskId, const std::string &location,
38         const std::string &cfgDir);
39     virtual int32_t AccDecompressAndVerifyPkg(const std::string &taskId, const std::string &srcPath,
40         const std::string &dstPath, const uint32_t type);
41     virtual int32_t AccDeleteDir(const std::string &taskId, const std::string &dstPath);
42     virtual int32_t CancelUpdateVabPackageZip(const std::string &taskId);
43     virtual int32_t StartUpdateVabPackageZip(const std::string &taskId, const std::vector<std::string> &pkgPath);
44     virtual int32_t CreateVabSnapshotCowImg(const std::unordered_map<std::string, uint64_t> &partitionInfo);
45     virtual int32_t StartVabMerge(const std::string &taskId);
46     virtual int32_t ClearVabMetadataAndCow();
47     virtual std::string GetUpdateResult(const std::string &taskId, const std::string &taskType,
48         const std::string &resultType);
49     virtual int32_t VabUpdateActive();
50     virtual int32_t GetMetadataResult(const std::string &action, bool &result);
51     virtual int32_t StartAbSync();
52     virtual int32_t SetCpuAffinity(const std::string &taskId, unsigned int reservedCores);
53 
54     virtual int32_t InstallCloudRom(const std::string &taskId, InstallMode installMode,
55         const std::vector<FeatureInfo> &featureInfos, RebootStatus rebootStatus);
56     virtual int32_t UninstallCloudRom(const std::string &taskId,
57         const std::vector<FeatureInfo> &featureInfos, RebootStatus rebootStatus);
58     virtual int32_t GetFeatureStatus(const std::vector<FeatureInfo> &featureInfos,
59         std::vector<FeatureStatus> &statusInfos);
60     virtual int32_t GetAllFeatureStatus(const std::string &baseVersion, std::vector<FeatureStatus> &statusInfos);
61     virtual int32_t ClearCloudRom(const std::string &baseVersion, const std::string &featureName);
62 
63 protected:
64     std::unique_ptr<SysInstallerManagerHelper> helper_ {};
65 
66 private:
67     SysInstallerManager() = default;
68     ~SysInstallerManager() = default;
69 };
70 
71 enum SysInstallerInitEvent {
72     SYS_PRE_INIT_EVENT = 0,
73     SYS_POST_INIT_EVENT,
74     SYS_POST_EVENT,
75     SYS_APP_QUICKFIX_EVENT,
76     SYS_INIT_EVENT_BUTT
77 };
78 using InitHandler = void (*)(void);
79 
80 class SysInstallerManagerInit {
81     DISALLOW_COPY_MOVE(SysInstallerManagerInit);
82 public:
GetInstance()83     static SysInstallerManagerInit &GetInstance()
84     {
85         static SysInstallerManagerInit instance;
86         return instance;
87     }
InvokeEvent(enum SysInstallerInitEvent eventId)88     void InvokeEvent(enum SysInstallerInitEvent eventId) const
89     {
90         if (eventId >= SYS_INIT_EVENT_BUTT) {
91             return;
92         }
93         for (const auto &handler : initEvent_[eventId]) {
94             if (handler != nullptr) {
95                 handler();
96             }
97         }
98     }
SubscribeEvent(enum SysInstallerInitEvent eventId,InitHandler handler)99     void SubscribeEvent(enum SysInstallerInitEvent eventId, InitHandler handler)
100     {
101         if (eventId < SYS_INIT_EVENT_BUTT) {
102             initEvent_[eventId].push_back(handler);
103         }
104     }
105 private:
106     SysInstallerManagerInit() = default;
107     ~SysInstallerManagerInit() = default;
108     std::vector<InitHandler> initEvent_[SYS_INIT_EVENT_BUTT];
109 };
110 } // SysInstaller
111 } // namespace OHOS
112 #endif // SYS_INSTALLER_MANAGER_HELPER_H
113