• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "sys_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<SysInstallerManagerHelper> ptr)27 void SysInstallerManager::RegisterDump(std::unique_ptr<SysInstallerManagerHelper> ptr)
28 {
29     helper_ = std::move(ptr);
30 }
31 
GetInstance()32 SysInstallerManager &SysInstallerManager::GetInstance()
33 {
34     static SysInstallerManager instance;
35     return instance;
36 }
37 
SysInstallerInit(const std::string & taskId)38 int32_t SysInstallerManager::SysInstallerInit(const std::string &taskId)
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<SysInstallerManagerHelper>());
46         }
47     }
48     return helper_->SysInstallerInit(taskId);
49 }
50 
StartUpdatePackageZip(const std::string & taskId,const std::string & pkgPath)51 int32_t SysInstallerManager::StartUpdatePackageZip(const std::string &taskId, const std::string &pkgPath)
52 {
53     if (helper_ == nullptr) {
54         LOG(ERROR) << "helper_ null";
55         return -1;
56     }
57     return helper_->StartUpdatePackageZip(taskId, pkgPath);
58 }
59 
SetUpdateCallback(const std::string & taskId,const sptr<ISysInstallerCallback> & updateCallback)60 int32_t SysInstallerManager::SetUpdateCallback(const std::string &taskId,
61     const sptr<ISysInstallerCallback> &updateCallback)
62 {
63     if (helper_ == nullptr) {
64         LOG(ERROR) << "helper_ null";
65         return -1;
66     }
67     return helper_->SetUpdateCallback(taskId, updateCallback);
68 }
69 
GetUpdateStatus(const std::string & taskId)70 int32_t SysInstallerManager::GetUpdateStatus(const std::string &taskId)
71 {
72     if (helper_ == nullptr) {
73         LOG(ERROR) << "helper_ null";
74         return -1;
75     }
76     return helper_->GetUpdateStatus(taskId);
77 }
78 
StartUpdateParaZip(const std::string & taskId,const std::string & pkgPath,const std::string & location,const std::string & cfgDir)79 int32_t SysInstallerManager::StartUpdateParaZip(const std::string &taskId, const std::string &pkgPath,
80     const std::string &location, const std::string &cfgDir)
81 {
82     if (helper_ == nullptr) {
83         LOG(ERROR) << "helper_ null";
84         return -1;
85     }
86     return helper_->StartUpdateParaZip(taskId, pkgPath, location, cfgDir);
87 }
88 
StartDeleteParaZip(const std::string & taskId,const std::string & location,const std::string & cfgDir)89 int32_t SysInstallerManager::StartDeleteParaZip(const std::string &taskId, const std::string &location,
90     const std::string &cfgDir)
91 {
92     if (helper_ == nullptr) {
93         LOG(ERROR) << "helper_ null";
94         return -1;
95     }
96     return helper_->StartDeleteParaZip(taskId, location, cfgDir);
97 }
98 
AccDecompressAndVerifyPkg(const std::string & taskId,const std::string & srcPath,const std::string & dstPath,const uint32_t type)99 int32_t SysInstallerManager::AccDecompressAndVerifyPkg(const std::string &taskId, const std::string &srcPath,
100     const std::string &dstPath, const uint32_t type)
101 {
102     if (helper_ == nullptr) {
103         LOG(ERROR) << "helper_ null";
104         return -1;
105     }
106     return helper_->AccDecompressAndVerifyPkg(taskId, srcPath, dstPath, type);
107 }
108 
AccDeleteDir(const std::string & taskId,const std::string & dstPath)109 int32_t SysInstallerManager::AccDeleteDir(const std::string &taskId, const std::string &dstPath)
110 {
111     if (helper_ == nullptr) {
112         LOG(ERROR) << "helper_ null";
113         return -1;
114     }
115     return helper_->AccDeleteDir(taskId, dstPath);
116 }
117 
StartUpdateVabPackageZip(const std::string & taskId,const std::vector<std::string> & pkgPath)118 int32_t SysInstallerManager::StartUpdateVabPackageZip(const std::string &taskId,
119     const std::vector<std::string> &pkgPath)
120 {
121     if (helper_ == nullptr) {
122         LOG(ERROR) << "helper_ null";
123         return -1;
124     }
125     return helper_->StartUpdateVabPackageZip(taskId, pkgPath);
126 }
127 
CancelUpdateVabPackageZip(const std::string & taskId)128 int32_t SysInstallerManager::CancelUpdateVabPackageZip(const std::string &taskId)
129 {
130     if (helper_ == nullptr) {
131         LOG(ERROR) << "helper_ null";
132         return -1;
133     }
134     return helper_->CancelUpdateVabPackageZip(taskId);
135 }
136 
StartVabMerge(const std::string & taskId)137 int32_t SysInstallerManager::StartVabMerge(const std::string &taskId)
138 {
139     if (helper_ == nullptr) {
140         LOG(ERROR) << "helper_ null";
141         return -1;
142     }
143     return helper_->StartVabMerge(taskId);
144 }
145 
CreateVabSnapshotCowImg(const std::unordered_map<std::string,uint64_t> & partitionInfo)146 int32_t SysInstallerManager::CreateVabSnapshotCowImg(const std::unordered_map<std::string, uint64_t> &partitionInfo)
147 {
148     if (helper_ == nullptr) {
149         LOG(ERROR) << "helper_ null";
150         return -1;
151     }
152     return helper_->CreateVabSnapshotCowImg(partitionInfo);
153 }
154 
ClearVabMetadataAndCow()155 int32_t SysInstallerManager::ClearVabMetadataAndCow()
156 {
157     if (helper_ == nullptr) {
158         LOG(ERROR) << "helper_ null";
159         return -1;
160     }
161     return helper_->ClearVabMetadataAndCow();
162 }
163 
GetUpdateResult(const std::string & taskId,const std::string & taskType,const std::string & resultType)164 std::string  SysInstallerManager::GetUpdateResult(const std::string &taskId, const std::string &taskType,
165     const std::string &resultType)
166 {
167     if (helper_ == nullptr) {
168         LOG(ERROR) << "helper_ null";
169         return std::string("");
170     }
171     return helper_->GetUpdateResult(taskId, taskType, resultType);
172 }
173 
VabUpdateActive()174 int32_t SysInstallerManager::VabUpdateActive()
175 {
176     if (helper_ == nullptr) {
177         LOG(ERROR) << "helper_ null";
178         return -1;
179     }
180     return helper_->VabUpdateActive();
181 }
182 
GetMetadataResult(const std::string & action,bool & result)183 int32_t SysInstallerManager::GetMetadataResult(const std::string &action, bool &result)
184 {
185     if (helper_ == nullptr) {
186         LOG(ERROR) << "helper_ null";
187         return -1;
188     }
189     return helper_->GetMetadataResult(action, result);
190 }
191 
StartAbSync()192 int32_t SysInstallerManager::StartAbSync()
193 {
194     if (helper_ == nullptr) {
195         LOG(ERROR) << "helper_ null";
196         return -1;
197     }
198     return helper_->StartAbSync();
199 }
200 
SetCpuAffinity(const std::string & taskId,unsigned int reservedCores)201 int32_t SysInstallerManager::SetCpuAffinity(const std::string &taskId, unsigned int reservedCores)
202 {
203     if (helper_ == nullptr) {
204         LOG(ERROR) << "helper_ null";
205         return -1;
206     }
207     return helper_->SetCpuAffinity(taskId, reservedCores);
208 }
209 
InstallCloudRom(const std::string & taskId,InstallMode installMode,const std::vector<FeatureInfo> & featureInfos,RebootStatus rebootStatus)210 int32_t SysInstallerManager::InstallCloudRom(const std::string &taskId,
211     InstallMode installMode, const std::vector<FeatureInfo> &featureInfos, RebootStatus rebootStatus)
212 {
213     if (helper_ == nullptr) {
214         LOG(ERROR) << "helper_ null";
215         return -1;
216     }
217     return helper_->InstallCloudRom(taskId, installMode, featureInfos, rebootStatus);
218 }
219 
UninstallCloudRom(const std::string & taskId,const std::vector<FeatureInfo> & featureInfos,RebootStatus rebootStatus)220 int32_t SysInstallerManager::UninstallCloudRom(const std::string &taskId,
221     const std::vector<FeatureInfo> &featureInfos, RebootStatus rebootStatus)
222 {
223     if (helper_ == nullptr) {
224         LOG(ERROR) << "helper_ null";
225         return -1;
226     }
227     return helper_->UninstallCloudRom(taskId, featureInfos, rebootStatus);
228 }
229 
GetFeatureStatus(const std::vector<FeatureInfo> & featureInfos,std::vector<FeatureStatus> & statusInfos)230 int32_t SysInstallerManager::GetFeatureStatus(const std::vector<FeatureInfo> &featureInfos,
231     std::vector<FeatureStatus> &statusInfos)
232 {
233     if (helper_ == nullptr) {
234         LOG(ERROR) << "helper_ null";
235         return -1;
236     }
237     return helper_->GetFeatureStatus(featureInfos, statusInfos);
238 }
239 
GetAllFeatureStatus(const std::string & baseVersion,std::vector<FeatureStatus> & statusInfos)240 int32_t SysInstallerManager::GetAllFeatureStatus(const std::string &baseVersion,
241     std::vector<FeatureStatus> &statusInfos)
242 {
243     if (helper_ == nullptr) {
244         LOG(ERROR) << "helper_ null";
245         return -1;
246     }
247     return helper_->GetAllFeatureStatus(baseVersion, statusInfos);
248 }
249 
ClearCloudRom(const std::string & baseVersion,const std::string & featureName)250 int32_t SysInstallerManager::ClearCloudRom(const std::string &baseVersion,
251     const std::string &featureName)
252 {
253     if (helper_ == nullptr) {
254         LOG(ERROR) << "helper_ null";
255         return -1;
256     }
257     return helper_->ClearCloudRom(baseVersion, featureName);
258 }
259 } // namespace SysInstaller
260 } // namespace OHOS
261