From 9732ec4fce3644d19bba5fba22f1569efdb35374 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Mon, 28 Feb 2022 22:42:50 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E4=BF=AE=E5=A4=8D=E9=95=BF=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E6=97=B6=E9=97=B4=E8=AE=B0=E5=BD=95=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E9=97=AE=E9=A2=98=EF=BC=8C=E9=95=BF=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=96=B0=E4=B8=80=E5=A4=A9=E8=BF=9B=E7=A8=8B=E5=B4=A9?= =?UTF-8?q?=E6=BA=83=E9=97=AE=E9=A2=98=EF=BC=8Cdatabase=E5=88=86=E7=BB=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=88=A0=E9=99=A4=E4=B8=8D=E5=85=A8=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- .../common/src/bundle_active_app_state_obsever.cpp | 2 +- .../src/bundle_active_continuous_task_observer.cpp | 2 +- services/common/src/bundle_active_core.cpp | 2 ++ services/common/src/bundle_active_service.cpp | 2 +- .../include/bundle_active_group_controller.h | 1 + .../include/bundle_active_group_handler.h | 2 +- .../src/bundle_active_group_controller.cpp | 11 +++++++++++ services/packageusage/include/bundle_active_event.h | 2 +- .../packageusage/src/bundle_active_package_stats.cpp | 2 +- .../packageusage/src/bundle_active_period_stats.cpp | 6 +++--- .../packageusage/src/bundle_active_user_service.cpp | 6 +++--- 11 files changed, 26 insertions(+), 12 deletions(-) diff --git a/services/common/src/bundle_active_app_state_obsever.cpp b/services/common/src/bundle_active_app_state_obsever.cpp index 2e458c1..cf613c6 100644 --- a/services/common/src/bundle_active_app_state_obsever.cpp +++ b/services/common/src/bundle_active_app_state_obsever.cpp @@ -48,7 +48,7 @@ void BundleActiveAppStateObserver::OnAbilityStateChanged(const AbilityStateData tmpHandlerObject.event_.bundleName_ = abilityStateData.bundleName; tmpHandlerObject.event_.abilityName_ = abilityStateData.abilityName; tmpHandlerObject.event_.abilityId_ = abilityStateData.abilityName; - tmpHandlerObject.event_.ContinuousTaskAbilityName_ = ""; + tmpHandlerObject.event_.continuousTaskAbilityName_ = ""; tmpHandlerObject.userId_ = userId; sptr timer = MiscServices::TimeServiceClient::GetInstance(); tmpHandlerObject.event_.timeStamp_ = timer->GetBootTimeMs(); diff --git a/services/common/src/bundle_active_continuous_task_observer.cpp b/services/common/src/bundle_active_continuous_task_observer.cpp index 4db0837..459524f 100644 --- a/services/common/src/bundle_active_continuous_task_observer.cpp +++ b/services/common/src/bundle_active_continuous_task_observer.cpp @@ -92,7 +92,7 @@ void BundleActiveContinuousTaskObserver::ReportContinuousTaskEvent( tmpHandlerObject.event_.bundleName_ = bundleName; tmpHandlerObject.event_.abilityName_ = ""; tmpHandlerObject.event_.abilityId_ = abilityId; - tmpHandlerObject.event_.ContinuousTaskAbilityName_ = abiliytName; + tmpHandlerObject.event_.continuousTaskAbilityName_ = abiliytName; tmpHandlerObject.userId_ = userId; sptr timer = MiscServices::TimeServiceClient::GetInstance(); tmpHandlerObject.event_.timeStamp_ = timer->GetBootTimeMs(); diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index d0f7505..5f09345 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -31,6 +31,7 @@ BundleActiveReportHandlerObject::BundleActiveReportHandlerObject(const BundleAct event_.timeStamp_ = orig.event_.timeStamp_; event_.eventId_ = orig.event_.eventId_; event_.isidle_ = orig.event_.isidle_; + event_.continuousTaskAbilityName_ = orig.event_.continuousTaskAbilityName_; userId_ = orig.userId_; bundleName_ = orig.bundleName_; } @@ -195,6 +196,7 @@ void BundleActiveCore::OnBundleUninstalled(const int userId, const std::string& return; } service->DeleteUninstalledBundleStats(bundleName); + bundleGroupController_->OnBundleUninstalled(userId, bundleName); } void BundleActiveCore::OnStatsChanged() diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 9d7728a..556c5d1 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -181,7 +181,7 @@ int BundleActiveService::ReportEvent(std::string& bundleName, std::string& abili tmpHandlerObject.event_.abilityName_ = abilityName; tmpHandlerObject.event_.abilityId_ = abilityId; tmpHandlerObject.event_.eventId_ = eventId; - tmpHandlerObject.event_.ContinuousTaskAbilityName_ = continuousTask; + tmpHandlerObject.event_.continuousTaskAbilityName_ = continuousTask; tmpHandlerObject.userId_ = userId; sptr timer = MiscServices::TimeServiceClient::GetInstance(); tmpHandlerObject.event_.timeStamp_ = timer->GetBootTimeMs(); diff --git a/services/packagegroup/include/bundle_active_group_controller.h b/services/packagegroup/include/bundle_active_group_controller.h index a8a2ec1..c0589b7 100644 --- a/services/packagegroup/include/bundle_active_group_controller.h +++ b/services/packagegroup/include/bundle_active_group_controller.h @@ -73,6 +73,7 @@ public: void CheckIdleStatsOneTime(); void PeriodCheckBundleState(const int userId); void OnUserRemoved(const int userId); + void OnBundleUninstalled(const int userId, const std::string bundleName); void OnScreenChanged(const bool& isScreenOn, const int64_t bootFromTimeStamp); void SetBundleGroup(const std::string& bundleName, const int userId, int newGroup, int reason, const int64_t bootBasedTimeStamp, const bool& resetTimeout); diff --git a/services/packagegroup/include/bundle_active_group_handler.h b/services/packagegroup/include/bundle_active_group_handler.h index 2bf694b..cb9ec0d 100644 --- a/services/packagegroup/include/bundle_active_group_handler.h +++ b/services/packagegroup/include/bundle_active_group_handler.h @@ -48,7 +48,7 @@ public: static const int MSG_CHECK_BUNDLE_STATE = 0; static const int MSG_ONE_TIME_CHECK_BUNDLE_STATE = 1; static const int MSG_CHECK_IDLE_STATE = 2; - static const int CHECK_IDLE_INTERVAL = THREE_HOUR; + static const int CHECK_IDLE_INTERVAL = TEN_MINUTE; private: std::shared_ptr bundleActiveGroupController_; diff --git a/services/packagegroup/src/bundle_active_group_controller.cpp b/services/packagegroup/src/bundle_active_group_controller.cpp index 9a4ed7c..ca79fea 100644 --- a/services/packagegroup/src/bundle_active_group_controller.cpp +++ b/services/packagegroup/src/bundle_active_group_controller.cpp @@ -60,6 +60,17 @@ void BundleActiveGroupController::SetHandlerAndCreateUserHistory( activeGroupHandler_ = groupHandler; } +void BundleActiveGroupController::OnBundleUninstalled(const int userId, const std::string bundleName) +{ + std::lock_guard lock(mutex_); + auto oneUserHistory = bundleUserHistory_->GetUserHistory(userId, false); + if (oneUserHistory == nullptr) { + return; + } + oneUserHistory->erase(bundleName); + bundleUserHistory_->WriteBundleUsage(userId); +} + bool BundleActiveGroupController::GetBundleMgrProxy() { if (!sptrBundleMgr_) { diff --git a/services/packageusage/include/bundle_active_event.h b/services/packageusage/include/bundle_active_event.h index e0d6a8f..d438384 100644 --- a/services/packageusage/include/bundle_active_event.h +++ b/services/packageusage/include/bundle_active_event.h @@ -42,7 +42,7 @@ public: static const int NOTIFICATION_SEEN = 17; inline static const std::string DEVICE_EVENT_PACKAGE_NAME = "openharmony"; std::string bundleName_; - std::string ContinuousTaskAbilityName_; + std::string continuousTaskAbilityName_; std::string abilityName_; std::string abilityId_; int64_t timeStamp_; diff --git a/services/packageusage/src/bundle_active_package_stats.cpp b/services/packageusage/src/bundle_active_package_stats.cpp index b081c3d..01048a2 100644 --- a/services/packageusage/src/bundle_active_package_stats.cpp +++ b/services/packageusage/src/bundle_active_package_stats.cpp @@ -189,7 +189,7 @@ void BundleActivePackageStats::UpdateLongTimeTask(const std::string& longTimeTas switch (eventId) { case BundleActiveEvent::LONG_TIME_TASK_STARTTED: - if (AnyLongTimeTaskStarted()) { + if (!AnyLongTimeTaskStarted()) { lastContiniousTaskUsed_ = timeStamp; } longTimeTasks_[longTimeTaskName] = eventId; diff --git a/services/packageusage/src/bundle_active_period_stats.cpp b/services/packageusage/src/bundle_active_period_stats.cpp index a3eb481..e9f0b71 100644 --- a/services/packageusage/src/bundle_active_period_stats.cpp +++ b/services/packageusage/src/bundle_active_period_stats.cpp @@ -47,7 +47,7 @@ BundleActiveEvent BundleActivePeriodStats::BuildEvent(std::string bundleName, st BundleActiveEvent newEvent; newEvent.bundleName_ = bundleName; if (!timeTaskName.empty()) { - newEvent.ContinuousTaskAbilityName_ = timeTaskName; + newEvent.continuousTaskAbilityName_ = timeTaskName; } return newEvent; } @@ -75,8 +75,8 @@ void BundleActivePeriodStats::Update(const std::string bundleName, const std::st void BundleActivePeriodStats::AddEvent(BundleActiveEvent event) { event.bundleName_ = GetCachedString(event.bundleName_); - if (!event.ContinuousTaskAbilityName_.empty()) { - event.ContinuousTaskAbilityName_ = GetCachedString(event.ContinuousTaskAbilityName_); + if (!event.continuousTaskAbilityName_.empty()) { + event.continuousTaskAbilityName_ = GetCachedString(event.continuousTaskAbilityName_); } events_.Insert(event); if (event.timeStamp_ > endTime_) { diff --git a/services/packageusage/src/bundle_active_user_service.cpp b/services/packageusage/src/bundle_active_user_service.cpp index 7e4efcf..cdc1639 100644 --- a/services/packageusage/src/bundle_active_user_service.cpp +++ b/services/packageusage/src/bundle_active_user_service.cpp @@ -123,7 +123,7 @@ void BundleActiveUserService::ReportEvent(const BundleActiveEvent& event) it->UpdateKeyguardHidden(event.timeStamp_); break; default: - it->Update(event.bundleName_, event.ContinuousTaskAbilityName_, event.timeStamp_, event.eventId_, + it->Update(event.bundleName_, event.continuousTaskAbilityName_, event.timeStamp_, event.eventId_, event.abilityId_); if (incrementBundleLaunch) { BUNDLE_ACTIVE_LOGI(" BundleActiveUserService::ReportEvent increase bundle started count"); @@ -150,7 +150,7 @@ void BundleActiveUserService::ReportForFlushAndShutdown(const BundleActiveEvent& RenewStatsInMemory(event.timeStamp_); } for (auto it : currentStats_) { - it->Update(event.bundleName_, event.ContinuousTaskAbilityName_, event.timeStamp_, event.eventId_, + it->Update(event.bundleName_, event.continuousTaskAbilityName_, event.timeStamp_, event.eventId_, event.abilityId_); } BUNDLE_ACTIVE_LOGI("BundleActiveUserService::ReportForFlushAndShutdown called notify"); @@ -257,7 +257,7 @@ void BundleActiveUserService::RenewStatsInMemory(const int64_t timeStamp) if (continueServices.find(continueBundleName) != continueServices.end()) { for (std::map::iterator it = continueServices[continueBundleName].begin(); it != continueServices[continueBundleName].end(); it++) { - (*itInterval)->Update(continueBundleName, it->first, beginTime, it->second, 0); + (*itInterval)->Update(continueBundleName, it->first, beginTime, it->second, ""); } } NotifyStatsChanged(); -- Gitee From 78fb8ef6f3621a481d9822be9899b8d47574e49e Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 1 Mar 2022 14:31:07 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcontroller=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=AF=BC=E8=87=B4core=E9=97=AE=E9=A2=98?= 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 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 556c5d1..06b2f63 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -81,6 +81,7 @@ void BundleActiveService::OnAddSystemAbility(int32_t systemAbilityId, const std: powerManagerClient.RegisterShutdownCallback(shutdownCallback_); InitAppStateSubscriber(reportHandler_); InitContinuousSubscriber(reportHandler_); + bundleActiveCore_->InitBundleGroupController(); } if (systemAbilityId == APP_MGR_SERVICE_ID) { if (reportHandler_ != nullptr) { @@ -92,9 +93,6 @@ void BundleActiveService::OnAddSystemAbility(int32_t systemAbilityId, const std: SubscribeContinuousTask(); } } - if (systemAbilityId == BUNDLE_MGR_SERVICE_SYS_ABILITY_ID) { - bundleActiveCore_->InitBundleGroupController(); - } } -- Gitee From 19bcdeaf650ab481d5646e9590fe17044165156e Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 1 Mar 2022 15:37:00 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/include/bundle_active_log.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/common/include/bundle_active_log.h b/services/common/include/bundle_active_log.h index d2056ed..3a24733 100644 --- a/services/common/include/bundle_active_log.h +++ b/services/common/include/bundle_active_log.h @@ -19,7 +19,7 @@ #include "hilog/log.h" #define LOG_TAG_BUNDLE_ACTIVE "BUNDLE_ACTIVE" -#define LOG_TAG_DOMAIN_ID_BUNDLE_ACTIVE 0xD001700 +#define LOG_TAG_DOMAIN_ID_BUNDLE_ACTIVE 0xD001701 static constexpr OHOS::HiviewDFX::HiLogLabel BUNDLE_ACTIVE_LOG_LABEL = { LOG_CORE, -- Gitee From db407344859eeef72aa08034dad89de1f4b6e27f Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 1 Mar 2022 16:20:43 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9isldiebundle=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=9D=83=E9=99=90=E6=A0=A1=E9=AA=8C=E9=80=BB=E8=BE=91?= 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 06b2f63..f4d2960 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -202,8 +202,12 @@ bool BundleActiveService::IsBundleIdle(const std::string& bundleName) OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, userId); if (ret == ERR_OK && userId != -1) { BUNDLE_ACTIVE_LOGI("BundleActiveService::IsBundleIdle user id is %{public}d", userId); - bool isSystemAppAndHasPermission = CheckBundleIsSystemAppAndHasPermission(callingUid, userId); - if (isSystemAppAndHasPermission == true) { + if (!GetBundleMgrProxy()) { + BUNDLE_ACTIVE_LOGE("Get bundle manager proxy failed!"); + return true; + } + bool bundleIsSystemApp = sptrBundleMgr_->CheckIsSystemAppByUid(callingUid); + if (bundleIsSystemApp == true) { result = bundleActiveCore_->IsBundleIdle(bundleName, userId); } } -- Gitee From 98319fa9bca9a5f63bbdd1c2e52bdfab9f296a56 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 1 Mar 2022 18:47:48 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9sa=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- .../common/include/bundle_active_service.h | 5 +- services/common/src/bundle_active_service.cpp | 100 ++++++++++-------- 2 files changed, 57 insertions(+), 48 deletions(-) diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h index 3b5ee1b..c0ec217 100644 --- a/services/common/include/bundle_active_service.h +++ b/services/common/include/bundle_active_service.h @@ -54,8 +54,6 @@ public: protected: void OnStart() override; void OnStop() override; - void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; - void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; private: std::shared_ptr bundleActiveCore_; @@ -64,7 +62,10 @@ private: std::shared_ptr continuousTaskObserver_; sptr sptrBundleMgr_; sptr shutdownCallback_; + std::shared_ptr runner_; + std::shared_ptr handler_; int ConvertIntervalType(const int intervalType); + void InitNecessaryState(); 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 f4d2960..be942f2 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -28,6 +28,7 @@ namespace DeviceUsageStats { static const int PERIOD_BEST_JS = 0; static const int PERIOD_YEARLY_JS = 4; static const int PERIOD_BEST_SERVICE = 4; +static const int DELAY_TIME = 2000; REGISTER_SYSTEM_ABILITY_BY_ID(BundleActiveService, DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID, true); using namespace OHOS::Security::AccessToken; using AccessTokenKit = OHOS::Security::AccessToken::AccessTokenKit; @@ -36,66 +37,77 @@ const std::string NEEDED_PERMISSION = "ohos.permission.BUNDLE_ACTIVE_INFO"; void BundleActiveService::OnStart() { BUNDLE_ACTIVE_LOGI("BundleActiveService::OnStart() called"); + runner_ = AppExecFwk::EventRunner::Create("device_usage_stats_init_handler"); + if (runner_ == nullptr) { + BUNDLE_ACTIVE_LOGI("BundleActiveService runner create failed!"); + return; + } + handler_ = std::make_shared(runner_); + if (handler_ == nullptr) { + BUNDLE_ACTIVE_LOGI("BundleActiveService handler create failed!"); + return; + } + + InitNecessaryState(); int ret = Publish(this); if (!ret) { BUNDLE_ACTIVE_LOGE("[Server] OnStart, Register SystemAbility[1907] FAIL."); return; } - AddSystemAbilityListener(POWER_MANAGER_SERVICE_ID); - AddSystemAbilityListener(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); - AddSystemAbilityListener(APP_MGR_SERVICE_ID); - AddSystemAbilityListener(BACKGROUND_TASK_MANAGER_SERVICE_ID); BUNDLE_ACTIVE_LOGI("[Server] OnStart, Register SystemAbility[1907] SUCCESS."); return; } -void BundleActiveService::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) +void BundleActiveService::InitNecessaryState() { - BUNDLE_ACTIVE_LOGI("BundleActiveService::OnAddSystemAbility called, SAID is %{public}d", systemAbilityId); - if (systemAbilityId == POWER_MANAGER_SERVICE_ID) { - if (bundleActiveCore_ == nullptr) { - bundleActiveCore_ = std::make_shared(); - bundleActiveCore_->Init(); + sptr systemAbilityManager + = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemAbilityManager == nullptr + || systemAbilityManager->CheckSystemAbility(APP_MGR_SERVICE_ID) == nullptr + || systemAbilityManager->CheckSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID) == nullptr + || systemAbilityManager->CheckSystemAbility(POWER_MANAGER_SERVICE_ID) == nullptr + || systemAbilityManager->CheckSystemAbility(COMMON_EVENT_SERVICE_ID) == nullptr + || systemAbilityManager->CheckSystemAbility(BACKGROUND_TASK_MANAGER_SERVICE_ID) == nullptr + || systemAbilityManager->CheckSystemAbiligy(TIME_SERVICE_ID) == nullptr) { + BUNDLE_ACTIVE_LOGI("request system service is not ready yet!"); + auto task = [this]() { this->InitNecessaryState(); }; + handler_->PostTask(task, DELAY_TIME); + return; + } + + if (bundleActiveCore_ == nullptr) { + bundleActiveCore_ = std::make_shared(); + bundleActiveCore_->Init(); + } + if (reportHandler_ == nullptr) { + std::string threadName = "bundle_active_report_handler"; + auto runner = AppExecFwk::EventRunner::Create(threadName); + if (runner == nullptr) { + BUNDLE_ACTIVE_LOGE("report handler is null"); + return; } + reportHandler_ = std::make_shared(runner); if (reportHandler_ == nullptr) { - std::string threadName = "bundle_active_report_handler"; - auto runner = AppExecFwk::EventRunner::Create(threadName); - if (runner == nullptr) { - BUNDLE_ACTIVE_LOGE("report handler is null"); - return; - } - reportHandler_ = std::make_shared(runner); - if (reportHandler_ == nullptr) { - return; - } - reportHandler_->Init(bundleActiveCore_); - } - if (reportHandler_ != nullptr && bundleActiveCore_ != nullptr) { - BUNDLE_ACTIVE_LOGI("core and handler is not null"); - bundleActiveCore_->SetHandler(reportHandler_); - } else { return; } - shutdownCallback_ = new BundleActiveShutdownCallbackService(bundleActiveCore_); - auto& powerManagerClient = OHOS::PowerMgr::PowerMgrClient::GetInstance(); - powerManagerClient.RegisterShutdownCallback(shutdownCallback_); - InitAppStateSubscriber(reportHandler_); - InitContinuousSubscriber(reportHandler_); - bundleActiveCore_->InitBundleGroupController(); - } - if (systemAbilityId == APP_MGR_SERVICE_ID) { - if (reportHandler_ != nullptr) { - SubscribeAppState(); - } + reportHandler_->Init(bundleActiveCore_); } - if (systemAbilityId == BACKGROUND_TASK_MANAGER_SERVICE_ID) { - if (reportHandler_ != nullptr) { - SubscribeContinuousTask(); - } + if (reportHandler_ != nullptr && bundleActiveCore_ != nullptr) { + BUNDLE_ACTIVE_LOGI("core and handler is not null"); + bundleActiveCore_->SetHandler(reportHandler_); + } else { + return; } + shutdownCallback_ = new BundleActiveShutdownCallbackService(bundleActiveCore_); + auto& powerManagerClient = OHOS::PowerMgr::PowerMgrClient::GetInstance(); + powerManagerClient.RegisterShutdownCallback(shutdownCallback_); + InitAppStateSubscriber(reportHandler_); + InitContinuousSubscriber(reportHandler_); + bundleActiveCore_->InitBundleGroupController(); + SubscribeAppState(); + SubscribeContinuousTask(); } - OHOS::sptr BundleActiveService::GetAppManagerInstance() { OHOS::sptr systemAbilityManager = @@ -152,10 +164,6 @@ bool BundleActiveService::SubscribeContinuousTask() return true; } -void BundleActiveService::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) -{ -} - void BundleActiveService::OnStop() { if (shutdownCallback_ != nullptr) { -- Gitee From 517e9678061c8bb7a119f81905fd3baa4ba83a0d Mon Sep 17 00:00:00 2001 From: houdisheng Date: Tue, 1 Mar 2022 19:30:53 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9sa=E5=90=AF=E5=8A=A8?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index be942f2..9b7bfd2 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -68,7 +68,7 @@ void BundleActiveService::InitNecessaryState() || systemAbilityManager->CheckSystemAbility(POWER_MANAGER_SERVICE_ID) == nullptr || systemAbilityManager->CheckSystemAbility(COMMON_EVENT_SERVICE_ID) == nullptr || systemAbilityManager->CheckSystemAbility(BACKGROUND_TASK_MANAGER_SERVICE_ID) == nullptr - || systemAbilityManager->CheckSystemAbiligy(TIME_SERVICE_ID) == nullptr) { + || systemAbilityManager->CheckSystemAbility(TIME_SERVICE_ID) == nullptr) { BUNDLE_ACTIVE_LOGI("request system service is not ready yet!"); auto task = [this]() { this->InitNecessaryState(); }; handler_->PostTask(task, DELAY_TIME); -- Gitee