1 /*
2 * Copyright (c) 2021 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 "update_service.h"
17
18 #include <dlfcn.h>
19 #include <unistd.h>
20 #include <updater_sa_ipc_interface_code.h>
21 #include <update_callback_stub.h>
22
23 #include "iservice_registry.h"
24 #include "ohos_types.h"
25 #include "system_ability_definition.h"
26
27 #include "access_manager.h"
28 #include "dupdate_net_manager.h"
29 #include "config_parse.h"
30 #include "firmware_common.h"
31 #include "firmware_manager.h"
32 #include "startup_manager.h"
33 #include "update_log.h"
34 #include "update_service_cache.h"
35 #include "update_service_local_updater.h"
36 #include "update_service_restorer.h"
37 #include "update_service_util.h"
38
39 #include "update_service_module.h"
40 #include "module_manager.h"
41
42 namespace OHOS {
43 namespace UpdateEngine {
REGISTER_SYSTEM_ABILITY_BY_ID(UpdateService,UPDATE_DISTRIBUTED_SERVICE_ID,true)44 REGISTER_SYSTEM_ABILITY_BY_ID(UpdateService, UPDATE_DISTRIBUTED_SERVICE_ID, true)
45
46 OHOS::sptr<UpdateService> UpdateService::updateService_ { nullptr };
47
OnRemoteDied(const wptr<IRemoteObject> & remote)48 void UpdateService::ClientDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
49 {
50 ENGINE_LOGI("client DeathRecipient OnRemoteDied: %{public}s", upgradeInfo_.ToString().c_str());
51 sptr<UpdateService> service = UpdateService::GetInstance();
52 if (service != nullptr) {
53 service->UnregisterUpdateCallback(upgradeInfo_);
54 }
55 }
56
ClientProxy(const UpgradeInfo & info,const sptr<IUpdateCallback> & callback)57 UpdateService::ClientProxy::ClientProxy(const UpgradeInfo &info, const sptr<IUpdateCallback> &callback)
58 : proxy_(callback)
59 {
60 ENGINE_LOGI("UpdateService::ClientProxy constructor");
61 auto clientDeathRecipient = new (std::nothrow) ClientDeathRecipient(info);
62 if (clientDeathRecipient != nullptr) {
63 deathRecipient_ = sptr<ClientDeathRecipient>(clientDeathRecipient);
64 } else {
65 ENGINE_LOGE("UpdateService::ClientProxy, new fail");
66 }
67 }
68
AddDeathRecipient()69 void UpdateService::ClientProxy::AddDeathRecipient()
70 {
71 ENGINE_LOGI("UpdateService::ClientProxy AddDeathRecipient in");
72 if (proxy_ != nullptr) {
73 auto remoteObject = proxy_->AsObject();
74 if ((remoteObject != nullptr) && (deathRecipient_ != nullptr)) {
75 remoteObject->AddDeathRecipient(deathRecipient_);
76 ENGINE_LOGI("UpdateService::ClientProxy AddDeathRecipient success");
77 }
78 }
79 }
80
RemoveDeathRecipient()81 void UpdateService::ClientProxy::RemoveDeathRecipient()
82 {
83 ENGINE_LOGI("UpdateService::ClientProxy RemoveDeathRecipient in");
84 if (proxy_ != nullptr) {
85 auto remoteObject = proxy_->AsObject();
86 if ((remoteObject != nullptr) && (deathRecipient_ != nullptr)) {
87 remoteObject->RemoveDeathRecipient(deathRecipient_);
88 ENGINE_LOGI("UpdateService::ClientProxy RemoveDeathRecipient success");
89 }
90 }
91 }
92
Get()93 sptr<IUpdateCallback> UpdateService::ClientProxy::Get()
94 {
95 return proxy_;
96 }
97
UpdateService(int32_t systemAbilityId,bool runOnCreate)98 UpdateService::UpdateService(int32_t systemAbilityId, bool runOnCreate)
99 : SystemAbility(systemAbilityId, runOnCreate)
100 {
101 updateImplMgr_ = std::make_shared<UpdateServiceImplManager>();
102 }
103
~UpdateService()104 UpdateService::~UpdateService()
105 {
106 ENGINE_LOGI("UpdateServerTest free now");
107 for (auto &iter : clientProxyMap_) {
108 iter.second.RemoveDeathRecipient();
109 }
110 }
111
GetInstance()112 sptr<UpdateService> UpdateService::GetInstance()
113 {
114 return updateService_;
115 }
116
RegisterUpdateCallback(const UpgradeInfo & info,const sptr<IUpdateCallback> & updateCallback)117 int32_t UpdateService::RegisterUpdateCallback(const UpgradeInfo &info, const sptr<IUpdateCallback> &updateCallback)
118 {
119 ENGINE_LOGI("RegisterUpdateCallback");
120 UnregisterUpdateCallback(info);
121 {
122 std::lock_guard<std::mutex> lock(clientProxyMapLock_);
123 ClientProxy clientProxy(info, updateCallback);
124 clientProxy.AddDeathRecipient();
125 clientProxyMap_.insert({info, clientProxy});
126 }
127 if (!info.IsLocal()) {
128 UpdateServiceCache::SetUpgradeInfo(info);
129 }
130 DelayedSingleton<AccessManager>::GetInstance()->SetRemoteIdle(clientProxyMap_.empty());
131 return INT_CALL_SUCCESS;
132 }
133
UnregisterUpdateCallback(const UpgradeInfo & info)134 int32_t UpdateService::UnregisterUpdateCallback(const UpgradeInfo &info)
135 {
136 ENGINE_LOGI("UnregisterUpdateCallback");
137 std::lock_guard<std::mutex> lock(clientProxyMapLock_);
138 auto iter = clientProxyMap_.find(info);
139 if (iter == clientProxyMap_.end()) {
140 return INT_CALL_SUCCESS;
141 }
142 iter->second.RemoveDeathRecipient();
143 clientProxyMap_.erase(info);
144 DelayedSingleton<AccessManager>::GetInstance()->SetRemoteIdle(clientProxyMap_.empty());
145 return INT_CALL_SUCCESS;
146 }
147
GetUpgradeCallback(const UpgradeInfo & info)148 sptr<IUpdateCallback> UpdateService::GetUpgradeCallback(const UpgradeInfo &info)
149 {
150 std::lock_guard<std::mutex> lock(clientProxyMapLock_);
151 auto iter = clientProxyMap_.find(info);
152 if (iter == clientProxyMap_.end()) {
153 return nullptr;
154 }
155 return iter->second.Get();
156 }
157
GetNewVersionInfo(const UpgradeInfo & info,NewVersionInfo & newVersionInfo,BusinessError & businessError)158 int32_t UpdateService::GetNewVersionInfo(const UpgradeInfo &info, NewVersionInfo &newVersionInfo,
159 BusinessError &businessError)
160 {
161 sptr<IServiceOnlineUpdater> onlineUpdater = updateImplMgr_->GetOnlineUpdater(info);
162 if (onlineUpdater == nullptr) {
163 ENGINE_LOGI("GetNewVersionInfo onlineUpdater null");
164 return INT_CALL_FAIL;
165 }
166 return onlineUpdater->GetNewVersionInfo(info, newVersionInfo, businessError);
167 }
168
GetNewVersionDescription(const UpgradeInfo & info,const VersionDigestInfo & versionDigestInfo,const DescriptionOptions & descriptionOptions,VersionDescriptionInfo & newVersionDescriptionInfo,BusinessError & businessError)169 int32_t UpdateService::GetNewVersionDescription(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo,
170 const DescriptionOptions &descriptionOptions, VersionDescriptionInfo &newVersionDescriptionInfo,
171 BusinessError &businessError)
172 {
173 sptr<IServiceOnlineUpdater> onlineUpdater = updateImplMgr_->GetOnlineUpdater(info);
174 if (onlineUpdater == nullptr) {
175 ENGINE_LOGI("GetNewVersionDescription onlineUpdater null");
176 return INT_CALL_FAIL;
177 }
178 return onlineUpdater->GetNewVersionDescription(info, versionDigestInfo, descriptionOptions,
179 newVersionDescriptionInfo, businessError);
180 }
181
GetCurrentVersionInfo(const UpgradeInfo & info,CurrentVersionInfo & currentVersionInfo,BusinessError & businessError)182 int32_t UpdateService::GetCurrentVersionInfo(const UpgradeInfo &info, CurrentVersionInfo ¤tVersionInfo,
183 BusinessError &businessError)
184 {
185 sptr<IServiceOnlineUpdater> onlineUpdater = updateImplMgr_->GetOnlineUpdater(info);
186 if (onlineUpdater == nullptr) {
187 ENGINE_LOGI("GetCurrentVersionInfo onlineUpdater null");
188 return INT_CALL_FAIL;
189 }
190 return onlineUpdater->GetCurrentVersionInfo(info, currentVersionInfo, businessError);
191 }
192
GetCurrentVersionDescription(const UpgradeInfo & info,const DescriptionOptions & descriptionOptions,VersionDescriptionInfo & currentVersionDescriptionInfo,BusinessError & businessError)193 int32_t UpdateService::GetCurrentVersionDescription(const UpgradeInfo &info,
194 const DescriptionOptions &descriptionOptions, VersionDescriptionInfo ¤tVersionDescriptionInfo,
195 BusinessError &businessError)
196 {
197 sptr<IServiceOnlineUpdater> onlineUpdater = updateImplMgr_->GetOnlineUpdater(info);
198 if (onlineUpdater == nullptr) {
199 ENGINE_LOGI("GetCurrentVersionDescription onlineUpdater null");
200 return INT_CALL_FAIL;
201 }
202 return onlineUpdater->GetCurrentVersionDescription(info, descriptionOptions, currentVersionDescriptionInfo,
203 businessError);
204 }
205
GetTaskInfo(const UpgradeInfo & info,TaskInfo & taskInfo,BusinessError & businessError)206 int32_t UpdateService::GetTaskInfo(const UpgradeInfo &info, TaskInfo &taskInfo, BusinessError &businessError)
207 {
208 sptr<IServiceOnlineUpdater> onlineUpdater = updateImplMgr_->GetOnlineUpdater(info);
209 if (onlineUpdater == nullptr) {
210 ENGINE_LOGI("GetTaskInfo onlineUpdater null");
211 return INT_CALL_FAIL;
212 }
213 return onlineUpdater->GetTaskInfo(info, taskInfo, businessError);
214 }
215
SetUpgradePolicy(const UpgradeInfo & info,const UpgradePolicy & policy,BusinessError & businessError)216 int32_t UpdateService::SetUpgradePolicy(const UpgradeInfo &info, const UpgradePolicy &policy,
217 BusinessError &businessError)
218 {
219 sptr<IServiceOnlineUpdater> onlineUpdater = updateImplMgr_->GetOnlineUpdater(info);
220 if (onlineUpdater == nullptr) {
221 ENGINE_LOGI("SetUpgradePolicy onlineUpdater null");
222 return INT_CALL_FAIL;
223 }
224 return onlineUpdater->SetUpgradePolicy(info, policy, businessError);
225 }
226
GetUpgradePolicy(const UpgradeInfo & info,UpgradePolicy & policy,BusinessError & businessError)227 int32_t UpdateService::GetUpgradePolicy(const UpgradeInfo &info, UpgradePolicy &policy, BusinessError &businessError)
228 {
229 sptr<IServiceOnlineUpdater> onlineUpdater = updateImplMgr_->GetOnlineUpdater(info);
230 if (onlineUpdater == nullptr) {
231 ENGINE_LOGI("GetUpgradePolicy onlineUpdater null");
232 return INT_CALL_FAIL;
233 }
234 return onlineUpdater->GetUpgradePolicy(info, policy, businessError);
235 }
236
CheckNewVersion(const UpgradeInfo & info,BusinessError & businessError,CheckResult & checkResult)237 int32_t UpdateService::CheckNewVersion(const UpgradeInfo &info, BusinessError &businessError, CheckResult &checkResult)
238 {
239 sptr<IServiceOnlineUpdater> onlineUpdater = updateImplMgr_->GetOnlineUpdater(info);
240 if (onlineUpdater == nullptr) {
241 ENGINE_LOGI("CheckNewVersion onlineUpdater null");
242 return INT_CALL_FAIL;
243 }
244 return onlineUpdater->CheckNewVersion(info, businessError, checkResult);
245 }
246
Download(const UpgradeInfo & info,const VersionDigestInfo & versionDigestInfo,const DownloadOptions & downloadOptions,BusinessError & businessError)247 int32_t UpdateService::Download(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo,
248 const DownloadOptions &downloadOptions, BusinessError &businessError)
249 {
250 sptr<IServiceOnlineUpdater> onlineUpdater = updateImplMgr_->GetOnlineUpdater(info);
251 if (onlineUpdater == nullptr) {
252 ENGINE_LOGI("Download onlineUpdater null");
253 return INT_CALL_FAIL;
254 }
255 return onlineUpdater->Download(info, versionDigestInfo, downloadOptions, businessError);
256 }
257
PauseDownload(const UpgradeInfo & info,const VersionDigestInfo & versionDigestInfo,const PauseDownloadOptions & pauseDownloadOptions,BusinessError & businessError)258 int32_t UpdateService::PauseDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo,
259 const PauseDownloadOptions &pauseDownloadOptions, BusinessError &businessError)
260 {
261 ENGINE_LOGI("PauseDownload");
262 businessError.errorNum = CallResult::SUCCESS;
263 businessError.Build(CallResult::UN_SUPPORT, "PauseDownload unsupport");
264 return INT_CALL_SUCCESS;
265 }
266
ResumeDownload(const UpgradeInfo & info,const VersionDigestInfo & versionDigestInfo,const ResumeDownloadOptions & resumeDownloadOptions,BusinessError & businessError)267 int32_t UpdateService::ResumeDownload(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo,
268 const ResumeDownloadOptions &resumeDownloadOptions, BusinessError &businessError)
269 {
270 ENGINE_LOGI("ResumeDownload allowNetwork:%{public}d", CAST_INT(resumeDownloadOptions.allowNetwork));
271 businessError.Build(CallResult::UN_SUPPORT, "ResumeDownload unsupport");
272 return INT_CALL_SUCCESS;
273 }
274
Upgrade(const UpgradeInfo & info,const VersionDigestInfo & versionDigestInfo,const UpgradeOptions & upgradeOptions,BusinessError & businessError)275 int32_t UpdateService::Upgrade(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo,
276 const UpgradeOptions &upgradeOptions, BusinessError &businessError)
277 {
278 sptr<IServiceOnlineUpdater> onlineUpdater = updateImplMgr_->GetOnlineUpdater(info);
279 if (onlineUpdater == nullptr) {
280 ENGINE_LOGI("Upgrade onlineUpdater null");
281 return INT_CALL_FAIL;
282 }
283 return onlineUpdater->Upgrade(info, versionDigestInfo, upgradeOptions, businessError);
284 }
285
ClearError(const UpgradeInfo & info,const VersionDigestInfo & versionDigestInfo,const ClearOptions & clearOptions,BusinessError & businessError)286 int32_t UpdateService::ClearError(const UpgradeInfo &info, const VersionDigestInfo &versionDigestInfo,
287 const ClearOptions &clearOptions, BusinessError &businessError)
288 {
289 sptr<IServiceOnlineUpdater> onlineUpdater = updateImplMgr_->GetOnlineUpdater(info);
290 if (onlineUpdater == nullptr) {
291 ENGINE_LOGI("ClearError onlineUpdater null");
292 return INT_CALL_FAIL;
293 }
294 return onlineUpdater->ClearError(info, versionDigestInfo, clearOptions, businessError);
295 }
296
TerminateUpgrade(const UpgradeInfo & info,BusinessError & businessError)297 int32_t UpdateService::TerminateUpgrade(const UpgradeInfo &info, BusinessError &businessError)
298 {
299 sptr<IServiceOnlineUpdater> onlineUpdater = updateImplMgr_->GetOnlineUpdater(info);
300 if (onlineUpdater == nullptr) {
301 ENGINE_LOGI("TerminateUpgrade onlineUpdater null");
302 return INT_CALL_FAIL;
303 }
304 return onlineUpdater->TerminateUpgrade(info, businessError);
305 }
306
Cancel(const UpgradeInfo & info,int32_t service,BusinessError & businessError)307 int32_t UpdateService::Cancel(const UpgradeInfo &info, int32_t service, BusinessError &businessError)
308 {
309 sptr<IServiceOnlineUpdater> onlineUpdater = updateImplMgr_->GetOnlineUpdater(info);
310 if (onlineUpdater == nullptr) {
311 ENGINE_LOGI("Cancel onlineUpdater null");
312 return INT_CALL_FAIL;
313 }
314 return onlineUpdater->Cancel(info, service, businessError);
315 }
316
FactoryReset(BusinessError & businessError)317 int32_t UpdateService::FactoryReset(BusinessError &businessError)
318 {
319 sptr<UpdateServiceRestorer> restorer = new UpdateServiceRestorer();
320 if (restorer == nullptr) {
321 ENGINE_LOGI("FactoryReset restorer null");
322 return INT_CALL_FAIL;
323 }
324 return restorer->FactoryReset(businessError);
325 }
326
ApplyNewVersion(const UpgradeInfo & info,const std::string & miscFile,const std::string & packageName,BusinessError & businessError)327 int32_t UpdateService::ApplyNewVersion(const UpgradeInfo &info, const std::string &miscFile,
328 const std::string &packageName, BusinessError &businessError)
329 {
330 sptr<UpdateServiceLocalUpdater> localUpdater = new UpdateServiceLocalUpdater();
331 if (localUpdater == nullptr) {
332 ENGINE_LOGI("FactoryReset localUpdater null");
333 return INT_CALL_FAIL;
334 }
335 return localUpdater->ApplyNewVersion(info, miscFile, packageName, businessError);
336 }
337
VerifyUpgradePackage(const std::string & packagePath,const std::string & keyPath,BusinessError & businessError)338 int32_t UpdateService::VerifyUpgradePackage(const std::string &packagePath, const std::string &keyPath,
339 BusinessError &businessError)
340 {
341 sptr<UpdateServiceLocalUpdater> localUpdater = new UpdateServiceLocalUpdater();
342 if (localUpdater == nullptr) {
343 ENGINE_LOGI("FactoryReset localUpdater null");
344 return INT_CALL_FAIL;
345 }
346 return localUpdater->VerifyUpgradePackage(packagePath, keyPath, businessError);
347 }
348
BuildUpgradeInfoDump(const int fd,UpgradeInfo & info)349 void BuildUpgradeInfoDump(const int fd, UpgradeInfo &info)
350 {
351 dprintf(fd, "---------------------upgrade info info--------------------\n");
352 dprintf(fd, "UpgradeApp: %s\n", info.upgradeApp.c_str());
353 dprintf(fd, "vendor: %s\n", info.businessType.vendor.c_str());
354 dprintf(fd, "subType: %d\n", static_cast<int>(info.businessType.subType));
355 }
356
BuildVersionInfoDump(const int fd,const CheckResult & checkResult)357 void BuildVersionInfoDump(const int fd, const CheckResult &checkResult)
358 {
359 dprintf(fd, "---------------------version info--------------------\n");
360 dprintf(fd, "isExistNewVersion: %d\n", checkResult.isExistNewVersion);
361 if (checkResult.newVersionInfo.versionComponents.empty()) {
362 return;
363 }
364 dprintf(fd, "PackageSize: %zu\n", static_cast<size_t>(checkResult.newVersionInfo.versionComponents[0].size));
365 dprintf(fd, "ComponentType: %d\n", checkResult.newVersionInfo.versionComponents[0].componentType);
366 dprintf(fd, "UpgradeAction: %s\n", checkResult.newVersionInfo.versionComponents[0].upgradeAction.c_str());
367 dprintf(fd, "DisplayVersion: %s\n", checkResult.newVersionInfo.versionComponents[0].displayVersion.c_str());
368 dprintf(fd, "InnerVersion: %s\n", checkResult.newVersionInfo.versionComponents[0].innerVersion.c_str());
369 dprintf(fd, "Content: %s\n", checkResult.newVersionInfo.versionComponents[0].descriptionInfo.content.c_str());
370 }
371
BuildTaskInfoDump(const int fd)372 void BuildTaskInfoDump(const int fd)
373 {
374 sptr<UpdateService> service = UpdateService::GetInstance();
375 if (service == nullptr) {
376 ENGINE_LOGI("BuildTaskInfoDump no instance");
377 return;
378 }
379
380 TaskInfo taskInfo;
381 BusinessError businessError;
382 UpgradeInfo upgradeInfo;
383 service->GetTaskInfo(upgradeInfo, taskInfo, businessError);
384 if (!taskInfo.existTask) {
385 dprintf(fd, "TaskInfo is empty\n");
386 return;
387 }
388
389 dprintf(fd, "---------------------OTA status info--------------------\n");
390 dprintf(fd, "Progress: %d\n", taskInfo.taskBody.progress);
391 dprintf(fd, "UpgradeStatus: %d\n", taskInfo.taskBody.status);
392 dprintf(fd, "SubStatus: %d\n", taskInfo.taskBody.subStatus);
393 for (auto &iter : taskInfo.taskBody.errorMessages) {
394 dprintf(fd, "ErrorCode: %d\n", iter.errorCode);
395 dprintf(fd, "ErrorMsg: %s\n", iter.errorMessage.c_str());
396 }
397 }
398
DumpUpgradeCallback(const int fd)399 void UpdateService::DumpUpgradeCallback(const int fd)
400 {
401 dprintf(fd, "---------------------callback info--------------------\n");
402 for (const auto &iter : clientProxyMap_) {
403 const UpgradeInfo& info = iter.first;
404 dprintf(fd, "%s\n", info.ToString().c_str());
405 }
406 }
407
Dump(int fd,const std::vector<std::u16string> & args)408 int UpdateService::Dump(int fd, const std::vector<std::u16string> &args)
409 {
410 if (fd < 0) {
411 ENGINE_LOGI("HiDumper handle invalid");
412 return -1;
413 }
414
415 if (args.size() == 0) {
416 UpgradeInfo upgradeInfo = UpdateServiceCache::GetUpgradeInfo(BusinessSubType::FIRMWARE);
417 BuildUpgradeInfoDump(fd, upgradeInfo);
418 BuildTaskInfoDump(fd);
419 DumpUpgradeCallback(fd);
420 } else {
421 dprintf(fd, "input error, no parameters required\n");
422 }
423 return 0;
424 }
425
OnStart(const SystemAbilityOnDemandReason & startReason)426 void UpdateService::OnStart(const SystemAbilityOnDemandReason &startReason)
427 {
428 ENGINE_LOGI("UpdaterService oh OnStart, startReason name %{public}s, id %{public}d, value %{public}s",
429 startReason.GetName().c_str(), CAST_INT(startReason.GetId()), startReason.GetValue().c_str());
430 updateService_ = this;
431 if (updateService_ == nullptr) {
432 ENGINE_LOGE("updateService_ null");
433 }
434
435 std::vector<uint32_t> codes = {
436 CAST_UINT(UpdaterSaInterfaceCode::CHECK_VERSION),
437 CAST_UINT(UpdaterSaInterfaceCode::DOWNLOAD),
438 CAST_UINT(UpdaterSaInterfaceCode::PAUSE_DOWNLOAD),
439 CAST_UINT(UpdaterSaInterfaceCode::RESUME_DOWNLOAD),
440 CAST_UINT(UpdaterSaInterfaceCode::UPGRADE),
441 CAST_UINT(UpdaterSaInterfaceCode::CLEAR_ERROR),
442 CAST_UINT(UpdaterSaInterfaceCode::TERMINATE_UPGRADE),
443 CAST_UINT(UpdaterSaInterfaceCode::SET_POLICY),
444 CAST_UINT(UpdaterSaInterfaceCode::GET_POLICY),
445 CAST_UINT(UpdaterSaInterfaceCode::GET_NEW_VERSION),
446 CAST_UINT(UpdaterSaInterfaceCode::GET_NEW_VERSION_DESCRIPTION),
447 CAST_UINT(UpdaterSaInterfaceCode::GET_CURRENT_VERSION),
448 CAST_UINT(UpdaterSaInterfaceCode::GET_CURRENT_VERSION_DESCRIPTION),
449 CAST_UINT(UpdaterSaInterfaceCode::GET_TASK_INFO),
450 CAST_UINT(UpdaterSaInterfaceCode::REGISTER_CALLBACK),
451 CAST_UINT(UpdaterSaInterfaceCode::UNREGISTER_CALLBACK),
452 CAST_UINT(UpdaterSaInterfaceCode::CANCEL),
453 CAST_UINT(UpdaterSaInterfaceCode::FACTORY_RESET),
454 CAST_UINT(UpdaterSaInterfaceCode::APPLY_NEW_VERSION),
455 CAST_UINT(UpdaterSaInterfaceCode::VERIFY_UPGRADE_PACKAGE)
456 };
457 ENGINE_LOGI("RegisterFunc HandleOhRemoteRequest");
458 RegisterFunc(codes, HandleOhRemoteRequest);
459
460 DelayedSingleton<ConfigParse>::GetInstance()->LoadConfigInfo(); // 启动读取配置信息
461 std::string libPath = DelayedSingleton<ConfigParse>::GetInstance()->GetModuleLibPath();
462 ENGINE_LOGI("GetModuleLibPath %{public}s ", libPath.c_str());
463 ModuleManager::GetInstance().LoadModule(libPath);
464
465 if (!ModuleManager::GetInstance().IsModuleLoaded()) {
466 ENGINE_LOGI("IsModuleLoaded false, init blue");
467 DelayedSingleton<NetManager>::GetInstance()->Init();
468
469 // 动态启停流程启动
470 DelayedSingleton<StartupManager>::GetInstance()->Start();
471 }
472
473 if (Publish(this)) {
474 ENGINE_LOGI("UpdaterService OnStart publish success");
475 } else {
476 ENGINE_LOGI("UpdaterService OnStart publish fail");
477 }
478
479 if (ModuleManager::GetInstance().IsModuleLoaded()) {
480 ENGINE_LOGI("IsModuleLoaded true");
481 ModuleManager::GetInstance().HandleOnStartOnStopFunc("OnStart", startReason);
482 }
483 }
484
OnIdle(const SystemAbilityOnDemandReason & idleReason)485 int32_t UpdateService::OnIdle(const SystemAbilityOnDemandReason &idleReason)
486 {
487 ENGINE_LOGI("UpdaterService OnIdle");
488 return ModuleManager::GetInstance().HandleOnIdleFunc("OnIdle", idleReason);
489 }
490
OnStop(const SystemAbilityOnDemandReason & stopReason)491 void UpdateService::OnStop(const SystemAbilityOnDemandReason &stopReason)
492 {
493 ENGINE_LOGI("UpdaterService OnStop");
494 ModuleManager::GetInstance().HandleOnStartOnStopFunc("OnStop", stopReason);
495 }
496
HandleOhRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)497 int32_t HandleOhRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
498 {
499 return UpdateService::GetInstance()-> HandleRemoteRequest(code, data, reply, option);
500 }
501 } // namespace UpdateEngine
502 } // namespace OHOS
503