diff --git a/frameworks/ans/core/common/include/ans_const_define.h b/frameworks/ans/core/common/include/ans_const_define.h index 353899e52df69d5b48dfff7777d8ed701d1adf7c..3343ccbce61c945460fb75fcd239df52cb2a000f 100644 --- a/frameworks/ans/core/common/include/ans_const_define.h +++ b/frameworks/ans/core/common/include/ans_const_define.h @@ -16,6 +16,10 @@ #ifndef BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_CONST_DEFINE_H #define BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_CONST_DEFINE_H +#include + +#include "uri.h" + namespace OHOS { namespace Notification { @@ -28,6 +32,10 @@ constexpr uint32_t MAX_SLOT_GROUP_NUM = 4; constexpr uint32_t MAX_ICON_SIZE = 50 * 1024; constexpr uint32_t MAX_PICTURE_SIZE = 2 * 1024 * 1024; +// Default sound for notification +const static Uri DEFAULT_NOTIFICATION_SOUND("file://system/etc/Light.ogg"); +const static std::vector DEFAULT_NOTIFICATION_VIBRATION = {200}; + } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/native/src/notification_slot.cpp b/frameworks/ans/native/src/notification_slot.cpp index 5c57480054f664c4c27eed551377b24e1cd60a7e..3ff67a5aa076fe586489cf65d7b7ec870c5f094c 100644 --- a/frameworks/ans/native/src/notification_slot.cpp +++ b/frameworks/ans/native/src/notification_slot.cpp @@ -15,6 +15,7 @@ #include "notification_slot.h" #include "ans_log_wrapper.h" +#include "ans_const_define.h" namespace OHOS { namespace Notification { @@ -97,14 +98,16 @@ void NotificationSlot::SetType(NotificationConstant::SlotType type) id_ = "SOCIAL_COMMUNICATION"; SetName("SOCIAL_COMMUNICATION"); SetLockscreenVisibleness(NotificationConstant::VisiblenessType::PUBLIC); - SetEnableVibration(true); + SetSound(DEFAULT_NOTIFICATION_SOUND); + SetVibrationStyle(DEFAULT_NOTIFICATION_VIBRATION); SetLevel(LEVEL_HIGH); break; case NotificationConstant::SlotType::SERVICE_REMINDER: id_ = "SERVICE_REMINDER"; SetName("SERVICE_REMINDER"); SetLockscreenVisibleness(NotificationConstant::VisiblenessType::PUBLIC); - SetEnableVibration(true); + SetSound(DEFAULT_NOTIFICATION_SOUND); + SetVibrationStyle(DEFAULT_NOTIFICATION_VIBRATION); SetLevel(LEVEL_DEFAULT); break; case NotificationConstant::SlotType::CONTENT_INFORMATION: diff --git a/frameworks/ans/test/moduletest/ans_innerkits_module_slot_test.cpp b/frameworks/ans/test/moduletest/ans_innerkits_module_slot_test.cpp index e7ced933603477f836afef13d7cccccf66b00ee6..91ab5d60ceca7edb086af6ba1c6ba31ec2843922 100644 --- a/frameworks/ans/test/moduletest/ans_innerkits_module_slot_test.cpp +++ b/frameworks/ans/test/moduletest/ans_innerkits_module_slot_test.cpp @@ -15,6 +15,7 @@ #include #include +#include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_manager_proxy.h" #include "advanced_notification_service.h" @@ -315,6 +316,74 @@ HWTEST_F(AnsInterfaceModuleSlotTest, ANS_Interface_MT_NotificationSlot_00500, Fu NotificationHelper::GetNotificationSlot(NotificationConstant::OTHER, spSlot)); } +/** + * @tc.number : ANS_Interface_MT_NotificationSlot_00600 + * @tc.name : NotificationSlot_00600 + * @tc.desc : Create notification slot(type is SOCIAL_COMMUNICATION), get sound and vibration. + * @tc.expected : Create notification slot success, get sound and vibration success. + */ +HWTEST_F(AnsInterfaceModuleSlotTest, ANS_Interface_MT_NotificationSlot_00600, Function | MediumTest | Level1) +{ + NotificationSlot slot(NotificationConstant::SOCIAL_COMMUNICATION); + EXPECT_EQ("SOCIAL_COMMUNICATION", slot.GetName()); + EXPECT_EQ(NotificationConstant::VisiblenessType::PUBLIC, slot.GetLockScreenVisibleness()); + EXPECT_EQ(DEFAULT_NOTIFICATION_SOUND.ToString(), slot.GetSound().ToString()); + EXPECT_TRUE(slot.CanVibrate()); + EXPECT_EQ(DEFAULT_NOTIFICATION_VIBRATION, slot.GetVibrationStyle()); + EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_HIGH, slot.GetLevel()); +} + +/** + * @tc.number : ANS_Interface_MT_NotificationSlot_00700 + * @tc.name : NotificationSlot_00700 + * @tc.desc : Create notification slot(type is SERVICE_REMINDER), get sound and vibration. + * @tc.expected : Create notification slot success, get sound and vibration success. + */ +HWTEST_F(AnsInterfaceModuleSlotTest, ANS_Interface_MT_NotificationSlot_00700, Function | MediumTest | Level1) +{ + NotificationSlot slot(NotificationConstant::SERVICE_REMINDER); + EXPECT_EQ("SERVICE_REMINDER", slot.GetName()); + EXPECT_EQ(NotificationConstant::VisiblenessType::PUBLIC, slot.GetLockScreenVisibleness()); + EXPECT_EQ(DEFAULT_NOTIFICATION_SOUND.ToString(), slot.GetSound().ToString()); + EXPECT_TRUE(slot.CanVibrate()); + EXPECT_EQ(DEFAULT_NOTIFICATION_VIBRATION, slot.GetVibrationStyle()); + EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_DEFAULT, slot.GetLevel()); +} + +/** + * @tc.number : ANS_Interface_MT_NotificationSlot_00800 + * @tc.name : NotificationSlot_00800 + * @tc.desc : Create notification slot(type is CONTENT_INFORMATION), get sound and vibration. + * @tc.expected : Create notification slot success, get sound and vibration success. + */ +HWTEST_F(AnsInterfaceModuleSlotTest, ANS_Interface_MT_NotificationSlot_00800, Function | MediumTest | Level1) +{ + NotificationSlot slot(NotificationConstant::CONTENT_INFORMATION); + EXPECT_EQ("CONTENT_INFORMATION", slot.GetName()); + EXPECT_EQ(NotificationConstant::VisiblenessType::SECRET, slot.GetLockScreenVisibleness()); + EXPECT_EQ("", slot.GetSound().ToString()); + EXPECT_FALSE(slot.CanVibrate()); + EXPECT_EQ(0, slot.GetVibrationStyle().size()); + EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_LOW, slot.GetLevel()); +} + +/** + * @tc.number : ANS_Interface_MT_NotificationSlot_00900 + * @tc.name : NotificationSlot_00900 + * @tc.desc : Create notification slot(type is OTHER), get sound and vibration. + * @tc.expected : Create notification slot success, get sound and vibration success. + */ +HWTEST_F(AnsInterfaceModuleSlotTest, ANS_Interface_MT_NotificationSlot_00900, Function | MediumTest | Level1) +{ + NotificationSlot slot(NotificationConstant::OTHER); + EXPECT_EQ("OTHER", slot.GetName()); + EXPECT_EQ(NotificationConstant::VisiblenessType::SECRET, slot.GetLockScreenVisibleness()); + EXPECT_EQ("", slot.GetSound().ToString()); + EXPECT_FALSE(slot.CanVibrate()); + EXPECT_EQ(0, slot.GetVibrationStyle().size()); + EXPECT_EQ(NotificationSlot::NotificationLevel::LEVEL_MIN, slot.GetLevel()); +} + /** * @tc.number : ANS_Interface_MT_NotificationSlotGroup_00100 * @tc.name : NotificationSlotGroup_00100 diff --git a/services/ans/src/notification_subscriber_manager.cpp b/services/ans/src/notification_subscriber_manager.cpp index b98b57051b6576687f61ad5e194a9eec586c9a4b..5f0eadd34e98b6cbfad655ae5207fabfbb3202c2 100644 --- a/services/ans/src/notification_subscriber_manager.cpp +++ b/services/ans/src/notification_subscriber_manager.cpp @@ -298,7 +298,6 @@ void NotificationSubscriberManager::NotifyUpdatedInner(const sptrsubscriber->OnDisturbModeChanged(mode); } }