From 35ee10693b60dbcb9111ce09fbb9bfdbf9d1852f Mon Sep 17 00:00:00 2001 From: houdisheng Date: Wed, 9 Mar 2022 20:25:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8A=A0=E5=BC=BA=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E6=97=B6=E5=AF=B9=E4=BE=9D=E8=B5=96=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=9A=84=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/src/bundle_active_service.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 5673785..8e40ae0 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -75,6 +75,19 @@ void BundleActiveService::InitNecessaryState() return; } + if (systemAbilityManager == nullptr + || systemAbilityManager->GetSystemAbility(APP_MGR_SERVICE_ID) == nullptr + || systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID) == nullptr + || systemAbilityManager->GetSystemAbility(POWER_MANAGER_SERVICE_ID) == nullptr + || systemAbilityManager->GetSystemAbility(COMMON_EVENT_SERVICE_ID) == nullptr + || systemAbilityManager->GetSystemAbility(BACKGROUND_TASK_MANAGER_SERVICE_ID) == nullptr + || systemAbilityManager->GetSystemAbility(TIME_SERVICE_ID) == nullptr) { + BUNDLE_ACTIVE_LOGI("request system service object is not ready yet!"); + auto task = [this]() { this->InitNecessaryState(); }; + handler_->PostTask(task, DELAY_TIME); + return; + } + if (bundleActiveCore_ == nullptr) { bundleActiveCore_ = std::make_shared(); bundleActiveCore_->Init(); @@ -118,6 +131,9 @@ OHOS::sptr BundleActiveService::GetAppManagerInstance OHOS::sptr systemAbilityManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); OHOS::sptr object = systemAbilityManager->GetSystemAbility(OHOS::APP_MGR_SERVICE_ID); + if (!object) { + return nullptr; + } return OHOS::iface_cast(object); } @@ -141,7 +157,7 @@ bool BundleActiveService::SubscribeAppState() { BUNDLE_ACTIVE_LOGI("SubscribeAppState called"); sptr appManager = GetAppManagerInstance(); - if (appStateObserver_ == nullptr) { + if (appStateObserver_ == nullptr || appManager == nullptr) { BUNDLE_ACTIVE_LOGE("SubscribeAppState appstateobserver is null, return"); return false; } -- Gitee From 029a1663db1e4bf0417bdcfc72e8850a9c5a9330 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Thu, 10 Mar 2022 10:11:15 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=80=BB=E8=BE=91=EF=BC=8C=E5=8A=A0?= =?UTF-8?q?=E5=BC=BA=E5=AF=B9=E4=BE=9D=E8=B5=96SA=E7=9A=84=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/include/bundle_active_service.h | 1 + services/common/src/bundle_active_service.cpp | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h index c0ec217..64732cd 100644 --- a/services/common/include/bundle_active_service.h +++ b/services/common/include/bundle_active_service.h @@ -66,6 +66,7 @@ private: std::shared_ptr handler_; int ConvertIntervalType(const int intervalType); void InitNecessaryState(); + void InitService(); bool GetBundleMgrProxy(); bool CheckBundleIsSystemAppAndHasPermission(const int uid, const int userId); void InitAppStateSubscriber(const std::shared_ptr& reportHandler); diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 8e40ae0..652450d 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -88,6 +88,11 @@ void BundleActiveService::InitNecessaryState() return; } + InitService(); +} + +void BundleActiveService::InitService() +{ if (bundleActiveCore_ == nullptr) { bundleActiveCore_ = std::make_shared(); bundleActiveCore_->Init(); -- Gitee