From 8003e34d04a872a5270c4f6dfa1e032d4db616f0 Mon Sep 17 00:00:00 2001 From: zhangzezhong Date: Sat, 17 May 2025 15:37:49 +0800 Subject: [PATCH] fix notification flags Signed-off-by: zhangzezhong --- frameworks/js/napi/src/manager/napi_slot.cpp | 5 ++--- ...dvanced_notification_slot_service_test.cpp | 20 ++++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/frameworks/js/napi/src/manager/napi_slot.cpp b/frameworks/js/napi/src/manager/napi_slot.cpp index 7b17b998a..c9e8306c7 100644 --- a/frameworks/js/napi/src/manager/napi_slot.cpp +++ b/frameworks/js/napi/src/manager/napi_slot.cpp @@ -20,7 +20,6 @@ namespace OHOS { namespace NotificationNapi { -uint32_t NOTIFICATION_SETTING_VIBRATION_ENABLE_BIT = 4; napi_value NapiAddSlot(napi_env env, napi_callback_info info) { ANS_LOGD("enter"); @@ -1000,8 +999,8 @@ void AsyncCompleteCallbackNapiGetNotificationSettings(napi_env env, napi_status if (asynccallbackinfo) { napi_value result = Common::NapiGetNull(env); napi_create_object(env, &result); - bool soundEnabled = (asynccallbackinfo->slotFlags >> 0) & 1; - bool vibrationEnabled = (asynccallbackinfo->slotFlags >> NOTIFICATION_SETTING_VIBRATION_ENABLE_BIT) & 1; + bool soundEnabled = asynccallbackinfo->slotFlags & NotificationConstant::ReminderFlag::SOUND_FLAG; + bool vibrationEnabled = asynccallbackinfo->slotFlags & NotificationConstant::ReminderFlag::VIBRATION_FLAG; napi_value vibrationValue; napi_value soundValue; napi_get_boolean(env, vibrationEnabled, &vibrationValue); diff --git a/services/ans/test/unittest/advanced_notification_slot_service_test.cpp b/services/ans/test/unittest/advanced_notification_slot_service_test.cpp index cf88d5ccf..7247d9f6b 100644 --- a/services/ans/test/unittest/advanced_notification_slot_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_slot_service_test.cpp @@ -549,7 +549,7 @@ HWTEST_F(AnsSlotServiceTest, GetConfigSlotReminderModeByType_00001, Function | S /** * @tc.name: GetNotificationSettings_00001 - * @tc.desc: Test GetNotificationSettings + * @tc.desc: Verify that bits except for the 0th and 4th are 0 * @tc.type: FUNC * @tc.require: issue */ @@ -587,5 +587,23 @@ HWTEST_F(AnsSlotServiceTest, GetNotificationSettings_00002, Function | SmallTest ASSERT_EQ(ret, ERR_OK); EXPECT_EQ(flag , 0x11); } + +/** + * @tc.name: GetNotificationSettings_00003 + * @tc.desc: Test GetNotificationSettings when notificationSvrQueue is nullptr + * @tc.type: FUNC + */ +HWTEST_F(AnsSlotServiceTest, GetNotificationSettings_00003, Function | SmallTest | Level1) +{ + MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP); + MockIsSystemApp(false); + MockIsVerfyPermisson(false); + std::shared_ptr notificationSvrQueue = advancedNotificationService_->notificationSvrQueue_; + advancedNotificationService_->notificationSvrQueue_ = nullptr; + uint32_t flag; + auto ret = advancedNotificationService_->GetNotificationSettings(flag); + advancedNotificationService_->notificationSvrQueue_ = notificationSvrQueue; + EXPECT_EQ(ret, ERR_ANS_INVALID_PARAM); +} } // namespace Notification } // namespace OHOS -- Gitee