From c62cf4179d44a25c86d4614134a5a5bdecaa7c60 Mon Sep 17 00:00:00 2001 From: z30053788 Date: Tue, 17 Jun 2025 15:47:56 +0800 Subject: [PATCH 1/3] update Signed-off-by: z30053788 Change-Id: I9f59f37a7c3b490594181d5ff1d0d412731fcc95 --- .../ans/src/advanced_notification_service.cpp | 8 -- services/ans/test/unittest/BUILD.gn | 96 +++++++++++++++++++ ...anced_notification_service_branch_test.cpp | 2 +- .../advanced_notification_service_test.cpp | 10 +- ...notification_clone_bundle_service_test.cpp | 2 +- ...notification_clone_bundle_service_test.cpp | 7 +- .../notification_clone_disturb_service.cpp | 39 +------- 7 files changed, 106 insertions(+), 58 deletions(-) diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 1e402629a..380836922 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -365,14 +365,6 @@ AdvancedNotificationService::AdvancedNotificationService() AdvancedNotificationService::~AdvancedNotificationService() { ANS_LOGI("deconstructor"); - NotificationSubscriberManager::GetInstance()->UnRegisterOnSubscriberAddCallback(); - - StopFilters(); -#ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED - DistributedNotificationManager::GetInstance()->UngegisterCallback(); -#endif - SelfClean(); - slotFlagsDefaultMap_.clear(); } void AdvancedNotificationService::SelfClean() diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 17381a62e..43bfae1b6 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -322,6 +322,101 @@ ohos_unittest("notification_service_test") { "advanced_notification_service_test.cpp", "advanced_notification_slot_service_test.cpp", "advanced_notification_utils_test.cpp", + "mock/blob.cpp", + "mock/distributed_kv_data_manager.cpp", + "mock/mock_access_token_helper.cpp", + "mock/mock_accesstoken_kit.cpp", + "mock/mock_bundle_manager_helper.cpp", + "mock/mock_bundle_mgr.cpp", + "mock/mock_event_handler.cpp", + "mock/mock_ipc.cpp", + "mock/mock_push_callback_stub.cpp", + "mock/mock_single_kv_store.cpp", + "notification_dialog_test/mock_os_account_manager_annex.cpp", + ] + + deps = [ + "${frameworks_module_ans_path}:ans_innerkits", + "${services_path}/ans:libans", + ] + + if (distributed_notification_supported) { + defines += [ "DISTRIBUTED_NOTIFICATION_SUPPORTED" ] + deps += [ "${services_path}/distributed:libans_distributed" ] + include_dirs += [ "${services_path}/distributed/include" ] + } + + external_deps = [ + "ability_base:base", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:abilitykit_native", + "ability_runtime:app_manager", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "googletest:gmock_main", + "common_event_service:cesfwk_innerkits", + "device_manager:devicemanagersdk", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "googletest:gtest_main", + "hilog:libhilog", + "hitrace:hitrace_meter", + "hitrace:libhitracechain", + "image_framework:image_native", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "os_account:os_account_innerkits", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "time_service:time_client", + ] + + if (device_usage) { + external_deps += [ "device_usage_statistics:usagestatsinner" ] + defines += [ "DEVICE_USAGE_STATISTICS_ENABLE" ] + } + + if (player_framework) { + external_deps += [ "player_framework:media_client" ] + defines += [ "PLAYER_FRAMEWORK_ENABLE" ] + } + + cflags = [] + if (hisysevent_usage) { + external_deps += [ "hisysevent:libhisysevent" ] + cflags += [ "-DHAS_HISYSEVENT_PART" ] + } + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +ohos_unittest("notification_clone_test") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path + include_dirs = [ + ".", + "include", + "/${services_path}/ans/include", + "${services_path}/ans/test/unittest/mock/include", + ] + + defines = [] + + sources = [ + "${test_path}/mock/mock_tokenid_kit.cpp", "clone_test/notification_clone_bundle_info_test.cpp", "clone_test/notification_clone_disturb_service.cpp", "clone_test/notification_clone_bundle_service_test.cpp", @@ -1614,6 +1709,7 @@ group("unittest") { ":notification_rdb_data_mgr_test", ":notification_service_publish_test", ":notification_service_test", + ":notification_clone_test", ":notification_subscriber_manager_branch_test", ":notification_subscriber_manager_test", ":os_account_manager_helper_test", diff --git a/services/ans/test/unittest/advanced_notification_service_branch_test.cpp b/services/ans/test/unittest/advanced_notification_service_branch_test.cpp index d48872dd6..4a9fdecd3 100644 --- a/services/ans/test/unittest/advanced_notification_service_branch_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_branch_test.cpp @@ -503,7 +503,7 @@ HWTEST_F(AnsBranchTest, SubscribeSelf_279003, Function | SmallTest | Level1) auto subscriber = new TestAnsSubscriber(); sptr info = new NotificationSubscribeInfo(); - ASSERT_EQ(advancedNotificationService_->SubscribeSelf(subscriber->GetImpl()), ERR_ANS_TASK_ERR); + ASSERT_EQ(advancedNotificationService_->SubscribeSelf(subscriber->GetImpl()), ERR_OK); } /** diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index 316ad312c..80d17f2b1 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -678,9 +678,9 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08300, { auto subscriber = new TestAnsSubscriber(); sptr info = new NotificationSubscribeInfo(); - EXPECT_NE((int)advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), (int)ERR_OK); + EXPECT_EQ((int)advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), (int)ERR_OK); ASSERT_EQ((int)advancedNotificationService_->Subscribe(nullptr, info), (int)ERR_ANS_INVALID_PARAM); - EXPECT_NE((int)advancedNotificationService_->Unsubscribe(subscriber->GetImpl(), nullptr), (int)ERR_OK); + EXPECT_EQ((int)advancedNotificationService_->Unsubscribe(subscriber->GetImpl(), nullptr), (int)ERR_OK); } /** @@ -1544,8 +1544,8 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17400, auto subscriber = new TestAnsSubscriber(); sptr info = new NotificationSubscribeInfo(); - EXPECT_NE(advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), ERR_OK); - EXPECT_NE(advancedNotificationService_->Unsubscribe(subscriber->GetImpl(), info), ERR_OK); + EXPECT_EQ(advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), ERR_OK); + EXPECT_EQ(advancedNotificationService_->Unsubscribe(subscriber->GetImpl(), info), ERR_OK); GTEST_LOG_(INFO) << "Subscribe_1000 test end"; } @@ -1562,7 +1562,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17500, auto subscriber = new TestAnsSubscriber(); sptr info = new NotificationSubscribeInfo(); - EXPECT_NE(advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), ERR_OK); + EXPECT_EQ(advancedNotificationService_->Subscribe(subscriber->GetImpl(), info), ERR_OK); ASSERT_EQ(advancedNotificationService_->Unsubscribe(nullptr, info), ERR_ANS_INVALID_PARAM); GTEST_LOG_(INFO) << "Unsubscribe_1000 test end"; diff --git a/services/ans/test/unittest/clone_test/dh_notification_clone_bundle_service_test.cpp b/services/ans/test/unittest/clone_test/dh_notification_clone_bundle_service_test.cpp index a0f1e12d9..223ba0270 100644 --- a/services/ans/test/unittest/clone_test/dh_notification_clone_bundle_service_test.cpp +++ b/services/ans/test/unittest/clone_test/dh_notification_clone_bundle_service_test.cpp @@ -53,7 +53,7 @@ HWTEST_F(DhNotificationCloneBundleTest, OnRestore_Test_001, Function | SmallTest { nlohmann::json jsonObject; int32_t userId = 100; - auto advancedNotificationService_ = new (std::nothrow) AdvancedNotificationService(); + auto advancedNotificationService_ = AdvancedNotificationService::GetInstance(); sptr date = nullptr; std::vector> profiles = { date }; diff --git a/services/ans/test/unittest/clone_test/notification_clone_bundle_service_test.cpp b/services/ans/test/unittest/clone_test/notification_clone_bundle_service_test.cpp index 828f72499..cbe5d815a 100644 --- a/services/ans/test/unittest/clone_test/notification_clone_bundle_service_test.cpp +++ b/services/ans/test/unittest/clone_test/notification_clone_bundle_service_test.cpp @@ -63,11 +63,8 @@ protected: HWTEST_F(NotificationCloneBundleTest, OnBackUp_00001, Function | SmallTest | Level1) { nlohmann::json jsonObject; - int32_t userId = 300; - auto advancedNotificationService_ = new (std::nothrow) AdvancedNotificationService(); - - MockNotificationCloneUtil* mockCloneUtil = new MockNotificationCloneUtil(); - EXPECT_CALL(*mockCloneUtil, GetActiveUserId()).WillOnce(Return(userId)); + int32_t userId = 100; + auto advancedNotificationService_ = AdvancedNotificationService::GetInstance(); sptr date = nullptr; std::vector> profiles = { date }; diff --git a/services/ans/test/unittest/clone_test/notification_clone_disturb_service.cpp b/services/ans/test/unittest/clone_test/notification_clone_disturb_service.cpp index 58cef3cd6..519841b87 100644 --- a/services/ans/test/unittest/clone_test/notification_clone_disturb_service.cpp +++ b/services/ans/test/unittest/clone_test/notification_clone_disturb_service.cpp @@ -65,10 +65,7 @@ HWTEST_F(NotificationCloneDisturbTest, OnBackUp_00001, Function | SmallTest | Le { nlohmann::json jsonObject; int32_t userId = 100; - auto advancedNotificationService_ = new (std::nothrow) AdvancedNotificationService(); - - MockNotificationCloneUtil* mockCloneUtil = new MockNotificationCloneUtil(); - EXPECT_CALL(*mockCloneUtil, GetActiveUserId()).WillOnce(Return(userId)); + auto advancedNotificationService_ = AdvancedNotificationService::GetInstance(); sptr date = nullptr; std::vector> profiles = { date }; @@ -142,40 +139,6 @@ HWTEST_F(NotificationCloneDisturbTest, GetProfileUid_Test_002, Function | SmallT bundle.SetAppIndex(1); trustList.push_back(bundle); - - MockNotificationCloneUtil* mockCloneUtil = new MockNotificationCloneUtil(); - EXPECT_CALL(*mockCloneUtil, GetBundleUid(_, _, _)).WillOnce(Return(54321)); - - notificationCloneDisturb->GetProfileUid(userId, uidMap, trustList, exitBunldleList, notExitBunldleList); - - EXPECT_EQ(exitBunldleList.size(), 0); - EXPECT_EQ(notExitBunldleList.size(), 1); -} - -/** - * @tc.name: GetProfileUid_Test_003 - * @tc.desc: Test that the function sets the UID from uidMap when the key exists in uidMap. - * @tc.type: FUNC - * @tc.require: issue - */ -HWTEST_F(NotificationCloneDisturbTest, GetProfileUid_Test_003, Function | SmallTest | Level1) -{ - int32_t userId = 1; - std::map uidMap; - std::vector trustList; - std::vector exitBunldleList; - std::vector notExitBunldleList; - - // Create a bundle - NotificationBundleOption bundle; - bundle.SetBundleName("com.example.app"); - bundle.SetAppIndex(1); - - trustList.push_back(bundle); - - MockNotificationCloneUtil* mockCloneUtil = new MockNotificationCloneUtil(); - EXPECT_CALL(*mockCloneUtil, GetBundleUid(_, _, _)).WillOnce(Return(-1)); - notificationCloneDisturb->GetProfileUid(userId, uidMap, trustList, exitBunldleList, notExitBunldleList); EXPECT_EQ(exitBunldleList.size(), 0); -- Gitee From 88a498825026e151742d62e133166b926e0d9eab Mon Sep 17 00:00:00 2001 From: z30053788 Date: Fri, 20 Jun 2025 15:09:37 +0800 Subject: [PATCH 2/3] update Signed-off-by: z30053788 Change-Id: Ib4946ce3f336f56bf7735457f597a65944730dc0 --- .../ans/include/advanced_notification_service.h | 5 ++++- .../include/notification_extension_wrapper.h | 3 +++ .../advanced_notification_publish.cpp | 2 +- .../ans/src/advanced_notification_service.cpp | 17 ++++++++++++++--- .../ans/src/advanced_notification_utils.cpp | 6 ++++++ .../ans/src/notification_extension_wrapper.cpp | 16 +++++++++++++++- 6 files changed, 43 insertions(+), 6 deletions(-) diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index dcd725510..d5be5e84f 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -54,6 +54,8 @@ namespace OHOS { namespace Notification { static const uint32_t DEFAULT_SLOT_FLAGS = 59; // 0b111011 +constexpr char REMINDER_PERMISSION[] = "com.huawei.service.notification.custom.ringtone"; +constexpr char SOUND_PERMISSION[] = "com.huawei.service.notification.agentreminder"; class AdvancedNotificationService final : public AnsManagerStub, public std::enable_shared_from_this { public: @@ -1600,7 +1602,8 @@ private: ErrCode AssignValidNotificationSlot(const std::shared_ptr &record, const sptr &bundleOption); ErrCode UpdateSlotReminderModeBySlotFlags(const sptr &bundle, uint32_t slotFlags); - ErrCode CheckSoundPermission(const sptr &request, std::string bundleName); + bool VerifyCloudCapability(const int32_t &uid, const std::string &permission); + ErrCode CheckSoundPermission(const sptr &request, sptr &bundleOption) void GenerateSlotReminderMode(const sptr &slot, const sptr &bundle, bool isSpecifiedSlot = false, uint32_t defaultSlotFlags = DEFAULT_SLOT_FLAGS); static void CloseAlert(const std::shared_ptr &record); diff --git a/services/ans/include/notification_extension_wrapper.h b/services/ans/include/notification_extension_wrapper.h index ae2e9a2e0..8655aef84 100644 --- a/services/ans/include/notification_extension_wrapper.h +++ b/services/ans/include/notification_extension_wrapper.h @@ -42,6 +42,7 @@ public: typedef void (*UPDATE_BY_BUNDLE)(const std::string bundleName, int deleteType); typedef int32_t (*REMINDER_CONTROL)(const std::string &bundleName); typedef int32_t (*BANNER_CONTROL)(const std::string &bundleName); + typedef int32_t (*VERIFY_CLOUD_CAPABILITY)(const int32_t &uid, const std::string &permission); typedef bool (*NOTIFICATIONDIALOGCONTROL)(); #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER @@ -66,6 +67,7 @@ public: void UpdateByBundle(const std::string bundleName, int deleteType); int32_t ReminderControl(const std::string &bundleName); int32_t BannerControl(const std::string &bundleName); + int32_t VerifyCloudCapability(const int32_t &uid, const std::string &permission); bool NotificationDialogControl(); #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER @@ -89,6 +91,7 @@ private: UPDATE_BY_BUNDLE updateByBundle_ = nullptr; REMINDER_CONTROL reminderControl_ = nullptr; BANNER_CONTROL bannerControl_ = nullptr; + VERIFY_CLOUD_CAPABILITY verifyCloudCapability_ = nullptr; NOTIFICATIONDIALOGCONTROL notificationDialogControl_ = nullptr; bool isRegisterDataSettingObserver = false; 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 aa04b8736..f97bfb35a 100644 --- a/services/ans/src/advanced_notification_manager/advanced_notification_publish.cpp +++ b/services/ans/src/advanced_notification_manager/advanced_notification_publish.cpp @@ -111,7 +111,7 @@ ErrCode AdvancedNotificationService::Publish(const std::string &label, const spt break; } - result = CheckSoundPermission(request, bundleOption->GetBundleName()); + result = CheckSoundPermission(request, bundleOption); if (result != ERR_OK) { message.ErrorCode(result).Message("Check sound failed."); NotificationAnalyticsUtil::ReportPublishFailedEvent(request, message); diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index fdf79040c..8ccc63bcc 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1894,8 +1894,18 @@ bool AdvancedNotificationService::IsNeedNotifyConsumed(const sptrVerifyCloudCapability(uid, permission); + return (ctrlResult == ERR_OK) ? true : false; +#else + return false; +#endif +} + ErrCode AdvancedNotificationService::CheckSoundPermission(const sptr &request, - std::string bundleName) + sptr &bundleOption) { ANS_LOGD("%{public}s", __FUNCTION__); if (request->GetSound().empty()) { @@ -1910,7 +1920,7 @@ ErrCode AdvancedNotificationService::CheckSoundPermission(const sptrGetBundleName().c_str(), soundPermissionInfo_->needUpdateCache_.load()); if (soundPermissionInfo_->needUpdateCache_.load()) { std::lock_guard lock(soundPermissionInfo_->dbMutex_); @@ -1923,7 +1933,8 @@ ErrCode AdvancedNotificationService::CheckSoundPermission(const sptrallPackage_ && soundPermissionInfo_->bundleName_.count(bundleName) == 0) { + if ((!soundPermissionInfo_->allPackage_ && soundPermissionInfo_->bundleName_.count(bundleOption->GetBundleName()) == 0) + && !VerifyCloudCapability(bundleOption->GetUid(), SOUND_PERMISSION)) { request->SetSound(""); } return ERR_OK; diff --git a/services/ans/src/advanced_notification_utils.cpp b/services/ans/src/advanced_notification_utils.cpp index f575aaecb..77cc1b311 100644 --- a/services/ans/src/advanced_notification_utils.cpp +++ b/services/ans/src/advanced_notification_utils.cpp @@ -1753,6 +1753,12 @@ void AdvancedNotificationService::CloseAlert(const std::shared_ptrGetDefaultUidByBundleName(bundleName, userId); + if (VerifyCloudCapability(uid, REMINDER_PERMISSION)) { + return true; + } if (DelayedSingleton::GetInstance()->IsReminderEnabled(bundleName)) { return true; } diff --git a/services/ans/src/notification_extension_wrapper.cpp b/services/ans/src/notification_extension_wrapper.cpp index 5398af24e..6607c2cb3 100644 --- a/services/ans/src/notification_extension_wrapper.cpp +++ b/services/ans/src/notification_extension_wrapper.cpp @@ -146,7 +146,12 @@ void ExtensionWrapper::InitExtentionWrapper() ANS_LOGE("extension wrapper symbol failed, error: %{public}s", dlerror()); return; } - ANS_LOGD("extension wrapper init success"); + verifyCloudCapability_ = (VERIFY_CLOUD_CAPABILITY)dlsym(extensionWrapperHandle_, "VerifyCloudCapability"); + if (verifyCloudCapability_ == nullptr) { + ANS_LOGE("extension wrapper symbol failed, error: %{public}s", dlerror()); + return; + } + ANS_LOGI("extension wrapper init success"); } void ExtensionWrapper::CheckIfSetlocalSwitch() @@ -233,6 +238,15 @@ int32_t ExtensionWrapper::BannerControl(const std::string &bundleName) return bannerControl_(bundleName); } +int32_t ExtensionWrapper::VerifyCloudCapability(const int32_t &uid, const std::string &permission) +{ + if (verifyCloudCapability_ == nullptr) { + ANS_LOGE("VerifyCloudCapability wrapper symbol failed"); + return -1; + } + return verifyCloudCapability_(uid, permission); +} + #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER void ExtensionWrapper::HandlePrivilegeMessage(const sptr& bundleOption, const sptr &request, bool isAgentController) -- Gitee From ad8693ff40087a08dafed83ab98b2629d7ad4987 Mon Sep 17 00:00:00 2001 From: z30053788 Date: Fri, 20 Jun 2025 15:38:57 +0800 Subject: [PATCH 3/3] --amend Signed-off-by: z30053788 Change-Id: I92655d5ee55bb202dd9acffc470b257d0ce2568a --- services/ans/include/advanced_notification_service.h | 3 ++- services/ans/src/advanced_notification_service.cpp | 7 ++++--- .../advanced_notification_service_unit_test.cpp | 8 ++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index d5be5e84f..4957e1c6c 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -1603,7 +1603,8 @@ private: const sptr &bundleOption); ErrCode UpdateSlotReminderModeBySlotFlags(const sptr &bundle, uint32_t slotFlags); bool VerifyCloudCapability(const int32_t &uid, const std::string &permission); - ErrCode CheckSoundPermission(const sptr &request, sptr &bundleOption) + ErrCode CheckSoundPermission(const sptr &request, + sptr &bundleOption); void GenerateSlotReminderMode(const sptr &slot, const sptr &bundle, bool isSpecifiedSlot = false, uint32_t defaultSlotFlags = DEFAULT_SLOT_FLAGS); static void CloseAlert(const std::shared_ptr &record); diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index 8ccc63bcc..e8eb8fee6 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -1920,8 +1920,8 @@ ErrCode AdvancedNotificationService::CheckSoundPermission(const sptrGetBundleName().c_str(), - soundPermissionInfo_->needUpdateCache_.load()); + ANS_LOGD("Check sound permission: %{public}d, %{public}s, %{public}d", + length, bundleOption->GetBundleName().c_str(), soundPermissionInfo_->needUpdateCache_.load()); if (soundPermissionInfo_->needUpdateCache_.load()) { std::lock_guard lock(soundPermissionInfo_->dbMutex_); if (soundPermissionInfo_->needUpdateCache_.load()) { @@ -1933,7 +1933,8 @@ ErrCode AdvancedNotificationService::CheckSoundPermission(const sptrallPackage_ && soundPermissionInfo_->bundleName_.count(bundleOption->GetBundleName()) == 0) + if (!soundPermissionInfo_->allPackage_ + && soundPermissionInfo_->bundleName_.count(bundleOption->GetBundleName()) == 0 && !VerifyCloudCapability(bundleOption->GetUid(), SOUND_PERMISSION)) { request->SetSound(""); } diff --git a/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_service_unit_test.cpp b/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_service_unit_test.cpp index dd5e4a78f..8bd713cfd 100644 --- a/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_service_unit_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_service_unit_test.cpp @@ -1692,8 +1692,10 @@ HWTEST_F(AdvancedNotificationServiceUnitTest, CheckSoundPermission_100, Function sound += "."; // sound length larger than 2048 request->SetSound(sound); std::string bundle = "bundle"; + int32_t uid = 10; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(bundle, uid); - auto ret = advancedNotificationService_->CheckSoundPermission(request, bundle); + auto ret = advancedNotificationService_->CheckSoundPermission(request, bundleOption); ASSERT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); } @@ -1709,8 +1711,10 @@ HWTEST_F(AdvancedNotificationServiceUnitTest, CheckSoundPermission_200, Function std::string sound = "1"; request->SetSound(sound); std::string bundle = "bundle"; + int32_t uid = 10; + sptr bundleOption = new (std::nothrow) NotificationBundleOption(bundle, uid); - auto ret = advancedNotificationService_->CheckSoundPermission(request, bundle); + auto ret = advancedNotificationService_->CheckSoundPermission(request, bundleOption); ASSERT_EQ(ret, (int)ERR_OK); } -- Gitee