From 6bd0ba6d7bf05ff817d962a11434a4e57a62cce0 Mon Sep 17 00:00:00 2001 From: y00620503 Date: Sat, 21 Jun 2025 17:30:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=AC=E5=85=B1=E4=BA=8B=E4=BB=B6=E5=8A=A0?= =?UTF-8?q?=E5=BC=BA=E9=99=90=E5=88=B6=EF=BC=8CTDD=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: y00620503 Change-Id: I4f1da40ffb1b015b36a276d1f5c2f38ac328962a --- .../appmgr/include/app_mgr_service_inner.h | 6 ++--- services/appmgr/src/app_mgr_service_inner.cpp | 10 ++++---- .../app_mgr_service_inner_test.cpp | 23 ++++++++++--------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 2a331fb48be..cb3da77cb2a 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -953,10 +953,10 @@ public: * @param eventName Indicates the event defined by CommonEventSupport * @param want Want contains information of the event wish to notify. * - * @return Returns 0 if the event is normal, 1 if the event needs to be managed. + * @return Returns false if the event is normal, true if the event needs to be managed. */ - int32_t NotifyAppStatusByCommonEventName(const std::string &bundleName, const std::string &eventName, - const Want &want); + bool IsSubscriberControlledAndNotifyAppStatusByCommonEventName(const std::string &bundleName, + const std::string &eventName, const Want &want); int32_t KillProcessByPid(const pid_t pid, const std::string& reason = "foundation"); diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index ae7074ff75a..10284b33e8f 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -4979,7 +4979,7 @@ void AppMgrServiceInner::RestartResidentProcess(std::shared_ptrGetRestartResidentProcCount(), appRecord->IsEmptyKeepAliveApp()); } -int32_t AppMgrServiceInner::NotifyAppStatusByCommonEventName(const std::string &bundleName, +bool AppMgrServiceInner::IsSubscriberControlledAndNotifyAppStatusByCommonEventName(const std::string &bundleName, const std::string &eventName, const Want &want) { EventFwk::CommonEventData commonData {want}; @@ -4991,7 +4991,7 @@ int32_t AppMgrServiceInner::NotifyAppStatusByCommonEventName(const std::string & TAG_LOGI(AAFwkTag::APPMGR, "bundle name: %{public}s, normal event: %{public}s", bundleName.c_str(), eventName.c_str()); EventFwk::CommonEventManager::PublishCommonEvent(commonData); - return 0; + return false; } EventFwk::CommonEventPublishInfo eventPublishData; std::vector permissions; @@ -5001,7 +5001,7 @@ int32_t AppMgrServiceInner::NotifyAppStatusByCommonEventName(const std::string & eventPublishData.SetSubscriberType(EventFwk::SubscriberType::SYSTEM_SUBSCRIBER_TYPE); eventPublishData.SetValidationRule(EventFwk::ValidationRule::OR); EventFwk::CommonEventManager::PublishCommonEvent(commonData, eventPublishData); - return 1; + return true; } void AppMgrServiceInner::NotifyAppStatus(const std::string &bundleName, int32_t appIndex, const std::string &eventData) @@ -5015,7 +5015,7 @@ void AppMgrServiceInner::NotifyAppStatus(const std::string &bundleName, int32_t want.SetElement(element); want.SetParam(Constants::USER_ID, 0); want.SetParam(Constants::APP_INDEX, appIndex); - NotifyAppStatusByCommonEventName(bundleName, eventData, want); + IsSubscriberControlledAndNotifyAppStatusByCommonEventName(bundleName, eventData, want); } void AppMgrServiceInner::NotifyAppStatusByCallerUid(const std::string &bundleName, const int32_t tokenId, @@ -5034,7 +5034,7 @@ void AppMgrServiceInner::NotifyAppStatusByCallerUid(const std::string &bundleNam want.SetParam(Constants::UID, callerUid); want.SetParam(Want::PARAM_RESV_CALLER_UID, callerUid); want.SetParam(TARGET_UID_KEY, targetUid); - NotifyAppStatusByCommonEventName(bundleName, eventData, want); + IsSubscriberControlledAndNotifyAppStatusByCommonEventName(bundleName, eventData, want); } int32_t AppMgrServiceInner::RegisterApplicationStateObserver( diff --git a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index 887efd256f2..a363d59a5e3 100644 --- a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp +++ b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp @@ -2295,30 +2295,31 @@ HWTEST_F(AppMgrServiceInnerTest, NotifyAppStatusByCallerUid_001, TestSize.Level2 } /** - * @tc.name: NotifyAppStatusByCommonEventName_001 - * @tc.desc: notify app status by special common event. + * @tc.name: IsSubscriberControlledAndNotifyAppStatusByCommonEventName_001 + * @tc.desc: notify app status by common event. * @tc.type: FUNC */ -HWTEST_F(AppMgrServiceInnerTest, NotifyAppStatusByCommonEventName_001, TestSize.Level2) +HWTEST_F(AppMgrServiceInnerTest, IsSubscriberControlledAndNotifyAppStatusByCommonEventName_001, TestSize.Level2) { - TAG_LOGI(AAFwkTag::TEST, "NotifyAppStatusByCommonEventName_001 start"); + TAG_LOGI(AAFwkTag::TEST, "IsSubscriberControlledAndNotifyAppStatusByCommonEventName_001 start"); auto appMgrServiceInner = std::make_shared(); EXPECT_NE(appMgrServiceInner, nullptr); std::string bundleName = "test_bundle_name"; std::string eventData = "usual.event.PACKAGE_DATA_CLEARED"; AAFwk::Want want; - int32_t ret = appMgrServiceInner->NotifyAppStatusByCommonEventName(bundleName, eventData, want); - EXPECT_EQ(ret, 1); + bool ret = appMgrServiceInner->IsSubscriberControlledAndNotifyAppStatusByCommonEventName(bundleName, eventData, + want); + EXPECT_TRUE(ret); eventData = "test_event_name"; - ret = appMgrServiceInner->NotifyAppStatusByCommonEventName(bundleName, eventData, want); - EXPECT_EQ(ret, 0); + ret = appMgrServiceInner->IsSubscriberControlledAndNotifyAppStatusByCommonEventName(bundleName, eventData, want); + EXPECT_FALSE(ret); eventData = "usual.event.PACKAGE_RESTARTED"; - ret = appMgrServiceInner->NotifyAppStatusByCommonEventName(bundleName, eventData, want); - EXPECT_EQ(ret, 1); - TAG_LOGI(AAFwkTag::TEST, "NotifyAppStatusByCommonEventName_001 end"); + ret = appMgrServiceInner->IsSubscriberControlledAndNotifyAppStatusByCommonEventName(bundleName, eventData, want); + EXPECT_TRUE(ret); + TAG_LOGI(AAFwkTag::TEST, "IsSubscriberControlledAndNotifyAppStatusByCommonEventName_001 end"); } /** -- Gitee