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