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