• 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 "installer_manager_helper.h"
20 #include "macros.h"
21 #include "status_manager.h"
22 
23 namespace OHOS {
24 namespace SysInstaller {
25 class InstallerManager {
26 public:
27     InstallerManager() = default;
28     virtual ~InstallerManager() = default;
29     void RegisterDump(std::unique_ptr<IInstallerManagerHelper> ptr);
30     static InstallerManager &GetInstance();
31 
32     virtual int32_t SysInstallerInit();
33     virtual int32_t StartUpdatePackageZip(const std::string &pkgPath);
34     virtual int32_t SetUpdateCallback(const sptr<ISysInstallerCallback> &updateCallback);
35     virtual int32_t GetUpdateStatus();
36     virtual int32_t StartUpdateParaZip(const std::string &pkgPath,
37         const std::string &location, const std::string &cfgDir);
38 
39 protected:
40     std::unique_ptr<IInstallerManagerHelper> helper_ {};
41 };
42 
43 enum SysInstallerInitEvent {
44     SYS_PRE_INIT_EVENT = 0,
45     SYS_POST_INIT_EVENT,
46 
47     SYS_INIT_EVENT_BUTT
48 };
49 using InitHandler = void (*)(void);
50 
51 class SysInstallerManagerInit {
52     DISALLOW_COPY_MOVE(SysInstallerManagerInit);
53 public:
GetInstance()54     static SysInstallerManagerInit &GetInstance()
55     {
56         static SysInstallerManagerInit instance;
57         return instance;
58     }
InvokeEvent(enum SysInstallerInitEvent eventId)59     void InvokeEvent(enum SysInstallerInitEvent eventId) const
60     {
61         if (eventId >= SYS_INIT_EVENT_BUTT) {
62             return;
63         }
64         for (const auto &handler : initEvent_[eventId]) {
65             if (handler != nullptr) {
66                 handler();
67             }
68         }
69     }
SubscribeEvent(enum SysInstallerInitEvent eventId,InitHandler handler)70     void SubscribeEvent(enum SysInstallerInitEvent eventId, InitHandler handler)
71     {
72         if (eventId < SYS_INIT_EVENT_BUTT) {
73             initEvent_[eventId].push_back(handler);
74         }
75     }
76 private:
77     SysInstallerManagerInit() = default;
78     ~SysInstallerManagerInit() = default;
79     std::vector<InitHandler> initEvent_[SYS_INIT_EVENT_BUTT];
80 };
81 } // SysInstaller
82 } // namespace OHOS
83 #endif // SYS_INSTALLER_MANAGER_HELPER_H
84