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_helper.h"
17
18 #include "action_processer.h"
19 #include "log/log.h"
20 #include "package/cert_verify.h"
21 #include "package/pkg_manager.h"
22 #include "utils.h"
23 #include "pkg_verify.h"
24 #include "ab_update.h"
25
26 namespace OHOS {
27 namespace SysInstaller {
28 using namespace Hpackage;
29 using namespace Updater;
30
SysInstallerInit()31 int32_t InstallerManagerHelper::SysInstallerInit()
32 {
33 LOG(INFO) << "SysInstallerInit";
34
35 if (statusManager_ == nullptr) {
36 statusManager_ = std::make_shared<StatusManager>();
37 }
38 statusManager_->Init();
39 ActionProcesser::GetInstance().SetStatusManager(statusManager_);
40 return 0;
41 }
42
StartUpdatePackageZip(const std::string & pkgPath)43 int32_t InstallerManagerHelper::StartUpdatePackageZip(const std::string &pkgPath)
44 {
45 LOG(INFO) << "StartUpdatePackageZip start";
46 if (statusManager_ == nullptr) {
47 LOG(ERROR) << "statusManager_ nullptr";
48 return -1;
49 }
50 if (ActionProcesser::GetInstance().IsRunning()) {
51 LOG(ERROR) << "ActionProcesser IsRunning";
52 return -1;
53 }
54 ActionProcesser::GetInstance().AddAction(std::make_unique<PkgVerify>(statusManager_, pkgPath));
55 ActionProcesser::GetInstance().AddAction(std::make_unique<ABUpdate>(statusManager_, pkgPath));
56 ActionProcesser::GetInstance().Start();
57 return 0;
58 }
59
SetUpdateCallback(const sptr<ISysInstallerCallback> & updateCallback)60 int32_t InstallerManagerHelper::SetUpdateCallback(const sptr<ISysInstallerCallback> &updateCallback)
61 {
62 if (statusManager_ == nullptr) {
63 LOG(ERROR) << "statusManager_ nullptr";
64 return -1;
65 }
66 return statusManager_->SetUpdateCallback(updateCallback);
67 }
68
GetUpdateStatus()69 int32_t InstallerManagerHelper::GetUpdateStatus()
70 {
71 if (statusManager_ == nullptr) {
72 LOG(ERROR) << "statusManager_ nullptr";
73 return -1;
74 }
75 return statusManager_->GetUpdateStatus();
76 }
77
StartUpdateParaZip(const std::string & pkgPath,const std::string & location,const std::string & cfgDir)78 int32_t InstallerManagerHelper::StartUpdateParaZip(const std::string &pkgPath,
79 const std::string &location, const std::string &cfgDir)
80 {
81 return -1;
82 }
83
StartDeleteParaZip(const std::string & location,const std::string & cfgDir)84 int32_t InstallerManagerHelper::StartDeleteParaZip(const std::string &location, const std::string &cfgDir)
85 {
86 return -1;
87 }
88
AccDecompressAndVerifyPkg(const std::string & srcPath,const std::string & dstPath,const uint32_t type)89 int32_t InstallerManagerHelper::AccDecompressAndVerifyPkg(const std::string &srcPath,
90 const std::string &dstPath, const uint32_t type)
91 {
92 return -1;
93 }
94
AccDeleteDir(const std::string & dstPath)95 int32_t InstallerManagerHelper::AccDeleteDir(const std::string &dstPath)
96 {
97 return -1;
98 }
99 } // namespace SysInstaller
100 } // namespace OHOS
101