From ca4f6a751808ec48a0284be7008c213112f528d9 Mon Sep 17 00:00:00 2001 From: wangsen1994 Date: Tue, 2 Sep 2025 16:05:00 +0800 Subject: [PATCH] =?UTF-8?q?localWantAgent=E6=9C=89=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E9=A3=8E=E9=99=A9=EF=BC=8C=E4=B8=8D=E4=BD=BF=E7=94=A8=EF=BC=8C?= =?UTF-8?q?=E6=B8=85=E7=90=86=E4=BD=BF=E7=94=A8=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangsen1994 --- .../js/napi/src/common_convert_request.cpp | 13 +- .../advanced_notification_publish.cpp | 16 +- ...nced_notification_service_publish_test.cpp | 145 ------------------ 3 files changed, 4 insertions(+), 170 deletions(-) diff --git a/frameworks/js/napi/src/common_convert_request.cpp b/frameworks/js/napi/src/common_convert_request.cpp index d3472b9fa..39c1a41db 100644 --- a/frameworks/js/napi/src/common_convert_request.cpp +++ b/frameworks/js/napi/src/common_convert_request.cpp @@ -1300,16 +1300,9 @@ napi_value Common::GetNotificationRemovalWantAgent( } std::shared_ptr removeWantAgent = std::make_shared(*wantAgent); - if (removeWantAgent->IsLocal()) { - const auto localPendingWant = removeWantAgent->GetLocalPendingWant(); - if (localPendingWant != nullptr && localPendingWant->GetType() >= OPERATION_MAX_TYPE) { - request.SetRemovalWantAgent(removeWantAgent); - } - } else { - if ((uint32_t)removeWantAgent->GetPendingWant()->GetType( - removeWantAgent->GetPendingWant()->GetTarget()) >= OPERATION_MAX_TYPE) { - request.SetRemovalWantAgent(removeWantAgent); - } + if ((uint32_t)removeWantAgent->GetPendingWant()->GetType( + removeWantAgent->GetPendingWant()->GetTarget()) >= OPERATION_MAX_TYPE) { + request.SetRemovalWantAgent(removeWantAgent); } } diff --git a/services/ans/src/advanced_notification_manager/advanced_notification_publish.cpp b/services/ans/src/advanced_notification_manager/advanced_notification_publish.cpp index 475bc7ea8..39640b445 100644 --- a/services/ans/src/advanced_notification_manager/advanced_notification_publish.cpp +++ b/services/ans/src/advanced_notification_manager/advanced_notification_publish.cpp @@ -407,9 +407,6 @@ ErrCode AdvancedNotificationService::CheckNotificationRequest(const sptrGetWantAgent(); - const auto removalWantAgent = request->GetRemovalWantAgent(); - auto content = request->GetContent(); if (content != nullptr && content->GetContentType() == NotificationContent::Type::MULTILINE) { ErrCode checkCode = CheckNotificationRequestLineWantAgents(content, isAgentController, @@ -419,17 +416,6 @@ ErrCode AdvancedNotificationService::CheckNotificationRequest(const sptrIsLocal()) || - (removalWantAgent != nullptr && removalWantAgent->IsLocal()); - if (isLocalWantAgent && !(isSystemApp || isSubsystem)) { - ANS_LOGE("Local wantAgent does not support non system app"); - return ERR_ANS_NON_SYSTEM_APP; - } - - if (isLocalWantAgent && !isAgentController) { - ANS_LOGE("Local wantAgent does not support permission denied"); - return ERR_ANS_PERMISSION_DENIED; - } if (!isSystemApp && !isSubsystem && request->GetExtendInfo() != nullptr) { request->SetExtendInfo(nullptr); } @@ -457,4 +443,4 @@ ErrCode AdvancedNotificationService::CheckNotificationRequestLineWantAgents( return ERR_OK; } } // Notification -} // OHOS \ No newline at end of file +} // OHOS diff --git a/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_service_publish_test.cpp b/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_service_publish_test.cpp index 96e0d7cb2..3dfabeca2 100644 --- a/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_service_publish_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_service_publish_test.cpp @@ -582,29 +582,6 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01300, SleepForFC(); } -/** - * @tc.number : ANS_Publish_01400 - * @tc.name : ANSPublish01400 - * @tc.desc : When an non system app wants to publish an notification with local wantAgent, the - * notification publishing interface returns ERR_ANS_NON_SYSTEM_APP; - */ -HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01400, Function | SmallTest | Level1) -{ - TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); - sptr req = new NotificationRequest(); - EXPECT_NE(req, nullptr); - std::shared_ptr want = std::make_shared(); - std::shared_ptr localPendingWant = - std::make_shared("TestBundleName", want, 0); - std::shared_ptr wantAgent = - std::make_shared(localPendingWant); - req->SetWantAgent(wantAgent); - MockIsSystemApp(false); - std::string label = "publish's label"; - ASSERT_EQ(advancedNotificationService_->Publish(label, req), (int)ERR_ANS_NON_SYSTEM_APP); - SleepForFC(); -} - /** * @tc.number : AdvancedNotificationServiceTest_04600 * @tc.name : ANS_Publish_0500 @@ -1734,128 +1711,6 @@ HWTEST_F(AdvancedNotificationServiceTest, OnReceiveEvent_1300, Function | SmallT } #endif -/** - * @tc.number : CheckNotificationRequest_0100 - * @tc.name : CheckNotificationRequest_0100 - * @tc.desc : Test CheckNotificationRequest method when request is null - * @tc.require : I5TIQR - */ -HWTEST_F(AdvancedNotificationServiceTest, CheckNotificationRequest_0100, Level1) -{ - AdvancedNotificationService advancedNotificationService; - - ASSERT_EQ(advancedNotificationService.CheckNotificationRequest(nullptr), ERR_ANS_INVALID_PARAM); -} - -/** - * @tc.number : CheckNotificationRequest_0200 - * @tc.name : CheckNotificationRequest_0200 - * @tc.desc : Test CheckNotificationRequest method when request has no wantAgent - * @tc.require : I5TIQR - */ -HWTEST_F(AdvancedNotificationServiceTest, CheckNotificationRequest_0200, Level1) -{ - AdvancedNotificationService advancedNotificationService; - auto request = new NotificationRequest(); - - ASSERT_EQ(advancedNotificationService.CheckNotificationRequest(request), ERR_OK); -} - -/** - * @tc.number : CheckNotificationRequest_0300 - * @tc.name : CheckNotificationRequest_0300 - * @tc.desc : Test CheckNotificationRequest method when request has no wantAgent - * @tc.require : I5TIQR - */ -HWTEST_F(AdvancedNotificationServiceTest, CheckNotificationRequest_0300, Level1) -{ - AdvancedNotificationService advancedNotificationService; - auto request = new NotificationRequest(); - std::shared_ptr want = std::make_shared(); - std::shared_ptr localPendingWant = - std::make_shared("TestBundleName", want, 0); - std::shared_ptr wantAgent = - std::make_shared(localPendingWant); - request->SetWantAgent(wantAgent); - MockSystemApp(); - - ASSERT_EQ(advancedNotificationService.CheckNotificationRequest(request), ERR_OK); -} - -/** - * @tc.number : CheckNotificationRequest_0300 - * @tc.name : CheckNotificationRequest_0300 - * @tc.desc : Test CheckNotificationRequest method when request has no wantAgent - * @tc.require : I5TIQR - */ -HWTEST_F(AdvancedNotificationServiceTest, CheckNotificationRequest_0400, Level1) -{ - AdvancedNotificationService advancedNotificationService; - auto request = new NotificationRequest(); - std::shared_ptr want = std::make_shared(); - std::shared_ptr localPendingWant = - std::make_shared("TestBundleName", want, 0); - std::shared_ptr wantAgent = - std::make_shared(localPendingWant); - request->SetRemovalWantAgent(wantAgent); - MockSystemApp(); - - ASSERT_EQ(advancedNotificationService.CheckNotificationRequest(request), ERR_OK); -} - -/** - * @tc.number : CheckNotificationRequest_0300 - * @tc.name : CheckNotificationRequest_0300 - * @tc.desc : Test CheckNotificationRequest method when request has no wantAgent - * @tc.require : I5TIQR - */ -HWTEST_F(AdvancedNotificationServiceTest, CheckNotificationRequest_0500, Level1) -{ - AdvancedNotificationService advancedNotificationService; - auto request = new NotificationRequest(); - std::shared_ptr want = std::make_shared(); - std::shared_ptr localPendingWant = - std::make_shared("TestBundleName", want, 0); - std::shared_ptr wantAgent = - std::make_shared(localPendingWant); - request->SetRemovalWantAgent(wantAgent); - MockIsSystemApp(false); - - ASSERT_EQ(advancedNotificationService.CheckNotificationRequest(request), ERR_OK); -} - -/** - * @tc.number : CheckNotificationRequest_0600 - * @tc.name : CheckNotificationRequest_0600 - * @tc.desc : Test CheckNotificationRequest method when request has linesWantAgent - * @tc.require : I5TIQR - */ -HWTEST_F(AdvancedNotificationServiceTest, CheckNotificationRequest_0600, Level1) -{ - AdvancedNotificationService advancedNotificationService; - auto request = new NotificationRequest(); - const std::shared_ptr multiLineContent = - std::make_shared(); - std::shared_ptr want = std::make_shared(); - std::shared_ptr localPendingWant = - std::make_shared("TestBundleName", want, 0); - std::shared_ptr wantAgent = - std::make_shared(localPendingWant); - std::vector> lineWantAgents; - lineWantAgents.emplace_back(wantAgent); - lineWantAgents.emplace_back(wantAgent); - lineWantAgents.emplace_back(wantAgent); - multiLineContent->AddSingleLine("test1"); - multiLineContent->AddSingleLine("test2"); - multiLineContent->AddSingleLine("test3"); - multiLineContent->SetLineWantAgents(lineWantAgents); - const std::shared_ptr content = std::make_shared(multiLineContent); - request->SetContent(content); - MockSystemApp(); - - ASSERT_EQ(advancedNotificationService.CheckNotificationRequest(request), ERR_OK); -} - /** * @tc.number : CheckNotificationRequestLineWantAgents_0100 * @tc.name : CheckNotificationRequestLineWantAgents_0100 -- Gitee