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