diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h index f0e5dd3ae85139266363bca54018ceb7eaac1c63..5f186a5c991ce910e88e25f0745ae5e2bd81aeac 100644 --- a/services/common/include/bundle_active_service.h +++ b/services/common/include/bundle_active_service.h @@ -211,7 +211,7 @@ protected: private: std::shared_ptr bundleActiveCore_; std::shared_ptr reportHandler_; - std::shared_ptr appStateObserver_; + sptr appStateObserver_; #ifdef BGTASKMGR_ENABLE std::shared_ptr continuousTaskObserver_; #endif diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 393d9f879cd4926a3e5bd3e1b3671f8a4e4db284..67b08f968df305bf664d0ae7491923ae5a759e9e 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -167,8 +167,12 @@ OHOS::sptr BundleActiveService::GetAppManagerInstance void BundleActiveService::InitAppStateSubscriber(const std::shared_ptr& reportHandler) { - if (appStateObserver_ == nullptr) { - appStateObserver_ = std::make_shared(); + if (!appStateObserver_) { + appStateObserver_ = new (std::nothrow)BundleActiveAppStateObserver(); + if (!appStateObserver_) { + BUNDLE_ACTIVE_LOGE("malloc app state observer failed"); + return; + } appStateObserver_->Init(reportHandler); } } @@ -190,7 +194,7 @@ bool BundleActiveService::SubscribeAppState() BUNDLE_ACTIVE_LOGE("SubscribeAppState appstateobserver is null, return"); return false; } - int32_t err = appManager->RegisterApplicationStateObserver(appStateObserver_.get()); + int32_t err = appManager->RegisterApplicationStateObserver(appStateObserver_); if (err != 0) { BUNDLE_ACTIVE_LOGE("RegisterApplicationStateObserver failed. err:%{public}d", err); return false;