From 0e0e258d607de68badc3d527f4af584dcef708ff Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Tue, 23 Aug 2022 15:25:21 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E9=92=88=E5=AF=B9foundation=E8=BF=9B?= =?UTF-8?q?=E7=A8=8Bkill=EF=BC=8Cdevice=E8=BF=9B=E7=A8=8B=E4=B8=8D?= =?UTF-8?q?=E9=87=8D=E5=90=AF=E7=9A=84=E4=B8=80=E4=BA=9B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- .../common/include/bundle_active_service.h | 11 ++++ services/common/src/bundle_active_service.cpp | 60 ++++++++++++++----- 2 files changed, 56 insertions(+), 15 deletions(-) diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h index ebe6615..e434f4c 100644 --- a/services/common/include/bundle_active_service.h +++ b/services/common/include/bundle_active_service.h @@ -18,6 +18,7 @@ #include "bundle_mgr_interface.h" #include "singleton.h" +#include "system_ability_status_change_stub.h" #include "ibundle_active_service.h" #include "bundle_active_stub.h" @@ -149,11 +150,19 @@ protected: */ void OnStop() override; +private: +class SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub { +public: + 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_; std::shared_ptr reportHandler_; std::shared_ptr appStateObserver_; std::shared_ptr continuousTaskObserver_; + sptr sysAbilityListener_ = nullptr; sptr sptrBundleMgr_; sptr shutdownCallback_; sptr powerStateCallback_; @@ -162,6 +171,8 @@ private: bool ready_ {false}; int32_t ConvertIntervalType(const int32_t intervalType); void InitNecessaryState(); + void InitNecessarySa(); + void InitSubscribe(); void InitService(); bool GetBundleMgrProxy(); bool CheckBundleIsSystemAppAndHasPermission(const int32_t uid, OHOS::Security::AccessToken::AccessTokenID tokenId, diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 37607d1..047e4e5 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -43,13 +43,9 @@ const std::string NEEDED_PERMISSION = "ohos.permission.BUNDLE_ACTIVE_INFO"; const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(DelayedSingleton::GetInstance().get()); -BundleActiveService::BundleActiveService() : SystemAbility(DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID, true) -{ -} +BundleActiveService::BundleActiveService() : SystemAbility(DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID, true) { } -BundleActiveService::~BundleActiveService() -{ -} +BundleActiveService::~BundleActiveService() { } void BundleActiveService::OnStart() { @@ -68,11 +64,33 @@ void BundleActiveService::OnStart() BUNDLE_ACTIVE_LOGI("BundleActiveService handler create failed!"); return; } + + sysAbilityListener_ = new (std::nothrow) SystemAbilityStatusChangeListener(); + if (sysAbilityListener_ == nullptr) { + BUNDLE_ACTIVE_LOGE("Failed to create statusChangeListener due to no memory"); + return; + } auto registerTask = [this]() { this->InitNecessaryState(); }; handler_->PostSyncTask(registerTask); } void BundleActiveService::InitNecessaryState() +{ + sptr systemAbilityManager + = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + InitNecessarySa(); + InitService(); + + ready_ = true; + int32_t ret = Publish(DelayedSingleton::GetInstance().get()); + if (!ret) { + BUNDLE_ACTIVE_LOGE("[Server] OnStart, Register SystemAbility[1907] FAIL."); + return; + } + BUNDLE_ACTIVE_LOGI("[Server] OnStart, Register SystemAbility[1907] SUCCESS."); +} + +void BundleActiveService::InitNecessarySa() { sptr systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -84,7 +102,7 @@ void BundleActiveService::InitNecessaryState() || systemAbilityManager->CheckSystemAbility(BACKGROUND_TASK_MANAGER_SERVICE_ID) == nullptr || systemAbilityManager->CheckSystemAbility(TIME_SERVICE_ID) == nullptr) { BUNDLE_ACTIVE_LOGI("request system service is not ready yet!"); - auto task = [this]() { this->InitNecessaryState(); }; + auto task = [this]() { this->InitNecessarySa(); }; handler_->PostTask(task, DELAY_TIME); return; } @@ -96,18 +114,15 @@ void BundleActiveService::InitNecessaryState() || 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(); }; + auto task = [this]() { this->InitNecessarySa(); }; handler_->PostTask(task, DELAY_TIME); return; } - InitService(); - ready_ = true; - int32_t ret = Publish(DelayedSingleton::GetInstance().get()); - if (!ret) { - BUNDLE_ACTIVE_LOGE("[Server] OnStart, Register SystemAbility[1907] FAIL."); - return; + InitSubscribe(); + if (systemAbilityManager->SubscribeSystemAbility(POWER_MANAGER_SERVICE_ID, sysAbilityListener_) != ERR_OK) { + sysAbilityListener_ = nullptr; + BUNDLE_ACTIVE_LOGE("subscribe system ability id: %{public}d failed", POWER_MANAGER_SERVICE_ID); } - BUNDLE_ACTIVE_LOGI("[Server] OnStart, Register SystemAbility[1907] SUCCESS."); } void BundleActiveService::InitService() @@ -135,6 +150,11 @@ void BundleActiveService::InitService() } else { return; } + InitSubscribe(); +} + +void BundleActiveService::InitSubscribe() +{ shutdownCallback_ = new (std::nothrow) BundleActiveShutdownCallbackService(bundleActiveCore_); powerStateCallback_ = new (std::nothrow) BundleActivePowerStateCallbackService(bundleActiveCore_); auto& powerManagerClient = OHOS::PowerMgr::PowerMgrClient::GetInstance(); @@ -151,6 +171,16 @@ void BundleActiveService::InitService() SubscribeContinuousTask(); } +void BundleActiveService::SystemAbilityStatusChangeListener::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) +{ + DelayedSingleton::GetInstance()->InitNecessarySa(); +} + +void BundleActiveService::SystemAbilityStatusChangeListener::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) +{ + +} + OHOS::sptr BundleActiveService::GetAppManagerInstance() { OHOS::sptr systemAbilityManager = -- Gitee From af29cb782a0196adc96ddbd7039f351cb4f403df Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Tue, 23 Aug 2022 17:34:27 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E9=92=88=E5=AF=B9foundation=E8=BF=9B?= =?UTF-8?q?=E7=A8=8Bkill=EF=BC=8Cdevice=E8=BF=9B=E7=A8=8B=E4=B8=8D?= =?UTF-8?q?=E9=87=8D=E5=90=AF=E7=9A=84=E4=B8=80=E4=BA=9B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- services/common/include/bundle_active_core.h | 2 ++ .../common/include/bundle_active_service.h | 2 ++ services/common/src/bundle_active_core.cpp | 18 ++++++++++++ services/common/src/bundle_active_service.cpp | 29 ++++++++++++++----- .../include/bundle_active_event.h | 1 + 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/services/common/include/bundle_active_core.h b/services/common/include/bundle_active_core.h index 11061e3..5d3b94b 100644 --- a/services/common/include/bundle_active_core.h +++ b/services/common/include/bundle_active_core.h @@ -193,6 +193,8 @@ public: const sptr &observer); int32_t currentUsedUser_; void OnBundleGroupChanged(const BundleActiveGroupCallbackInfo& callbackInfo); + void OnFoundationkilled(); + void OnFoundationRestarted(); private: void AddObserverDeathRecipient(const sptr &observer); diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h index e434f4c..1dc9c18 100644 --- a/services/common/include/bundle_active_service.h +++ b/services/common/include/bundle_active_service.h @@ -174,6 +174,8 @@ private: void InitNecessarySa(); void InitSubscribe(); void InitService(); + void OnFoundationkilled(); + void OnFoundationRestarted(); bool GetBundleMgrProxy(); bool CheckBundleIsSystemAppAndHasPermission(const int32_t uid, OHOS::Security::AccessToken::AccessTokenID tokenId, int32_t& errCode); diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index e97e0db..b725308 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -315,6 +315,8 @@ void BundleActiveCore::RestoreToDatabaseLocked(const int32_t userId) } if (bundleGroupController_ != nullptr) { bundleGroupController_->RestoreDurationToDatabase(); + bundleGroupController_->CheckEachBundleState(userId); + bundleGroupController_->RestoreToDatabase(userId); } if (!handler_.expired()) { BUNDLE_ACTIVE_LOGI("RestoreToDatabaseLocked remove flush to disk event"); @@ -755,6 +757,22 @@ int32_t BundleActiveCore::UnregisterGroupCallBack(const AccessToken::AccessToken return 0; } +void BundleActiveCore::OnFoundationkilled() +{ + RestoreToDatabase(currentUsedUser_); +} + +void BundleActiveCore::OnFoundationRestarted() +{ + int64_t systemTime = GetSystemTimeMs(); + int64_t timeNow = CheckTimeChangeAndGetWallTime(currentUsedUser_); + if (timeNow == -1) { + return ; + } + auto userService = GetUserDataAndInitializeIfNeeded(currentUsedUser_, timeNow, debugCore_); + userService->LoadActiveStats(systemTime, true, false); +} + void BundleActiveCore::AddObserverDeathRecipient(const sptr &observer) { std::lock_guard lock(deathRecipientMutex_); diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 047e4e5..a9f7695 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -80,7 +80,11 @@ void BundleActiveService::InitNecessaryState() = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); InitNecessarySa(); InitService(); - + if (systemAbilityManager->SubscribeSystemAbility(POWER_MANAGER_SERVICE_ID, sysAbilityListener_) != ERR_OK) { + sysAbilityListener_ = nullptr; + BUNDLE_ACTIVE_LOGE("subscribe system ability id: %{public}d failed", POWER_MANAGER_SERVICE_ID); + } + ready_ = true; int32_t ret = Publish(DelayedSingleton::GetInstance().get()); if (!ret) { @@ -117,12 +121,7 @@ void BundleActiveService::InitNecessarySa() auto task = [this]() { this->InitNecessarySa(); }; handler_->PostTask(task, DELAY_TIME); return; - } - InitSubscribe(); - if (systemAbilityManager->SubscribeSystemAbility(POWER_MANAGER_SERVICE_ID, sysAbilityListener_) != ERR_OK) { - sysAbilityListener_ = nullptr; - BUNDLE_ACTIVE_LOGE("subscribe system ability id: %{public}d failed", POWER_MANAGER_SERVICE_ID); - } + } } void BundleActiveService::InitService() @@ -173,12 +172,26 @@ void BundleActiveService::InitSubscribe() void BundleActiveService::SystemAbilityStatusChangeListener::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) { - DelayedSingleton::GetInstance()->InitNecessarySa(); + DelayedSingleton::GetInstance()->OnFoundationRestarted(); +} + +void BundleActiveService::OnFoundationRestarted() +{ + InitNecessarySa(); + InitSubscribe(); + bundleActiveCore_->OnFoundationRestarted(); } void BundleActiveService::SystemAbilityStatusChangeListener::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) { + DelayedSingleton::GetInstance()->OnFoundationkilled(); +} +void BundleActiveService::OnFoundationkilled() +{ + appStateObserver_ = nullptr; + continuousTaskObserver_ = nullptr; + bundleActiveCore_->OnFoundationkilled(); } OHOS::sptr BundleActiveService::GetAppManagerInstance() diff --git a/services/packageusage/include/bundle_active_event.h b/services/packageusage/include/bundle_active_event.h index 57889be..74b5a82 100644 --- a/services/packageusage/include/bundle_active_event.h +++ b/services/packageusage/include/bundle_active_event.h @@ -50,6 +50,7 @@ public: static const int32_t SYSTEM_UNLOCK = 21; static const int32_t SYSTEM_SLEEP = 22; static const int32_t SYSTEM_WAKEUP = 23; + static const int32_t FOUNDATION_KILL = 24; inline static const std::string DEVICE_EVENT_PACKAGE_NAME = "openharmony"; std::string bundleName_; std::string continuousTaskAbilityName_; -- Gitee From 4bef5d6ab4de6739140c285ce64eda144a211469 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Tue, 23 Aug 2022 19:13:16 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E9=92=88=E5=AF=B9foundation=E8=BF=9B?= =?UTF-8?q?=E7=A8=8Bkill=EF=BC=8Cdevice=E8=BF=9B=E7=A8=8B=E4=B8=8D?= =?UTF-8?q?=E9=87=8D=E5=90=AF=E7=9A=84=E4=B8=80=E4=BA=9B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- services/common/src/bundle_active_service.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index a9f7695..de94a4d 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -121,7 +121,7 @@ void BundleActiveService::InitNecessarySa() auto task = [this]() { this->InitNecessarySa(); }; handler_->PostTask(task, DELAY_TIME); return; - } + } } void BundleActiveService::InitService() @@ -170,25 +170,31 @@ void BundleActiveService::InitSubscribe() SubscribeContinuousTask(); } -void BundleActiveService::SystemAbilityStatusChangeListener::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) +void BundleActiveService::SystemAbilityStatusChangeListener::OnAddSystemAbility( + int32_t systemAbilityId, const std::string& deviceId) { + BUNDLE_ACTIVE_LOGD("BundleActiveService::SystemAbilityStatusChangeListener::OnAddSystemAbility"); DelayedSingleton::GetInstance()->OnFoundationRestarted(); } void BundleActiveService::OnFoundationRestarted() { + BUNDLE_ACTIVE_LOGD("BundleActiveService::OnFoundationRestarted enter"); InitNecessarySa(); InitSubscribe(); bundleActiveCore_->OnFoundationRestarted(); } -void BundleActiveService::SystemAbilityStatusChangeListener::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) +void BundleActiveService::SystemAbilityStatusChangeListener::OnRemoveSystemAbility( + int32_t systemAbilityId, const std::string& deviceId) { + BUNDLE_ACTIVE_LOGD("BundleActiveService::SystemAbilityStatusChangeListener::OnRemoveSystemAbility"); DelayedSingleton::GetInstance()->OnFoundationkilled(); } void BundleActiveService::OnFoundationkilled() { + BUNDLE_ACTIVE_LOGD("BundleActiveService::OnFoundationkilled"); appStateObserver_ = nullptr; continuousTaskObserver_ = nullptr; bundleActiveCore_->OnFoundationkilled(); -- Gitee From f2931840e599afd04d0b1817b94d27533f0c0c49 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Tue, 23 Aug 2022 20:09:45 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E9=92=88=E5=AF=B9foundation=E8=BF=9B?= =?UTF-8?q?=E7=A8=8Bkill=EF=BC=8Cdevice=E8=BF=9B=E7=A8=8B=E4=B8=8D?= =?UTF-8?q?=E9=87=8D=E5=90=AF=E7=9A=84=E4=B8=80=E4=BA=9B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- .../common/include/bundle_active_service.h | 2 +- services/common/src/bundle_active_service.cpp | 46 +++++++++++++------ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h index 1dc9c18..2fa7870 100644 --- a/services/common/include/bundle_active_service.h +++ b/services/common/include/bundle_active_service.h @@ -171,7 +171,7 @@ private: bool ready_ {false}; int32_t ConvertIntervalType(const int32_t intervalType); void InitNecessaryState(); - void InitNecessarySa(); + void InitFoundationRestart(); void InitSubscribe(); void InitService(); void OnFoundationkilled(); diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index de94a4d..8eec890 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -78,7 +78,30 @@ void BundleActiveService::InitNecessaryState() { sptr systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - InitNecessarySa(); + 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->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); + return; + } + + if (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; + } InitService(); if (systemAbilityManager->SubscribeSystemAbility(POWER_MANAGER_SERVICE_ID, sysAbilityListener_) != ERR_OK) { sysAbilityListener_ = nullptr; @@ -94,7 +117,7 @@ void BundleActiveService::InitNecessaryState() BUNDLE_ACTIVE_LOGI("[Server] OnStart, Register SystemAbility[1907] SUCCESS."); } -void BundleActiveService::InitNecessarySa() +void BundleActiveService::InitFoundationRestart() { sptr systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -106,7 +129,7 @@ void BundleActiveService::InitNecessarySa() || systemAbilityManager->CheckSystemAbility(BACKGROUND_TASK_MANAGER_SERVICE_ID) == nullptr || systemAbilityManager->CheckSystemAbility(TIME_SERVICE_ID) == nullptr) { BUNDLE_ACTIVE_LOGI("request system service is not ready yet!"); - auto task = [this]() { this->InitNecessarySa(); }; + auto task = [this]() { this->InitFoundationRestart(); }; handler_->PostTask(task, DELAY_TIME); return; } @@ -118,10 +141,12 @@ void BundleActiveService::InitNecessarySa() || 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->InitNecessarySa(); }; + auto task = [this]() { this->InitFoundationRestart(); }; handler_->PostTask(task, DELAY_TIME); return; } + InitSubscribe(); + bundleActiveCore_->OnFoundationRestarted(); } void BundleActiveService::InitService() @@ -174,15 +199,7 @@ void BundleActiveService::SystemAbilityStatusChangeListener::OnAddSystemAbility( int32_t systemAbilityId, const std::string& deviceId) { BUNDLE_ACTIVE_LOGD("BundleActiveService::SystemAbilityStatusChangeListener::OnAddSystemAbility"); - DelayedSingleton::GetInstance()->OnFoundationRestarted(); -} - -void BundleActiveService::OnFoundationRestarted() -{ - BUNDLE_ACTIVE_LOGD("BundleActiveService::OnFoundationRestarted enter"); - InitNecessarySa(); - InitSubscribe(); - bundleActiveCore_->OnFoundationRestarted(); + DelayedSingleton::GetInstance()->InitFoundationRestart(); } void BundleActiveService::SystemAbilityStatusChangeListener::OnRemoveSystemAbility( @@ -197,6 +214,9 @@ void BundleActiveService::OnFoundationkilled() BUNDLE_ACTIVE_LOGD("BundleActiveService::OnFoundationkilled"); appStateObserver_ = nullptr; continuousTaskObserver_ = nullptr; + shutdownCallback_ = nullptr; + powerStateCallback_ = nullptr; + sptrBundleMgr_ = nullptr; bundleActiveCore_->OnFoundationkilled(); } -- Gitee From f25a0eb5def71fb50aafd749cf932deebc1d7cdb Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Fri, 2 Sep 2022 11:33:36 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E9=92=88=E5=AF=B9foundation=E8=BF=9B?= =?UTF-8?q?=E7=A8=8B=E9=87=8D=E5=90=AF=EF=BC=8Cdevice=E4=B8=8D=E5=81=9A?= =?UTF-8?q?=E9=87=8D=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- .../common/include/bundle_active_service.h | 2 +- services/common/src/bundle_active_service.cpp | 50 +++++++++++++------ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h index 1dc9c18..2fa7870 100644 --- a/services/common/include/bundle_active_service.h +++ b/services/common/include/bundle_active_service.h @@ -171,7 +171,7 @@ private: bool ready_ {false}; int32_t ConvertIntervalType(const int32_t intervalType); void InitNecessaryState(); - void InitNecessarySa(); + void InitFoundationRestart(); void InitSubscribe(); void InitService(); void OnFoundationkilled(); diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index de94a4d..1a152f5 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -78,7 +78,30 @@ void BundleActiveService::InitNecessaryState() { sptr systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - InitNecessarySa(); + 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->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); + return; + } + + if (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; + } InitService(); if (systemAbilityManager->SubscribeSystemAbility(POWER_MANAGER_SERVICE_ID, sysAbilityListener_) != ERR_OK) { sysAbilityListener_ = nullptr; @@ -94,8 +117,10 @@ void BundleActiveService::InitNecessaryState() BUNDLE_ACTIVE_LOGI("[Server] OnStart, Register SystemAbility[1907] SUCCESS."); } -void BundleActiveService::InitNecessarySa() +void BundleActiveService::InitFoundationRestart() { + appStateObserver_ = nullptr; + sptrBundleMgr_ = nullptr; sptr systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (systemAbilityManager == nullptr @@ -106,7 +131,7 @@ void BundleActiveService::InitNecessarySa() || systemAbilityManager->CheckSystemAbility(BACKGROUND_TASK_MANAGER_SERVICE_ID) == nullptr || systemAbilityManager->CheckSystemAbility(TIME_SERVICE_ID) == nullptr) { BUNDLE_ACTIVE_LOGI("request system service is not ready yet!"); - auto task = [this]() { this->InitNecessarySa(); }; + auto task = [this]() { this->InitFoundationRestart(); }; handler_->PostTask(task, DELAY_TIME); return; } @@ -118,10 +143,12 @@ void BundleActiveService::InitNecessarySa() || 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->InitNecessarySa(); }; + auto task = [this]() { this->InitFoundationRestart(); }; handler_->PostTask(task, DELAY_TIME); return; } + InitSubscribe(); + bundleActiveCore_->OnFoundationRestarted(); } void BundleActiveService::InitService() @@ -174,15 +201,7 @@ void BundleActiveService::SystemAbilityStatusChangeListener::OnAddSystemAbility( int32_t systemAbilityId, const std::string& deviceId) { BUNDLE_ACTIVE_LOGD("BundleActiveService::SystemAbilityStatusChangeListener::OnAddSystemAbility"); - DelayedSingleton::GetInstance()->OnFoundationRestarted(); -} - -void BundleActiveService::OnFoundationRestarted() -{ - BUNDLE_ACTIVE_LOGD("BundleActiveService::OnFoundationRestarted enter"); - InitNecessarySa(); - InitSubscribe(); - bundleActiveCore_->OnFoundationRestarted(); + DelayedSingleton::GetInstance()->InitFoundationRestart(); } void BundleActiveService::SystemAbilityStatusChangeListener::OnRemoveSystemAbility( @@ -195,8 +214,9 @@ void BundleActiveService::SystemAbilityStatusChangeListener::OnRemoveSystemAbili void BundleActiveService::OnFoundationkilled() { BUNDLE_ACTIVE_LOGD("BundleActiveService::OnFoundationkilled"); - appStateObserver_ = nullptr; continuousTaskObserver_ = nullptr; + shutdownCallback_ = nullptr; + powerStateCallback_ = nullptr; bundleActiveCore_->OnFoundationkilled(); } @@ -278,7 +298,7 @@ int32_t BundleActiveService::ReportEvent(BundleActiveEvent& event, const int32_t int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid(); BUNDLE_ACTIVE_LOGI("calling process name is %{public}s, uid is %{public}d", callingTokenInfo.processName.c_str(), callingUid); - if (callingTokenInfo.processName == PERMITTED_PROCESS_NAME) { + if (callingTokenInfo.processName == PERMITTED_PROCESS_NAME && reportHandler_) { BundleActiveReportHandlerObject tmpHandlerObject(userId, ""); tmpHandlerObject.event_ = event; sptr timer = MiscServices::TimeServiceClient::GetInstance(); -- Gitee From d53ef33c09f6fef74e50c358df463b75777ceb6f Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Wed, 7 Sep 2022 14:39:48 +0800 Subject: [PATCH 6/7] =?UTF-8?q?foundation=20kill,=20device=E4=B8=8Dkill?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- services/common/src/bundle_active_service.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 1a152f5..928da09 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -119,8 +119,6 @@ void BundleActiveService::InitNecessaryState() void BundleActiveService::InitFoundationRestart() { - appStateObserver_ = nullptr; - sptrBundleMgr_ = nullptr; sptr systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (systemAbilityManager == nullptr @@ -147,6 +145,9 @@ void BundleActiveService::InitFoundationRestart() handler_->PostTask(task, DELAY_TIME); return; } + shutdownCallback_ = nullptr; + powerStateCallback_ = nullptr; + sptrBundleMgr_ = nullptr; InitSubscribe(); bundleActiveCore_->OnFoundationRestarted(); } @@ -214,9 +215,6 @@ void BundleActiveService::SystemAbilityStatusChangeListener::OnRemoveSystemAbili void BundleActiveService::OnFoundationkilled() { BUNDLE_ACTIVE_LOGD("BundleActiveService::OnFoundationkilled"); - continuousTaskObserver_ = nullptr; - shutdownCallback_ = nullptr; - powerStateCallback_ = nullptr; bundleActiveCore_->OnFoundationkilled(); } -- Gitee From a16cf3768e42c9c5b65915eeb35a8112b114d98a Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Wed, 7 Sep 2022 14:43:01 +0800 Subject: [PATCH 7/7] =?UTF-8?q?foundation=20kill,=20device=E4=B8=8Dkill?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- services/packageusage/include/bundle_active_event.h | 1 - 1 file changed, 1 deletion(-) diff --git a/services/packageusage/include/bundle_active_event.h b/services/packageusage/include/bundle_active_event.h index 74b5a82..57889be 100644 --- a/services/packageusage/include/bundle_active_event.h +++ b/services/packageusage/include/bundle_active_event.h @@ -50,7 +50,6 @@ public: static const int32_t SYSTEM_UNLOCK = 21; static const int32_t SYSTEM_SLEEP = 22; static const int32_t SYSTEM_WAKEUP = 23; - static const int32_t FOUNDATION_KILL = 24; inline static const std::string DEVICE_EVENT_PACKAGE_NAME = "openharmony"; std::string bundleName_; std::string continuousTaskAbilityName_; -- Gitee