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 "log/log.h"
19 #include "utils.h"
20
21 #include "ab_update.h"
22
23 namespace OHOS {
24 namespace SysInstaller {
25 using namespace Updater;
SysInstallerInit()26 int32_t InstallerManagerHelper::SysInstallerInit()
27 {
28 LOG(INFO) << "SysInstallerInit";
29
30 if (statusManager_ == nullptr) {
31 statusManager_ = std::make_shared<StatusManager>();
32 }
33 statusManager_->Init();
34 return 0;
35 }
36
StartUpdatePackageZip(const std::string & pkgPath)37 int32_t InstallerManagerHelper::StartUpdatePackageZip(const std::string &pkgPath)
38 {
39 LOG(INFO) << "StartUpdatePackageZip start";
40 if (statusManager_ == nullptr) {
41 LOG(ERROR) << "statusManager_ nullptr";
42 return -1;
43 }
44
45 std::string realPath {};
46 if (!Utils::PathToRealPath(pkgPath, realPath)) {
47 LOG(ERROR) << "get real path failed";
48 return -1;
49 }
50
51 ABUpdate abUpdate(statusManager_);
52 return abUpdate.StartABUpdate(realPath);
53 }
54
SetUpdateCallback(const sptr<ISysInstallerCallback> & updateCallback)55 int32_t InstallerManagerHelper::SetUpdateCallback(const sptr<ISysInstallerCallback> &updateCallback)
56 {
57 if (statusManager_ == nullptr) {
58 LOG(ERROR) << "statusManager_ nullptr";
59 return -1;
60 }
61 return statusManager_->SetUpdateCallback(updateCallback);
62 }
63
GetUpdateStatus()64 int32_t InstallerManagerHelper::GetUpdateStatus()
65 {
66 if (statusManager_ == nullptr) {
67 LOG(ERROR) << "statusManager_ nullptr";
68 return -1;
69 }
70 return statusManager_->GetUpdateStatus();
71 }
72
StartUpdateParaZip(const std::string & pkgPath,const std::string & location,const std::string & cfgDir)73 int32_t InstallerManagerHelper::StartUpdateParaZip(const std::string &pkgPath,
74 const std::string &location, const std::string &cfgDir)
75 {
76 return -1;
77 }
78 } // namespace SysInstaller
79 } // namespace OHOS
80