• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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 "bundle_mgr_service.h"
17 
18 #include <sys/stat.h>
19 
20 #include "account_helper.h"
21 #ifdef CODE_SIGNATURE_ENABLE
22 #include "aot/aot_sign_data_cache_mgr.h"
23 #endif
24 #include "aot/aot_device_idle_listener.h"
25 #include "bundle_common_event.h"
26 #include "bundle_memory_guard.h"
27 #include "bundle_resource_helper.h"
28 #include "datetime_ex.h"
29 #include "el5_filekey_callback.h"
30 #include "el5_filekey_manager_kit.h"
31 #include "installd_client.h"
32 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
33 #include "app_control_manager_host_impl.h"
34 #endif
35 #include "perf_profile.h"
36 #include "scope_guard.h"
37 #include "bundle_backup_mgr.h"
38 #include "system_ability_definition.h"
39 #include "system_ability_helper.h"
40 #include "xcollie_helper.h"
41 
42 namespace OHOS {
43 namespace AppExecFwk {
44 namespace {
45 constexpr int32_t BUNDLE_BROKER_SERVICE_ABILITY_ID = 0x00010500;
46 constexpr int16_t EL5_FILEKEY_SERVICE_ABILITY_ID = 8250;
47 constexpr const char* FUN_BMS_START = "BundleMgrService::Start";
48 constexpr unsigned int BMS_START_TIME_OUT_SECONDS = 60 * 4;
49 const std::string EXTENSION_BACKUP = "backup";
50 const std::string EXTENSION_RESTORE = "restore";
51 } // namespace
52 
53 const bool REGISTER_RESULT =
54     SystemAbility::MakeAndRegisterAbility(DelayedSingleton<BundleMgrService>::GetInstance().get());
55 
BundleMgrService()56 BundleMgrService::BundleMgrService() : SystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, true)
57 {
58     APP_LOGI("instance is created");
59     PerfProfile::GetInstance().SetBmsLoadStartTime(GetTickCount());
60 }
61 
~BundleMgrService()62 BundleMgrService::~BundleMgrService()
63 {
64     host_ = nullptr;
65     installer_ = nullptr;
66     if (handler_) {
67         handler_.reset();
68     }
69     if (dataMgr_) {
70         dataMgr_.reset();
71     }
72 #ifdef BUNDLE_FRAMEWORK_FREE_INSTALL
73     {
74         std::lock_guard<ffrt::mutex> connectLock(bundleConnectMutex_);
75         if (!connectAbilityMgr_.empty()) {
76             connectAbilityMgr_.clear();
77         }
78     }
79 #endif
80     if (hidumpHelper_) {
81         hidumpHelper_.reset();
82     }
83     APP_LOGI("BundleMgrService instance is destroyed");
84 }
85 
OnStart()86 void BundleMgrService::OnStart()
87 {
88     APP_LOGI_NOFUNC("BundleMgrService OnStart start");
89     if (!Init()) {
90         APP_LOGE("BundleMgrService init fail");
91         return;
92     }
93 
94     AddSystemAbilityListener(COMMON_EVENT_SERVICE_ID);
95     AddSystemAbilityListener(BUNDLE_BROKER_SERVICE_ABILITY_ID);
96     AddSystemAbilityListener(EL5_FILEKEY_SERVICE_ABILITY_ID);
97     APP_LOGI_NOFUNC("BundleMgrService OnStart end");
98 }
99 
OnStop()100 void BundleMgrService::OnStop()
101 {
102     APP_LOGI("OnStop is called");
103     SelfClean();
104 }
105 
OnDeviceLevelChanged(int32_t type,int32_t level,std::string & action)106 void BundleMgrService::OnDeviceLevelChanged(int32_t type, int32_t level, std::string& action)
107 {
108     APP_LOGD("SystemAbility OnDeviceLevelChanged is called");
109     // DeviceStatus::DEVICE_IDLE = 5
110     if (type == 5) {
111         APP_LOGI("receive device idle notification");
112         // 1.screen-off; 2.last-time >= 10mins; 3.power-capacity > 91%
113         AOTDeviceIdleListener::GetInstance().OnReceiveDeviceIdle();
114     }
115 }
116 
IsServiceReady() const117 bool BundleMgrService::IsServiceReady() const
118 {
119     return ready_;
120 }
121 
Init()122 bool BundleMgrService::Init()
123 {
124     if (ready_) {
125         APP_LOGW("init more than one time");
126         return false;
127     }
128 
129     APP_LOGI_NOFUNC("BundleMgrService Init begin");
130     CreateBmsServiceDir();
131     InitBmsParam();
132     InitPreInstallExceptionMgr();
133     CHECK_INIT_RESULT(InitBundleMgrHost(), "Init bundleMgr fail");
134     CHECK_INIT_RESULT(InitBundleInstaller(), "Init bundleInstaller fail");
135     InitBundleDataMgr();
136     CHECK_INIT_RESULT(InitBundleUserMgr(), "Init bundleUserMgr fail");
137     CHECK_INIT_RESULT(InitVerifyManager(), "Init verifyManager fail");
138     CHECK_INIT_RESULT(InitExtendResourceManager(), "Init extendResourceManager fail");
139     CHECK_INIT_RESULT(InitBundleEventHandler(), "Init bundleEventHandler fail");
140     InitHidumpHelper();
141     InitFreeInstall();
142     CHECK_INIT_RESULT(InitDefaultApp(), "Init defaultApp fail");
143     CHECK_INIT_RESULT(InitAppControl(), "Init appControl fail");
144     CHECK_INIT_RESULT(InitBundleMgrExt(), "Init bundle mgr ext fail");
145     CHECK_INIT_RESULT(InitQuickFixManager(), "Init quickFixManager fail");
146     CHECK_INIT_RESULT(InitOverlayManager(), "Init overlayManager fail");
147     CHECK_INIT_RESULT(InitBundleResourceMgr(), "Init BundleResourceMgr fail");
148     BundleResourceHelper::BundleSystemStateInit();
149     ready_ = true;
150     APP_LOGI_NOFUNC("BundleMgrService Init success");
151     return true;
152 }
153 
InitBmsParam()154 void BundleMgrService::InitBmsParam()
155 {
156     bmsParam_ = std::make_shared<BmsParam>();
157 }
158 
InitPreInstallExceptionMgr()159 void BundleMgrService::InitPreInstallExceptionMgr()
160 {
161     preInstallExceptionMgr_ = std::make_shared<PreInstallExceptionMgr>();
162 }
163 
InitBundleMgrHost()164 bool BundleMgrService::InitBundleMgrHost()
165 {
166     if (host_ == nullptr) {
167         host_ = new (std::nothrow) BundleMgrHostImpl();
168     }
169 
170     return host_ != nullptr;
171 }
172 
InitBundleInstaller()173 bool BundleMgrService::InitBundleInstaller()
174 {
175     if (installer_ == nullptr) {
176         installer_ = new (std::nothrow) BundleInstallerHost();
177         if (installer_ == nullptr) {
178             APP_LOGE("init installer fail");
179             return false;
180         }
181         installer_->Init();
182     }
183 
184     return true;
185 }
186 
InitBundleDataMgr()187 void BundleMgrService::InitBundleDataMgr()
188 {
189     if (dataMgr_ == nullptr) {
190         APP_LOGI("Create BundledataMgr");
191         dataMgr_ = std::make_shared<BundleDataMgr>();
192         dataMgr_->AddUserId(Constants::DEFAULT_USERID);
193     }
194 }
195 
InitBundleUserMgr()196 bool BundleMgrService::InitBundleUserMgr()
197 {
198     if (userMgrHost_ == nullptr) {
199         userMgrHost_ = new (std::nothrow) BundleUserMgrHostImpl();
200     }
201 
202     return userMgrHost_ != nullptr;
203 }
204 
InitVerifyManager()205 bool BundleMgrService::InitVerifyManager()
206 {
207     if (verifyManager_ == nullptr) {
208         verifyManager_ = new (std::nothrow) VerifyManagerHostImpl();
209     }
210 
211     return verifyManager_ != nullptr;
212 }
213 
InitExtendResourceManager()214 bool BundleMgrService::InitExtendResourceManager()
215 {
216     if (extendResourceManager_ == nullptr) {
217         extendResourceManager_ = new (std::nothrow) ExtendResourceManagerHostImpl();
218     }
219 
220     return extendResourceManager_ != nullptr;
221 }
222 
InitBundleEventHandler()223 bool BundleMgrService::InitBundleEventHandler()
224 {
225     if (handler_ == nullptr) {
226         handler_ = std::make_shared<BMSEventHandler>();
227     }
228     auto task = [handler = handler_]() {
229         BundleMemoryGuard memoryGuard;
230         int32_t timerId = XCollieHelper::SetRecoveryTimer(FUN_BMS_START, BMS_START_TIME_OUT_SECONDS);
231         ScopeGuard cancelTimerGuard([timerId] { XCollieHelper::CancelTimer(timerId); });
232         handler->BmsStartEvent();
233     };
234     std::thread(task).detach();
235     return true;
236 }
237 
InitHidumpHelper()238 void BundleMgrService::InitHidumpHelper()
239 {
240     if (hidumpHelper_ == nullptr) {
241         APP_LOGI("Create hidump helper");
242         hidumpHelper_ = std::make_shared<HidumpHelper>(dataMgr_);
243     }
244 }
245 
InitFreeInstall()246 void BundleMgrService::InitFreeInstall()
247 {
248 #ifdef BUNDLE_FRAMEWORK_FREE_INSTALL
249     if (agingMgr_ == nullptr) {
250         APP_LOGI("Create aging manager");
251         agingMgr_ = std::make_shared<BundleAgingMgr>();
252         agingMgr_->InitAgingtTimer();
253     }
254     if (bundleDistributedManager_ == nullptr) {
255         APP_LOGI("Create bundleDistributedManager");
256         bundleDistributedManager_ = std::make_shared<BundleDistributedManager>();
257     }
258 #endif
259 }
260 
InitDefaultApp()261 bool BundleMgrService::InitDefaultApp()
262 {
263 #ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
264     if (defaultAppHostImpl_ == nullptr) {
265         defaultAppHostImpl_ = new (std::nothrow) DefaultAppHostImpl();
266         if (defaultAppHostImpl_ == nullptr) {
267             APP_LOGE("create DefaultAppHostImpl failed");
268             return false;
269         }
270     }
271 #endif
272     return true;
273 }
274 
InitAppControl()275 bool BundleMgrService::InitAppControl()
276 {
277 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
278     if (appControlManagerHostImpl_ == nullptr) {
279         appControlManagerHostImpl_ = new (std::nothrow) AppControlManagerHostImpl();
280         if (appControlManagerHostImpl_ == nullptr) {
281             APP_LOGE("create appControlManagerHostImpl failed");
282             return false;
283         }
284     }
285 #endif
286     return true;
287 }
288 
InitBundleMgrExt()289 bool BundleMgrService::InitBundleMgrExt()
290 {
291     if (bundleMgrExtHostImpl_ == nullptr) {
292         bundleMgrExtHostImpl_ = new (std::nothrow) BundleMgrExtHostImpl();
293         if (bundleMgrExtHostImpl_ == nullptr) {
294             APP_LOGE("create bundleMgrExtHostImpl failed");
295             return false;
296         }
297     }
298     return true;
299 }
300 
InitQuickFixManager()301 bool BundleMgrService::InitQuickFixManager()
302 {
303 #ifdef BUNDLE_FRAMEWORK_QUICK_FIX
304     if (quickFixManagerHostImpl_ == nullptr) {
305         quickFixManagerHostImpl_ = new (std::nothrow) QuickFixManagerHostImpl();
306         if (quickFixManagerHostImpl_ == nullptr) {
307             APP_LOGE("create QuickFixManagerHostImpl failed");
308             return false;
309         }
310     }
311 #endif
312     return true;
313 }
314 
InitOverlayManager()315 bool BundleMgrService::InitOverlayManager()
316 {
317 #ifdef BUNDLE_FRAMEWORK_OVERLAY_INSTALLATION
318     if (overlayManagerHostImpl_ == nullptr) {
319         overlayManagerHostImpl_ = new (std::nothrow) OverlayManagerHostImpl();
320         if (overlayManagerHostImpl_ == nullptr) {
321             APP_LOGE("create OverlayManagerHostImpl failed");
322             return false;
323         }
324     }
325 #endif
326     return true;
327 }
328 
CreateBmsServiceDir()329 void BundleMgrService::CreateBmsServiceDir()
330 {
331     auto ret = InstalldClient::GetInstance()->Mkdir(
332         ServiceConstants::HAP_COPY_PATH, S_IRWXU | S_IXGRP | S_IRGRP | S_IROTH | S_IXOTH,
333         Constants::FOUNDATION_UID, ServiceConstants::BMS_GID);
334     if (ret != ERR_OK) {
335         APP_LOGE("create dir failed, ret %{public}d", ret);
336     }
337     ret = InstalldClient::GetInstance()->Mkdir(
338         std::string(ServiceConstants::HAP_COPY_PATH) + ServiceConstants::GALLERY_DOWNLOAD_PATH,
339         S_IRWXU | S_IRWXG | S_IXOTH,
340         Constants::FOUNDATION_UID, ServiceConstants::APP_INSTALL_GID);
341     if (ret != ERR_OK) {
342         APP_LOGE("create app_install failed, ret %{public}d", ret);
343     }
344 }
345 
InitBundleResourceMgr()346 bool BundleMgrService::InitBundleResourceMgr()
347 {
348 #ifdef BUNDLE_FRAMEWORK_BUNDLE_RESOURCE
349     if (bundleResourceHostImpl_ == nullptr) {
350         bundleResourceHostImpl_ = new (std::nothrow) BundleResourceHostImpl();
351         if (bundleResourceHostImpl_ == nullptr) {
352             APP_LOGE("create bundleResourceHostImpl failed");
353             return false;
354         }
355     }
356 #endif
357     return true;
358 }
359 
GetBundleInstaller() const360 sptr<BundleInstallerHost> BundleMgrService::GetBundleInstaller() const
361 {
362     return installer_;
363 }
364 
RegisterDataMgr(std::shared_ptr<BundleDataMgr> dataMgrImpl)365 void BundleMgrService::RegisterDataMgr(std::shared_ptr<BundleDataMgr> dataMgrImpl)
366 {
367     dataMgr_ = dataMgrImpl;
368     if (dataMgr_ != nullptr) {
369         dataMgr_->AddUserId(Constants::DEFAULT_USERID);
370     }
371 }
372 
GetDataMgr() const373 const std::shared_ptr<BundleDataMgr> BundleMgrService::GetDataMgr() const
374 {
375     return dataMgr_;
376 }
377 
378 #ifdef BUNDLE_FRAMEWORK_FREE_INSTALL
GetAgingMgr() const379 const std::shared_ptr<BundleAgingMgr> BundleMgrService::GetAgingMgr() const
380 {
381     return agingMgr_;
382 }
383 
GetConnectAbility(int32_t userId)384 const std::shared_ptr<BundleConnectAbilityMgr> BundleMgrService::GetConnectAbility(int32_t userId)
385 {
386     int32_t currentUserId = userId;
387     if (currentUserId == Constants::UNSPECIFIED_USERID) {
388         currentUserId = AccountHelper::GetCurrentActiveUserId();
389     }
390     std::lock_guard<ffrt::mutex> connectLock(bundleConnectMutex_);
391     if (connectAbilityMgr_.find(userId) == connectAbilityMgr_.end() ||
392         connectAbilityMgr_[userId] == nullptr) {
393         auto ptr = std::make_shared<BundleConnectAbilityMgr>();
394         connectAbilityMgr_[userId] = ptr;
395     }
396     return connectAbilityMgr_[userId];
397 }
398 
GetBundleDistributedManager() const399 const std::shared_ptr<BundleDistributedManager> BundleMgrService::GetBundleDistributedManager() const
400 {
401     return bundleDistributedManager_;
402 }
403 #endif
404 
SelfClean()405 void BundleMgrService::SelfClean()
406 {
407     if (ready_) {
408         ready_ = false;
409         if (registerToService_) {
410             registerToService_ = false;
411         }
412     }
413 #ifdef BUNDLE_FRAMEWORK_FREE_INSTALL
414     agingMgr_.reset();
415     {
416         std::lock_guard<ffrt::mutex> connectLock(bundleConnectMutex_);
417         connectAbilityMgr_.clear();
418     }
419     bundleDistributedManager_.reset();
420 #endif
421 }
422 
GetBundleUserMgr() const423 sptr<BundleUserMgrHostImpl> BundleMgrService::GetBundleUserMgr() const
424 {
425     return userMgrHost_;
426 }
427 
GetVerifyManager() const428 sptr<IVerifyManager> BundleMgrService::GetVerifyManager() const
429 {
430     return verifyManager_;
431 }
432 
GetExtendResourceManager() const433 sptr<IExtendResourceManager> BundleMgrService::GetExtendResourceManager() const
434 {
435     return extendResourceManager_;
436 }
437 
GetBmsParam() const438 const std::shared_ptr<BmsParam> BundleMgrService::GetBmsParam() const
439 {
440     return bmsParam_;
441 }
442 
GetPreInstallExceptionMgr() const443 const std::shared_ptr<PreInstallExceptionMgr> BundleMgrService::GetPreInstallExceptionMgr() const
444 {
445     return preInstallExceptionMgr_;
446 }
447 
448 #ifdef BUNDLE_FRAMEWORK_DEFAULT_APP
GetDefaultAppProxy() const449 sptr<IDefaultApp> BundleMgrService::GetDefaultAppProxy() const
450 {
451     return defaultAppHostImpl_;
452 }
453 #endif
454 
455 #ifdef BUNDLE_FRAMEWORK_APP_CONTROL
GetAppControlProxy() const456 sptr<IAppControlMgr> BundleMgrService::GetAppControlProxy() const
457 {
458     return appControlManagerHostImpl_;
459 }
460 #endif
461 
GetBundleMgrExtProxy() const462 sptr<IBundleMgrExt> BundleMgrService::GetBundleMgrExtProxy() const
463 {
464     return bundleMgrExtHostImpl_;
465 }
466 
467 #ifdef BUNDLE_FRAMEWORK_QUICK_FIX
GetQuickFixManagerProxy() const468 sptr<QuickFixManagerHostImpl> BundleMgrService::GetQuickFixManagerProxy() const
469 {
470     return quickFixManagerHostImpl_;
471 }
472 #endif
473 
474 #ifdef BUNDLE_FRAMEWORK_OVERLAY_INSTALLATION
GetOverlayManagerProxy() const475 sptr<IOverlayManager> BundleMgrService::GetOverlayManagerProxy() const
476 {
477     return overlayManagerHostImpl_;
478 }
479 #endif
480 
481 #ifdef BUNDLE_FRAMEWORK_BUNDLE_RESOURCE
GetBundleResourceProxy() const482 sptr<IBundleResource> BundleMgrService::GetBundleResourceProxy() const
483 {
484     return bundleResourceHostImpl_;
485 }
486 #endif
487 
CheckAllUser()488 void BundleMgrService::CheckAllUser()
489 {
490     if (dataMgr_ == nullptr) {
491         return;
492     }
493 
494     APP_LOGI("Check all user start");
495     std::set<int32_t> userIds = dataMgr_->GetAllUser();
496     AccountHelper::QueryAllCreatedOsAccounts(userIds);
497     for (auto userId : userIds) {
498         if (userId == Constants::DEFAULT_USERID) {
499             continue;
500         }
501 
502         bool isExists = false;
503         if (AccountHelper::IsOsAccountExists(userId, isExists) != ERR_OK) {
504             APP_LOGW("Failed query whether user(%{public}d) exists", userId);
505             continue;
506         }
507 
508         if (!isExists) {
509             APP_LOGE("Query user(%{public}d) success but not complete and remove it", userId);
510             userMgrHost_->RemoveUser(userId);
511 #ifdef BUNDLE_FRAMEWORK_FREE_INSTALL
512             {
513                 std::lock_guard<ffrt::mutex> connectLock(bundleConnectMutex_);
514                 connectAbilityMgr_.erase(userId);
515             }
516 #endif
517             continue;
518         }
519         if (!dataMgr_->HasUserId(userId)) {
520             dataMgr_->AddUserId(userId);
521         }
522     }
523     APP_LOGI("Check all user end");
524 }
525 
RegisterService()526 void BundleMgrService::RegisterService()
527 {
528     if (!registerToService_) {
529         if (!SystemAbilityHelper::AddSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, host_)) {
530             APP_LOGE("fail to register to system ability manager");
531             return;
532         }
533         APP_LOGI("BundleMgrService register to sam success");
534         registerToService_ = true;
535     }
536 
537     PerfProfile::GetInstance().SetBmsLoadEndTime(GetTickCount());
538     PerfProfile::GetInstance().Dump();
539 }
540 
NotifyBundleScanStatus()541 void BundleMgrService::NotifyBundleScanStatus()
542 {
543     APP_LOGI("PublishCommonEvent for bundle scan finished");
544     AAFwk::Want want;
545     want.SetAction(COMMON_EVENT_BUNDLE_SCAN_FINISHED);
546     EventFwk::CommonEventData commonEventData { want };
547     if (!EventFwk::CommonEventManager::PublishCommonEvent(commonEventData)) {
548         notifyBundleScanStatus = true;
549         APP_LOGE("PublishCommonEvent for bundle scan finished failed");
550     } else {
551         APP_LOGI("PublishCommonEvent for bundle scan finished succeed");
552     }
553 }
554 
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)555 void BundleMgrService::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
556 {
557     APP_LOGI("OnAddSystemAbility systemAbilityId:%{public}d added", systemAbilityId);
558     if (COMMON_EVENT_SERVICE_ID == systemAbilityId && notifyBundleScanStatus) {
559         NotifyBundleScanStatus();
560     }
561 #ifdef CODE_SIGNATURE_ENABLE
562     if (systemAbilityId == COMMON_EVENT_SERVICE_ID) {
563         AOTSignDataCacheMgr::GetInstance().RegisterScreenUnlockListener();
564     }
565 #endif
566     if (BUNDLE_BROKER_SERVICE_ABILITY_ID == systemAbilityId) {
567         if (host_ != nullptr) {
568             isBrokerServiceStarted_ = true;
569             host_->SetBrokerServiceStatus(true);
570         }
571     }
572     if (EL5_FILEKEY_SERVICE_ABILITY_ID == systemAbilityId) {
573         int32_t reg = Security::AccessToken::El5FilekeyManagerKit::RegisterCallback(sptr(new El5FilekeyCallback()));
574         APP_LOGI("Register El5FilekeyCallback result: %{public}d", reg);
575     }
576 }
577 
Hidump(const std::vector<std::string> & args,std::string & result) const578 bool BundleMgrService::Hidump(const std::vector<std::string> &args, std::string& result) const
579 {
580     if (hidumpHelper_ && hidumpHelper_->Dump(args, result)) {
581         return true;
582     }
583 
584     APP_LOGD("HidumpHelper failed");
585     return false;
586 }
587 
IsBrokerServiceStarted() const588 bool BundleMgrService::IsBrokerServiceStarted() const
589 {
590     return isBrokerServiceStarted_;
591 }
592 
OnExtension(const std::string & extension,MessageParcel & data,MessageParcel & reply)593 int32_t BundleMgrService::OnExtension(const std::string& extension, MessageParcel& data, MessageParcel& reply)
594 {
595     APP_LOGI("extension is %{public}s.", extension.c_str());
596     std::shared_ptr<BundleBackupMgr> bundleBackupMgr = DelayedSingleton<BundleBackupMgr>::GetInstance();
597     if (bundleBackupMgr == nullptr) {
598         APP_LOGE("Get BundleBackupMgr failed");
599         return ERR_APPEXECFWK_NULL_PTR;
600     }
601     ErrCode ret = ERR_OK;
602     if (extension == EXTENSION_BACKUP) {
603         ret = bundleBackupMgr->OnBackup(data, reply);
604         if (ret != ERR_OK) {
605             APP_LOGE("OnBackup failed, err is %{public}d.", ret);
606             return ret;
607         }
608     } else if (extension == EXTENSION_RESTORE) {
609         ret = bundleBackupMgr->OnRestore(data, reply);
610         if (ret != ERR_OK) {
611             APP_LOGE("OnRestore failed, err is %{public}d.", ret);
612             return ret;
613         }
614     }
615     return ERR_OK;
616 }
617 }  // namespace AppExecFwk
618 }  // namespace OHOS
619