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 #include "installer_manager.h"
17
18 #include "log/log.h"
19 #include "package/pkg_manager.h"
20 #include "utils.h"
21 #include "updater_main.h"
22
23 namespace OHOS {
24 namespace SysInstaller {
25 using namespace Updater;
26
RegisterDump(std::unique_ptr<IInstallerManagerHelper> ptr)27 void InstallerManager::RegisterDump(std::unique_ptr<IInstallerManagerHelper> ptr)
28 {
29 helper_ = std::move(ptr);
30 }
31
GetInstance()32 InstallerManager &InstallerManager::GetInstance()
33 {
34 static InstallerManager instance;
35 return instance;
36 }
37
SysInstallerInit()38 int32_t InstallerManager::SysInstallerInit()
39 {
40 if (helper_ == nullptr) {
41 SysInstallerManagerInit::GetInstance().InvokeEvent(SYS_PRE_INIT_EVENT);
42 UpdaterInit::GetInstance().InvokeEvent(UPDATER_PRE_INIT_EVENT);
43 UpdaterInit::GetInstance().InvokeEvent(UPDATER_INIT_EVENT);
44 if (helper_ == nullptr) {
45 RegisterDump(std::make_unique<InstallerManagerHelper>());
46 }
47 }
48 return helper_->SysInstallerInit();
49 }
50
StartUpdatePackageZip(const std::string & pkgPath)51 int32_t InstallerManager::StartUpdatePackageZip(const std::string &pkgPath)
52 {
53 if (helper_ == nullptr) {
54 LOG(ERROR) << "helper_ null";
55 return -1;
56 }
57 return helper_->StartUpdatePackageZip(pkgPath);
58 }
59
SetUpdateCallback(const sptr<ISysInstallerCallback> & updateCallback)60 int32_t InstallerManager::SetUpdateCallback(const sptr<ISysInstallerCallback> &updateCallback)
61 {
62 if (helper_ == nullptr) {
63 LOG(ERROR) << "helper_ null";
64 return -1;
65 }
66 return helper_->SetUpdateCallback(updateCallback);
67 }
68
GetUpdateStatus()69 int32_t InstallerManager::GetUpdateStatus()
70 {
71 if (helper_ == nullptr) {
72 LOG(ERROR) << "helper_ null";
73 return -1;
74 }
75 return helper_->GetUpdateStatus();
76 }
77
StartUpdateParaZip(const std::string & pkgPath,const std::string & location,const std::string & cfgDir)78 int32_t InstallerManager::StartUpdateParaZip(const std::string &pkgPath,
79 const std::string &location, const std::string &cfgDir)
80 {
81 if (helper_ == nullptr) {
82 LOG(ERROR) << "helper_ null";
83 return -1;
84 }
85 return helper_->StartUpdateParaZip(pkgPath, location, cfgDir);
86 }
87
StartDeleteParaZip(const std::string & location,const std::string & cfgDir)88 int32_t InstallerManager::StartDeleteParaZip(const std::string &location, const std::string &cfgDir)
89 {
90 if (helper_ == nullptr) {
91 LOG(ERROR) << "helper_ null";
92 return -1;
93 }
94 return helper_->StartDeleteParaZip(location, cfgDir);
95 }
96 } // namespace SysInstaller
97 } // namespace OHOS
98