diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 2a331fb48be89f1ca62a4748a9ea2a95c7ee50df..cb3da77cb2acf5de7013d3380f521524331eeced 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 ae7074ff75afd912139cae0b62478150890554c9..10284b33e8f32666a721598b8375e9961e119997 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 887efd256f2a576fa131154090d1c88f27c77c7b..a363d59a5e3f462f7b91e4c635903e581811bc89 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"); } /**