diff --git a/frameworks/js/napi/src/manager/napi_slot.cpp b/frameworks/js/napi/src/manager/napi_slot.cpp index 7b17b998a223a7fc3b26295e0d4e4ab1e68caed3..c9e8306c71279b6b7273d5f003eb37c3ece7f8f9 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 cf88d5ccfbe2b5a8ed7315ac2f9fe76de7f21a87..7247d9f6bbe9ec71e08de9854adfe0ca17b48340 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