From 1d0a09560116f2af324a7342e31185ece566000c Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Tue, 9 Nov 2021 15:52:11 +0000 Subject: [PATCH] Add default values of sound and vibration to the social and service reminder type slots Signed-off-by: zhaoyuan17 --- .../core/common/include/ans_const_define.h | 8 +++ .../ans/native/src/notification_slot.cpp | 7 +- .../ans_innerkits_module_slot_test.cpp | 69 +++++++++++++++++++ .../src/notification_subscriber_manager.cpp | 1 - 4 files changed, 82 insertions(+), 3 deletions(-) diff --git a/frameworks/ans/core/common/include/ans_const_define.h b/frameworks/ans/core/common/include/ans_const_define.h index 353899e52..3343ccbce 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 5c5748005..3ff67a5aa 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 e7ced9336..91ab5d60c 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 b98b57051..5f0eadd34 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); } } -- Gitee