From edd675c90b1466d40c0dbc9e4a22b7d56eafd920 Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Mon, 22 Nov 2021 23:34:57 +0800 Subject: [PATCH 1/2] Add DoNotDisturbMode feature Signed-off-by: zhaoyuan17 --- frameworks/ans/core/BUILD.gn | 1 + .../core/common/include/ans_const_define.h | 1 + .../core/common/include/ans_inner_errors.h | 1 + .../common/include/ans_permission_define.h | 58 +-- .../ans/core/include/ans_manager_interface.h | 11 +- .../ans/core/include/ans_manager_proxy.h | 5 +- .../ans/core/include/ans_manager_stub.h | 10 +- .../ans/core/include/ans_notification.h | 46 +- .../core/include/ans_subscriber_interface.h | 5 +- .../ans/core/include/ans_subscriber_proxy.h | 2 +- .../ans/core/include/ans_subscriber_stub.h | 4 +- frameworks/ans/core/src/ans_manager_proxy.cpp | 160 ++++--- frameworks/ans/core/src/ans_manager_stub.cpp | 95 ++-- frameworks/ans/core/src/ans_notification.cpp | 68 ++- .../ans/core/src/ans_subscriber_proxy.cpp | 12 +- .../ans/core/src/ans_subscriber_stub.cpp | 13 +- frameworks/ans/native/BUILD.gn | 1 + .../src/notification_do_not_disturb_date.cpp | 104 +++++ .../ans/native/src/notification_helper.cpp | 23 +- .../native/src/notification_subscriber.cpp | 4 +- frameworks/ans/test/moduletest/BUILD.gn | 8 + .../test/moduletest/ans_fw_module_test.cpp | 363 ++++++++++++++- .../ans_innerkits_module_publish_test.cpp | 122 +---- .../ans/test/moduletest/ans_mt_constant.h | 2 - .../test/moduletest/mock/permission_kit.cpp | 90 ++++ .../wantagent/src/want_agent_helper.cpp | 1 + .../native/include/notification_constant.h | 17 +- .../notification_conversational_content.h | 2 +- .../notification_do_not_disturb_date.h | 116 +++++ .../ans/native/include/notification_helper.h | 62 +-- .../ans/native/include/notification_slot.h | 4 +- .../native/include/notification_slot_group.h | 2 +- .../native/include/notification_subscriber.h | 9 +- interfaces/kits/napi/ans/include/common.h | 13 +- interfaces/kits/napi/ans/include/constant.h | 1 + .../kits/napi/ans/include/disturb_mode.h | 4 +- interfaces/kits/napi/ans/include/subscribe.h | 6 +- interfaces/kits/napi/ans/src/common.cpp | 117 ++++- interfaces/kits/napi/ans/src/constant.cpp | 21 + interfaces/kits/napi/ans/src/disturb_mode.cpp | 259 +++++++++-- interfaces/kits/napi/ans/src/init.cpp | 4 +- interfaces/kits/napi/ans/src/publish.cpp | 6 +- interfaces/kits/napi/ans/src/subscribe.cpp | 108 ++++- sa_profile/3203.xml | 1 + services/ans/BUILD.gn | 2 +- .../include/advanced_notification_service.h | 8 +- services/ans/include/disturb_filter.h | 3 + .../ans/include/notification_preferences.h | 68 +-- .../notification_preferences_database.h | 9 +- .../include/notification_preferences_info.h | 7 +- .../include/notification_subscriber_manager.h | 4 +- services/ans/include/preferences_constant.h | 4 +- .../ans/src/advanced_notification_service.cpp | 215 +++++++-- services/ans/src/disturb_filter.cpp | 81 ---- services/ans/src/notification_preferences.cpp | 10 +- .../src/notification_preferences_database.cpp | 100 +++- .../ans/src/notification_preferences_info.cpp | 8 +- .../src/notification_subscriber_manager.cpp | 12 +- services/ans/test/unittest/BUILD.gn | 4 +- ...nced_notification_service_ability_test.cpp | 2 +- .../advanced_notification_service_test.cpp | 318 +++++++++---- .../unittest/bundle_manager_helper_test.cpp | 4 +- .../ans/test/unittest/mock/permission_kit.cpp | 90 ++++ ...notification_preferences_database_test.cpp | 72 ++- .../notification_preferences_test.cpp | 41 +- .../notification_slot_filter_test.cpp | 6 +- .../notification_subscriber_manager_test.cpp | 23 +- .../test/unittest/permission_filter_test.cpp | 4 +- services/test/moduletest/BUILD.gn | 3 +- services/test/moduletest/ans_module_test.cpp | 430 ++++++++++-------- .../test/moduletest/mock/permission_kit.cpp | 90 ++++ .../include/notificationgetparam.h | 5 +- .../notificationfuzzconfig/config.json | 4 +- .../src/notificationfuzztestmanager.cpp | 13 +- .../src/notificationgetparam.cpp | 54 ++- 75 files changed, 2645 insertions(+), 1011 deletions(-) rename services/ans/test/unittest/disturb_filter_test.cpp => frameworks/ans/core/common/include/ans_permission_define.h (31%) create mode 100644 frameworks/ans/native/src/notification_do_not_disturb_date.cpp create mode 100644 frameworks/ans/test/moduletest/mock/permission_kit.cpp create mode 100644 interfaces/innerkits/ans/native/include/notification_do_not_disturb_date.h delete mode 100644 services/ans/src/disturb_filter.cpp create mode 100644 services/ans/test/unittest/mock/permission_kit.cpp create mode 100644 services/test/moduletest/mock/permission_kit.cpp diff --git a/frameworks/ans/core/BUILD.gn b/frameworks/ans/core/BUILD.gn index 69083c26e..e262036dd 100644 --- a/frameworks/ans/core/BUILD.gn +++ b/frameworks/ans/core/BUILD.gn @@ -51,6 +51,7 @@ ohos_shared_library("ans_core") { "${frameworks_path}/ans/native/src/notification_content.cpp", "${frameworks_path}/ans/native/src/notification_conversational_content.cpp", "${frameworks_path}/ans/native/src/notification_conversational_message.cpp", + "${frameworks_path}/ans/native/src/notification_do_not_disturb_date.cpp", "${frameworks_path}/ans/native/src/notification_helper.cpp", "${frameworks_path}/ans/native/src/notification_long_text_content.cpp", "${frameworks_path}/ans/native/src/notification_media_content.cpp", diff --git a/frameworks/ans/core/common/include/ans_const_define.h b/frameworks/ans/core/common/include/ans_const_define.h index 3343ccbce..60a2cc4f8 100644 --- a/frameworks/ans/core/common/include/ans_const_define.h +++ b/frameworks/ans/core/common/include/ans_const_define.h @@ -31,6 +31,7 @@ constexpr uint32_t MAX_SLOT_NUM = 5; 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; +constexpr bool SUPPORT_DO_NOT_DISTRUB = true; // Default sound for notification const static Uri DEFAULT_NOTIFICATION_SOUND("file://system/etc/Light.ogg"); diff --git a/frameworks/ans/core/common/include/ans_inner_errors.h b/frameworks/ans/core/common/include/ans_inner_errors.h index 3552497d1..a671871f3 100644 --- a/frameworks/ans/core/common/include/ans_inner_errors.h +++ b/frameworks/ans/core/common/include/ans_inner_errors.h @@ -55,6 +55,7 @@ enum ErrorCode : uint32_t { ERR_ANS_NO_MEMORY, ERR_ANS_TASK_ERR, ERR_ANS_NON_SYSTEM_APP, + ERR_ANS_PERMISSION_DENIED, ERR_ANS_NOTIFICATION_NOT_EXISTS, ERR_ANS_NOTIFICATION_IS_UNREMOVABLE, ERR_ANS_OVER_MAX_ACITVE_PERSECOND, diff --git a/services/ans/test/unittest/disturb_filter_test.cpp b/frameworks/ans/core/common/include/ans_permission_define.h similarity index 31% rename from services/ans/test/unittest/disturb_filter_test.cpp rename to frameworks/ans/core/common/include/ans_permission_define.h index 7ef21bb50..058c75d2c 100644 --- a/services/ans/test/unittest/disturb_filter_test.cpp +++ b/frameworks/ans/core/common/include/ans_permission_define.h @@ -13,58 +13,16 @@ * limitations under the License. */ -#include -#include +#ifndef BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_PERMISSION_DEFINE_H +#define BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_PERMISSION_DEFINE_H -#include "disturb_filter.h" +#include -using namespace testing::ext; namespace OHOS { namespace Notification { - -class DisturbFilterTest : public testing::Test { -public: - static void SetUpTestCase(){}; - static void TearDownTestCase(){}; - void SetUp(){}; - void TearDown(){}; -}; - -/** - * @tc.number : DisturbFilterTest_00100 - * @tc.name : AMS_ANS_OnStart_0100 - * @tc.desc : Test OnStart function - */ -HWTEST_F(DisturbFilterTest, DisturbFilterTest_00100, Function | SmallTest | Level1) -{ - DisturbFilter disturbFilter; - disturbFilter.OnStart(); -} - -/** - * @tc.number : DisturbFilterTest_00200 - * @tc.name : AMS_ANS_OnStop_0100 - * @tc.desc : Test OnStop function for data - */ -HWTEST_F(DisturbFilterTest, DisturbFilterTest_00200, Function | SmallTest | Level1) -{ - DisturbFilter disturbFilter; - disturbFilter.OnStop(); -} - -/** - * @tc.number : DisturbFilterTest_00300 - * @tc.name : AMS_ANS_OnPublish_0100 - * @tc.desc : Test OnPublish function for data - */ -HWTEST_F(DisturbFilterTest, DisturbFilterTest_00300, Function | SmallTest | Level1) -{ - DisturbFilter disturbFilter; - std::shared_ptr record = std::make_shared(); - record->request = new NotificationRequest(); - record->notification = new Notification(record->request); - record->slot = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); - disturbFilter.OnPublish(record); -} +// Permission +const std::string ANS_PERMISSION_CONTROLLER = "ohos.permission.NOTIFICATION_CONTROLLER"; } // namespace Notification -} // namespace OHOS \ No newline at end of file +} // namespace OHOS + +#endif // BASE_NOTIFICATION_ANS_STANDARD_INNERKITS_BASE_INCLUDE_ANS_PERMISSION_DEFINE_H diff --git a/frameworks/ans/core/include/ans_manager_interface.h b/frameworks/ans/core/include/ans_manager_interface.h index 7baefa8d0..70caf0f64 100644 --- a/frameworks/ans/core/include/ans_manager_interface.h +++ b/frameworks/ans/core/include/ans_manager_interface.h @@ -22,6 +22,7 @@ #include "ans_subscriber_interface.h" #include "iremote_broker.h" #include "notification_bundle_option.h" +#include "notification_do_not_disturb_date.h" #include "notification_constant.h" #include "notification_request.h" #include "notification_slot.h" @@ -68,8 +69,6 @@ public: const sptr notification, const std::string &representativeBundle) = 0; virtual ErrCode SetNotificationBadgeNum(int num) = 0; virtual ErrCode GetBundleImportance(int &importance) = 0; - virtual ErrCode SetDisturbMode(NotificationConstant::DisturbMode mode) = 0; - virtual ErrCode GetDisturbMode(NotificationConstant::DisturbMode &mode) = 0; virtual ErrCode HasNotificationPolicyAccessPermission(bool &granted) = 0; virtual ErrCode SetPrivateNotificationsAllowed(bool allow) = 0; virtual ErrCode GetPrivateNotificationsAllowed(bool &allow) = 0; @@ -104,6 +103,9 @@ public: virtual ErrCode IsAllowedNotify(bool &allowed) = 0; virtual ErrCode IsSpecialBundleAllowedNotify(const sptr &bundleOption, bool &allowed) = 0; + virtual ErrCode SetDoNotDisturbDate(const sptr & date) = 0; + virtual ErrCode GetDoNotDisturbDate(sptr & date) = 0; + virtual ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport) = 0; virtual ErrCode CancelGroup(const std::string &groupName) = 0; virtual ErrCode RemoveGroupByBundle( const sptr &bundleOption, const std::string &groupName) = 0; @@ -137,8 +139,6 @@ protected: PUBLISH_AS_BUNDLE, SET_NOTIFICATION_BADGE_NUM, GET_BUNDLE_IMPORTANCE, - SET_DISTURB_MODE, - GET_DISTURB_MODE, IS_NOTIFICATION_POLICY_ACCESS_GRANTED, SET_PRIVATIVE_NOTIFICATIONS_ALLOWED, GET_PRIVATIVE_NOTIFICATIONS_ALLOWED, @@ -162,6 +162,9 @@ protected: GET_CURRENT_APP_SORTING, IS_ALLOWED_NOTIFY, IS_SPECIAL_BUNDLE_ALLOWED_NOTIFY, + SET_DO_NOT_DISTURB_DATE, + GET_DO_NOT_DISTURB_DATE, + DOES_SUPPORT_DO_NOT_DISTURB_MODE, CANCEL_GROUP, REMOVE_GROUP_BY_BUNDLE, SHELL_DUMP, diff --git a/frameworks/ans/core/include/ans_manager_proxy.h b/frameworks/ans/core/include/ans_manager_proxy.h index 24a8105ca..b780d0d0b 100644 --- a/frameworks/ans/core/include/ans_manager_proxy.h +++ b/frameworks/ans/core/include/ans_manager_proxy.h @@ -57,8 +57,6 @@ public: const sptr notification, const std::string &representativeBundle) override; ErrCode SetNotificationBadgeNum(int num) override; ErrCode GetBundleImportance(int &importance) override; - ErrCode SetDisturbMode(NotificationConstant::DisturbMode mode) override; - ErrCode GetDisturbMode(NotificationConstant::DisturbMode &mode) override; ErrCode HasNotificationPolicyAccessPermission(bool &granted) override; ErrCode SetPrivateNotificationsAllowed(bool allow) override; ErrCode GetPrivateNotificationsAllowed(bool &allow) override; @@ -93,6 +91,9 @@ public: ErrCode IsAllowedNotify(bool &allowed) override; ErrCode IsSpecialBundleAllowedNotify(const sptr &bundleOption, bool &allowed) override; + ErrCode SetDoNotDisturbDate(const sptr &date) override; + ErrCode GetDoNotDisturbDate(sptr &date) override; + ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport) override; ErrCode CancelGroup(const std::string &groupName) override; ErrCode RemoveGroupByBundle( const sptr &bundleOption, const std::string &groupName) override; diff --git a/frameworks/ans/core/include/ans_manager_stub.h b/frameworks/ans/core/include/ans_manager_stub.h index 082bec359..04338d636 100644 --- a/frameworks/ans/core/include/ans_manager_stub.h +++ b/frameworks/ans/core/include/ans_manager_stub.h @@ -62,8 +62,6 @@ public: const sptr notification, const std::string &representativeBundle) override; virtual ErrCode SetNotificationBadgeNum(int num) override; virtual ErrCode GetBundleImportance(int &importance) override; - virtual ErrCode SetDisturbMode(NotificationConstant::DisturbMode mode) override; - virtual ErrCode GetDisturbMode(NotificationConstant::DisturbMode &mode) override; virtual ErrCode HasNotificationPolicyAccessPermission(bool &granted) override; virtual ErrCode SetPrivateNotificationsAllowed(bool allow) override; virtual ErrCode GetPrivateNotificationsAllowed(bool &allow) override; @@ -98,6 +96,9 @@ public: virtual ErrCode IsSpecialBundleAllowedNotify( const sptr &bundleOption, bool &allowed) override; + virtual ErrCode SetDoNotDisturbDate(const sptr &date) override; + virtual ErrCode GetDoNotDisturbDate(sptr &date) override; + virtual ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport) override; virtual ErrCode CancelGroup(const std::string &groupName) override; virtual ErrCode RemoveGroupByBundle( const sptr &bundleOption, const std::string &groupName) override; @@ -133,8 +134,6 @@ private: ErrCode HandlePublishAsBundle(MessageParcel &data, MessageParcel &reply); ErrCode HandleSetNotificationBadgeNum(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetBundleImportance(MessageParcel &data, MessageParcel &reply); - ErrCode HandleSetDisturbMode(MessageParcel &data, MessageParcel &reply); - ErrCode HandleGetDisturbMode(MessageParcel &data, MessageParcel &reply); ErrCode HandleIsNotificationPolicyAccessGranted(MessageParcel &data, MessageParcel &reply); ErrCode HandleSetPrivateNotificationsAllowed(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetPrivateNotificationsAllowed(MessageParcel &data, MessageParcel &reply); @@ -161,6 +160,9 @@ private: ErrCode HandleShellDump(MessageParcel &data, MessageParcel &reply); ErrCode HandleCancelGroup(MessageParcel &data, MessageParcel &reply); ErrCode HandleRemoveGroupByBundle(MessageParcel &data, MessageParcel &reply); + ErrCode HandleSetDoNotDisturbDate(MessageParcel &data, MessageParcel &reply); + ErrCode HandleGetDoNotDisturbDate(MessageParcel &data, MessageParcel &reply); + ErrCode HandleDoesSupportDoNotDisturbMode(MessageParcel &data, MessageParcel &reply); template bool WriteParcelableVector(const std::vector> &parcelableVector, MessageParcel &reply, ErrCode &result); diff --git a/frameworks/ans/core/include/ans_notification.h b/frameworks/ans/core/include/ans_notification.h index ce3893a34..066b03bb2 100644 --- a/frameworks/ans/core/include/ans_notification.h +++ b/frameworks/ans/core/include/ans_notification.h @@ -21,6 +21,7 @@ #include "ans_manager_death_recipient.h" #include "ans_manager_interface.h" #include "notification_bundle_option.h" +#include "notification_do_not_disturb_date.h" #include "notification_request.h" #include "notification_slot.h" #include "notification_slot_group.h" @@ -574,25 +575,6 @@ public: */ ErrCode GetShowBadgeEnabled(bool &enabled); - /** - * Sets the type of the Do Not Disturb mode. The Do Not Disturb mode type specifies the type of notifications - * that are allowed to interrupt users. - * @note Your application must have system signature to call this method. - * - * @param mode Indicates the Do Not Disturb mode to set. The value must be - * {NotificationConstant.DisturbMode.ALLOW_ALL}, {NotificationConstant.DisturbMode.ALLOW_PRIORITY}, - * {NotificationConstant.DisturbMode.ALLOW_NONE}, or {NotificationConstant.DisturbMode.ALLOW_ALARMS}. - * @return Returns set disturb mode result. - */ - ErrCode SetDisturbMode(NotificationConstant::DisturbMode mode); - - /** - * Obtains the Disturb Mode. - * @param disturbMode The current type of the Do Not Disturb mode. - * @return Returns get disturb mode result. - */ - ErrCode GetDisturbMode(NotificationConstant::DisturbMode &disturbMode); - /** * Cancel the notification of the specified group of this application. * @@ -610,6 +592,32 @@ public: */ ErrCode RemoveGroupByBundle(const NotificationBundleOption &bundleOption, const std::string &groupName); + /** + * Sets the do not disturb time. + * @note Your application must have system signature to call this method. + * + * @param doNotDisturbDate Indicates the do not disturb time to set. + * @return Returns set do not disturb time result. + */ + ErrCode SetDoNotDisturbDate(const NotificationDoNotDisturbDate & doNotDisturbDate); + + /** + * Obtains the do not disturb time. + * @note Your application must have system signature to call this method. + * + * @param doNotDisturbDate Indicates the do not disturb time to get. + * @return Returns set do not disturb time result. + */ + ErrCode GetDoNotDisturbDate(NotificationDoNotDisturbDate & doNotDisturbDate); + + /** + * Obtains the flag that whether to support do not disturb mode. + * + * @param doesSupport Specifies whether to support do not disturb mode. + * @return Returns check result. + */ + ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport); + /** * Reset ans manager proxy when OnRemoteDied called. */ diff --git a/frameworks/ans/core/include/ans_subscriber_interface.h b/frameworks/ans/core/include/ans_subscriber_interface.h index e49cb26ea..326680107 100644 --- a/frameworks/ans/core/include/ans_subscriber_interface.h +++ b/frameworks/ans/core/include/ans_subscriber_interface.h @@ -20,6 +20,7 @@ #include "notification.h" #include "notification_constant.h" +#include "notification_do_not_disturb_date.h" #include "notification_request.h" #include "notification_sorting.h" #include "notification_sorting_map.h" @@ -43,7 +44,7 @@ public: virtual void OnCanceled(const sptr ¬ification, const sptr ¬ificationMap, int deleteReason) = 0; virtual void OnUpdated(const sptr ¬ificationMap) = 0; - virtual void OnDisturbModeChanged(NotificationConstant::DisturbMode mode) = 0; + virtual void OnDoNotDisturbDateChange(const sptr &date) = 0; protected: enum TransactId : uint32_t { @@ -54,7 +55,7 @@ protected: ON_CANCELED, ON_CANCELED_MAP, ON_UPDATED, - ON_DISTURB_MODE_CHANGED, + ON_DND_DATE_CHANGED, }; }; } // namespace Notification diff --git a/frameworks/ans/core/include/ans_subscriber_proxy.h b/frameworks/ans/core/include/ans_subscriber_proxy.h index f3101c52f..ea286a7a9 100644 --- a/frameworks/ans/core/include/ans_subscriber_proxy.h +++ b/frameworks/ans/core/include/ans_subscriber_proxy.h @@ -38,7 +38,7 @@ public: void OnCanceled(const sptr ¬ification, const sptr ¬ificationMap, int deleteReason) override; void OnUpdated(const sptr ¬ificationMap) override; - void OnDisturbModeChanged(NotificationConstant::DisturbMode mode) override; + void OnDoNotDisturbDateChange(const sptr &date) override; private: ErrCode InnerTransact(uint32_t code, MessageOption &flags, MessageParcel &data, MessageParcel &reply); diff --git a/frameworks/ans/core/include/ans_subscriber_stub.h b/frameworks/ans/core/include/ans_subscriber_stub.h index b8c8b82de..403731bf3 100644 --- a/frameworks/ans/core/include/ans_subscriber_stub.h +++ b/frameworks/ans/core/include/ans_subscriber_stub.h @@ -40,7 +40,7 @@ public: void OnCanceled(const sptr ¬ification, const sptr ¬ificationMap, int deleteReason) override; void OnUpdated(const sptr ¬ificationMap) override; - void OnDisturbModeChanged(NotificationConstant::DisturbMode mode) override; + void OnDoNotDisturbDateChange(const sptr &date) override; private: std::map> interfaces_; @@ -52,7 +52,7 @@ private: ErrCode HandleOnCanceled(MessageParcel &data, MessageParcel &reply); ErrCode HandleOnCanceledMap(MessageParcel &data, MessageParcel &reply); ErrCode HandleOnUpdated(MessageParcel &data, MessageParcel &reply); - ErrCode HandleOnDisturbModeChanged(MessageParcel &data, MessageParcel &reply); + ErrCode HandleOnDoNotDisturbDateChange(MessageParcel &data, MessageParcel &reply); }; } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/core/src/ans_manager_proxy.cpp b/frameworks/ans/core/src/ans_manager_proxy.cpp index 5505d1e18..69c1809ad 100644 --- a/frameworks/ans/core/src/ans_manager_proxy.cpp +++ b/frameworks/ans/core/src/ans_manager_proxy.cpp @@ -845,67 +845,6 @@ ErrCode AnsManagerProxy::GetBundleImportance(int &importance) return result; } -ErrCode AnsManagerProxy::SetDisturbMode(NotificationConstant::DisturbMode mode) -{ - if ((mode < NotificationConstant::DisturbMode::ALLOW_ALARMS) || - (mode > NotificationConstant::DisturbMode::ALLOW_UNKNOWN)) { - ANS_LOGW("[SetDisturbMode] fail: input mode is not in DisturbMode."); - return ERR_ANS_PARCELABLE_FAILED; - } - - MessageParcel data; - if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { - ANS_LOGW("[SetDisturbMode] fail: write interface token failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - if (!data.WriteInt32(mode)) { - ANS_LOGW("[SetDisturbMode] fail: write mode failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - ErrCode result = InnerTransact(SET_DISTURB_MODE, option, data, reply); - if (result != ERR_OK) { - ANS_LOGW("[SetDisturbMode] fail: transact ErrCode=%{public}d", result); - return ERR_ANS_TRANSACT_FAILED; - } - - if (!reply.ReadInt32(result)) { - ANS_LOGW("[SetDisturbMode] fail: read result failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - return result; -} - -ErrCode AnsManagerProxy::GetDisturbMode(NotificationConstant::DisturbMode &mode) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { - ANS_LOGW("[GetDisturbMode] fail: write interface token failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - ErrCode result = InnerTransact(GET_DISTURB_MODE, option, data, reply); - if (result != ERR_OK) { - ANS_LOGW("[GetDisturbMode] fail: transact ErrCode=%{public}d", result); - return ERR_ANS_TRANSACT_FAILED; - } - - if (!reply.ReadInt32(result)) { - ANS_LOGW("[GetDisturbMode] fail: read result failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - mode = static_cast(reply.ReadInt32()); - - return result; -} - ErrCode AnsManagerProxy::HasNotificationPolicyAccessPermission(bool &granted) { MessageParcel data; @@ -1770,7 +1709,7 @@ ErrCode AnsManagerProxy::CancelGroup(const std::string &groupName) return ERR_ANS_PARCELABLE_FAILED; } - return ERR_OK; + return result; } ErrCode AnsManagerProxy::RemoveGroupByBundle( @@ -1805,7 +1744,102 @@ ErrCode AnsManagerProxy::RemoveGroupByBundle( return ERR_ANS_PARCELABLE_FAILED; } - return ERR_OK; + return result; +} + +ErrCode AnsManagerProxy::SetDoNotDisturbDate(const sptr &date) +{ + if (date == nullptr) { + ANS_LOGW("[SetDoNotDisturbDate] fail: date is empty."); + return ERR_ANS_INVALID_PARAM; + } + + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANS_LOGW("[SetDoNotDisturbDate] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteParcelable(date)) { + ANS_LOGW("[SetDoNotDisturbDate] fail: write date failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + ErrCode result = InnerTransact(SET_DO_NOT_DISTURB_DATE, option, data, reply); + if (result != ERR_OK) { + ANS_LOGW("[SetDoNotDisturbDate] fail: transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } + + if (!reply.ReadInt32(result)) { + ANS_LOGW("[SetDoNotDisturbDate] fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return result; +} + +ErrCode AnsManagerProxy::GetDoNotDisturbDate(sptr &date) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANS_LOGW("[GetDoNotDisturbDate] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + ErrCode result = InnerTransact(GET_DO_NOT_DISTURB_DATE, option, data, reply); + if (result != ERR_OK) { + ANS_LOGW("[GetDoNotDisturbDate] fail: transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } + + if (!reply.ReadInt32(result)) { + ANS_LOGW("[GetDoNotDisturbDate] fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (result == ERR_OK) { + date = reply.ReadParcelable(); + if (date == nullptr) { + ANS_LOGW("[GetDoNotDisturbDate] fail: read date failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + } + + return result; +} + +ErrCode AnsManagerProxy::DoesSupportDoNotDisturbMode(bool &doesSupport) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANS_LOGW("[DoesSupportDoNotDisturbMode] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + ErrCode result = InnerTransact(DOES_SUPPORT_DO_NOT_DISTURB_MODE, option, data, reply); + if (result != ERR_OK) { + ANS_LOGW("[DoesSupportDoNotDisturbMode] fail: transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } + + if (!reply.ReadInt32(result)) { + ANS_LOGW("[DoesSupportDoNotDisturbMode] fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.ReadBool(doesSupport)) { + ANS_LOGW("[DoesSupportDoNotDisturbMode] fail: read doesSupport failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return result; } ErrCode AnsManagerProxy::ShellDump(const std::string &dumpOption, std::vector &dumpInfo) diff --git a/frameworks/ans/core/src/ans_manager_stub.cpp b/frameworks/ans/core/src/ans_manager_stub.cpp index cf1024bea..8928488bb 100644 --- a/frameworks/ans/core/src/ans_manager_stub.cpp +++ b/frameworks/ans/core/src/ans_manager_stub.cpp @@ -101,12 +101,6 @@ const std::map(data.ReadInt32()); - ErrCode result = SetDisturbMode(mode); + sptr date = data.ReadParcelable(); + if (date == nullptr) { + ANS_LOGW("[HandleSetDoNotDisturbDate] fail: read date failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + ErrCode result = SetDoNotDisturbDate(date); + if (!reply.WriteInt32(result)) { - ANS_LOGW("[HandleSetDisturbMode] fail: write result failed, ErrCode=%{public}d", result); + ANS_LOGW("[HandleSetDoNotDisturbDate] fail: write result failed, ErrCode=%{public}d", result); return ERR_ANS_PARCELABLE_FAILED; } + + return ERR_OK; +} + +ErrCode AnsManagerStub::HandleGetDoNotDisturbDate(MessageParcel &data, MessageParcel &reply) +{ + sptr date = nullptr; + + ErrCode result = GetDoNotDisturbDate(date); + + if (!reply.WriteInt32(result)) { + ANS_LOGW("[HandleSetDoNotDisturbDate] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (result == ERR_OK) { + if (!reply.WriteParcelable(date)) { + ANS_LOGW("[HandleSetDoNotDisturbDate] fail: write date failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + } + return ERR_OK; } -ErrCode AnsManagerStub::HandleGetDisturbMode(MessageParcel &data, MessageParcel &reply) +ErrCode AnsManagerStub::HandleDoesSupportDoNotDisturbMode(MessageParcel &data, MessageParcel &reply) { - NotificationConstant::DisturbMode mode; - ErrCode result = GetDisturbMode(mode); + bool support = false; + + ErrCode result = DoesSupportDoNotDisturbMode(support); if (!reply.WriteInt32(result)) { - ANS_LOGW("[HandleGetDisturbMode] fail: write result failed, ErrCode=%{public}d", result); + ANS_LOGW("[HandleDoesSupportDoNotDisturbMode] fail: write result failed, ErrCode=%{public}d", result); return ERR_ANS_PARCELABLE_FAILED; } - if (!reply.WriteInt32(mode)) { - ANS_LOGW("[HandleGetDisturbMode] fail: write mode failed."); + if (!reply.WriteBool(support)) { + ANS_LOGW("[HandleDoesSupportDoNotDisturbMode] fail: write doesSupport failed."); return ERR_ANS_PARCELABLE_FAILED; } + return ERR_OK; } @@ -1405,18 +1438,6 @@ ErrCode AnsManagerStub::GetBundleImportance(int &importance) return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::SetDisturbMode(NotificationConstant::DisturbMode mode) -{ - ANS_LOGW("AnsManagerStub::SetDisturbMode called!"); - return ERR_INVALID_OPERATION; -} - -ErrCode AnsManagerStub::GetDisturbMode(NotificationConstant::DisturbMode &mode) -{ - ANS_LOGW("AnsManagerStub::GetDisturbMode called!"); - return ERR_INVALID_OPERATION; -} - ErrCode AnsManagerStub::HasNotificationPolicyAccessPermission(bool &granted) { ANS_LOGW("AnsManagerStub::HasNotificationPolicyAccessPermission called!"); @@ -1573,6 +1594,24 @@ ErrCode AnsManagerStub::RemoveGroupByBundle( return ERR_INVALID_OPERATION; } +ErrCode AnsManagerStub::SetDoNotDisturbDate(const sptr &date) +{ + ANS_LOGW("AnsManagerStub::SetDoNotDisturbDate called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::GetDoNotDisturbDate(sptr &date) +{ + ANS_LOGW("AnsManagerStub::GetDoNotDisturbDate called!"); + return ERR_INVALID_OPERATION; +} + +ErrCode AnsManagerStub::DoesSupportDoNotDisturbMode(bool &doesSupport) +{ + ANS_LOGW("AnsManagerStub::DoesSupportDoNotDisturbMode called!"); + return ERR_INVALID_OPERATION; +} + ErrCode AnsManagerStub::ShellDump(const std::string &dumpOption, std::vector &dumpInfo) { ANS_LOGW("AnsManagerStub::ShellDump called!"); diff --git a/frameworks/ans/core/src/ans_notification.cpp b/frameworks/ans/core/src/ans_notification.cpp index d57d6fc56..ec677c790 100644 --- a/frameworks/ans/core/src/ans_notification.cpp +++ b/frameworks/ans/core/src/ans_notification.cpp @@ -737,24 +737,6 @@ ErrCode AnsNotification::GetShowBadgeEnabled(bool &enabled) return ansManagerProxy_->GetShowBadgeEnabled(enabled); } -ErrCode AnsNotification::SetDisturbMode(NotificationConstant::DisturbMode mode) -{ - if (!GetAnsManagerProxy()) { - ANS_LOGE("GetAnsManagerProxy fail."); - return ERR_ANS_SERVICE_NOT_CONNECTED; - } - return ansManagerProxy_->SetDisturbMode(mode); -} - -ErrCode AnsNotification::GetDisturbMode(NotificationConstant::DisturbMode &disturbMode) -{ - if (!GetAnsManagerProxy()) { - ANS_LOGE("GetAnsManagerProxy fail."); - return ERR_ANS_SERVICE_NOT_CONNECTED; - } - return ansManagerProxy_->GetDisturbMode(disturbMode); -} - ErrCode AnsNotification::CancelGroup(const std::string &groupName) { if (groupName.empty()) { @@ -787,6 +769,56 @@ ErrCode AnsNotification::RemoveGroupByBundle( return ansManagerProxy_->RemoveGroupByBundle(bo, groupName); } +ErrCode AnsNotification::SetDoNotDisturbDate(const NotificationDoNotDisturbDate &doNotDisturbDate) +{ + if (!GetAnsManagerProxy()) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + auto dndDatePtr = new (std::nothrow) NotificationDoNotDisturbDate(doNotDisturbDate); + if (dndDatePtr == nullptr) { + ANS_LOGE("create DoNotDisturbDate failed."); + return ERR_ANS_NO_MEMORY; + } + + sptr dndDate(dndDatePtr); + return ansManagerProxy_->SetDoNotDisturbDate(dndDate); +} + +ErrCode AnsNotification::GetDoNotDisturbDate(NotificationDoNotDisturbDate &doNotDisturbDate) +{ + if (!GetAnsManagerProxy()) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + sptr dndDate; + auto ret = ansManagerProxy_->GetDoNotDisturbDate(dndDate); + if (ret != ERR_OK) { + ANS_LOGE("Get DoNotDisturbDate failed."); + return ret; + } + + if (!dndDate) { + ANS_LOGE("Invalid DoNotDisturbDate."); + return ERR_ANS_NO_MEMORY; + } + + doNotDisturbDate = *dndDate; + return ret; +} + +ErrCode AnsNotification::DoesSupportDoNotDisturbMode(bool &doesSupport) +{ + if (!GetAnsManagerProxy()) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return ansManagerProxy_->DoesSupportDoNotDisturbMode(doesSupport); +} + void AnsNotification::ResetAnsManagerProxy() { ANS_LOGI("enter"); diff --git a/frameworks/ans/core/src/ans_subscriber_proxy.cpp b/frameworks/ans/core/src/ans_subscriber_proxy.cpp index 7cef65d7d..b1abfafed 100644 --- a/frameworks/ans/core/src/ans_subscriber_proxy.cpp +++ b/frameworks/ans/core/src/ans_subscriber_proxy.cpp @@ -253,24 +253,24 @@ void AnsSubscriberProxy::OnUpdated(const sptr ¬ificat } } -void AnsSubscriberProxy::OnDisturbModeChanged(NotificationConstant::DisturbMode mode) +void AnsSubscriberProxy::OnDoNotDisturbDateChange(const sptr &date) { MessageParcel data; if (!data.WriteInterfaceToken(AnsSubscriberProxy::GetDescriptor())) { - ANS_LOGW("[OnDisturbModeChanged] fail: write interface token failed."); + ANS_LOGW("[OnDoNotDisturbDateChange] fail: write interface token failed."); return; } - if (!data.WriteUint32(mode)) { - ANS_LOGW("[OnDisturbModeChanged] fail: write mode failed"); + if (!data.WriteParcelable(date)) { + ANS_LOGW("[OnDoNotDisturbDateChange] fail: write date failed"); return; } MessageParcel reply; MessageOption option = {MessageOption::TF_ASYNC}; - ErrCode result = InnerTransact(ON_DISTURB_MODE_CHANGED, option, data, reply); + ErrCode result = InnerTransact(ON_DND_DATE_CHANGED, option, data, reply); if (result != ERR_OK) { - ANS_LOGW("[OnDisturbModeChanged] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED"); + ANS_LOGW("[OnDoNotDisturbDateChange] fail: transact ErrCode=ERR_ANS_TRANSACT_FAILED"); return; } } diff --git a/frameworks/ans/core/src/ans_subscriber_stub.cpp b/frameworks/ans/core/src/ans_subscriber_stub.cpp index 716affd1e..2b36124c2 100644 --- a/frameworks/ans/core/src/ans_subscriber_stub.cpp +++ b/frameworks/ans/core/src/ans_subscriber_stub.cpp @@ -42,8 +42,9 @@ AnsSubscriberStub::AnsSubscriberStub() std::bind(&AnsSubscriberStub::HandleOnCanceledMap, this, std::placeholders::_1, std::placeholders::_2)); interfaces_.emplace( ON_UPDATED, std::bind(&AnsSubscriberStub::HandleOnUpdated, this, std::placeholders::_1, std::placeholders::_2)); - interfaces_.emplace(ON_DISTURB_MODE_CHANGED, - std::bind(&AnsSubscriberStub::HandleOnDisturbModeChanged, this, std::placeholders::_1, std::placeholders::_2)); + interfaces_.emplace(ON_DND_DATE_CHANGED, + std::bind( + &AnsSubscriberStub::HandleOnDoNotDisturbDateChange, this, std::placeholders::_1, std::placeholders::_2)); } AnsSubscriberStub::~AnsSubscriberStub() @@ -183,10 +184,10 @@ ErrCode AnsSubscriberStub::HandleOnUpdated(MessageParcel &data, MessageParcel &r return ERR_OK; } -ErrCode AnsSubscriberStub::HandleOnDisturbModeChanged(MessageParcel &data, MessageParcel &reply) +ErrCode AnsSubscriberStub::HandleOnDoNotDisturbDateChange(MessageParcel &data, MessageParcel &reply) { - NotificationConstant::DisturbMode mode = static_cast(data.ReadUint32()); - OnDisturbModeChanged(mode); + sptr date = data.ReadParcelable(); + OnDoNotDisturbDateChange(date); return ERR_OK; } @@ -213,7 +214,7 @@ void AnsSubscriberStub::OnCanceled( void AnsSubscriberStub::OnUpdated(const sptr ¬ificationMap) {} -void AnsSubscriberStub::OnDisturbModeChanged(NotificationConstant::DisturbMode mode) +void AnsSubscriberStub::OnDoNotDisturbDateChange(const sptr &date) {} } // namespace Notification diff --git a/frameworks/ans/native/BUILD.gn b/frameworks/ans/native/BUILD.gn index 835e149ff..f83983bd0 100755 --- a/frameworks/ans/native/BUILD.gn +++ b/frameworks/ans/native/BUILD.gn @@ -48,6 +48,7 @@ ohos_shared_library("ans_innerkits") { "src/notification_content.cpp", "src/notification_conversational_content.cpp", "src/notification_conversational_message.cpp", + "src/notification_do_not_disturb_date.cpp", "src/notification_helper.cpp", "src/notification_long_text_content.cpp", "src/notification_media_content.cpp", diff --git a/frameworks/ans/native/src/notification_do_not_disturb_date.cpp b/frameworks/ans/native/src/notification_do_not_disturb_date.cpp new file mode 100644 index 000000000..4492263fe --- /dev/null +++ b/frameworks/ans/native/src/notification_do_not_disturb_date.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "notification_do_not_disturb_date.h" +#include "ans_log_wrapper.h" + +namespace OHOS { +namespace Notification { +NotificationDoNotDisturbDate::NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType doNotDisturbType, + int64_t beginDate, int64_t endDate) + : doNotDisturbType_(doNotDisturbType), beginDate_(beginDate), endDate_(endDate) +{} + +void NotificationDoNotDisturbDate::SetDoNotDisturbType(NotificationConstant::DoNotDisturbType doNotDisturbType) +{ + doNotDisturbType_ = doNotDisturbType; +} + +NotificationConstant::DoNotDisturbType NotificationDoNotDisturbDate::GetDoNotDisturbType() const +{ + return doNotDisturbType_; +} + +void NotificationDoNotDisturbDate::SetBeginDate(const int64_t beginDate) +{ + beginDate_ = beginDate; +} + +int64_t NotificationDoNotDisturbDate::GetBeginDate() const +{ + return beginDate_; +} + +void NotificationDoNotDisturbDate::SetEndDate(const int64_t endDate) +{ + endDate_ = endDate; +} + +int64_t NotificationDoNotDisturbDate::GetEndDate() const +{ + return endDate_; +} + +std::string NotificationDoNotDisturbDate::Dump() +{ + return "NotificationDoNotDisturbDate[ "\ + "doNotDisturbType = " + std::to_string(static_cast(doNotDisturbType_)) + + ", beginDate = " + std::to_string(beginDate_) + + ", endDate = " + std::to_string(endDate_) + " ]"; +} + +bool NotificationDoNotDisturbDate::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteInt32(static_cast(doNotDisturbType_))) { + ANS_LOGE("Failed to write doNotDisturbType"); + return false; + } + + if (!parcel.WriteInt64(beginDate_)) { + ANS_LOGE("Failed to write begin time"); + return false; + } + + if (!parcel.WriteInt64(endDate_)) { + ANS_LOGE("Failed to write end time"); + return false; + } + + return true; +} + +NotificationDoNotDisturbDate *NotificationDoNotDisturbDate::Unmarshalling(Parcel &parcel) +{ + auto objptr = new (std::nothrow) NotificationDoNotDisturbDate(); + if ((objptr != nullptr) && !objptr->ReadFromParcel(parcel)) { + delete objptr; + objptr = nullptr; + } + + return objptr; +} + +bool NotificationDoNotDisturbDate::ReadFromParcel(Parcel &parcel) +{ + doNotDisturbType_ = static_cast(parcel.ReadInt32()); + beginDate_ = parcel.ReadInt64(); + endDate_ = parcel.ReadInt64(); + + return true; +} +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/ans/native/src/notification_helper.cpp b/frameworks/ans/native/src/notification_helper.cpp index 7b2ae30cb..020fe4a0b 100644 --- a/frameworks/ans/native/src/notification_helper.cpp +++ b/frameworks/ans/native/src/notification_helper.cpp @@ -296,25 +296,30 @@ ErrCode NotificationHelper::GetShowBadgeEnabled(bool &enabled) return DelayedSingleton::GetInstance()->GetShowBadgeEnabled(enabled); } -ErrCode NotificationHelper::SetDisturbMode(NotificationConstant::DisturbMode mode) +ErrCode NotificationHelper::CancelGroup(const std::string &groupName) { - return DelayedSingleton::GetInstance()->SetDisturbMode(mode); + return DelayedSingleton::GetInstance()->CancelGroup(groupName); } -ErrCode NotificationHelper::GetDisturbMode(NotificationConstant::DisturbMode &disturbMode) +ErrCode NotificationHelper::RemoveGroupByBundle( + const NotificationBundleOption &bundleOption, const std::string &groupName) { - return DelayedSingleton::GetInstance()->GetDisturbMode(disturbMode); + return DelayedSingleton::GetInstance()->RemoveGroupByBundle(bundleOption, groupName); } -ErrCode NotificationHelper::CancelGroup(const std::string &groupName) +ErrCode NotificationHelper::SetDoNotDisturbDate(const NotificationDoNotDisturbDate & doNotDisturbDate) { - return DelayedSingleton::GetInstance()->CancelGroup(groupName); + return DelayedSingleton::GetInstance()->SetDoNotDisturbDate(doNotDisturbDate); } -ErrCode NotificationHelper::RemoveGroupByBundle( - const NotificationBundleOption &bundleOption, const std::string &groupName) +ErrCode NotificationHelper::GetDoNotDisturbDate(NotificationDoNotDisturbDate & doNotDisturbDate) { - return DelayedSingleton::GetInstance()->RemoveGroupByBundle(bundleOption, groupName); + return DelayedSingleton::GetInstance()->GetDoNotDisturbDate(doNotDisturbDate); +} + +ErrCode NotificationHelper::DoesSupportDoNotDisturbMode(bool &doesSupport) +{ + return DelayedSingleton::GetInstance()->DoesSupportDoNotDisturbMode(doesSupport); } } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/frameworks/ans/native/src/notification_subscriber.cpp b/frameworks/ans/native/src/notification_subscriber.cpp index e26174d32..62e2c09e6 100644 --- a/frameworks/ans/native/src/notification_subscriber.cpp +++ b/frameworks/ans/native/src/notification_subscriber.cpp @@ -87,9 +87,9 @@ void NotificationSubscriber::SubscriberImpl::OnUpdated(const sptr(*notificationMap)); } -void NotificationSubscriber::SubscriberImpl::OnDisturbModeChanged(NotificationConstant::DisturbMode mode) +void NotificationSubscriber::SubscriberImpl::OnDoNotDisturbDateChange(const sptr &date) { - subscriber_.OnDisturbModeChanged(mode); + subscriber_.OnDoNotDisturbDateChange(std::make_shared(*date)); } bool NotificationSubscriber::SubscriberImpl::GetAnsManagerProxy() diff --git a/frameworks/ans/test/moduletest/BUILD.gn b/frameworks/ans/test/moduletest/BUILD.gn index f2edf4096..85cc90dc9 100755 --- a/frameworks/ans/test/moduletest/BUILD.gn +++ b/frameworks/ans/test/moduletest/BUILD.gn @@ -82,6 +82,7 @@ ohos_moduletest("ans_fw_module_test") { "mock/mock_bundle_mgr_proxy.cpp", "mock/mock_ipc.cpp", "mock/mock_single_kv_store.cpp", + "mock/permission_kit.cpp", ] configs = [ "//utils/native/base:utils_config" ] @@ -112,6 +113,7 @@ ohos_moduletest("ans_fw_module_test") { "ces_standard:cesfwk_innerkits", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", + "permission_standard:libpermissionsdk_standard", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] @@ -163,6 +165,7 @@ ohos_moduletest("ans_innerkits_module_publish_test") { "mock/mock_bundle_mgr_proxy.cpp", "mock/mock_ipc.cpp", "mock/mock_single_kv_store.cpp", + "mock/permission_kit.cpp", ] configs = [ "//utils/native/base:utils_config" ] @@ -193,6 +196,7 @@ ohos_moduletest("ans_innerkits_module_publish_test") { "ces_standard:cesfwk_innerkits", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", + "permission_standard:libpermissionsdk_standard", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] @@ -243,6 +247,7 @@ ohos_moduletest("ans_innerkits_module_slot_test") { "mock/mock_bundle_mgr_proxy.cpp", "mock/mock_ipc.cpp", "mock/mock_single_kv_store.cpp", + "mock/permission_kit.cpp", ] configs = [ "//utils/native/base:utils_config" ] @@ -271,6 +276,7 @@ ohos_moduletest("ans_innerkits_module_slot_test") { "ces_standard:cesfwk_innerkits", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", + "permission_standard:libpermissionsdk_standard", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] @@ -321,6 +327,7 @@ ohos_moduletest("ans_innerkits_module_setting_test") { "mock/mock_bundle_mgr_proxy.cpp", "mock/mock_ipc.cpp", "mock/mock_single_kv_store.cpp", + "mock/permission_kit.cpp", ] configs = [ "//utils/native/base:utils_config" ] @@ -349,6 +356,7 @@ ohos_moduletest("ans_innerkits_module_setting_test") { "ces_standard:cesfwk_innerkits", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", + "permission_standard:libpermissionsdk_standard", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] diff --git a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp index b90656172..b4e5d98b8 100644 --- a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp +++ b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp @@ -40,13 +40,12 @@ using namespace OHOS::Media; namespace OHOS { namespace Notification { - enum class SubscriberEventType { ON_SUBSCRIBERESULT, ON_UNSUBSCRIBERESULT, ON_DIED, ON_UPDATE, - ON_DISTURBMODECHANGED, + ON_DND_CHANGED, ON_CANCELED, ON_CANCELED_WITH_SORTINGMAP_AND_DELETEREASON, ON_CONSUMED, @@ -117,22 +116,23 @@ private: std::shared_ptr sortingMap_; }; -class OnDisturbModeChangedEvent : public SubscriberEvent { +class OnDoNotDisturbDateChangedEvent : public SubscriberEvent { public: - OnDisturbModeChangedEvent(int disturbMode) - : SubscriberEvent(SubscriberEventType::ON_DISTURBMODECHANGED), disturbMode_(disturbMode) + explicit OnDoNotDisturbDateChangedEvent( + const std::shared_ptr &date) + : SubscriberEvent(SubscriberEventType::ON_DND_CHANGED), date_(date) {} - ~OnDisturbModeChangedEvent() override + ~OnDoNotDisturbDateChangedEvent() override {} - int GetDisturbModeChanged() + const std::shared_ptr &GetDoNotDisturbDate() const { - return disturbMode_; + return date_; } private: - int disturbMode_; + std::shared_ptr date_; }; class OnOnCanceledEvent : public SubscriberEvent { @@ -252,9 +252,9 @@ public: std::unique_lock lck(mtx_); events_.push_back(event); } - void OnDisturbModeChanged(int disturbMode) override + void OnDoNotDisturbDateChange(const std::shared_ptr &date) override { - std::shared_ptr event = std::make_shared(disturbMode); + std::shared_ptr event = std::make_shared(date); std::unique_lock lck(mtx_); events_.push_back(event); } @@ -826,6 +826,7 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_Subscriber_00100, Function | MediumTest | Le } EXPECT_TRUE(waitOnSubscriber); subscriber.ClearEvents(); + EXPECT_EQ(NotificationHelper::UnSubscribeNotification(subscriber, info), ERR_OK); SleepForFC(); } @@ -1193,5 +1194,345 @@ HWTEST_F(AnsFWModuleTest, ANS_FW_MT_PublishNotificationWithPixelMap_00300, Funct EXPECT_EQ(NotificationHelper::PublishNotification(req), (int)ERR_ANS_ICON_OVER_SIZE); } +/** + * + * @tc.number : ANS_FW_MT_OnDoNotDisturbDateChange_00100 + * @tc.name : + * @tc.desc : OnDoNotDisturbDateChange callback. + */ +HWTEST_F(AnsFWModuleTest, ANS_FW_MT_OnDoNotDisturbDateChange_00100, Function | MediumTest | Level1) +{ + TestAnsSubscriber subscriber; + EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); + + NotificationDoNotDisturbDate date(NotificationConstant::DoNotDisturbType::NONE, 0, 0); + EXPECT_EQ(NotificationHelper::SetDoNotDisturbDate(date), ERR_OK); + + std::this_thread::sleep_for(std::chrono::seconds(1)); + + std::list> events = subscriber.GetEvents(); + for (auto event : events) { + if (event->GetType() == SubscriberEventType::ON_DND_CHANGED) { + std::shared_ptr ev = + std::static_pointer_cast(event); + auto date = ev->GetDoNotDisturbDate(); + ASSERT_NE(date, nullptr); + EXPECT_EQ(date->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::NONE); + } + } + + EXPECT_EQ(NotificationHelper::UnSubscribeNotification(subscriber), ERR_OK); +} + +/** + * + * @tc.number : ANS_FW_MT_OnDoNotDisturbDateChange_00200 + * @tc.name : + * @tc.desc : OnDoNotDisturbDateChange callback. + */ +HWTEST_F(AnsFWModuleTest, ANS_FW_MT_OnDoNotDisturbDateChange_00200, Function | MediumTest | Level1) +{ + TestAnsSubscriber subscriber; + EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); + + std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); + auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t beginDate = beginDuration.count(); + timePoint += std::chrono::hours(1); + auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t endDate = endDuration.count(); + NotificationDoNotDisturbDate date(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate); + EXPECT_EQ(NotificationHelper::SetDoNotDisturbDate(date), ERR_OK); + + std::this_thread::sleep_for(std::chrono::seconds(1)); + + std::list> events = subscriber.GetEvents(); + for (auto event : events) { + if (event->GetType() == SubscriberEventType::ON_DND_CHANGED) { + std::shared_ptr ev = + std::static_pointer_cast(event); + auto date = ev->GetDoNotDisturbDate(); + ASSERT_NE(date, nullptr); + EXPECT_EQ(date->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::ONCE); + } + } + + EXPECT_EQ(NotificationHelper::UnSubscribeNotification(subscriber), ERR_OK); +} + +/** + * + * @tc.number : ANS_FW_MT_OnDoNotDisturbDateChange_00300 + * @tc.name : + * @tc.desc : OnDoNotDisturbDateChange callback. + */ +HWTEST_F(AnsFWModuleTest, ANS_FW_MT_OnDoNotDisturbDateChange_00300, Function | MediumTest | Level1) +{ + TestAnsSubscriber subscriber; + EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); + + std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); + auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t beginDate = beginDuration.count(); + timePoint += std::chrono::hours(1); + auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t endDate = endDuration.count(); + NotificationDoNotDisturbDate date(NotificationConstant::DoNotDisturbType::DAILY, beginDate, endDate); + EXPECT_EQ(NotificationHelper::SetDoNotDisturbDate(date), ERR_OK); + + std::this_thread::sleep_for(std::chrono::seconds(1)); + + std::list> events = subscriber.GetEvents(); + for (auto event : events) { + if (event->GetType() == SubscriberEventType::ON_DND_CHANGED) { + std::shared_ptr ev = + std::static_pointer_cast(event); + auto date = ev->GetDoNotDisturbDate(); + ASSERT_NE(date, nullptr); + EXPECT_EQ(date->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::DAILY); + } + } + + EXPECT_EQ(NotificationHelper::UnSubscribeNotification(subscriber), ERR_OK); +} + +/** + * + * @tc.number : ANS_FW_MT_OnDoNotDisturbDateChange_00400 + * @tc.name : + * @tc.desc : OnDoNotDisturbDateChange callback. + */ +HWTEST_F(AnsFWModuleTest, ANS_FW_MT_OnDoNotDisturbDateChange_00400, Function | MediumTest | Level1) +{ + TestAnsSubscriber subscriber; + EXPECT_EQ(NotificationHelper::SubscribeNotification(subscriber), ERR_OK); + + std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); + auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t beginDate = beginDuration.count(); + timePoint += std::chrono::hours(1); + auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t endDate = endDuration.count(); + NotificationDoNotDisturbDate date(NotificationConstant::DoNotDisturbType::CLEARLY, beginDate, endDate); + EXPECT_EQ(NotificationHelper::SetDoNotDisturbDate(date), ERR_OK); + + std::this_thread::sleep_for(std::chrono::seconds(1)); + + std::list> events = subscriber.GetEvents(); + for (auto event : events) { + if (event->GetType() == SubscriberEventType::ON_DND_CHANGED) { + std::shared_ptr ev = + std::static_pointer_cast(event); + auto date = ev->GetDoNotDisturbDate(); + ASSERT_NE(date, nullptr); + EXPECT_EQ(date->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::CLEARLY); + } + } + + EXPECT_EQ(NotificationHelper::UnSubscribeNotification(subscriber), ERR_OK); +} + +static NotificationDoNotDisturbDate GetDoNotDisturbDateInstance( + NotificationConstant::DoNotDisturbType type, int64_t intervalHours) +{ + std::chrono::time_point beginTp = std::chrono::system_clock::now(); + + auto beginDur = std::chrono::duration_cast(beginTp.time_since_epoch()); + auto beginMs = beginDur.count(); + + auto endDur = beginDur + std::chrono::hours(intervalHours); + auto endMs = endDur.count(); + + return {type, beginMs, endMs}; +} + +/** + * + * @tc.number : ANS_FW_MT_GetDoNotDisturbDate_00100 + * @tc.name : + * @tc.desc : GetDoNotDisturbDate. + */ +HWTEST_F(AnsFWModuleTest, ANS_FW_MT_GetDoNotDisturbDate_00100, Function | MediumTest | Level1) +{ + NotificationDoNotDisturbDate setDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0); + EXPECT_EQ(NotificationHelper::SetDoNotDisturbDate(setDate), ERR_OK); + + NotificationDoNotDisturbDate getDate; + EXPECT_EQ(NotificationHelper::GetDoNotDisturbDate(getDate), ERR_OK); + EXPECT_EQ(getDate.GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::NONE); + EXPECT_EQ(getDate.GetBeginDate(), 0); + EXPECT_EQ(getDate.GetEndDate(), 0); +} + +/** + * + * @tc.number : ANS_FW_MT_DoesSupportDoNotDisturbMode_00100 + * @tc.name : + * @tc.desc : DoesSupportDoNotDisturbMode. + */ +HWTEST_F(AnsFWModuleTest, ANS_FW_MT_DoesSupportDoNotDisturbMode_00100, Function | MediumTest | Level1) +{ + bool isSupport = false; + EXPECT_EQ(NotificationHelper::DoesSupportDoNotDisturbMode(isSupport), ERR_OK); + EXPECT_EQ(isSupport, SUPPORT_DO_NOT_DISTRUB); +} + +/** + * @tc.number : ANS_Interface_MT_DoNotDisturb_01000 + * @tc.name : DoNotDisturb_01000 + * @tc.desc : Set and get DoNotDisturbDate. E.g. 01:40 ~ 02:40 + * @tc.expected : Set and get DoNotDisturbDate successfully. + */ +HWTEST_F(AnsFWModuleTest, ANS_FW_MT_DoNotDisturb_01000, Function | MediumTest | Level1) +{ + auto srcDate = GetDoNotDisturbDateInstance(NotificationConstant::DoNotDisturbType::ONCE, 1); + EXPECT_EQ(NotificationHelper::SetDoNotDisturbDate(srcDate), ERR_OK); + + NotificationDoNotDisturbDate disDate; + EXPECT_EQ(NotificationHelper::GetDoNotDisturbDate(disDate), ERR_OK); + + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_01000:: srcDate : beginMs : " << srcDate.GetBeginDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_01000:: srcDate : endMs : " << srcDate.GetEndDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_01000:: disDate : beginMs : " << disDate.GetBeginDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_01000:: disDate : endMs : " << disDate.GetEndDate(); + + EXPECT_EQ(srcDate.GetDoNotDisturbType(), disDate.GetDoNotDisturbType()); +} + +/** + * @tc.number : ANS_Interface_MT_DoNotDisturb_02000 + * @tc.name : DoNotDisturb_02000 + * @tc.desc : Set and get DoNotDisturbDate. E.g. 1970-01-01 01:40 ~ 1970-01-02 01:40 + * @tc.expected : Set and get DoNotDisturbDate successfully. + */ +HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_DoNotDisturb_02000, Function | MediumTest | Level1) +{ + auto srcDate = GetDoNotDisturbDateInstance(NotificationConstant::DoNotDisturbType::ONCE, 24); + EXPECT_EQ(NotificationHelper::SetDoNotDisturbDate(srcDate), ERR_OK); + + NotificationDoNotDisturbDate disDate; + EXPECT_EQ(NotificationHelper::GetDoNotDisturbDate(disDate), ERR_OK); + + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_02000:: srcDate : beginMs : " << srcDate.GetBeginDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_02000:: srcDate : endMs : " << srcDate.GetEndDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_02000:: disDate : beginMs : " << disDate.GetBeginDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_02000:: disDate : endMs : " << disDate.GetEndDate(); + + EXPECT_EQ(srcDate.GetDoNotDisturbType(), disDate.GetDoNotDisturbType()); + + EXPECT_NE(disDate.GetBeginDate(), disDate.GetEndDate()); +} + +/** + * @tc.number : ANS_Interface_MT_DoNotDisturb_03000 + * @tc.name : DoNotDisturb_03000 + * @tc.desc : Set and get DoNotDisturbDate. E.g. 1970-01-01 01:40 ~ 1970-01-02 02:40 + * @tc.expected : Set and get DoNotDisturbDate successfully. + */ +HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_DoNotDisturb_03000, Function | MediumTest | Level1) +{ + auto srcDate = GetDoNotDisturbDateInstance(NotificationConstant::DoNotDisturbType::ONCE, 25); + EXPECT_EQ(NotificationHelper::SetDoNotDisturbDate(srcDate), ERR_OK); + + NotificationDoNotDisturbDate disDate; + EXPECT_EQ(NotificationHelper::GetDoNotDisturbDate(disDate), ERR_OK); + + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_03000:: srcDate : beginMs : " << srcDate.GetBeginDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_03000:: srcDate : endMs : " << srcDate.GetEndDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_03000:: disDate : beginMs : " << disDate.GetBeginDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_03000:: disDate : endMs : " << disDate.GetEndDate(); + + EXPECT_EQ(srcDate.GetDoNotDisturbType(), disDate.GetDoNotDisturbType()); +} + +/** + * @tc.number : ANS_Interface_MT_DoNotDisturb_04000 + * @tc.name : DoNotDisturb_04000 + * @tc.desc : Set and get DoNotDisturbDate. E.g. 01:40 ~ 07:40 + * @tc.expected : Set and get DoNotDisturbDate successfully. + */ +HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_DoNotDisturb_04000, Function | MediumTest | Level1) +{ + auto srcDate = GetDoNotDisturbDateInstance(NotificationConstant::DoNotDisturbType::DAILY, 6); + EXPECT_EQ(NotificationHelper::SetDoNotDisturbDate(srcDate), ERR_OK); + + NotificationDoNotDisturbDate disDate; + EXPECT_EQ(NotificationHelper::GetDoNotDisturbDate(disDate), ERR_OK); + + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_04000:: srcDate : beginMs : " << srcDate.GetBeginDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_04000:: srcDate : endMs : " << srcDate.GetEndDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_04000:: disDate : beginMs : " << disDate.GetBeginDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_04000:: disDate : endMs : " << disDate.GetEndDate(); + + EXPECT_EQ(srcDate.GetDoNotDisturbType(), disDate.GetDoNotDisturbType()); +} + +/** + * @tc.number : ANS_Interface_MT_DoNotDisturb_05000 + * @tc.name : DoNotDisturb_05000 + * @tc.desc : Set and get DoNotDisturbDate. E.g. 1970-01-01 01:40 ~ 1970-01-02 01:40 + * @tc.expected : Set and get DoNotDisturbDate successfully. + */ +HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_DoNotDisturb_05000, Function | MediumTest | Level1) +{ + auto srcDate = GetDoNotDisturbDateInstance(NotificationConstant::DoNotDisturbType::DAILY, 24); + EXPECT_EQ(NotificationHelper::SetDoNotDisturbDate(srcDate), ERR_OK); + + NotificationDoNotDisturbDate disDate; + EXPECT_EQ(NotificationHelper::GetDoNotDisturbDate(disDate), ERR_OK); + + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_05000:: srcDate : beginMs : " << srcDate.GetBeginDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_05000:: srcDate : endMs : " << srcDate.GetEndDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_05000:: disDate : beginMs : " << disDate.GetBeginDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_05000:: disDate : endMs : " << disDate.GetEndDate(); + + EXPECT_EQ(srcDate.GetDoNotDisturbType(), disDate.GetDoNotDisturbType()); + + EXPECT_NE(disDate.GetBeginDate(), disDate.GetEndDate()); +} + +/** + * @tc.number : ANS_Interface_MT_DoNotDisturb_06000 + * @tc.name : DoNotDisturb_06000 + * @tc.desc : Set and get DoNotDisturbDate. E.g. 1970-01-01 01:40 ~ 1970-01-02 02:40 + * @tc.expected : Set and get DoNotDisturbDate successfully. + */ +HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_DoNotDisturb_06000, Function | MediumTest | Level1) +{ + auto srcDate = GetDoNotDisturbDateInstance(NotificationConstant::DoNotDisturbType::DAILY, 25); + EXPECT_EQ(NotificationHelper::SetDoNotDisturbDate(srcDate), ERR_OK); + + NotificationDoNotDisturbDate disDate; + EXPECT_EQ(NotificationHelper::GetDoNotDisturbDate(disDate), ERR_OK); + + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_06000:: srcDate : beginMs : " << srcDate.GetBeginDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_06000:: srcDate : endMs : " << srcDate.GetEndDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_06000:: disDate : beginMs : " << disDate.GetBeginDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_06000:: disDate : endMs : " << disDate.GetEndDate(); + + EXPECT_EQ(srcDate.GetDoNotDisturbType(), disDate.GetDoNotDisturbType()); +} + +/** + * @tc.number : ANS_Interface_MT_DoNotDisturb_07000 + * @tc.name : DoNotDisturb_07000 + * @tc.desc : Set and get DoNotDisturbDate. E.g. 1970-01-01 01:40 ~ 1970-01-03 01:40 + * @tc.expected : Set and get DoNotDisturbDate successfully. + */ +HWTEST_F(AnsFWModuleTest, ANS_Interface_MT_DoNotDisturb_07000, Function | MediumTest | Level1) +{ + auto srcDate = GetDoNotDisturbDateInstance(NotificationConstant::DoNotDisturbType::CLEARLY, 48); + EXPECT_EQ(NotificationHelper::SetDoNotDisturbDate(srcDate), ERR_OK); + + NotificationDoNotDisturbDate disDate; + EXPECT_EQ(NotificationHelper::GetDoNotDisturbDate(disDate), ERR_OK); + + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_07000:: srcDate : beginMs : " << srcDate.GetBeginDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_07000:: srcDate : endMs : " << srcDate.GetEndDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_07000:: disDate : beginMs : " << disDate.GetBeginDate(); + GTEST_LOG_(INFO) << "ANS_Interface_MT_DoNotDisturb_07000:: disDate : endMs : " << disDate.GetEndDate(); + + EXPECT_EQ(srcDate.GetDoNotDisturbType(), disDate.GetDoNotDisturbType()); +} } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp index e32c361fb..aae3d31d7 100644 --- a/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp +++ b/frameworks/ans/test/moduletest/ans_innerkits_module_publish_test.cpp @@ -53,9 +53,6 @@ const int32_t CASE_TEN = 10; const int32_t CASE_ELEVEN = 11; const int32_t CASE_TWELVE = 12; const int32_t CASE_THIRTEEN = 13; -const int32_t CASE_FOURTEEN = 14; -const int32_t CASE_FIFTEEN = 15; -const int32_t CASE_SIXTEEN = 16; const int32_t CALLING_UID = 9999; const int32_t PIXEL_MAP_TEST_WIDTH = 32; @@ -90,7 +87,7 @@ public: virtual void OnUpdate(const std::shared_ptr &sortingMap) override {} - virtual void OnDisturbModeChanged(int disturbMode) override + virtual void OnDoNotDisturbDateChange(const std::shared_ptr &date) override {} virtual void OnCanceled(const std::shared_ptr &request) override @@ -108,7 +105,6 @@ public: OnConsumedReceived = true; g_consumed_mtx.unlock(); NotificationRequest notificationRequest = request->GetNotificationRequest(); - NotificationConstant::DisturbMode disturbMode; if (CASE_ONE == notificationRequest.GetNotificationId()) { CheckCaseOneResult(notificationRequest); } else if (CASE_TWO == notificationRequest.GetNotificationId()) { @@ -134,15 +130,6 @@ public: } else if (CASE_TWELVE == notificationRequest.GetNotificationId()) { EXPECT_EQ(NotificationConstant::CUSTOM, notificationRequest.GetSlotType()); } else if (CASE_THIRTEEN == notificationRequest.GetNotificationId()) { - EXPECT_EQ(0, NotificationHelper::GetDisturbMode(disturbMode)); - EXPECT_EQ(NotificationConstant::ALLOW_ALARMS, disturbMode); - } else if (CASE_FOURTEEN == notificationRequest.GetNotificationId()) { - EXPECT_EQ(0, NotificationHelper::GetDisturbMode(disturbMode)); - EXPECT_EQ(NotificationConstant::ALLOW_ALL, disturbMode); - } else if (CASE_FIFTEEN == notificationRequest.GetNotificationId()) { - EXPECT_EQ(0, NotificationHelper::GetDisturbMode(disturbMode)); - EXPECT_EQ(NotificationConstant::ALLOW_NONE, disturbMode); - } else if (CASE_SIXTEEN == notificationRequest.GetNotificationId()) { EXPECT_EQ(NotificationRequest::GroupAlertType::ALL, notificationRequest.GetGroupAlertType()); EXPECT_EQ(true, notificationRequest.IsGroupOverview()); } else { @@ -1007,111 +994,6 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_03000, Function WaitOnUnsubscribeResult(); } -/** - * @tc.number : ANS_Interface_MT_Publish_04000 - * @tc.name : Publish_04000 - * @tc.desc : Add notification slot(type is SOCIAL_COMMUNICATION), make a subscriber and publish a notification in - * disturbed mode (mode is ALLOW_ALARMS) - * @tc.expected : Add notification slot success, make a subscriber and a publish notification in undisturbed mode - * success. - */ -HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_04000, Function | MediumTest | Level1) -{ - NotificationSlot slot(NotificationConstant::SOCIAL_COMMUNICATION); - EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot)); - auto subscriber = TestAnsSubscriber(); - g_subscribe_mtx.lock(); - EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber)); - WaitOnSubscribeResult(); - EXPECT_EQ(0, NotificationHelper::SetDisturbMode(NotificationConstant::ALLOW_ALARMS)); - MessageUser messageUser; - std::shared_ptr normalContent = std::make_shared(); - EXPECT_NE(normalContent, nullptr); - std::shared_ptr content = std::make_shared(normalContent); - EXPECT_NE(content, nullptr); - NotificationRequest req; - req.SetContent(content); - req.SetSlotType(NotificationConstant::SOCIAL_COMMUNICATION); - req.SetClassification(CLASSIFICATION_ALARM); - req.SetNotificationId(CASE_THIRTEEN); - g_consumed_mtx.lock(); - EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); - WaitOnConsumed(); - g_unsubscribe_mtx.lock(); - EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(subscriber)); - WaitOnUnsubscribeResult(); -} - -/** - * @tc.number : ANS_Interface_MT_Publish_05000 - * @tc.name : Publish_05000 - * @tc.desc : Add notification slot(type is SOCIAL_COMMUNICATION), make a subscriber and publish a notification - * in disturbed mode (mode is ALLOW_ALL) - * @tc.expected : Add notification slot success, make a subscriber and pulish a notification in undisturbed mode - * success. - */ -HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_05000, Function | MediumTest | Level1) -{ - NotificationSlot slot(NotificationConstant::SOCIAL_COMMUNICATION); - EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot)); - auto subscriber = TestAnsSubscriber(); - g_subscribe_mtx.lock(); - EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber)); - WaitOnSubscribeResult(); - EXPECT_EQ(0, NotificationHelper::SetDisturbMode(NotificationConstant::ALLOW_ALL)); - MessageUser messageUser; - std::shared_ptr normalContent = std::make_shared(); - EXPECT_NE(normalContent, nullptr); - std::shared_ptr content = std::make_shared(normalContent); - EXPECT_NE(content, nullptr); - NotificationRequest req; - req.SetContent(content); - req.SetSlotType(NotificationConstant::SOCIAL_COMMUNICATION); - req.SetNotificationId(CASE_FOURTEEN); - g_consumed_mtx.lock(); - EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); - WaitOnConsumed(); - // Wait OnUnsubscribeResult - g_unsubscribe_mtx.lock(); - EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(subscriber)); - WaitOnUnsubscribeResult(); -} - -/** - * @tc.number : ANS_Interface_MT_Publish_06000 - * @tc.name : Publish_06000 - * @tc.desc : Add notification slot(type is SOCIAL_COMMUNICATION), make a subscriber and publish a notification - * in disturbed mode (mode is ALLOW_NONE) - * @tc.expected : Add notification slot success, make a subscriber and pulush a notification in undisturbed mode - * success. - */ -HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_06000, Function | MediumTest | Level1) -{ - NotificationSlot slot(NotificationConstant::SOCIAL_COMMUNICATION); - slot.EnableBypassDnd(true); - EXPECT_EQ(0, NotificationHelper::AddNotificationSlot(slot)); - auto subscriber = TestAnsSubscriber(); - g_subscribe_mtx.lock(); - EXPECT_EQ(0, NotificationHelper::SubscribeNotification(subscriber)); - WaitOnSubscribeResult(); - EXPECT_EQ(0, NotificationHelper::SetDisturbMode(NotificationConstant::ALLOW_NONE)); - MessageUser messageUser; - std::shared_ptr normalContent = std::make_shared(); - EXPECT_NE(normalContent, nullptr); - std::shared_ptr content = std::make_shared(normalContent); - EXPECT_NE(content, nullptr); - NotificationRequest req; - req.SetContent(content); - req.SetSlotType(NotificationConstant::SOCIAL_COMMUNICATION); - req.SetNotificationId(CASE_FIFTEEN); - g_consumed_mtx.lock(); - EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); - WaitOnConsumed(); - g_unsubscribe_mtx.lock(); - EXPECT_EQ(0, NotificationHelper::UnSubscribeNotification(subscriber)); - WaitOnUnsubscribeResult(); -} - /** * @tc.number : ANS_Interface_MT_Publish_07000 * @tc.name : Publish_07000 @@ -1138,7 +1020,7 @@ HWTEST_F(AnsInterfaceModulePublishTest, ANS_Interface_MT_Publish_07000, Function req.SetSlotType(NotificationConstant::SOCIAL_COMMUNICATION); req.SetGroupName("groupnotifcation"); req.SetGroupOverview(true); - req.SetNotificationId(CASE_SIXTEEN); + req.SetNotificationId(CASE_THIRTEEN); req.SetGroupAlertType(NotificationRequest::GroupAlertType::ALL); g_consumed_mtx.lock(); EXPECT_EQ(0, NotificationHelper::PublishNotification(req)); diff --git a/frameworks/ans/test/moduletest/ans_mt_constant.h b/frameworks/ans/test/moduletest/ans_mt_constant.h index 99d2a2796..855cf4dff 100644 --- a/frameworks/ans/test/moduletest/ans_mt_constant.h +++ b/frameworks/ans/test/moduletest/ans_mt_constant.h @@ -20,7 +20,6 @@ namespace OHOS { namespace Notification { - namespace { const std::string APP_NAME = "bundleName"; const std::string NOTIFICATION_LABEL_0 = "Label0"; @@ -34,7 +33,6 @@ constexpr int CANCEL_REASON_DELETE = 2; constexpr int APP_CANCEL_REASON_DELETE = 8; constexpr int APP_CANCEL_ALL_REASON_DELETE = 9; } // namespace - } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/test/moduletest/mock/permission_kit.cpp b/frameworks/ans/test/moduletest/mock/permission_kit.cpp new file mode 100644 index 000000000..36855b9de --- /dev/null +++ b/frameworks/ans/test/moduletest/mock/permission_kit.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "permission/permission_kit.h" + +namespace OHOS { +namespace Security { +namespace Permission { +using namespace std; + +int PermissionKit::VerifyPermission(const string &bundleName, const string &permissionName, int userId) +{ + return TypePermissionState::PERMISSION_GRANTED; +} + +bool PermissionKit::CanRequestPermission(const string &bundleName, const string &permissionName, int userId) +{ + return 0; +} + +int PermissionKit::GrantUserGrantedPermission(const string &bundleName, const string &permissionName, int userId) +{ + return 0; +} + +int PermissionKit::GrantSystemGrantedPermission(const string &bundleName, const string &permissionName) +{ + return 0; +} + +int PermissionKit::RevokeUserGrantedPermission(const string &bundleName, const string &permissionName, int userId) +{ + return 0; +} + +int PermissionKit::RevokeSystemGrantedPermission(const string &bundleName, const string &permissionName) +{ + return 0; +} + +int PermissionKit::AddUserGrantedReqPermissions( + const string &bundleName, const std::vector &permList, int userId) +{ + return 0; +} + +int PermissionKit::AddSystemGrantedReqPermissions(const string &bundleName, const std::vector &permList) +{ + return 0; +} + +int PermissionKit::RemoveUserGrantedReqPermissions(const string &bundleName, int userId) +{ + return 0; +} + +int PermissionKit::RemoveSystemGrantedReqPermissions(const string &bundleName) +{ + return 0; +} + +int PermissionKit::AddDefPermissions(const std::vector &permList) +{ + return 0; +} + +int PermissionKit::RemoveDefPermissions(const string &bundleName) +{ + return 0; +} + +int PermissionKit::GetDefPermission(const string &permissionName, PermissionDef &permissionDefResult) +{ + return 0; +} +} // namespace Permission +} // namespace Security +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/wantagent/src/want_agent_helper.cpp b/frameworks/wantagent/src/want_agent_helper.cpp index 5b3c49c1b..fcb6d2757 100644 --- a/frameworks/wantagent/src/want_agent_helper.cpp +++ b/frameworks/wantagent/src/want_agent_helper.cpp @@ -152,6 +152,7 @@ std::shared_ptr WantAgentHelper::GetWantAgent(const WantAgentInfo &pa wantSenderInfo.allWants.push_back(wantsInfo); wantSenderInfo.bundleName = want->GetOperation().GetBundleName(); wantSenderInfo.flags = FlagsTransformer(paramsInfo.GetFlags()); + wantSenderInfo.type = (int32_t)paramsInfo.GetOperationType(); sptr target = AbilityManagerClient::GetInstance()->GetWantSender(wantSenderInfo, nullptr); if (target == nullptr) { diff --git a/interfaces/innerkits/ans/native/include/notification_constant.h b/interfaces/innerkits/ans/native/include/notification_constant.h index 554699724..dcf4fe973 100644 --- a/interfaces/innerkits/ans/native/include/notification_constant.h +++ b/interfaces/innerkits/ans/native/include/notification_constant.h @@ -22,16 +22,6 @@ namespace OHOS { namespace Notification { class NotificationConstant { public: - enum DisturbMode { - ALLOW_ALARMS, // Indicates that only notifications of the NotificationRequest::CLASSIFICATION_ALARM - // category are allowed to interrupt the user in Do Not Disturb mode. - ALLOW_ALL, // Indicates that all notifications are allowed to interrupt the user in Do Not Disturb mode. - ALLOW_NONE, // Indicates that no notifications are allowed to interrupt the user in Do Not Disturb mode. - ALLOW_PRIORITY, // Indicates that only notifications meeting the specified priority criteria are allowed - // to interrupt the user in Do Not Disturb mode. - ALLOW_UNKNOWN, // Indicates the value returned if the Do Not Disturb mode type cannot be obtained. - }; - enum InputEditType { EDIT_AUTO, // Indicates that the system determines whether to allow the user to edit the options before they // are sent to the application. @@ -94,6 +84,13 @@ public: SECRET }; + enum class DoNotDisturbType { + NONE = 0, + ONCE = 1, // only once + DAILY = 2, // every day + CLEARLY = 3, // time period + }; + /** * Indicates that a notification is deleted because it is clicked. */ diff --git a/interfaces/innerkits/ans/native/include/notification_conversational_content.h b/interfaces/innerkits/ans/native/include/notification_conversational_content.h index 5b91d30e2..7ff86bac9 100644 --- a/interfaces/innerkits/ans/native/include/notification_conversational_content.h +++ b/interfaces/innerkits/ans/native/include/notification_conversational_content.h @@ -52,7 +52,7 @@ public: /** * Sets the title to be displayed for the conversation. - * The title set in this method will overwrite the one set by calling setTitle(std::tring). + * The title set in this method will overwrite the one set by calling setTitle(std::string). * @param conversationTitle Indicates the title to be displayed for the conversation. */ void SetConversationTitle(const std::string &conversationTitle); diff --git a/interfaces/innerkits/ans/native/include/notification_do_not_disturb_date.h b/interfaces/innerkits/ans/native/include/notification_do_not_disturb_date.h new file mode 100644 index 000000000..0f08ea71d --- /dev/null +++ b/interfaces/innerkits/ans/native/include/notification_do_not_disturb_date.h @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef BASE_NOTIFICATION_ANS_STANDARD_NATIVE_INCLUDE_NOTIFICATION_DO_NOT_DISTURB_DATE_H +#define BASE_NOTIFICATION_ANS_STANDARD_NATIVE_INCLUDE_NOTIFICATION_DO_NOT_DISTURB_DATE_H + +#include "notification_constant.h" +#include "parcel.h" + +namespace OHOS { +namespace Notification { +class NotificationDoNotDisturbDate : public Parcelable { +public: + /** + * Default constructor used to create a NotificationDoNotDisturbDate instance. + */ + NotificationDoNotDisturbDate() = default; + + /** + * A constructor used to create a NotificationDoNotDisturbDate instance with the input parameters passed. + * @param doNotDisturbType Indicates the do not disturb type to add. + * @param beginDate Indicates the begin time to add. + * @param endDate Indicates the begin time to add. + */ + NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType doNotDisturbType, + int64_t beginDate, int64_t endDate); + + /** + * Default deconstructor used to deconstruct. + */ + ~NotificationDoNotDisturbDate() = default; + + /** + * Sets do not disturb type for this NotificationDoNotDisturbDate. + * @param doNotDisturbType Indicates the do not disturb type to add. + * For available values, see NotificationConstant::DoNotDisturbType. + */ + void SetDoNotDisturbType(NotificationConstant::DoNotDisturbType doNotDisturbType); + + /** + * Obtains the do not disturb type of this NotificationDoNotDisturbDate. + * @return the do not disturb type of this NotificationDoNotDisturbDate, + * as enumerated in NotificationConstant::DoNotDisturbType. + */ + NotificationConstant::DoNotDisturbType GetDoNotDisturbType() const; + + /** + * Sets begin time for this NotificationDoNotDisturbDate. + * @param beginDate Indicates the begin time to add. + */ + void SetBeginDate(const int64_t beginDate); + + /** + * Obtains the begin time of this NotificationDoNotDisturbDate. + * @return the begin time of this NotificationDoNotDisturbDate. + */ + int64_t GetBeginDate() const; + + /** + * Sets end time for this NotificationDoNotDisturbDate. + * @param endDate Indicates the end time to add. + */ + void SetEndDate(const int64_t endDate); + + /** + * Obtains the end time of this NotificationDoNotDisturbDate. + * @return the end time of this NotificationDoNotDisturbDate. + */ + int64_t GetEndDate() const; + + /** + * Returns a string representation of the object. + * @return a string representation of the object. + */ + std::string Dump(); + + /** + * Marshal a object into a Parcel. + * @param parcel the object into the parcel + */ + virtual bool Marshalling(Parcel &parcel) const override; + + /** + * Unmarshal object from a Parcel. + * @return the NotificationDoNotDisturbDate + */ + static NotificationDoNotDisturbDate *Unmarshalling(Parcel &parcel); + +private: + /** + * Read a NotificationDoNotDisturbDate object from a Parcel. + * @param parcel the parcel + */ + bool ReadFromParcel(Parcel &parcel); + +private: + NotificationConstant::DoNotDisturbType doNotDisturbType_ {NotificationConstant::DoNotDisturbType::NONE}; + int64_t beginDate_ {0}; + int64_t endDate_ {0}; +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_ANS_STANDARD_NATIVE_INCLUDE_NOTIFICATION_DO_NOT_DISTURB_DATE_H \ No newline at end of file diff --git a/interfaces/innerkits/ans/native/include/notification_helper.h b/interfaces/innerkits/ans/native/include/notification_helper.h index f0873ff22..73bd56b50 100644 --- a/interfaces/innerkits/ans/native/include/notification_helper.h +++ b/interfaces/innerkits/ans/native/include/notification_helper.h @@ -17,6 +17,7 @@ #define BASE_NOTIFICATION_ANS_STANDARD_KITS_NATIVE_INCLUDE_NOTIFICATION_HELPER_H #include "notification_bundle_option.h" +#include "notification_do_not_disturb_date.h" #include "notification_request.h" #include "notification_slot.h" #include "notification_slot_group.h" @@ -96,7 +97,7 @@ public: * calling NotificationSlot::SetSlotGroup(string). * @note A NotificationSlotGroup instance cannot be used directly after being initialized. * Instead, you have to call this method to create a notification slot group so that you can bind - * NotificationSlot objects to it. + * NotificationSlot objects to it. * * @param slotGroup Indicates the notification slot group to be created, which is set by NotificationSlotGroup. * This parameter must be specified. the notification slot to be created, which is set by @@ -334,9 +335,9 @@ public: * @note To subscribe to a notification, inherit the {NotificationSubscriber} class, override its * callback methods and create a subscriber. The subscriber will be used as a parameter of this method. * After the notification is published, subscribers that meet the filter criteria can receive the - * notification. To subscribe to notifications published only by specified sources, for example, notifications from - * certain applications, call the {SubscribeNotification(NotificationSubscriber, NotificationSubscribeInfo)} - * method. + * notification. To subscribe to notifications published only by specified sources, for example, + * notifications from certain applications, + * call the {SubscribeNotification(NotificationSubscriber, NotificationSubscribeInfo)} method. * * @param subscriber Indicates the {NotificationSubscriber} to receive notifications. * This parameter must be specified. @@ -352,8 +353,8 @@ public: * To subscribe to a notification, inherit the {NotificationSubscriber} class, override its * callback methods and create a subscriber. The subscriber will be used as a parameter of this method. * After the notification is published, subscribers that meet the filter criteria can receive the - * notification. To subscribe to and receive all notifications, call the - * {SubscribeNotification(NotificationSubscriber)} method. + * notification. To subscribe to and receive all notifications, call the + * {SubscribeNotification(NotificationSubscriber)} method. * * @param subscriber Indicates the subscribers to receive notifications. This parameter must be specified. * For details, see {NotificationSubscriber}. @@ -509,8 +510,8 @@ public: * @param deviceId Indicates the ID of the device running the application. At present, this parameter can only * be null or an empty string, indicating the current device. * @param enabled Specifies whether to allow all applications to publish notifications. The value true - * indicates that notifications are allowed, and the value false indicates that notifications are not - * allowed. + * indicates that notifications are allowed, and the value false indicates that notifications + * are not allowed. * @return Returns set notifications enabled for all bundles result. */ static ErrCode SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled); @@ -569,25 +570,6 @@ public: */ static ErrCode GetShowBadgeEnabled(bool &enabled); - /** - * Sets the type of the Do Not Disturb mode. The Do Not Disturb mode type specifies the type of notifications - * that are allowed to interrupt users. - * @note Your application must have system signature to call this method. - * - * @param mode Indicates the Do Not Disturb mode to set. The value must be - * {NotificationConstant.DisturbMode.ALLOW_ALL}, {NotificationConstant.DisturbMode.ALLOW_PRIORITY}, - * {NotificationConstant.DisturbMode.ALLOW_NONE}, or {NotificationConstant.DisturbMode.ALLOW_ALARMS}. - * @return Returns set disturb mode result. - */ - static ErrCode SetDisturbMode(NotificationConstant::DisturbMode mode); - - /** - * Obtains the Disturb Mode. - * @param disturbMode The current type of the Do Not Disturb mode. - * @return Returns get disturb mode result. - */ - static ErrCode GetDisturbMode(NotificationConstant::DisturbMode &disturbMode); - /** * Cancel the notification of the specified group of this application. * @@ -604,6 +586,32 @@ public: * @return Returns remove group by bundle result. */ static ErrCode RemoveGroupByBundle(const NotificationBundleOption &bundleOption, const std::string &groupName); + + /** + * Sets the do not disturb time. + * @note Your application must have system signature to call this method. + * + * @param doNotDisturbDate Indicates the do not disturb time to set. + * @return Returns set do not disturb time result. + */ + static ErrCode SetDoNotDisturbDate(const NotificationDoNotDisturbDate & doNotDisturbDate); + + /** + * Obtains the do not disturb time. + * @note Your application must have system signature to call this method. + * + * @param doNotDisturbDate Indicates the do not disturb time to get. + * @return Returns set do not disturb time result. + */ + static ErrCode GetDoNotDisturbDate(NotificationDoNotDisturbDate & doNotDisturbDate); + + /** + * Obtains the flag that whether to support do not disturb mode. + * + * @param doesSupport Specifies whether to support do not disturb mode. + * @return Returns check result. + */ + static ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport); }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/innerkits/ans/native/include/notification_slot.h b/interfaces/innerkits/ans/native/include/notification_slot.h index f9594c65e..b8adaaf72 100644 --- a/interfaces/innerkits/ans/native/include/notification_slot.h +++ b/interfaces/innerkits/ans/native/include/notification_slot.h @@ -240,8 +240,8 @@ public: * @note If an empty array or null is passed to this method, the system then calls * SetEnableVibration(bool) with the input parameter set to false. * If a valid value is passed to this method, the system calls SetEnableVibration(bool) with the input - * parameter set to true. This method takes effect only before - * NotificationHelper::AddNotificationSlot(NotificationSlot) is called. + * parameter set to true. This method takes effect only before + * NotificationHelper::AddNotificationSlot(NotificationSlot) is called. * * @param vibration Indicates the vibration style to set. */ diff --git a/interfaces/innerkits/ans/native/include/notification_slot_group.h b/interfaces/innerkits/ans/native/include/notification_slot_group.h index f979cdd93..723128910 100644 --- a/interfaces/innerkits/ans/native/include/notification_slot_group.h +++ b/interfaces/innerkits/ans/native/include/notification_slot_group.h @@ -30,7 +30,7 @@ public: * * @param id Indicates the ID of the NotificationSlotGroup. * The ID must be unique and its length must not exceed 1000 characters (the excess part is automatically - * truncated). + * truncated). * @param name Indicates the name of the NotificationSlotGroup. * Its length must not exceed 1000 characters (the excess part is automatically truncated). */ diff --git a/interfaces/innerkits/ans/native/include/notification_subscriber.h b/interfaces/innerkits/ans/native/include/notification_subscriber.h index 114a52f8b..54ce4f337 100644 --- a/interfaces/innerkits/ans/native/include/notification_subscriber.h +++ b/interfaces/innerkits/ans/native/include/notification_subscriber.h @@ -20,7 +20,6 @@ #include "ans_manager_interface.h" #include "ans_subscriber_stub.h" -#include "notification_constant.h" #include "notification_request.h" #include "notification_sorting.h" #include "notification_sorting_map.h" @@ -98,11 +97,11 @@ public: virtual void OnDied() = 0; /** - * @brief Called when the Do Not Disturb mode type changes. + * @brief Called when the Do Not Disturb date changes. * - * @param disturbMode Indicates the current Do Not Disturb mode type. + * @param date Indicates the current Do Not Disturb date. **/ - virtual void OnDisturbModeChanged(int disturbMode) = 0; + virtual void OnDoNotDisturbDateChange(const std::shared_ptr &date) = 0; private: class SubscriberImpl final : public AnsSubscriberStub { @@ -139,7 +138,7 @@ private: void OnUpdated(const sptr ¬ificationMap) override; - void OnDisturbModeChanged(NotificationConstant::DisturbMode mode) override; + void OnDoNotDisturbDateChange(const sptr &date) override; bool GetAnsManagerProxy(); diff --git a/interfaces/kits/napi/ans/include/common.h b/interfaces/kits/napi/ans/include/common.h index bf1977401..c95b1a1fd 100644 --- a/interfaces/kits/napi/ans/include/common.h +++ b/interfaces/kits/napi/ans/include/common.h @@ -87,6 +87,8 @@ enum DisturbMode { ALLOW_UNKNOWN, ALLOW_ALL, ALLOW_PRIORITY, ALLOW_NONE, ALLOW_A enum InputEditType { EDIT_AUTO, EDIT_DISABLED, EDIT_ENABLED }; +enum DoNotDisturbType { TYPE_NONE, TYPE_ONCE, TYPE_DAILY, TYPE_CLEARLY }; + struct NotificationSubscribeInfo { std::vector bundleNames; int userId = 0; @@ -140,6 +142,8 @@ public: static napi_value JSParaError(const napi_env &env, const napi_ref &callback); + static napi_value ParseParaOnlyCallback(const napi_env &env, const napi_callback_info &info, napi_ref &callback); + static napi_value SetNotification( const napi_env &env, OHOS::Notification::Notification *notification, napi_value &result); @@ -180,6 +184,9 @@ public: static napi_value SetNotificationActionButton( const napi_env &env, const std::shared_ptr &actionButton, napi_value &result); + static napi_value SetDoNotDisturbDate( + const napi_env &env, const NotificationDoNotDisturbDate &date, napi_value &result); + static napi_value GetNotificationSubscriberInfo( const napi_env &env, const napi_value &value, NotificationSubscribeInfo &result); @@ -212,7 +219,9 @@ public: static bool ReasonCToJS(const int &inType, int &outType); - static bool DisturbModeJSToC(const enum DisturbMode &inType, enum NotificationConstant::DisturbMode &outType); + static bool DoNotDisturbTypeJSToC(const DoNotDisturbType &inType, NotificationConstant::DoNotDisturbType &outType); + + static bool DoNotDisturbTypeCToJS(const NotificationConstant::DoNotDisturbType &inType, DoNotDisturbType &outType); static napi_value CreateWantAgentByJS(const napi_env &env, const std::shared_ptr &agent); @@ -221,6 +230,8 @@ private: static const int ARGS_TWO = 2; static const int PARAM0 = 0; static const int PARAM1 = 1; + static const int ONLY_CALLBACK_MAX_PARA = 1; + static const int ONLY_CALLBACK_MIN_PARA = 0; static std::set> wantAgent_; }; diff --git a/interfaces/kits/napi/ans/include/constant.h b/interfaces/kits/napi/ans/include/constant.h index 249864af9..96cb86f39 100644 --- a/interfaces/kits/napi/ans/include/constant.h +++ b/interfaces/kits/napi/ans/include/constant.h @@ -30,6 +30,7 @@ napi_value InputsSourceInit(napi_env env, napi_value exports); napi_value DoNotDisturbMode(napi_env env, napi_value exports); napi_value InputEditTypeInit(napi_env env, napi_value exports); napi_value ContentTypeInit(napi_env env, napi_value exports); +napi_value DoNotDisturbTypeInit(napi_env env, napi_value exports); napi_value ConstantInit(napi_env env, napi_value exports); } // namespace NotificationNapi diff --git a/interfaces/kits/napi/ans/include/disturb_mode.h b/interfaces/kits/napi/ans/include/disturb_mode.h index 9a199f9a7..5b86d6eec 100644 --- a/interfaces/kits/napi/ans/include/disturb_mode.h +++ b/interfaces/kits/napi/ans/include/disturb_mode.h @@ -21,7 +21,9 @@ namespace OHOS { namespace NotificationNapi { using namespace OHOS::Notification; -napi_value SetDoNotDisturbMode(napi_env env, napi_callback_info info); +napi_value SetDoNotDisturbDate(napi_env env, napi_callback_info info); +napi_value GetDoNotDisturbDate(napi_env env, napi_callback_info info); +napi_value SupportDoNotDisturbMode(napi_env env, napi_callback_info info); } // namespace NotificationNapi } // namespace OHOS diff --git a/interfaces/kits/napi/ans/include/subscribe.h b/interfaces/kits/napi/ans/include/subscribe.h index 77a3174cb..08c0df5e3 100644 --- a/interfaces/kits/napi/ans/include/subscribe.h +++ b/interfaces/kits/napi/ans/include/subscribe.h @@ -45,7 +45,7 @@ public: virtual void OnDied() override; - virtual void OnDisturbModeChanged(int disturbMode) override; + virtual void OnDoNotDisturbDateChange(const std::shared_ptr &date) override; void SetCallbackInfo(const napi_env &env, const std::string &type, const napi_ref &ref); @@ -64,6 +64,8 @@ private: void SetDisturbModeCallbackInfo(const napi_env &env, const napi_ref &ref); + void SetDisturbDateCallbackInfo(const napi_env &env, const napi_ref &ref); + private: struct CallbackInfo { napi_env env = nullptr; @@ -77,6 +79,8 @@ private: CallbackInfo unsubscribeCallbackInfo_; CallbackInfo dieCallbackInfo_; CallbackInfo disturbModeCallbackInfo_; + CallbackInfo disturbDateCallbackInfo_; + }; struct SubscriberInstancesInfo { diff --git a/interfaces/kits/napi/ans/src/common.cpp b/interfaces/kits/napi/ans/src/common.cpp index 62765bfd5..0db4a1946 100644 --- a/interfaces/kits/napi/ans/src/common.cpp +++ b/interfaces/kits/napi/ans/src/common.cpp @@ -200,6 +200,27 @@ napi_value Common::JSParaError(const napi_env &env, const napi_ref &callback) } } +napi_value Common::ParseParaOnlyCallback(const napi_env &env, const napi_callback_info &info, napi_ref &callback) +{ + ANS_LOGI("enter"); + + size_t argc = ONLY_CALLBACK_MAX_PARA; + napi_value argv[ONLY_CALLBACK_MAX_PARA] = {nullptr}; + napi_value thisVar = nullptr; + NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); + NAPI_ASSERT(env, argc >= ONLY_CALLBACK_MIN_PARA, "Wrong number of arguments"); + + // argv[0]:callback + napi_valuetype valuetype = napi_undefined; + if (argc >= ONLY_CALLBACK_MAX_PARA) { + NAPI_CALL(env, napi_typeof(env, argv[ONLY_CALLBACK_MIN_PARA], &valuetype)); + NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); + napi_create_reference(env, argv[ONLY_CALLBACK_MIN_PARA], 1, &callback); + } + + return Common::NapiGetNull(env); +} + napi_value Common::SetNotification( const napi_env &env, OHOS::Notification::Notification *notification, napi_value &result) { @@ -987,6 +1008,34 @@ napi_value Common::SetNotificationActionButton( return NapiGetboolean(env, true); } +napi_value Common::SetDoNotDisturbDate( + const napi_env &env, const NotificationDoNotDisturbDate &date, napi_value &result) +{ + ANS_LOGI("enter"); + enum DoNotDisturbType outType = DoNotDisturbType::TYPE_NONE; + if (DoNotDisturbTypeCToJS(date.GetDoNotDisturbType(), outType)) { + // type:DoNotDisturbType + napi_value typeNapi = nullptr; + napi_create_int32(env, outType, &typeNapi); + napi_set_named_property(env, result, "type", typeNapi); + + // begin:Date + double begind = double(date.GetBeginDate()); + napi_value beginNapi = nullptr; + napi_create_date(env, begind, &beginNapi); + napi_set_named_property(env, result, "begin", beginNapi); + + // end:Date + double endd = double(date.GetEndDate()); + napi_value endNapi = nullptr; + napi_create_date(env, endd, &endNapi); + napi_set_named_property(env, result, "end", endNapi); + } else { + return NapiGetboolean(env, false); + } + return NapiGetboolean(env, true); +} + napi_value Common::GetNotificationSubscriberInfo( const napi_env &env, const napi_value &value, NotificationSubscribeInfo &subscriberInfo) { @@ -2733,18 +2782,6 @@ napi_value Common::GetNotificationSlot(const napi_env &env, const napi_value &va slot.SetLockscreenVisibleness(NotificationConstant::VisiblenessType(lockscreenVisibility)); } - // vibrationEnabled?: boolean - NAPI_CALL(env, napi_has_named_property(env, value, "vibrationEnabled", &hasProperty)); - if (hasProperty) { - bool vibrationEnabled = false; - napi_get_named_property(env, value, "vibrationEnabled", &nobj); - NAPI_CALL(env, napi_typeof(env, nobj, &valuetype)); - NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); - napi_get_value_bool(env, nobj, &vibrationEnabled); - ANS_LOGI("vibrationEnabled is: %{public}d", vibrationEnabled); - slot.SetEnableVibration(vibrationEnabled); - } - // sound?: string NAPI_CALL(env, napi_has_named_property(env, value, "sound", &hasProperty)); if (hasProperty) { @@ -2805,6 +2842,19 @@ napi_value Common::GetNotificationSlot(const napi_env &env, const napi_value &va } slot.SetVibrationStyle(vibrationValues); } + + // vibrationEnabled?: boolean + NAPI_CALL(env, napi_has_named_property(env, value, "vibrationEnabled", &hasProperty)); + if (hasProperty) { + bool vibrationEnabled = false; + napi_get_named_property(env, value, "vibrationEnabled", &nobj); + NAPI_CALL(env, napi_typeof(env, nobj, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_boolean, "Wrong argument type. Bool expected."); + napi_get_value_bool(env, nobj, &vibrationEnabled); + ANS_LOGI("vibrationEnabled is: %{public}d", vibrationEnabled); + slot.SetEnableVibration(vibrationEnabled); + } + return NapiGetNull(env); } @@ -3050,26 +3100,45 @@ bool Common::ReasonCToJS(const int &inType, int &outType) return true; } -bool Common::DisturbModeJSToC(const enum DisturbMode &inType, enum NotificationConstant::DisturbMode &outType) +bool Common::DoNotDisturbTypeJSToC(const DoNotDisturbType &inType, NotificationConstant::DoNotDisturbType &outType) { switch (inType) { - case DisturbMode::ALLOW_UNKNOWN: - outType = NotificationConstant::DisturbMode::ALLOW_UNKNOWN; + case DoNotDisturbType::TYPE_NONE: + outType = NotificationConstant::DoNotDisturbType::NONE; + break; + case DoNotDisturbType::TYPE_ONCE: + outType = NotificationConstant::DoNotDisturbType::ONCE; + break; + case DoNotDisturbType::TYPE_DAILY: + outType = NotificationConstant::DoNotDisturbType::DAILY; break; - case DisturbMode::ALLOW_ALL: - outType = NotificationConstant::DisturbMode::ALLOW_ALL; + case DoNotDisturbType::TYPE_CLEARLY: + outType = NotificationConstant::DoNotDisturbType::CLEARLY; + break; + default: + ANS_LOGE("DoNotDisturbType %{public}d is an invalid value", inType); + return false; + } + return true; +} + +bool Common::DoNotDisturbTypeCToJS(const NotificationConstant::DoNotDisturbType &inType, DoNotDisturbType &outType) +{ + switch (inType) { + case NotificationConstant::DoNotDisturbType::NONE: + outType = DoNotDisturbType::TYPE_NONE; break; - case DisturbMode::ALLOW_PRIORITY: - outType = NotificationConstant::DisturbMode::ALLOW_PRIORITY; + case NotificationConstant::DoNotDisturbType::ONCE: + outType = DoNotDisturbType::TYPE_ONCE; break; - case DisturbMode::ALLOW_NONE: - outType = NotificationConstant::DisturbMode::ALLOW_NONE; + case NotificationConstant::DoNotDisturbType::DAILY: + outType = DoNotDisturbType::TYPE_DAILY; break; - case DisturbMode::ALLOW_ALARMS: - outType = NotificationConstant::DisturbMode::ALLOW_ALARMS; + case NotificationConstant::DoNotDisturbType::CLEARLY: + outType = DoNotDisturbType::TYPE_CLEARLY; break; default: - ANS_LOGE("DisturbMode %{public}d is an invalid value", inType); + ANS_LOGE("DoNotDisturbType %{public}d is an invalid value", inType); return false; } return true; diff --git a/interfaces/kits/napi/ans/src/constant.cpp b/interfaces/kits/napi/ans/src/constant.cpp index 3b16f7734..e3946a976 100644 --- a/interfaces/kits/napi/ans/src/constant.cpp +++ b/interfaces/kits/napi/ans/src/constant.cpp @@ -208,6 +208,26 @@ napi_value ContentTypeInit(napi_env env, napi_value exports) return exports; } +napi_value DoNotDisturbTypeInit(napi_env env, napi_value exports) +{ + ANS_LOGI("%{public}s, called", __func__); + + napi_value obj = nullptr; + napi_create_object(env, &obj); + + SetNamedPropertyByInteger(env, obj, DoNotDisturbType::TYPE_NONE, "TYPE_NONE"); + SetNamedPropertyByInteger(env, obj, DoNotDisturbType::TYPE_ONCE, "TYPE_ONCE"); + SetNamedPropertyByInteger(env, obj, DoNotDisturbType::TYPE_DAILY, "TYPE_DAILY"); + SetNamedPropertyByInteger(env, obj, DoNotDisturbType::TYPE_CLEARLY, "TYPE_CLEARLY"); + + napi_property_descriptor exportFuncs[] = { + DECLARE_NAPI_PROPERTY("DoNotDisturbType", obj), + }; + + napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs); + return exports; +} + napi_value ConstantInit(napi_env env, napi_value exports) { NotificationReasonInit(env, exports); @@ -218,6 +238,7 @@ napi_value ConstantInit(napi_env env, napi_value exports) DoNotDisturbMode(env, exports); InputEditTypeInit(env, exports); ContentTypeInit(env, exports); + DoNotDisturbTypeInit(env, exports); return exports; } diff --git a/interfaces/kits/napi/ans/src/disturb_mode.cpp b/interfaces/kits/napi/ans/src/disturb_mode.cpp index 5bb64c12c..2c261ebe8 100644 --- a/interfaces/kits/napi/ans/src/disturb_mode.cpp +++ b/interfaces/kits/napi/ans/src/disturb_mode.cpp @@ -17,64 +17,128 @@ namespace OHOS { namespace NotificationNapi { -const int DISTURB_MODE_MAX_PARA = 2; -const int DISTURB_MODE_MIN_PARA = 1; +const int SET_DISTURB_MAX_PARA = 2; +const int SET_DISTURB_MIN_PARA = 1; -struct DisturbModeParams { - NotificationConstant::DisturbMode mode = NotificationConstant::DisturbMode::ALLOW_UNKNOWN; +struct SetDoNotDisturbDateParams { + NotificationDoNotDisturbDate date; napi_ref callback = nullptr; }; -struct AsyncCallbackInfoDisturbMode { +struct AsyncCallbackInfoSetDoNotDisturb { napi_env env = nullptr; napi_async_work asyncWork = nullptr; - DisturbModeParams params; + SetDoNotDisturbDateParams params; CallbackPromiseInfo info; }; -napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, DisturbModeParams ¶ms) +struct AsyncCallbackInfoGetDoNotDisturb { + napi_env env = nullptr; + napi_async_work asyncWork = nullptr; + napi_ref callback = nullptr; + NotificationDoNotDisturbDate date; + CallbackPromiseInfo info; +}; + +struct AsyncCallbackInfoSupportDoNotDisturb { + napi_env env = nullptr; + napi_async_work asyncWork = nullptr; + napi_ref callback = nullptr; + bool disturbMode = false; + CallbackPromiseInfo info; +}; + +napi_value GetDoNotDisturbDate(const napi_env &env, const napi_value &argv, SetDoNotDisturbDateParams ¶ms) +{ + ANS_LOGI("enter"); + napi_value value = nullptr; + bool hasProperty = false; + napi_valuetype valuetype = napi_undefined; + // argv[0]: date:type + NAPI_CALL(env, napi_has_named_property(env, argv, "type", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property type expected."); + napi_get_named_property(env, argv, "type", &value); + NAPI_CALL(env, napi_typeof(env, value, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); + int type = 0; + NotificationConstant::DoNotDisturbType outType = NotificationConstant::DoNotDisturbType::NONE; + napi_get_value_int32(env, value, &type); + ANS_LOGI("type is: %{public}d", type); + if (!Common::DoNotDisturbTypeJSToC(DoNotDisturbType(type), outType)) { + return nullptr; + } + params.date.SetDoNotDisturbType(outType); + + // argv[0]: date:begin + NAPI_CALL(env, napi_has_named_property(env, argv, "begin", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property type expected."); + double begin = 0; + napi_get_named_property(env, argv, "begin", &value); + bool isDate = false; + napi_is_date(env, value, &isDate); + if (!isDate) { + ANS_LOGE("Wrong argument type. Date expected."); + return nullptr; + } + napi_get_date_value(env, value, &begin); + params.date.SetBeginDate(int64_t(begin)); + + // argv[0]: date:end + NAPI_CALL(env, napi_has_named_property(env, argv, "end", &hasProperty)); + NAPI_ASSERT(env, hasProperty, "Property type expected."); + double end = 0; + napi_get_named_property(env, argv, "end", &value); + isDate = false; + napi_is_date(env, value, &isDate); + if (!isDate) { + ANS_LOGE("Wrong argument type. Date expected."); + return nullptr; + } + napi_get_date_value(env, value, &end); + params.date.SetEndDate(int64_t(end)); + + return Common::NapiGetNull(env); +} + +napi_value ParseParameters(const napi_env &env, const napi_callback_info &info, SetDoNotDisturbDateParams ¶ms) { ANS_LOGI("enter"); - size_t argc = DISTURB_MODE_MAX_PARA; - napi_value argv[DISTURB_MODE_MAX_PARA] = {nullptr}; + size_t argc = SET_DISTURB_MAX_PARA; + napi_value argv[SET_DISTURB_MAX_PARA] = {nullptr}; napi_value thisVar = nullptr; NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); - NAPI_ASSERT(env, argc >= DISTURB_MODE_MIN_PARA, "Wrong number of arguments"); + NAPI_ASSERT(env, argc >= SET_DISTURB_MIN_PARA, "Wrong number of arguments"); - // argv[0]: mode + // argv[0]: date napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. Number expected."); - int mode = 0; - napi_get_value_int32(env, argv[0], &mode); - ANS_LOGI("mode is: %{public}d", mode); - - if (!Common::DisturbModeJSToC(DisturbMode(mode), params.mode)) { + NAPI_ASSERT(env, valuetype == napi_object, "Wrong argument type. Object expected."); + if (GetDoNotDisturbDate(env, argv[0], params) == nullptr) { return nullptr; } // argv[1]:callback - if (argc >= DISTURB_MODE_MAX_PARA) { - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); + if (argc >= SET_DISTURB_MAX_PARA) { + NAPI_CALL(env, napi_typeof(env, argv[SET_DISTURB_MIN_PARA], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - napi_create_reference(env, argv[1], 1, ¶ms.callback); + napi_create_reference(env, argv[SET_DISTURB_MIN_PARA], 1, ¶ms.callback); } return Common::NapiGetNull(env); } -napi_value SetDoNotDisturbMode(napi_env env, napi_callback_info info) +napi_value SetDoNotDisturbDate(napi_env env, napi_callback_info info) { ANS_LOGI("enter"); - DisturbModeParams params {}; + SetDoNotDisturbDateParams params {}; if (ParseParameters(env, info, params) == nullptr) { return Common::NapiGetUndefined(env); } - AsyncCallbackInfoDisturbMode *asynccallbackinfo = - new (std::nothrow) AsyncCallbackInfoDisturbMode {.env = env, .asyncWork = nullptr, .params = params}; + AsyncCallbackInfoSetDoNotDisturb *asynccallbackinfo = + new (std::nothrow) AsyncCallbackInfoSetDoNotDisturb {.env = env, .asyncWork = nullptr, .params = params}; if (!asynccallbackinfo) { return Common::JSParaError(env, params.callback); } @@ -82,21 +146,19 @@ napi_value SetDoNotDisturbMode(napi_env env, napi_callback_info info) Common::PaddingCallbackPromiseInfo(env, params.callback, asynccallbackinfo->info, promise); napi_value resourceName = nullptr; - napi_create_string_latin1(env, "setDoNotDisturbMode", NAPI_AUTO_LENGTH, &resourceName); + napi_create_string_latin1(env, "setDoNotDisturbDate", NAPI_AUTO_LENGTH, &resourceName); // Asynchronous function call napi_create_async_work(env, nullptr, resourceName, [](napi_env env, void *data) { - ANS_LOGI("SetDoNotDisturbMode napi_create_async_work start"); - AsyncCallbackInfoDisturbMode *asynccallbackinfo = (AsyncCallbackInfoDisturbMode *)data; - ANS_LOGI("asynccallbackinfo->params.mode = %{public}d", asynccallbackinfo->params.mode); - asynccallbackinfo->info.errorCode = NotificationHelper::SetDisturbMode(asynccallbackinfo->params.mode); - ANS_LOGI("asynccallbackinfo->info.errorCode = %{public}d", asynccallbackinfo->info.errorCode); + ANS_LOGI("SetDoNotDisturbDate napi_create_async_work start"); + AsyncCallbackInfoSetDoNotDisturb *asynccallbackinfo = (AsyncCallbackInfoSetDoNotDisturb *)data; + asynccallbackinfo->info.errorCode = NotificationHelper::SetDoNotDisturbDate(asynccallbackinfo->params.date); }, [](napi_env env, napi_status status, void *data) { - ANS_LOGI("SetDoNotDisturbMode napi_create_async_work end"); - AsyncCallbackInfoDisturbMode *asynccallbackinfo = (AsyncCallbackInfoDisturbMode *)data; + ANS_LOGI("SetDoNotDisturbDate napi_create_async_work end"); + AsyncCallbackInfoSetDoNotDisturb *asynccallbackinfo = (AsyncCallbackInfoSetDoNotDisturb *)data; Common::ReturnCallbackPromise(env, asynccallbackinfo->info, Common::NapiGetNull(env)); @@ -122,5 +184,138 @@ napi_value SetDoNotDisturbMode(napi_env env, napi_callback_info info) } } +void AsyncCompleteCallbackGetDoNotDisturbDate(napi_env env, napi_status status, void *data) +{ + ANS_LOGI("enter"); + if (!data) { + ANS_LOGE("Invalid async callback data"); + return; + } + AsyncCallbackInfoGetDoNotDisturb *asynccallbackinfo = (AsyncCallbackInfoGetDoNotDisturb *)data; + napi_value result = Common::NapiGetNull(env); + if (asynccallbackinfo->info.errorCode == ERR_OK) { + napi_create_object(env, &result); + if (!Common::SetDoNotDisturbDate(env, asynccallbackinfo->date, result)) { + asynccallbackinfo->info.errorCode = ERROR; + } + } + + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); + + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + if (asynccallbackinfo) { + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } +} + +napi_value GetDoNotDisturbDate(napi_env env, napi_callback_info info) +{ + ANS_LOGI("enter"); + + napi_ref callback = nullptr; + if (Common::ParseParaOnlyCallback(env, info, callback) == nullptr) { + return Common::NapiGetUndefined(env); + } + + AsyncCallbackInfoGetDoNotDisturb *asynccallbackinfo = + new (std::nothrow) AsyncCallbackInfoGetDoNotDisturb {.env = env, .asyncWork = nullptr, .callback = callback}; + if (!asynccallbackinfo) { + return Common::JSParaError(env, callback); + } + napi_value promise = nullptr; + Common::PaddingCallbackPromiseInfo(env, callback, asynccallbackinfo->info, promise); + + napi_value resourceName = nullptr; + napi_create_string_latin1(env, "getDoNotDisturbDate", NAPI_AUTO_LENGTH, &resourceName); + // Asynchronous function call + napi_create_async_work(env, + nullptr, + resourceName, + [](napi_env env, void *data) { + ANS_LOGI("GetDoNotDisturbDate napi_create_async_work start"); + AsyncCallbackInfoGetDoNotDisturb *asynccallbackinfo = (AsyncCallbackInfoGetDoNotDisturb *)data; + asynccallbackinfo->info.errorCode = NotificationHelper::GetDoNotDisturbDate(asynccallbackinfo->date); + }, + AsyncCompleteCallbackGetDoNotDisturbDate, + (void *)asynccallbackinfo, + &asynccallbackinfo->asyncWork); + + NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork)); + + if (asynccallbackinfo->info.isCallback) { + return Common::NapiGetNull(env); + } else { + return promise; + } +} + +napi_value SupportDoNotDisturbMode(napi_env env, napi_callback_info info) +{ + ANS_LOGI("enter"); + + napi_ref callback = nullptr; + if (Common::ParseParaOnlyCallback(env, info, callback) == nullptr) { + return Common::NapiGetUndefined(env); + } + + AsyncCallbackInfoSupportDoNotDisturb *asynccallbackinfo = + new (std::nothrow) AsyncCallbackInfoSupportDoNotDisturb { + .env = env, .asyncWork = nullptr, .callback = callback}; + + if (!asynccallbackinfo) { + return Common::JSParaError(env, callback); + } + napi_value promise = nullptr; + Common::PaddingCallbackPromiseInfo(env, callback, asynccallbackinfo->info, promise); + + napi_value resourceName = nullptr; + napi_create_string_latin1(env, "supportDoNotDisturbMode", NAPI_AUTO_LENGTH, &resourceName); + // Asynchronous function call + napi_create_async_work(env, + nullptr, + resourceName, + [](napi_env env, void *data) { + ANS_LOGI("SupportDoNotDisturbMode napi_create_async_work start"); + AsyncCallbackInfoSupportDoNotDisturb *asynccallbackinfo = (AsyncCallbackInfoSupportDoNotDisturb *)data; + asynccallbackinfo->info.errorCode = + NotificationHelper::DoesSupportDoNotDisturbMode(asynccallbackinfo->disturbMode); + ANS_LOGI("asynccallbackinfo->disturbMode = %{public}d", asynccallbackinfo->disturbMode); + ANS_LOGI("asynccallbackinfo->info.errorCode = %{public}d", asynccallbackinfo->info.errorCode); + }, + [](napi_env env, napi_status status, void *data) { + ANS_LOGI("SupportDoNotDisturbMode napi_create_async_work end"); + AsyncCallbackInfoSupportDoNotDisturb *asynccallbackinfo = (AsyncCallbackInfoSupportDoNotDisturb *)data; + + napi_value result = nullptr; + napi_get_boolean(env, asynccallbackinfo->disturbMode, &result); + Common::ReturnCallbackPromise(env, asynccallbackinfo->info, result); + + if (asynccallbackinfo->info.callback != nullptr) { + napi_delete_reference(env, asynccallbackinfo->info.callback); + } + + napi_delete_async_work(env, asynccallbackinfo->asyncWork); + if (asynccallbackinfo) { + delete asynccallbackinfo; + asynccallbackinfo = nullptr; + } + }, + (void *)asynccallbackinfo, + &asynccallbackinfo->asyncWork); + + NAPI_CALL(env, napi_queue_async_work(env, asynccallbackinfo->asyncWork)); + + if (asynccallbackinfo->info.isCallback) { + return Common::NapiGetNull(env); + } else { + return promise; + } +} + } // namespace NotificationNapi } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/napi/ans/src/init.cpp b/interfaces/kits/napi/ans/src/init.cpp index 46ccbece6..e72eddaec 100644 --- a/interfaces/kits/napi/ans/src/init.cpp +++ b/interfaces/kits/napi/ans/src/init.cpp @@ -62,7 +62,9 @@ napi_value NotificationInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("isNotificationEnabled", IsNotificationEnabled), DECLARE_NAPI_FUNCTION("displayBadge", DisplayBadge), DECLARE_NAPI_FUNCTION("isBadgeDisplayed", IsBadgeDisplayed), - DECLARE_NAPI_FUNCTION("setDoNotDisturbMode", SetDoNotDisturbMode), + DECLARE_NAPI_FUNCTION("setDoNotDisturbDate", SetDoNotDisturbDate), + DECLARE_NAPI_FUNCTION("getDoNotDisturbDate", GetDoNotDisturbDate), + DECLARE_NAPI_FUNCTION("supportDoNotDisturbMode", SupportDoNotDisturbMode), }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); diff --git a/interfaces/kits/napi/ans/src/publish.cpp b/interfaces/kits/napi/ans/src/publish.cpp index 7bcaf88c2..d94182cef 100644 --- a/interfaces/kits/napi/ans/src/publish.cpp +++ b/interfaces/kits/napi/ans/src/publish.cpp @@ -26,12 +26,10 @@ struct AsyncCallbackInfoPublish { napi_env env = nullptr; napi_async_work asyncWork = nullptr; NotificationRequest request; - std::string lable; CallbackPromiseInfo info; }; struct ParametersInfoPublish { - std::string lable; NotificationRequest request; napi_ref callback = nullptr; }; @@ -92,7 +90,7 @@ napi_value Publish(napi_env env, napi_callback_info info) if (!asynccallbackinfo) { return Common::JSParaError(env, params.callback); } - asynccallbackinfo->lable = params.lable; + asynccallbackinfo->request = params.request; Common::PaddingCallbackPromiseInfo(env, params.callback, asynccallbackinfo->info, promise); @@ -111,7 +109,7 @@ napi_value Publish(napi_env env, napi_callback_info info) asynccallbackinfo->request.GetContent()->GetContentType()); asynccallbackinfo->info.errorCode = - NotificationHelper::PublishNotification(asynccallbackinfo->lable, asynccallbackinfo->request); + NotificationHelper::PublishNotification(asynccallbackinfo->request); }, [](napi_env env, napi_status status, void *data) { ANS_LOGI("Publish napi_create_async_work complete start"); diff --git a/interfaces/kits/napi/ans/src/subscribe.cpp b/interfaces/kits/napi/ans/src/subscribe.cpp index 54bfadeae..ee5de8347 100644 --- a/interfaces/kits/napi/ans/src/subscribe.cpp +++ b/interfaces/kits/napi/ans/src/subscribe.cpp @@ -28,12 +28,14 @@ const std::string CONNECTED = "onConnect"; const std::string DIS_CONNECTED = "onDisconnect"; const std::string DIE = "onDestroy"; const std::string DISTURB_MODE_CHANGE = "onDisturbModeChange"; +const std::string DISTURB_DATE_CHANGE = "onDoNotDisturbDateChange"; struct NotificationReceiveDataWorker { napi_env env = nullptr; napi_ref ref = nullptr; std::shared_ptr request; std::shared_ptr sortingMap; + NotificationDoNotDisturbDate date; int deleteReason = 0; int result = 0; int disturbMode = 0; @@ -292,8 +294,8 @@ void SubscriberInstance::OnConsumed(const std::shared_ptrGetNotificationRequest().GetNotificationId()); - ANS_LOGI("OnConsumed sortingMap size = %{public}zu", sortingMap->GetKey().size()); + ANS_LOGI("OnConsumed Notification key = %{public}s, sortingMap size = %{public}zu", + request->GetKey().c_str(), sortingMap->GetKey().size()); uv_loop_s *loop = nullptr; napi_get_uv_event_loop(consumeCallbackInfo_.env, &loop); @@ -624,8 +626,87 @@ void SubscriberInstance::OnDied() } } -void SubscriberInstance::OnDisturbModeChanged(int disturbMode) -{} +void UvQueueWorkOnDoNotDisturbDateChange(uv_work_t *work, int status) +{ + ANS_LOGI("OnDoNotDisturbDateChange uv_work_t start"); + + if (work == nullptr) { + ANS_LOGE("work is null"); + return; + } + + NotificationReceiveDataWorker *dataWorkerData = (NotificationReceiveDataWorker *)work->data; + if (dataWorkerData == nullptr) { + ANS_LOGE("dataWorkerData is null"); + delete work; + work = nullptr; + return; + } + + napi_value result = nullptr; + napi_create_object(dataWorkerData->env, &result); + + if (!Common::SetDoNotDisturbDate(dataWorkerData->env, dataWorkerData->date, result)) { + result = Common::NapiGetNull(dataWorkerData->env); + } + + Common::SetCallback(dataWorkerData->env, dataWorkerData->ref, result); + + delete dataWorkerData; + dataWorkerData = nullptr; + delete work; + work = nullptr; +} + +void SubscriberInstance::OnDoNotDisturbDateChange(const std::shared_ptr &date) +{ + ANS_LOGI("enter"); + + if (disturbDateCallbackInfo_.ref == nullptr) { + ANS_LOGI("disturbDateCallbackInfo_ callback unset"); + return; + } + + if (date == nullptr) { + ANS_LOGE("date is null"); + return; + } + + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(disturbDateCallbackInfo_.env, &loop); + if (loop == nullptr) { + ANS_LOGE("loop instance is nullptr"); + return; + } + + NotificationReceiveDataWorker *dataWorker = new (std::nothrow) NotificationReceiveDataWorker(); + if (dataWorker == nullptr) { + ANS_LOGE("new dataWorker failed"); + return; + } + + dataWorker->date = *date; + dataWorker->env = disturbDateCallbackInfo_.env; + dataWorker->ref = disturbDateCallbackInfo_.ref; + + uv_work_t *work = new (std::nothrow) uv_work_t; + if (work == nullptr) { + ANS_LOGE("new work failed"); + delete dataWorker; + dataWorker = nullptr; + return; + } + + work->data = (void *)dataWorker; + + int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, UvQueueWorkOnDoNotDisturbDateChange); + if (ret != 0) { + delete dataWorker; + dataWorker = nullptr; + delete work; + work = nullptr; + } +} void SubscriberInstance::SetCancelCallbackInfo(const napi_env &env, const napi_ref &ref) { @@ -669,6 +750,12 @@ void SubscriberInstance::SetDisturbModeCallbackInfo(const napi_env &env, const n disturbModeCallbackInfo_.ref = ref; } +void SubscriberInstance::SetDisturbDateCallbackInfo(const napi_env &env, const napi_ref &ref) +{ + disturbDateCallbackInfo_.env = env; + disturbDateCallbackInfo_.ref = ref; +} + void SubscriberInstance::SetCallbackInfo(const napi_env &env, const std::string &type, const napi_ref &ref) { if (type == CONSUME) { @@ -685,6 +772,8 @@ void SubscriberInstance::SetCallbackInfo(const napi_env &env, const std::string SetDieCallbackInfo(env, ref); } else if (type == DISTURB_MODE_CHANGE) { SetDisturbModeCallbackInfo(env, ref); + } else if (type == DISTURB_DATE_CHANGE) { + SetDisturbDateCallbackInfo(env, ref); } else { ANS_LOGW("type is error"); } @@ -801,6 +890,17 @@ napi_value GetNotificationSubscriber( subscriberInfo.subscriber->SetCallbackInfo(env, DISTURB_MODE_CHANGE, result); } + // onDoNotDisturbDateChange?:(mode: notification.DoNotDisturbDate) => void + NAPI_CALL(env, napi_has_named_property(env, value, "onDoNotDisturbDateChange", &hasProperty)); + if (hasProperty) { + napi_value nOnDisturbDateChanged = nullptr; + napi_get_named_property(env, value, "onDoNotDisturbDateChange", &nOnDisturbDateChanged); + NAPI_CALL(env, napi_typeof(env, nOnDisturbDateChanged, &valuetype)); + NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); + napi_create_reference(env, nOnDisturbDateChanged, 1, &result); + subscriberInfo.subscriber->SetCallbackInfo(env, DISTURB_DATE_CHANGE, result); + } + return Common::NapiGetNull(env); } diff --git a/sa_profile/3203.xml b/sa_profile/3203.xml index ccaa7c4fb..55c3ff31e 100755 --- a/sa_profile/3203.xml +++ b/sa_profile/3203.xml @@ -17,6 +17,7 @@ 3203 /system/lib/libans.z.so + 1301 3299 5000 true diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index 180ec3c81..249f437bb 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -38,7 +38,6 @@ ohos_shared_library("libans") { "src/advanced_notification_service.cpp", "src/advanced_notification_service_ability.cpp", "src/bundle_manager_helper.cpp", - "src/disturb_filter.cpp", "src/notification_preferences.cpp", "src/notification_preferences_database.cpp", "src/notification_preferences_info.cpp", @@ -57,6 +56,7 @@ ohos_shared_library("libans") { "${core_path}:ans_core", "${frameworks_path}/ans/native:ans_innerkits", "${frameworks_path}/wantagent:wantagent_innerkits", + "//base/security/permission/interfaces/innerkits/permission_standard/permissionsdk:libpermissionsdk_standard", "//foundation/aafwk/standard/services/abilitymgr:abilityms", "//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits/distributeddata:distributeddata_inner", "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index c05bd30af..a476c597b 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -71,8 +71,6 @@ public: const sptr notification, const std::string &representativeBundle) override; ErrCode SetNotificationBadgeNum(int num) override; ErrCode GetBundleImportance(int &importance) override; - ErrCode SetDisturbMode(NotificationConstant::DisturbMode mode) override; - ErrCode GetDisturbMode(NotificationConstant::DisturbMode &mode) override; ErrCode HasNotificationPolicyAccessPermission(bool &granted) override; ErrCode SetPrivateNotificationsAllowed(bool allow) override; ErrCode GetPrivateNotificationsAllowed(bool &allow) override; @@ -101,6 +99,9 @@ public: ErrCode IsAllowedNotify(bool &allowed) override; ErrCode IsSpecialBundleAllowedNotify(const sptr &bundleOption, bool &allowed) override; + ErrCode SetDoNotDisturbDate(const sptr &date) override; + ErrCode GetDoNotDisturbDate(sptr &date) override; + ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport) override; ErrCode CancelGroup(const std::string &groupName) override; ErrCode RemoveGroupByBundle( const sptr &bundleOption, const std::string &groupName) override; @@ -144,7 +145,10 @@ private: ErrCode SetRecentNotificationCount(const std::string arg); void UpdateRecentNotification(sptr ¬ification, bool isDelete, int reason); + void AdjustDateForDndTypeOnce(int64_t &beginDate, int64_t &endDate); + private: + bool CheckPermission(const std::string &bundleName); static sptr instance_; static std::mutex instanceMutex_; diff --git a/services/ans/include/disturb_filter.h b/services/ans/include/disturb_filter.h index 7ced699c5..3a28a324d 100644 --- a/services/ans/include/disturb_filter.h +++ b/services/ans/include/disturb_filter.h @@ -30,6 +30,9 @@ public: void OnStop() override; ErrCode OnPublish(const std::shared_ptr &record) override; + +private: + void GetTimeInterval(int64_t &beginDate, int64_t &endDate); }; } // namespace Notification diff --git a/services/ans/include/notification_preferences.h b/services/ans/include/notification_preferences.h index 103c4c10d..3104edf45 100644 --- a/services/ans/include/notification_preferences.h +++ b/services/ans/include/notification_preferences.h @@ -19,36 +19,41 @@ #include "refbase.h" #include "singleton.h" +#include "notification_do_not_disturb_date.h" #include "notification_preferences_database.h" - namespace OHOS { namespace Notification { class NotificationPreferences final { public: DISALLOW_COPY_AND_MOVE(NotificationPreferences); static NotificationPreferences &GetInstance(); - ErrCode AddNotificationSlots(const sptr &bundleOption, const std::vector> &slots); + ErrCode AddNotificationSlots( + const sptr &bundleOption, const std::vector> &slots); ErrCode AddNotificationSlotGroups( const sptr &bundleOption, const std::vector> &groups); ErrCode AddNotificationBundleProperty(const sptr &bundleOption); - ErrCode RemoveNotificationSlot(const sptr &bundleOption, const NotificationConstant::SlotType &slotType); + ErrCode RemoveNotificationSlot( + const sptr &bundleOption, const NotificationConstant::SlotType &slotType); ErrCode RemoveNotificationAllSlots(const sptr &bundleOption); - ErrCode RemoveNotificationSlotGroups(const sptr &bundleOption, const std::vector &groupIds); + ErrCode RemoveNotificationSlotGroups( + const sptr &bundleOption, const std::vector &groupIds); ErrCode RemoveNotificationForBundle(const sptr &bundleOption); - ErrCode UpdateNotificationSlots(const sptr &bundleOption, const std::vector> &slot); + ErrCode UpdateNotificationSlots( + const sptr &bundleOption, const std::vector> &slot); ErrCode UpdateNotificationSlotGroups( const sptr &bundleOption, const std::vector> &groups); - ErrCode GetNotificationSlot( - const sptr &bundleOption, const NotificationConstant::SlotType &type, sptr &slot); - ErrCode GetNotificationAllSlots(const sptr &bundleOption, std::vector> &slots); + ErrCode GetNotificationSlot(const sptr &bundleOption, + const NotificationConstant::SlotType &type, sptr &slot); + ErrCode GetNotificationAllSlots( + const sptr &bundleOption, std::vector> &slots); ErrCode GetNotificationSlotsNumForBundle(const sptr &bundleOption, int &num); - ErrCode GetNotificationSlotGroup( - const sptr &bundleOption, const std::string &groupId, sptr &group); + ErrCode GetNotificationSlotGroup(const sptr &bundleOption, const std::string &groupId, + sptr &group); ErrCode GetNotificationAllSlotGroups( const sptr &bundleOption, std::vector> &groups); - ErrCode GetNotificationAllSlotInSlotGroup( - const sptr &bundleOption, const std::string &groupId, std::vector> &slots); + ErrCode GetNotificationAllSlotInSlotGroup(const sptr &bundleOption, + const std::string &groupId, std::vector> &slots); ErrCode IsShowBadge(const sptr &bundleOption, bool &enable); ErrCode SetShowBadge(const sptr &bundleOption, const bool enable); ErrCode GetImportance(const sptr &bundleOption, int &importance); @@ -61,33 +66,35 @@ public: ErrCode SetNotificationsEnabledForBundle(const sptr &bundleOption, const bool enabled); ErrCode GetNotificationsEnabled(bool &enabled); ErrCode SetNotificationsEnabled(const bool &enabled); - ErrCode GetDisturbMode(NotificationConstant::DisturbMode &mode); - ErrCode SetDisturbMode(const NotificationConstant::DisturbMode &mode); + ErrCode GetDoNotDisturbDate(sptr &date); + ErrCode SetDoNotDisturbDate(const sptr date); + ErrCode ClearNotificationInRestoreFactorySettings(); void OnDistributedKvStoreDeathRecipient(); private: - ErrCode CheckSlotForCreateSlot(const sptr &bundleOption, const sptr &slot, - NotificationPreferencesInfo &preferencesInfo) const; - ErrCode CheckGroupForCreateSlotGroup(const sptr &bundleOption, const sptr &group, - NotificationPreferencesInfo &preferencesInfo) const; - ErrCode CheckSlotForRemoveSlot(const sptr &bundleOption, const NotificationConstant::SlotType &slotType, - NotificationPreferencesInfo &preferencesInfo) const; - ErrCode CheckGroupForRemoveSlotGroup( - const sptr &bundleOption, const std::string &groupId, NotificationPreferencesInfo &preferencesInfo) const; - ErrCode CheckSlotForUpdateSlot(const sptr &bundleOption, const sptr &slot, - NotificationPreferencesInfo &preferencesInfo) const; - ErrCode CheckGroupForUpdateSlotGroup(const sptr &bundleOption, const sptr &group, + ErrCode CheckSlotForCreateSlot(const sptr &bundleOption, + const sptr &slot, NotificationPreferencesInfo &preferencesInfo) const; + ErrCode CheckGroupForCreateSlotGroup(const sptr &bundleOption, + const sptr &group, NotificationPreferencesInfo &preferencesInfo) const; + ErrCode CheckSlotForRemoveSlot(const sptr &bundleOption, + const NotificationConstant::SlotType &slotType, NotificationPreferencesInfo &preferencesInfo) const; + ErrCode CheckGroupForRemoveSlotGroup(const sptr &bundleOption, const std::string &groupId, NotificationPreferencesInfo &preferencesInfo) const; + ErrCode CheckSlotForUpdateSlot(const sptr &bundleOption, + const sptr &slot, NotificationPreferencesInfo &preferencesInfo) const; + ErrCode CheckGroupForUpdateSlotGroup(const sptr &bundleOption, + const sptr &group, NotificationPreferencesInfo &preferencesInfo) const; template - ErrCode SetBundleProperty(NotificationPreferencesInfo &preferencesInfo, const sptr &bundleOption, - const BundleType &type, const T &value); + ErrCode SetBundleProperty(NotificationPreferencesInfo &preferencesInfo, + const sptr &bundleOption, const BundleType &type, const T &value); template - ErrCode SaveBundleProperty(NotificationPreferencesInfo::BundleInfo &bundleInfo, const sptr &bundleOption, - const BundleType &type, const T &value); + ErrCode SaveBundleProperty(NotificationPreferencesInfo::BundleInfo &bundleInfo, + const sptr &bundleOption, const BundleType &type, const T &value); template - ErrCode GetBundleProperty(const sptr &bundleOption, const BundleType &type, T &value) const; + ErrCode GetBundleProperty( + const sptr &bundleOption, const BundleType &type, T &value) const; std::string GenerateBundleKey(const sptr &bundleOption) const; private: @@ -95,7 +102,6 @@ private: std::unique_ptr preferncesDB_ = nullptr; DECLARE_DELAYED_REF_SINGLETON(NotificationPreferences); }; - } // namespace Notification } // namespace OHOS diff --git a/services/ans/include/notification_preferences_database.h b/services/ans/include/notification_preferences_database.h index b88bafbf2..9b6526db7 100644 --- a/services/ans/include/notification_preferences_database.h +++ b/services/ans/include/notification_preferences_database.h @@ -39,7 +39,7 @@ public: bool PutPrivateNotificationsAllowed(const std::string &bundleKey, const bool &allow); bool PutNotificationsEnabledForBundle(const std::string &bundleKey, const bool &enabled); bool PutNotificationsEnabled(const bool &enabled); - bool PutDisturbMode(const NotificationConstant::DisturbMode &mode); + bool PutDoNotDisturbDate(const sptr &date); bool ParseFromDisturbeDB(NotificationPreferencesInfo &info); @@ -87,6 +87,7 @@ private: std::string VectorToString(const std::vector &data) const; void StringToVector(const std::string &str, std::vector &data) const; int StringToInt(const std::string &str) const; + int64_t StringToInt64(const std::string &str) const; bool IsSlotKey(const std::string &bundleKey, const std::string &key) const; bool IsGroupKey(const std::string &bundleKey, const std::string &key) const; std::string GenerateSlotKey( @@ -102,7 +103,9 @@ private: const OHOS::DistributedKv::Entry &entry); void ParseBundlePropertyFromDisturbeDB(NotificationPreferencesInfo::BundleInfo &bundleInfo, const std::string &bundleKey, const OHOS::DistributedKv::Entry &entry); - void ParseDisturbeMode(NotificationPreferencesInfo &info); + void ParseDoNotDisturbType(NotificationPreferencesInfo &info); + void ParseDoNotDisturbBeginDate(NotificationPreferencesInfo &info); + void ParseDoNotDisturbEndDate(NotificationPreferencesInfo &info); void ParseEnableAllNotification(NotificationPreferencesInfo &info); void ParseGroupDescription( const std::string &bundleKey, sptr &group, const OHOS::DistributedKv::Entry &entry); @@ -121,7 +124,7 @@ private: void ParseSlotShowBadge(sptr &slot, const std::string &value) const; void ParseSlotEnableLight(sptr &slot, const std::string &value) const; void ParseSlotEnableVrbration(sptr &slot, const std::string &value) const; - void ParseSlotLedLightColor(sptr &slot, const std::string &kevaluey) const; + void ParseSlotLedLightColor(sptr &slot, const std::string &value) const; void ParseSlotLockscreenVisibleness(sptr &slot, const std::string &value) const; void ParseSlotSound(sptr &slot, const std::string &value) const; void ParseSlotVibrationSytle(sptr &slot, const std::string &value) const; diff --git a/services/ans/include/notification_preferences_info.h b/services/ans/include/notification_preferences_info.h index 4e7845325..ac53056ce 100644 --- a/services/ans/include/notification_preferences_info.h +++ b/services/ans/include/notification_preferences_info.h @@ -21,6 +21,7 @@ #include #include "notification_bundle_option.h" +#include "notification_do_not_disturb_date.h" #include "notification_slot.h" #include "notification_slot_group.h" #include "preferences_constant.h" @@ -81,8 +82,8 @@ public: {} void SetEnabledAllNotification(const bool &value); bool GetEnabledAllNotification() const; - void SetDisturbMode(const NotificationConstant::DisturbMode &mode); - NotificationConstant::DisturbMode GetDisturbMode() const; + void SetDoNotDisturbDate(const sptr &date); + sptr GetDoNotDisturbDate() const; void SetBundleInfo(const BundleInfo &info); bool GetBundleInfo(const sptr &bundleOption, BundleInfo &info) const; bool RemoveBundleInfo(const sptr &bundleOption); @@ -91,7 +92,7 @@ public: private: bool isEnabledAllNotification_ = true; - NotificationConstant::DisturbMode disturbMode_ = NotificationConstant::DisturbMode::ALLOW_ALL; + sptr doNotDisturbDate_ = new NotificationDoNotDisturbDate(); std::map infos_; }; } // namespace Notification diff --git a/services/ans/include/notification_subscriber_manager.h b/services/ans/include/notification_subscriber_manager.h index 075878932..ea96bfa6b 100644 --- a/services/ans/include/notification_subscriber_manager.h +++ b/services/ans/include/notification_subscriber_manager.h @@ -45,7 +45,7 @@ public: void NotifyCanceled( const sptr ¬ification, const sptr ¬ificationMap, int deleteReason); void NotifyUpdated(const sptr ¬ificationMap); - void NotifyDisturbModeChanged(const NotificationConstant::DisturbMode &mode); + void NotifyDoNotDisturbDateChanged(const sptr &date); void OnRemoteDied(const wptr &object); private: @@ -67,7 +67,7 @@ private: void NotifyCanceledInner( const sptr ¬ification, const sptr ¬ificationMap, int deleteReason); void NotifyUpdatedInner(const sptr ¬ificationMap); - void NotifyDisturbModeChangedInner(const NotificationConstant::DisturbMode &mode); + void NotifyDoNotDisturbDateChangedInner(const sptr &date); private: std::list> subscriberRecordList_ {}; diff --git a/services/ans/include/preferences_constant.h b/services/ans/include/preferences_constant.h index 30702e8fe..f4ced9362 100644 --- a/services/ans/include/preferences_constant.h +++ b/services/ans/include/preferences_constant.h @@ -19,7 +19,9 @@ namespace OHOS { namespace Notification { -const static std::string KEY_DISTURB_MODE = "ans_disturbMode"; +const static std::string KEY_DO_NOT_DISTURB_TYPE = "ans_doNotDisturbType"; +const static std::string KEY_DO_NOT_DISTURB_BEGIN_DATE = "ans_doNotDisturbBeginDate"; +const static std::string KEY_DO_NOT_DISTURB_END_DATE = "ans_doNotDisturbEndDate"; const static std::string KEY_ENABLE_ALL_NOTIFICATION = "ans_notificationAll"; const static std::string KEY_BUNDLE_LABEL = "label_ans_bundle_"; const static std::string KEY_UNDER_LINE = "_"; diff --git a/services/ans/src/advanced_notification_service.cpp b/services/ans/src/advanced_notification_service.cpp index f91e697ea..cde4d34cd 100644 --- a/services/ans/src/advanced_notification_service.cpp +++ b/services/ans/src/advanced_notification_service.cpp @@ -22,8 +22,8 @@ #include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_log_wrapper.h" +#include "ans_permission_define.h" #include "bundle_manager_helper.h" -#include "disturb_filter.h" #include "ipc_skeleton.h" #include "notification_constant.h" #include "notification_filter.h" @@ -31,6 +31,7 @@ #include "notification_slot.h" #include "notification_slot_filter.h" #include "notification_subscriber_manager.h" +#include "permission/permission_kit.h" #include "permission_filter.h" namespace OHOS { @@ -46,6 +47,8 @@ static const int32_t NOTIFICATION_MAX_COUNT = 1024; static const int32_t DEFAULT_RECENT_COUNT = 16; +constexpr int HOURS_IN_ONE_DAY = 24; + struct RecentNotification { sptr notification = nullptr; bool isActive = false; @@ -65,7 +68,6 @@ std::mutex AdvancedNotificationService::instanceMutex_; static const std::shared_ptr NOTIFICATION_FILTERS[] = { std::make_shared(), std::make_shared(), - std::make_shared(), }; inline std::string GetClientBundleName() @@ -661,37 +663,6 @@ ErrCode AdvancedNotificationService::GetBundleImportance(int &importance) return result; } -ErrCode AdvancedNotificationService::SetDisturbMode(NotificationConstant::DisturbMode mode) -{ - ANS_LOGD("%{public}s", __FUNCTION__); - - if (!IsSystemApp()) { - return ERR_ANS_NON_SYSTEM_APP; - } - - ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { - result = NotificationPreferences::GetInstance().SetDisturbMode(mode); - if (result == ERR_OK) { - NotificationSubscriberManager::GetInstance()->NotifyDisturbModeChanged(mode); - } - })); - return result; -} - -ErrCode AdvancedNotificationService::GetDisturbMode(NotificationConstant::DisturbMode &mode) -{ - ANS_LOGD("%{public}s", __FUNCTION__); - - if (!IsSystemApp()) { - return ERR_ANS_NON_SYSTEM_APP; - } - - ErrCode result = ERR_OK; - handler_->PostSyncTask(std::bind([&]() { result = NotificationPreferences::GetInstance().GetDisturbMode(mode); })); - return result; -} - ErrCode AdvancedNotificationService::HasNotificationPolicyAccessPermission(bool &granted) { return ERR_OK; @@ -1721,5 +1692,183 @@ ErrCode AdvancedNotificationService::RemoveGroupByBundle( return ERR_OK; } + +inline int64_t ResetSeconds(int64_t date) +{ + auto milliseconds = std::chrono::milliseconds(date); + auto tp = std::chrono::time_point(milliseconds); + auto tp_minutes = std::chrono::time_point_cast(tp); + auto duration = std::chrono::duration_cast(tp_minutes.time_since_epoch()); + return duration.count(); +} + +inline int64_t GetCurrentTime() +{ + auto now = std::chrono::system_clock::now(); + auto duration = std::chrono::duration_cast(now.time_since_epoch()); + return duration.count(); +} + +inline tm GetLocalTime(time_t time) +{ + tm result = {0}; + tm *lt = localtime(&time); + if (lt != nullptr) { + result = *lt; + } + return result; +} + +void AdvancedNotificationService::AdjustDateForDndTypeOnce(int64_t &beginDate, int64_t &endDate) +{ + std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); + time_t nowT = std::chrono::system_clock::to_time_t(now); + tm nowTm = GetLocalTime(nowT); + + auto beginDateMilliseconds = std::chrono::milliseconds(beginDate); + auto beginDateTimePoint = + std::chrono::time_point(beginDateMilliseconds); + time_t beginDateT = std::chrono::system_clock::to_time_t(beginDateTimePoint); + tm beginDateTm = GetLocalTime(beginDateT); + + auto endDateMilliseconds = std::chrono::milliseconds(endDate); + auto endDateTimePoint = + std::chrono::time_point(endDateMilliseconds); + time_t endDateT = std::chrono::system_clock::to_time_t(endDateTimePoint); + tm endDateTm = GetLocalTime(endDateT); + + tm todayBeginTm = nowTm; + todayBeginTm.tm_sec = 0; + todayBeginTm.tm_min = beginDateTm.tm_min; + todayBeginTm.tm_hour = beginDateTm.tm_hour; + + tm todayEndTm = nowTm; + todayEndTm.tm_sec = 0; + todayEndTm.tm_min = endDateTm.tm_min; + todayEndTm.tm_hour = endDateTm.tm_hour; + + time_t todayBeginT = mktime(&todayBeginTm); + if (todayBeginT == -1) { + return; + } + time_t todayEndT = mktime(&todayEndTm); + if (todayEndT == -1) { + return; + } + + auto newBeginTimePoint = std::chrono::system_clock::from_time_t(todayBeginT); + auto newEndTimePoint = std::chrono::system_clock::from_time_t(todayEndT); + + if (newBeginTimePoint >= newEndTimePoint) { + newEndTimePoint += std::chrono::hours(HOURS_IN_ONE_DAY); + } + + if (newEndTimePoint < now) { + newBeginTimePoint += std::chrono::hours(HOURS_IN_ONE_DAY); + newEndTimePoint += std::chrono::hours(HOURS_IN_ONE_DAY); + } + + auto newBeginDuration = std::chrono::duration_cast(newBeginTimePoint.time_since_epoch()); + beginDate = newBeginDuration.count(); + + auto newEndDuration = std::chrono::duration_cast(newEndTimePoint.time_since_epoch()); + endDate = newEndDuration.count(); +} + +ErrCode AdvancedNotificationService::SetDoNotDisturbDate(const sptr &date) +{ + ANS_LOGD("%{public}s", __FUNCTION__); + + if (!IsSystemApp()) { + return ERR_ANS_NON_SYSTEM_APP; + } + + if (date == nullptr) { + return ERR_ANS_INVALID_PARAM; + } + + ErrCode result = ERR_OK; + + int64_t beginDate = ResetSeconds(date->GetBeginDate()); + int64_t endDate = ResetSeconds(date->GetEndDate()); + + if (date->GetDoNotDisturbType() == NotificationConstant::DoNotDisturbType::NONE) { + beginDate = 0; + endDate = 0; + } + if (date->GetDoNotDisturbType() == NotificationConstant::DoNotDisturbType::ONCE) { + AdjustDateForDndTypeOnce(beginDate, endDate); + } + + const sptr newConfig = new NotificationDoNotDisturbDate( + date->GetDoNotDisturbType(), + beginDate, + endDate + ); + + handler_->PostSyncTask(std::bind([&]() { + result = NotificationPreferences::GetInstance().SetDoNotDisturbDate(newConfig); + if (result == ERR_OK) { + NotificationSubscriberManager::GetInstance()->NotifyDoNotDisturbDateChanged(newConfig); + } + })); + + return ERR_OK; +} + +ErrCode AdvancedNotificationService::GetDoNotDisturbDate(sptr &date) +{ + ANS_LOGD("%{public}s", __FUNCTION__); + + ErrCode result = ERR_OK; + + handler_->PostSyncTask(std::bind([&]() { + sptr currentConfig = nullptr; + result = NotificationPreferences::GetInstance().GetDoNotDisturbDate(currentConfig); + if (result == ERR_OK) { + int64_t now = GetCurrentTime(); + switch (currentConfig->GetDoNotDisturbType()) { + case NotificationConstant::DoNotDisturbType::CLEARLY: + case NotificationConstant::DoNotDisturbType::ONCE: + if (now >= currentConfig->GetEndDate()) { + date = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0); + NotificationPreferences::GetInstance().SetDoNotDisturbDate(date); + } else { + date = currentConfig; + } + break; + default: + date = currentConfig; + break; + } + } + })); + + return ERR_OK; +} + +ErrCode AdvancedNotificationService::DoesSupportDoNotDisturbMode(bool &doesSupport) +{ + ANS_LOGD("%{public}s", __FUNCTION__); + doesSupport = SUPPORT_DO_NOT_DISTRUB; + return ERR_OK; +} + +bool AdvancedNotificationService::CheckPermission(const std::string &bundleName) +{ + ANS_LOGD("%{public}s", __FUNCTION__); + bool isGranted = false; + if (bundleName.empty()) { + ANS_LOGE("Bundle name is empty."); + return isGranted; + } + int result = Security::Permission::PermissionKit::VerifyPermission(bundleName, ANS_PERMISSION_CONTROLLER, 0); + if (Security::Permission::TypePermissionState::PERMISSION_GRANTED == result) { + isGranted = true; + } else { + ANS_LOGE("Permission granted failed."); + } + return isGranted; +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/disturb_filter.cpp b/services/ans/src/disturb_filter.cpp deleted file mode 100644 index d5ebca7ba..000000000 --- a/services/ans/src/disturb_filter.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "disturb_filter.h" - -#include "ans_inner_errors.h" -#include "notification_preferences.h" - -namespace OHOS { -namespace Notification { - -void DisturbFilter::OnStart() -{} - -void DisturbFilter::OnStop() -{} - -ErrCode DisturbFilter::OnPublish(const std::shared_ptr &record) -{ - NotificationConstant::DisturbMode mode; - ErrCode result = NotificationPreferences::GetInstance().GetDisturbMode(mode); - if (result != ERR_OK) { - return result; - } - - bool disturb = false; - - switch (mode) { - case NotificationConstant::DisturbMode::ALLOW_ALARMS: - if (record->request->GetClassification() == NotificationRequest::CLASSIFICATION_ALARM) { - disturb = true; - } else { - if (record->slot == nullptr) { - result = ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_NOT_EXIST; - break; - } - disturb = record->slot->IsEnableBypassDnd(); - } - break; - case NotificationConstant::DisturbMode::ALLOW_ALL: - disturb = true; - break; - case NotificationConstant::DisturbMode::ALLOW_NONE: - if (record->slot == nullptr) { - result = ERR_ANS_PREFERENCES_NOTIFICATION_SLOT_NOT_EXIST; - break; - } - disturb = record->slot->IsEnableBypassDnd(); - break; - case NotificationConstant::DisturbMode::ALLOW_PRIORITY: - break; - case NotificationConstant::DisturbMode::ALLOW_UNKNOWN: - // DO NOTHING - break; - default: - break; - } - - if (!disturb) { - record->notification->SetEnableLight(false); - record->notification->SetEnableSound(false); - record->notification->SetEnableViration(false); - } - - return result; -} - -} // namespace Notification -} // namespace OHOS \ No newline at end of file diff --git a/services/ans/src/notification_preferences.cpp b/services/ans/src/notification_preferences.cpp index a95b1fcc5..dcf308015 100644 --- a/services/ans/src/notification_preferences.cpp +++ b/services/ans/src/notification_preferences.cpp @@ -512,18 +512,18 @@ ErrCode NotificationPreferences::SetNotificationsEnabled(const bool &enabled) return result; } -ErrCode NotificationPreferences::GetDisturbMode(NotificationConstant::DisturbMode &mode) +ErrCode NotificationPreferences::GetDoNotDisturbDate(sptr &date) { - mode = preferencesInfo_.GetDisturbMode(); + date = preferencesInfo_.GetDoNotDisturbDate(); return ERR_OK; } -ErrCode NotificationPreferences::SetDisturbMode(const NotificationConstant::DisturbMode &mode) +ErrCode NotificationPreferences::SetDoNotDisturbDate(const sptr date) { NotificationPreferencesInfo preferencesInfo = preferencesInfo_; - preferencesInfo.SetDisturbMode(mode); + preferencesInfo.SetDoNotDisturbDate(date); ErrCode result = ERR_OK; - if (!preferncesDB_->PutDisturbMode(mode)) { + if (!preferncesDB_->PutDoNotDisturbDate(date)) { result = ERR_ANS_PREFERENCES_NOTIFICATION_DB_OPERATION_FAILED; } diff --git a/services/ans/src/notification_preferences_database.cpp b/services/ans/src/notification_preferences_database.cpp index d9e16a85f..1243e4071 100644 --- a/services/ans/src/notification_preferences_database.cpp +++ b/services/ans/src/notification_preferences_database.cpp @@ -78,7 +78,7 @@ const std::map &date) { + if (date == nullptr) { + ANS_LOGE("Invalid date."); + return false; + } + if (!CheckKvStore()) { ANS_LOGE("KvStore is nullptr."); return false; } - OHOS::DistributedKv::Key disturbModeKey(KEY_DISTURB_MODE); - OHOS::DistributedKv::Value disturbModeValue(std::to_string(mode)); - OHOS::DistributedKv::Status status; - status = kvStorePtr_->Put(disturbModeKey, disturbModeValue); + OHOS::DistributedKv::Entry type; + type.key = OHOS::DistributedKv::Key(KEY_DO_NOT_DISTURB_TYPE); + type.value = OHOS::DistributedKv::Value(std::to_string((int)date->GetDoNotDisturbType())); + + OHOS::DistributedKv::Entry beginDate; + beginDate.key = OHOS::DistributedKv::Key(KEY_DO_NOT_DISTURB_BEGIN_DATE); + beginDate.value = OHOS::DistributedKv::Value(std::to_string(date->GetBeginDate())); + + OHOS::DistributedKv::Entry endDate; + endDate.key = OHOS::DistributedKv::Key(KEY_DO_NOT_DISTURB_END_DATE); + endDate.value = OHOS::DistributedKv::Value(std::to_string(date->GetEndDate())); + + std::vector entries = { + type, + beginDate, + endDate, + }; + + OHOS::DistributedKv::Status status = kvStorePtr_->PutBatch(entries); if (status != OHOS::DistributedKv::Status::SUCCESS) { - ANS_LOGE("Store disturbe modeFailed. %{public}d", status); + ANS_LOGE("Store DoNotDisturbDate failed. %{public}d", status); return false; } + return true; } @@ -485,7 +506,9 @@ bool NotificationPreferencesDatabase::PutBundlePropertyValueToDisturbeDB( bool NotificationPreferencesDatabase::ParseFromDisturbeDB(NotificationPreferencesInfo &info) { ANS_LOGD("%{public}s", __FUNCTION__); - ParseDisturbeMode(info); + ParseDoNotDisturbType(info); + ParseDoNotDisturbBeginDate(info); + ParseDoNotDisturbEndDate(info); ParseEnableAllNotification(info); if (!CheckKvStore()) { @@ -784,7 +807,7 @@ void NotificationPreferencesDatabase::GenerateSlotEntry(const std::string &bundl std::to_string(static_cast(slot->GetLockScreenVisibleness())), entries); GenerateEntry(GenerateSlotKey(bundleKey, slotType, KEY_SLOT_SOUND), slot->GetSound().ToString(), entries); - GenerateEntry(GenerateSlotKey(bundleKey, slotType, KEY_SLOT_VIBRATION_STYLE), + GenerateEntry(GenerateSlotKey(bundleKey, slotType, KEY_SLOT_ENABLE_BYPASS_DND), std::to_string(slot->IsEnableBypassDnd()), entries); GenerateEntry(GenerateSlotKey(bundleKey, slotType, KEY_SLOT_VIBRATION_STYLE), @@ -919,6 +942,11 @@ void NotificationPreferencesDatabase::ParseSlot( auto func = iter->second; func(this, slot, valueStr); } + + if (!typeStr.compare(KEY_SLOT_VIBRATION_STYLE)) { + GetValueFromDisturbeDB(findString + KEY_SLOT_ENABLE_VRBRATION, + [&](OHOS::DistributedKv::Value &value) { ParseSlotEnableVrbration(slot, value.ToString()); }); + } } std::string NotificationPreferencesDatabase::FindLastString( @@ -962,6 +990,15 @@ int NotificationPreferencesDatabase::StringToInt(const std::string &str) const return value; } +int64_t NotificationPreferencesDatabase::StringToInt64(const std::string &str) const +{ + int value = 0; + if (!str.empty()) { + value = stoll(str, nullptr); + } + return value; +} + bool NotificationPreferencesDatabase::IsSlotKey(const std::string &bundleKey, const std::string &key) const { std::string tempStr = FindLastString(bundleKey, key); @@ -1064,15 +1101,16 @@ std::string NotificationPreferencesDatabase::SubUniqueIdentifyFromString( return slotType; } -void NotificationPreferencesDatabase::ParseDisturbeMode(NotificationPreferencesInfo &info) +void NotificationPreferencesDatabase::ParseDoNotDisturbType(NotificationPreferencesInfo &info) { GetValueFromDisturbeDB( - KEY_DISTURB_MODE, [&](OHOS::DistributedKv::Status &status, OHOS::DistributedKv::Value &value) { + KEY_DO_NOT_DISTURB_TYPE, [&](OHOS::DistributedKv::Status &status, OHOS::DistributedKv::Value &value) { if (status == OHOS::DistributedKv::Status::KEY_NOT_FOUND) { - PutDisturbMode(info.GetDisturbMode()); + PutDoNotDisturbDate(info.GetDoNotDisturbDate()); } else if (status == OHOS::DistributedKv::Status::SUCCESS) { if (!value.ToString().empty()) { - info.SetDisturbMode(static_cast(StringToInt(value.ToString()))); + auto date = info.GetDoNotDisturbDate(); + date->SetDoNotDisturbType((NotificationConstant::DoNotDisturbType)StringToInt(value.ToString())); } } else { ANS_LOGW("Parse disturbe mode failed, use defalut value."); @@ -1080,6 +1118,40 @@ void NotificationPreferencesDatabase::ParseDisturbeMode(NotificationPreferencesI }); } +void NotificationPreferencesDatabase::ParseDoNotDisturbBeginDate(NotificationPreferencesInfo &info) +{ + GetValueFromDisturbeDB( + KEY_DO_NOT_DISTURB_BEGIN_DATE, [&](OHOS::DistributedKv::Status &status, OHOS::DistributedKv::Value &value) { + if (status == OHOS::DistributedKv::Status::KEY_NOT_FOUND) { + PutDoNotDisturbDate(info.GetDoNotDisturbDate()); + } else if (status == OHOS::DistributedKv::Status::SUCCESS) { + if (!value.ToString().empty()) { + auto date = info.GetDoNotDisturbDate(); + date->SetBeginDate(StringToInt64(value.ToString())); + } + } else { + ANS_LOGW("Parse disturbe start time failed, use defalut value."); + } + }); +} + +void NotificationPreferencesDatabase::ParseDoNotDisturbEndDate(NotificationPreferencesInfo &info) +{ + GetValueFromDisturbeDB( + KEY_DO_NOT_DISTURB_END_DATE, [&](OHOS::DistributedKv::Status &status, OHOS::DistributedKv::Value &value) { + if (status == OHOS::DistributedKv::Status::KEY_NOT_FOUND) { + PutDoNotDisturbDate(info.GetDoNotDisturbDate()); + } else if (status == OHOS::DistributedKv::Status::SUCCESS) { + if (!value.ToString().empty()) { + auto date = info.GetDoNotDisturbDate(); + date->SetEndDate(StringToInt64(value.ToString())); + } + } else { + ANS_LOGW("Parse disturbe end time failed, use defalut value."); + } + }); +} + void NotificationPreferencesDatabase::ParseEnableAllNotification(NotificationPreferencesInfo &info) { GetValueFromDisturbeDB( @@ -1213,6 +1285,7 @@ void NotificationPreferencesDatabase::ParseSlotLockscreenVisibleness( void NotificationPreferencesDatabase::ParseSlotSound(sptr &slot, const std::string &value) const { + ANS_LOGD("ParseSlotSound slot sound is %{public}s.", value.c_str()); std::string slotUri = value; Uri uri(slotUri); slot->SetSound(uri); @@ -1221,6 +1294,7 @@ void NotificationPreferencesDatabase::ParseSlotSound(sptr &slo void NotificationPreferencesDatabase::ParseSlotVibrationSytle( sptr &slot, const std::string &value) const { + ANS_LOGD("ParseSlotVibrationSytle slot vibration style is %{public}s.", value.c_str()); std::vector vibrationStyle; StringToVector(value, vibrationStyle); slot->SetVibrationStyle(vibrationStyle); diff --git a/services/ans/src/notification_preferences_info.cpp b/services/ans/src/notification_preferences_info.cpp index 9e58416e9..539035fb8 100644 --- a/services/ans/src/notification_preferences_info.cpp +++ b/services/ans/src/notification_preferences_info.cpp @@ -238,14 +238,14 @@ bool NotificationPreferencesInfo::GetEnabledAllNotification() const return isEnabledAllNotification_; } -void NotificationPreferencesInfo::SetDisturbMode(const NotificationConstant::DisturbMode &mode) +void NotificationPreferencesInfo::SetDoNotDisturbDate(const sptr &date) { - disturbMode_ = mode; + doNotDisturbDate_ = date; } -NotificationConstant::DisturbMode NotificationPreferencesInfo::GetDisturbMode() const +sptr NotificationPreferencesInfo::GetDoNotDisturbDate() const { - return disturbMode_; + return doNotDisturbDate_; } void NotificationPreferencesInfo::SetBundleInfo(const BundleInfo &info) diff --git a/services/ans/src/notification_subscriber_manager.cpp b/services/ans/src/notification_subscriber_manager.cpp index 5f0eadd34..0f4a21bb9 100644 --- a/services/ans/src/notification_subscriber_manager.cpp +++ b/services/ans/src/notification_subscriber_manager.cpp @@ -118,17 +118,17 @@ void NotificationSubscriberManager::NotifyUpdated(const sptrPostTask(NotifyUpdatedFunc); } -void NotificationSubscriberManager::NotifyDisturbModeChanged(const NotificationConstant::DisturbMode &mode) +void NotificationSubscriberManager::NotifyDoNotDisturbDateChanged(const sptr &date) { if (handler_ == nullptr) { ANS_LOGE("handler is nullptr"); return; } - AppExecFwk::EventHandler::Callback NotifyDisturbModeChangedFunc = - std::bind(&NotificationSubscriberManager::NotifyDisturbModeChangedInner, this, mode); + AppExecFwk::EventHandler::Callback func = + std::bind(&NotificationSubscriberManager::NotifyDoNotDisturbDateChangedInner, this, date); - handler_->PostTask(NotifyDisturbModeChangedFunc); + handler_->PostTask(func); } void NotificationSubscriberManager::OnRemoteDied(const wptr &object) @@ -295,10 +295,10 @@ void NotificationSubscriberManager::NotifyUpdatedInner(const sptr &date) { for (auto record : subscriberRecordList_) { - record->subscriber->OnDisturbModeChanged(mode); + record->subscriber->OnDoNotDisturbDateChange(date); } } } // namespace Notification diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 0f88ad802..d131b5f6f 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -41,7 +41,6 @@ ohos_unittest("ans_unit_test") { sources = [ "${services_path}/ans/src/advanced_notification_service.cpp", "${services_path}/ans/src/advanced_notification_service_ability.cpp", - "${services_path}/ans/src/disturb_filter.cpp", "${services_path}/ans/src/notification_preferences.cpp", "${services_path}/ans/src/notification_preferences_database.cpp", "${services_path}/ans/src/notification_preferences_info.cpp", @@ -53,13 +52,13 @@ ohos_unittest("ans_unit_test") { "//foundation/distributeddatamgr/distributeddatamgr/services/distributeddataservice/adapter/autils/src/constant.cpp", "advanced_notification_service_ability_test.cpp", "advanced_notification_service_test.cpp", - "disturb_filter_test.cpp", "mock/blob.cpp", "mock/distributed_kv_data_manager.cpp", "mock/mock_bundle_manager_helper.cpp", "mock/mock_event_handler.cpp", "mock/mock_ipc.cpp", "mock/mock_single_kv_store.cpp", + "mock/permission_kit.cpp", "notification_preferences_database_test.cpp", "notification_preferences_test.cpp", "notification_slot_filter_test.cpp", @@ -87,6 +86,7 @@ ohos_unittest("ans_unit_test") { "ces_standard:cesfwk_innerkits", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", + "permission_standard:libpermissionsdk_standard", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] diff --git a/services/ans/test/unittest/advanced_notification_service_ability_test.cpp b/services/ans/test/unittest/advanced_notification_service_ability_test.cpp index a13769aa9..e447dec8c 100644 --- a/services/ans/test/unittest/advanced_notification_service_ability_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_ability_test.cpp @@ -33,7 +33,7 @@ public: /** * @tc.number : AdvancedNotificationServiceAbilityTest_00100 - * @tc.name : AMS_ANS_AdvancedNotificationServiceAbility_0100 + * @tc.name : ANS_AdvancedNotificationServiceAbility_0100 * @tc.desc : Structure AdvancedNotificationServiceAbility with systemAbilityId and runOnCreate */ HWTEST_F( diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index de51a5ba0..1d6b79c69 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -88,7 +88,7 @@ public: {} void OnUpdate(const std::shared_ptr &sortingMap) override {} - void OnDisturbModeChanged(int disturbMode) override + void OnDoNotDisturbDateChange(const std::shared_ptr &date) override {} void OnCanceled(const std::shared_ptr &request) override {} @@ -119,7 +119,7 @@ void AdvancedNotificationServiceTest::TestAddSlotGroup() } /** - * @tc.number : AMS_ANS_Publish_00100 + * @tc.number : ANS_Publish_00100 * @tc.name : ANSPublish00100 * @tc.desc : Publish a normal text type notification. */ @@ -143,7 +143,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00100, } /** - * @tc.number : AMS_ANS_Publish_00200 + * @tc.number : ANS_Publish_00200 * @tc.name : ANSPublish00200 * @tc.desc : Publish a normal text type notification twice. */ @@ -168,7 +168,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00200, } /** - * @tc.number : AMS_ANS_Publish_00300 + * @tc.number : ANS_Publish_00300 * @tc.name : ANSPublish00300 * @tc.desc : When slotType is CUSTOM and not systemApp, the notification publish fails, * and the notification publish interface returns ERR_ANS_NON_SYSTEM_APP. @@ -193,7 +193,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00300, } /** - * @tc.number : AMS_ANS_Publish_00400 + * @tc.number : ANS_Publish_00400 * @tc.name : ANSPublish00400 * @tc.desc : When the obtained bundleName is empty, the notification publish interface returns * ERR_ANS_INVALID_BUNDLE. @@ -218,7 +218,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00400, } /** - * @tc.number : AMS_ANS_Publish_00500 + * @tc.number : ANS_Publish_00500 * @tc.name : ANSPublish00500 * @tc.desc : When the obtained bundleName does not have a corresponding slot in the database, * create the corresponding slot and publish a notification. @@ -243,7 +243,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00500, } /** - * @tc.number : AMS_ANS_Publish_00600 + * @tc.number : ANS_Publish_00600 * @tc.name : ANSPublish00600 * @tc.desc : When the obtained bundleName have a corresponding slot in the database, * the test publish interface can successfully publish a notification of normal text type. @@ -268,7 +268,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00600, } /** - * @tc.number : AMS_ANS_Publish_00700 + * @tc.number : ANS_Publish_00700 * @tc.name : ANSPublish00700 * @tc.desc : When the obtained bundleName have a corresponding slot in the database, * create the corresponding slot and publish a notification. @@ -292,7 +292,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00700, } /** - * @tc.number : AMS_ANS_Publish_00800 + * @tc.number : ANS_Publish_00800 * @tc.name : ANSPublish00800 * @tc.desc : Create a slot of type SOCIAL_COMMUNICATION and successfully publish a notification */ @@ -316,7 +316,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00800, } /** - * @tc.number : AMS_ANS_Publish_00900 + * @tc.number : ANS_Publish_00900 * @tc.name : ANSPublish00900 * @tc.desc : Create a slot of type SERVICE_REMINDER and successfully publish a notification */ @@ -340,7 +340,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_00900, } /** - * @tc.number : AMS_ANS_Publish_01000 + * @tc.number : ANS_Publish_01000 * @tc.name : ANSPublish01000 * @tc.desc : Create a slot of type CONTENT_INFORMATION and successfully publish a notification */ @@ -364,7 +364,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01000, } /** - * @tc.number : AMS_ANS_Publish_01100 + * @tc.number : ANS_Publish_01100 * @tc.name : ANSPublish01100 * @tc.desc : Create a slot of type OTHER and successfully publish a notification */ @@ -388,7 +388,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01100, } /** - * @tc.number : AMS_ANS_Publish_01200 + * @tc.number : ANS_Publish_01200 * @tc.name : ANSPublish01200 * @tc.desc : Create a slot of type CUSTOM and successfully publish a notification */ @@ -412,7 +412,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01200, } /** - * @tc.number : AMS_ANS_Publish_01300 + * @tc.number : ANS_Publish_01300 * @tc.name : ANSPublish01300 * @tc.desc : When a bundle is not allowed to publish a notification, the notification publishing interface returns @@ -441,7 +441,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01300, } /** - * @tc.number : AMS_ANS_Publish_01400 + * @tc.number : ANS_Publish_01400 * @tc.name : ANSPublish01400 * @tc.desc : */ @@ -455,7 +455,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01400, /** * @tc.number : AdvancedNotificationServiceTest_01600 - * @tc.name : AMS_ANS_GetSlot_0200 + * @tc.name : ANS_GetSlot_0200 * @tc.desc : Test GetSlots function when add two identical data */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01600, Function | SmallTest | Level1) @@ -474,7 +474,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01600, /** * @tc.number : AdvancedNotificationServiceTest_01700 - * @tc.name : AMS_ANS_GetSlotGroup_0100 + * @tc.name : ANS_GetSlotGroup_0100 * @tc.desc : Test GetSlotGroup function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01700, Function | SmallTest | Level1) @@ -493,7 +493,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01700, /** * @tc.number : AdvancedNotificationServiceTest_01800 - * @tc.name : AMS_ANS_SetNotificationBadgeNum_0100 + * @tc.name : ANS_SetNotificationBadgeNum_0100 * @tc.desc : Test SetNotificationBadgeNum function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01800, Function | SmallTest | Level1) @@ -504,7 +504,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01800, /** * @tc.number : AdvancedNotificationServiceTest_01900 - * @tc.name : AMS_ANS_GetBundleImportance_0100 + * @tc.name : ANS_GetBundleImportance_0100 * @tc.desc : Test GetBundleImportance function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01900, Function | SmallTest | Level1) @@ -516,7 +516,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_01900, /** * @tc.number : AdvancedNotificationServiceTest_02000 - * @tc.name : AMS_ANS_SetPrivateNotificationsAllowed_0100 + * @tc.name : ANS_SetPrivateNotificationsAllowed_0100 * @tc.desc : Test SetPrivateNotificationsAllowed function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02000, Function | SmallTest | Level1) @@ -527,7 +527,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02000, /** * @tc.number : AdvancedNotificationServiceTest_02100 - * @tc.name : AMS_ANS_GetPrivateNotificationsAllowed_0100 + * @tc.name : ANS_GetPrivateNotificationsAllowed_0100 * @tc.desc : Test GetPrivateNotificationsAllowed function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02100, Function | SmallTest | Level1) @@ -541,7 +541,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02100, /** * @tc.number : AdvancedNotificationServiceTest_02200 - * @tc.name : AMS_ANS_UpdateSlots_0100 + * @tc.name : ANS_UpdateSlots_0100 * @tc.desc : Test UpdateSlots function when no slot */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02200, Function | SmallTest | Level1) @@ -557,7 +557,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02200, /** * @tc.number : AdvancedNotificationServiceTest_02300 - * @tc.name : AMS_ANS_UpdateSlots_0200 + * @tc.name : ANS_UpdateSlots_0200 * @tc.desc : Test UpdateSlots function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02300, Function | SmallTest | Level1) @@ -573,7 +573,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02300, /** * @tc.number : AdvancedNotificationServiceTest_02400 - * @tc.name : AMS_ANS_UpdateSlotGroups_0100 + * @tc.name : ANS_UpdateSlotGroups_0100 * @tc.desc : Test UpdateSlotGroups function when no group */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02400, Function | SmallTest | Level1) @@ -589,7 +589,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02400, /** * @tc.number : AdvancedNotificationServiceTest_02500 - * @tc.name : AMS_ANS_UpdateSlotGroups_0200 + * @tc.name : ANS_UpdateSlotGroups_0200 * @tc.desc : Test UpdateSlotGroups function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02500, Function | SmallTest | Level1) @@ -605,7 +605,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02500, /** * @tc.number : AdvancedNotificationServiceTest_02700 - * @tc.name : AMS_ANS_SetShowBadgeEnabledForBundle_0100 + * @tc.name : ANS_SetShowBadgeEnabledForBundle_0100 * @tc.desc : Test the SetShowBadgeEnabledForBundle function when the parameter is wrong */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02700, Function | SmallTest | Level1) @@ -617,7 +617,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02700, /** * @tc.number : AdvancedNotificationServiceTest_02800 - * @tc.name : AMS_ANS_GetShowBadgeEnabledForBundle_0100 + * @tc.name : ANS_GetShowBadgeEnabledForBundle_0100 * @tc.desc : Test GetShowBadgeEnabledForBundle function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02800, Function | SmallTest | Level1) @@ -634,7 +634,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02800, /** * @tc.number : AdvancedNotificationServiceTest_02900 - * @tc.name : AMS_ANS_GetActiveNotifications_0100 + * @tc.name : ANS_GetActiveNotifications_0100 * @tc.desc : Test GetActiveNotifications function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02900, Function | SmallTest | Level1) @@ -643,34 +643,9 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_02900, EXPECT_EQ((int)advancedNotificationService_->GetActiveNotifications(notifications), (int)ERR_OK); } -/** - * @tc.number : AdvancedNotificationServiceTest_03400 - * @tc.name : AMS_ANS_SetDisturbMode_0100 - * @tc.desc : Test SetDisturbMode function - */ -HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_03400, Function | SmallTest | Level1) -{ - EXPECT_EQ( - (int)advancedNotificationService_->SetDisturbMode(NotificationConstant::DisturbMode::ALLOW_NONE), (int)ERR_OK); -} - -/** - * @tc.number : AdvancedNotificationServiceTest_03500 - * @tc.name : AMS_ANS_GetDisturbMode_0100 - * @tc.desc : Test GetDisturbMode function - */ -HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_03500, Function | SmallTest | Level1) -{ - EXPECT_EQ( - (int)advancedNotificationService_->SetDisturbMode(NotificationConstant::DisturbMode::ALLOW_NONE), (int)ERR_OK); - NotificationConstant::DisturbMode mode; - EXPECT_EQ((int)advancedNotificationService_->GetDisturbMode(mode), (int)ERR_OK); - EXPECT_EQ(mode, NotificationConstant::DisturbMode::ALLOW_NONE); -} - /** * @tc.number : AdvancedNotificationServiceTest_03700 - * @tc.name : AMS_ANS_Delete_0100 + * @tc.name : ANS_Delete_0100 * @tc.desc : Test Delete function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_03700, Function | SmallTest | Level1) @@ -681,7 +656,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_03700, /** * @tc.number : AdvancedNotificationServiceTest_03800 - * @tc.name : AMS_ANS_DeleteByBundle_0100 + * @tc.name : ANS_DeleteByBundle_0100 * @tc.desc : Test DeleteByBundle function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_03800, Function | SmallTest | Level1) @@ -693,7 +668,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_03800, /** * @tc.number : AdvancedNotificationServiceTest_03900 - * @tc.name : AMS_ANS_DeleteAll_0100 + * @tc.name : ANS_DeleteAll_0100 * @tc.desc : Test DeleteAll function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_03900, Function | SmallTest | Level1) @@ -703,7 +678,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_03900, /** * @tc.number : AdvancedNotificationServiceTest_04000 - * @tc.name : AMS_ANS_GetSlotsByBundle_0100 + * @tc.name : ANS_GetSlotsByBundle_0100 * @tc.desc : Test GetSlotsByBundle function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04000, Function | SmallTest | Level1) @@ -718,7 +693,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04000, /** * @tc.number : AdvancedNotificationServiceTest_04100 - * @tc.name : AMS_ANS_GetSpecialActiveNotifications_0100 + * @tc.name : ANS_GetSpecialActiveNotifications_0100 * @tc.desc : Test GetSpecialActiveNotifications function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04100, Function | SmallTest | Level1) @@ -754,7 +729,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04100, /** * @tc.number : AdvancedNotificationServiceTest_04600 - * @tc.name : AMS_ANS_Publish_0500 + * @tc.name : ANS_Publish_0500 * @tc.desc : publish function when NotificationsEnabled is false */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04600, Function | SmallTest | Level1) @@ -770,7 +745,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04600, /** * @tc.number : AdvancedNotificationServiceTest_04700 - * @tc.name : AMS_ANS_Cancel_0100 + * @tc.name : ANS_Cancel_0100 * @tc.desc : public two notification to cancel one of them */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04700, Function | SmallTest | Level1) @@ -794,7 +769,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04700, /** * @tc.number : AdvancedNotificationServiceTest_04800 - * @tc.name : AMS_ANS_Cancel_0200 + * @tc.name : ANS_Cancel_0200 * @tc.desc : Test Cancel function when notification no exists */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04800, Function | SmallTest | Level1) @@ -806,7 +781,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04800, /** * @tc.number : AdvancedNotificationServiceTest_04900 - * @tc.name : AMS_ANS_CancelAll_0100 + * @tc.name : ANS_CancelAll_0100 * @tc.desc : Test CancelAll function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04900, Function | SmallTest | Level1) @@ -819,7 +794,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_04900, /** * @tc.number : AdvancedNotificationServiceTest_05000 - * @tc.name : AMS_ANS_Cancel_0100 + * @tc.name : ANS_Cancel_0100 * @tc.desc : Test Cancel function when unremovable is true */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05000, Function | SmallTest | Level1) @@ -837,7 +812,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05000, /** * @tc.number : AdvancedNotificationServiceTest_05100 - * @tc.name : AMS_ANS_AddSlots_0100 + * @tc.name : ANS_AddSlots_0100 * @tc.desc : Test AddSlots function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05100, Function | SmallTest | Level1) @@ -852,7 +827,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05100, /** * @tc.number : AdvancedNotificationServiceTest_05200 - * @tc.name : AMS_ANS_RemoveSlotByType_0100 + * @tc.name : ANS_RemoveSlotByType_0100 * @tc.desc : Test RemoveSlotByType function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05200, Function | SmallTest | Level1) @@ -863,7 +838,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05200, /** * @tc.number : AdvancedNotificationServiceTest_05300 - * @tc.name : AMS_ANS_RemoveSlotByType_0200 + * @tc.name : ANS_RemoveSlotByType_0200 * @tc.desc : Test RemoveSlotByType function when no type */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05300, Function | SmallTest | Level1) @@ -875,7 +850,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05300, /** * @tc.number : AdvancedNotificationServiceTest_05400 - * @tc.name : AMS_ANS_AddSlotGroups_0100 + * @tc.name : ANS_AddSlotGroups_0100 * @tc.desc : Test AddSlotGroups function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05400, Function | SmallTest | Level1) @@ -890,7 +865,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05400, /** * @tc.number : AdvancedNotificationServiceTest_05500 - * @tc.name : AMS_ANS_RemoveSlotGroups_0100 + * @tc.name : ANS_RemoveSlotGroups_0100 * @tc.desc : Test RemoveSlotGroups function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05500, Function | SmallTest | Level1) @@ -903,7 +878,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05500, /** * @tc.number : AdvancedNotificationServiceTest_05600 - * @tc.name : AMS_ANS_GetSlot_0100 + * @tc.name : ANS_GetSlot_0100 * @tc.desc : Test GetSlot function for data */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05600, Function | SmallTest | Level1) @@ -921,7 +896,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05600, /** * @tc.number : AdvancedNotificationServiceTest_05800 - * @tc.name : AMS_ANS_GetSlotGroup_0100 + * @tc.name : ANS_GetSlotGroup_0100 * @tc.desc : Test GetSlotGroup function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05800, Function | SmallTest | Level1) @@ -940,7 +915,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05800, /** * @tc.number : AdvancedNotificationServiceTest_05900 - * @tc.name : AMS_ANS_SetNotificationBadgeNum_0100 + * @tc.name : ANS_SetNotificationBadgeNum_0100 * @tc.desc : Test SetNotificationBadgeNum function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05900, Function | SmallTest | Level1) @@ -951,7 +926,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_05900, /** * @tc.number : AdvancedNotificationServiceTest_06000 - * @tc.name : AMS_ANS_GetBundleImportance_0100 + * @tc.name : ANS_GetBundleImportance_0100 * @tc.desc : Test GetBundleImportance function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06000, Function | SmallTest | Level1) @@ -963,7 +938,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06000, /** * @tc.number : AdvancedNotificationServiceTest_06100 - * @tc.name : AMS_ANS_SetPrivateNotificationsAllowed_0100 + * @tc.name : ANS_SetPrivateNotificationsAllowed_0100 * @tc.desc : Test SetPrivateNotificationsAllowed function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06100, Function | SmallTest | Level1) @@ -974,7 +949,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06100, /** * @tc.number : AdvancedNotificationServiceTest_06200 - * @tc.name : AMS_ANS_GetPrivateNotificationsAllowed_0100 + * @tc.name : ANS_GetPrivateNotificationsAllowed_0100 * @tc.desc : Test GetPrivateNotificationsAllowed function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06200, Function | SmallTest | Level1) @@ -988,7 +963,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06200, /** * @tc.number : AdvancedNotificationServiceTest_06300 - * @tc.name : AMS_ANS_UpdateSlots_0100 + * @tc.name : ANS_UpdateSlots_0100 * @tc.desc : Test UpdateSlots function when no slot */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06300, Function | SmallTest | Level1) @@ -1004,7 +979,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06300, /** * @tc.number : AdvancedNotificationServiceTest_06400 - * @tc.name : AMS_ANS_UpdateSlots_0200 + * @tc.name : ANS_UpdateSlots_0200 * @tc.desc : Test UpdateSlots function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06400, Function | SmallTest | Level1) @@ -1020,7 +995,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06400, /** * @tc.number : AdvancedNotificationServiceTest_06500 - * @tc.name : AMS_ANS_UpdateSlotGroups_0100 + * @tc.name : ANS_UpdateSlotGroups_0100 * @tc.desc : Test UpdateSlotGroups function when no group */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06500, Function | SmallTest | Level1) @@ -1036,7 +1011,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06500, /** * @tc.number : AdvancedNotificationServiceTest_06600 - * @tc.name : AMS_ANS_UpdateSlotGroups_0200 + * @tc.name : ANS_UpdateSlotGroups_0200 * @tc.desc : Test UpdateSlotGroups function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06600, Function | SmallTest | Level1) @@ -1052,7 +1027,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06600, /** * @tc.number : AdvancedNotificationServiceTest_06800 - * @tc.name : AMS_ANS_SetShowBadgeEnabledForBundle_0100 + * @tc.name : ANS_SetShowBadgeEnabledForBundle_0100 * @tc.desc : Test the SetShowBadgeEnabledForBundle function when the parameter is wrong */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06800, Function | SmallTest | Level1) @@ -1064,7 +1039,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06800, /** * @tc.number : AdvancedNotificationServiceTest_06900 - * @tc.name : AMS_ANS_GetShowBadgeEnabledForBundle_0100 + * @tc.name : ANS_GetShowBadgeEnabledForBundle_0100 * @tc.desc : Test GetShowBadgeEnabledForBundle function when no bundle */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06900, Function | SmallTest | Level1) @@ -1077,7 +1052,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_06900, /** * @tc.number : AdvancedNotificationServiceTest_07000 - * @tc.name : AMS_ANS_GetActiveNotifications_0100 + * @tc.name : ANS_GetActiveNotifications_0100 * @tc.desc : Test GetActiveNotifications function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_07000, Function | SmallTest | Level1) @@ -1088,7 +1063,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_07000, /** * @tc.number : AdvancedNotificationServiceTest_07800 - * @tc.name : AMS_ANS_Delete_0100 + * @tc.name : ANS_Delete_0100 * @tc.desc : Test Delete function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_07800, Function | SmallTest | Level1) @@ -1099,7 +1074,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_07800, /** * @tc.number : AdvancedNotificationServiceTest_07900 - * @tc.name : AMS_ANS_DeleteByBundle_0100 + * @tc.name : ANS_DeleteByBundle_0100 * @tc.desc : Test DeleteByBundle function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_07900, Function | SmallTest | Level1) @@ -1111,7 +1086,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_07900, /** * @tc.number : AdvancedNotificationServiceTest_08000 - * @tc.name : AMS_ANS_DeleteAll_0100 + * @tc.name : ANS_DeleteAll_0100 * @tc.desc : Test DeleteAll function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08000, Function | SmallTest | Level1) @@ -1121,7 +1096,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08000, /** * @tc.number : AdvancedNotificationServiceTest_08300 - * @tc.name : AMS_ANS_Subscribe_0100 + * @tc.name : ANS_Subscribe_0100 * @tc.desc : Test Subscribe function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08300, Function | SmallTest | Level1) @@ -1134,7 +1109,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08300, /** * @tc.number : AdvancedNotificationServiceTest_08600 - * @tc.name : AMS_ANS_GetShowBadgeEnabledForBundle_0200 + * @tc.name : ANS_GetShowBadgeEnabledForBundle_0200 * @tc.desc : Test GetShowBadgeEnabledForBundle function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08600, Function | SmallTest | Level1) @@ -1152,7 +1127,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08600, /** * @tc.number : AdvancedNotificationServiceTest_08700 - * @tc.name : AMS_ANS_GetSlotByType_0100 + * @tc.name : ANS_GetSlotByType_0100 * @tc.desc : Test GetSlotByType function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08700, Function | SmallTest | Level1) @@ -1165,7 +1140,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08700, /** * @tc.number : AdvancedNotificationServiceTest_08900 - * @tc.name : AMS_ANS_GetSlotGroups_0100 + * @tc.name : ANS_GetSlotGroups_0100 * @tc.desc : Test GetSlotGroups function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08900, Function | SmallTest | Level1) @@ -1182,7 +1157,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_08900, /** * @tc.number : AdvancedNotificationServiceTest_09000 - * @tc.name : AMS_ANS_GetAllActiveNotifications_0100 + * @tc.name : ANS_GetAllActiveNotifications_0100 * @tc.desc : Test GetAllActiveNotifications function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09000, Function | SmallTest | Level1) @@ -1193,7 +1168,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09000, /** * @tc.number : AdvancedNotificationServiceTest_09200 - * @tc.name : AMS_ANS_SetNotificationsEnabledForAllBundles_0200 + * @tc.name : ANS_SetNotificationsEnabledForAllBundles_0200 * @tc.desc : Test SetNotificationsEnabledForAllBundles function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09200, Function | SmallTest | Level1) @@ -1204,7 +1179,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09200, /** * @tc.number : AdvancedNotificationServiceTest_09300 - * @tc.name : AMS_ANS_SetNotificationsEnabledForSpecialBundle_0100 + * @tc.name : ANS_SetNotificationsEnabledForSpecialBundle_0100 * @tc.desc : Test SetNotificationsEnabledForSpecialBundle function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09300, Function | SmallTest | Level1) @@ -1218,7 +1193,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09300, /** * @tc.number : AdvancedNotificationServiceTest_09600 - * @tc.name : AMS_ANS_IsAllowedNotify_0200 + * @tc.name : ANS_IsAllowedNotify_0200 * @tc.desc : Test IsAllowedNotify function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09600, Function | SmallTest | Level1) @@ -1232,7 +1207,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09600, /** * @tc.number : AdvancedNotificationServiceTest_09700 - * @tc.name : AMS_ANS_IsSpecialBundleAllowedNotify_0100 + * @tc.name : ANS_IsSpecialBundleAllowedNotify_0100 * @tc.desc : Test IsSpecialBundleAllowedNotify function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09700, Function | SmallTest | Level1) @@ -1246,7 +1221,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09700, /** * @tc.number : AdvancedNotificationServiceTest_09800 - * @tc.name : AMS_ANS_IsSpecialBundleAllowedNotify_0200 + * @tc.name : ANS_IsSpecialBundleAllowedNotify_0200 * @tc.desc : Test IsSpecialBundleAllowedNotify function */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09800, Function | SmallTest | Level1) @@ -1260,7 +1235,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09800, /** * @tc.number : AdvancedNotificationServiceTest_09900 - * @tc.name : AMS_ANS_GetSlotsByBundle_0200 + * @tc.name : ANS_GetSlotsByBundle_0200 * @tc.desc : Test GetSlotsByBundle function when no bundle */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_09900, Function | SmallTest | Level1) @@ -1295,7 +1270,7 @@ inline std::shared_ptr MakePixelMap(int32_t width, int32_t height) /** * @tc.number : AdvancedNotificationServiceTest_10000 - * @tc.name : AMS_ANS_Publish_With_PixelMap + * @tc.name : ANS_Publish_With_PixelMap * @tc.desc : Publish a notification with pixelMap. */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10000, Function | SmallTest | Level1) @@ -1327,7 +1302,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10000, /** * @tc.number : AdvancedNotificationServiceTest_10100 - * @tc.name : AMS_ANS_Publish_With_PixelMap_Oversize_00100 + * @tc.name : ANS_Publish_With_PixelMap_Oversize_00100 * @tc.desc : Publish a notification with oversize pixelMap. */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10100, Function | SmallTest | Level1) @@ -1359,7 +1334,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10100, /** * @tc.number : AdvancedNotificationServiceTest_10200 - * @tc.name : AMS_ANS_Publish_With_PixelMap_Oversize_00200 + * @tc.name : ANS_Publish_With_PixelMap_Oversize_00200 * @tc.desc : Publish a notification with oversize pixelMap. */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10200, Function | SmallTest | Level1) @@ -1391,7 +1366,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10200, /** * @tc.number : AdvancedNotificationServiceTest_10300 - * @tc.name : AMS_ANS_Cancel_By_Group_10300 + * @tc.name : ANS_Cancel_By_Group_10300 * @tc.desc : Cancel notification by group name. */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10300, Function | SmallTest | Level1) @@ -1416,7 +1391,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10300, /** * @tc.number : AdvancedNotificationServiceTest_10400 - * @tc.name : AMS_ANS_Remove_By_Group_10400 + * @tc.name : ANS_Remove_By_Group_10400 * @tc.desc : Remove notification by group name. */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10400, Function | SmallTest | Level1) @@ -1439,5 +1414,148 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10400, EXPECT_EQ(advancedNotificationService_->RemoveGroupByBundle(bundleOption, groupName), (int)ERR_OK); SleepForFC(); } + +/** + * @tc.number : AdvancedNotificationServiceTest_10500 + * @tc.name : ANS_SetDisturbMode_10500 + * @tc.desc : Test SetDisturbMode function + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10500, Function | SmallTest | Level1) +{ + sptr date = + new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0); + EXPECT_EQ((int)advancedNotificationService_->SetDoNotDisturbDate(date), (int)ERR_OK); + + std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); + auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t beginDate = beginDuration.count(); + timePoint += std::chrono::hours(1); + auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t endDate = endDuration.count(); + date = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate); + EXPECT_EQ((int)advancedNotificationService_->SetDoNotDisturbDate(date), (int)ERR_OK); + + timePoint = std::chrono::system_clock::now(); + beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + beginDate = beginDuration.count(); + timePoint += std::chrono::hours(1); + endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + endDate = endDuration.count(); + date = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::DAILY, beginDate, endDate); + EXPECT_EQ((int)advancedNotificationService_->SetDoNotDisturbDate(date), (int)ERR_OK); + + timePoint = std::chrono::system_clock::now(); + beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + beginDate = beginDuration.count(); + timePoint += std::chrono::hours(1); + endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + endDate = endDuration.count(); + date = new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::CLEARLY, beginDate, endDate); + EXPECT_EQ((int)advancedNotificationService_->SetDoNotDisturbDate(date), (int)ERR_OK); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_10600 + * @tc.name : ANS_GetDisturbMode_10600 + * @tc.desc : Test GetDisturbMode function + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10600, Function | SmallTest | Level1) +{ + sptr date = + new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0); + + EXPECT_EQ((int)advancedNotificationService_->SetDoNotDisturbDate(date), (int)ERR_OK); + + sptr result = nullptr; + EXPECT_EQ((int)advancedNotificationService_->GetDoNotDisturbDate(result), (int)ERR_OK); + ASSERT_NE(result, nullptr); + EXPECT_EQ(result->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::NONE); + EXPECT_EQ(result->GetBeginDate(), 0); + EXPECT_EQ(result->GetEndDate(), 0); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_10700 + * @tc.name : ANS_GetDisturbMode_10700 + * @tc.desc : Test GetDisturbMode function + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10700, Function | SmallTest | Level1) +{ + std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); + timePoint = std::chrono::time_point_cast(timePoint); + timePoint += std::chrono::hours(1); + auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t beginDate = beginDuration.count(); + timePoint += std::chrono::hours(1); + auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t endDate = endDuration.count(); + + sptr date = + new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate); + EXPECT_EQ((int)advancedNotificationService_->SetDoNotDisturbDate(date), (int)ERR_OK); + + sptr result = nullptr; + EXPECT_EQ((int)advancedNotificationService_->GetDoNotDisturbDate(result), (int)ERR_OK); + ASSERT_NE(result, nullptr); + EXPECT_EQ(result->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::ONCE); + EXPECT_EQ(result->GetBeginDate(), beginDate); + EXPECT_EQ(result->GetEndDate(), endDate); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_10800 + * @tc.name : ANS_GetDisturbMode_10800 + * @tc.desc : Test GetDisturbMode function + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10800, Function | SmallTest | Level1) +{ + std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); + timePoint = std::chrono::time_point_cast(timePoint); + timePoint += std::chrono::hours(1); + auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t beginDate = beginDuration.count(); + timePoint += std::chrono::hours(1); + auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t endDate = endDuration.count(); + + sptr date = + new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::DAILY, beginDate, endDate); + + EXPECT_EQ((int)advancedNotificationService_->SetDoNotDisturbDate(date), (int)ERR_OK); + sptr result = nullptr; + EXPECT_EQ((int)advancedNotificationService_->GetDoNotDisturbDate(result), (int)ERR_OK); + ASSERT_NE(result, nullptr); + EXPECT_EQ(result->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::DAILY); + EXPECT_EQ(result->GetBeginDate(), beginDate); + EXPECT_EQ(result->GetEndDate(), endDate); +} + +/** + * @tc.number : AdvancedNotificationServiceTest_10900 + * @tc.name : ANS_GetDisturbMode_10900 + * @tc.desc : Test GetDisturbMode function + */ +HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_10900, Function | SmallTest | Level1) +{ + std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); + timePoint = std::chrono::time_point_cast(timePoint); + timePoint += std::chrono::hours(1); + auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t beginDate = beginDuration.count(); + timePoint += std::chrono::hours(1); + auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t endDate = endDuration.count(); + + sptr date = + new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::CLEARLY, beginDate, endDate); + EXPECT_EQ((int)advancedNotificationService_->SetDoNotDisturbDate(date), (int)ERR_OK); + + sptr result = nullptr; + EXPECT_EQ((int)advancedNotificationService_->GetDoNotDisturbDate(result), (int)ERR_OK); + ASSERT_NE(result, nullptr); + EXPECT_EQ(result->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::CLEARLY); + EXPECT_EQ(result->GetBeginDate(), beginDate); + EXPECT_EQ(result->GetEndDate(), endDate); +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/bundle_manager_helper_test.cpp b/services/ans/test/unittest/bundle_manager_helper_test.cpp index 69f6b11f2..dc710dad0 100644 --- a/services/ans/test/unittest/bundle_manager_helper_test.cpp +++ b/services/ans/test/unittest/bundle_manager_helper_test.cpp @@ -36,7 +36,7 @@ public: /** * @tc.number : BundleManagerHelperTest_00100 - * @tc.name : AMS_ANS_GetBundleNameByUid_0100 + * @tc.name : ANS_GetBundleNameByUid_0100 * @tc.desc : Test GetBundleNameByUid function */ HWTEST_F(BundleManagerHelperTest, BundleManagerHelperTest_00100, Function | SmallTest | Level1) @@ -48,7 +48,7 @@ HWTEST_F(BundleManagerHelperTest, BundleManagerHelperTest_00100, Function | Smal /** * @tc.number : BundleManagerHelperTest_00200 - * @tc.name : AMS_ANS_IsSystemApp_0100 + * @tc.name : ANS_IsSystemApp_0100 * @tc.desc : Test IsSystemApp function */ HWTEST_F(BundleManagerHelperTest, BundleManagerHelperTest_00200, Function | SmallTest | Level1) diff --git a/services/ans/test/unittest/mock/permission_kit.cpp b/services/ans/test/unittest/mock/permission_kit.cpp new file mode 100644 index 000000000..36855b9de --- /dev/null +++ b/services/ans/test/unittest/mock/permission_kit.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "permission/permission_kit.h" + +namespace OHOS { +namespace Security { +namespace Permission { +using namespace std; + +int PermissionKit::VerifyPermission(const string &bundleName, const string &permissionName, int userId) +{ + return TypePermissionState::PERMISSION_GRANTED; +} + +bool PermissionKit::CanRequestPermission(const string &bundleName, const string &permissionName, int userId) +{ + return 0; +} + +int PermissionKit::GrantUserGrantedPermission(const string &bundleName, const string &permissionName, int userId) +{ + return 0; +} + +int PermissionKit::GrantSystemGrantedPermission(const string &bundleName, const string &permissionName) +{ + return 0; +} + +int PermissionKit::RevokeUserGrantedPermission(const string &bundleName, const string &permissionName, int userId) +{ + return 0; +} + +int PermissionKit::RevokeSystemGrantedPermission(const string &bundleName, const string &permissionName) +{ + return 0; +} + +int PermissionKit::AddUserGrantedReqPermissions( + const string &bundleName, const std::vector &permList, int userId) +{ + return 0; +} + +int PermissionKit::AddSystemGrantedReqPermissions(const string &bundleName, const std::vector &permList) +{ + return 0; +} + +int PermissionKit::RemoveUserGrantedReqPermissions(const string &bundleName, int userId) +{ + return 0; +} + +int PermissionKit::RemoveSystemGrantedReqPermissions(const string &bundleName) +{ + return 0; +} + +int PermissionKit::AddDefPermissions(const std::vector &permList) +{ + return 0; +} + +int PermissionKit::RemoveDefPermissions(const string &bundleName) +{ + return 0; +} + +int PermissionKit::GetDefPermission(const string &permissionName, PermissionDef &permissionDefResult) +{ + return 0; +} +} // namespace Permission +} // namespace Security +} // namespace OHOS \ No newline at end of file diff --git a/services/ans/test/unittest/notification_preferences_database_test.cpp b/services/ans/test/unittest/notification_preferences_database_test.cpp index 36f044d30..6cb5f7743 100644 --- a/services/ans/test/unittest/notification_preferences_database_test.cpp +++ b/services/ans/test/unittest/notification_preferences_database_test.cpp @@ -241,17 +241,71 @@ HWTEST_F(NotificationPreferencesDatabaseTest, PutNotificationsEnabled_00100, Fun } /** - * @tc.number : PutDisturbMode_00100 + * @tc.number : PutDoNotDisturbDate_00100 * @tc.name : - * @tc.desc : Put disturbe mode into disturbe DB, return is true. + * @tc.desc : Put disturbe mode into disturbe DB when DoNotDisturbType is NONE, return is true. */ -HWTEST_F(NotificationPreferencesDatabaseTest, PutDisturbMode_00100, Function | SmallTest | Level1) +HWTEST_F(NotificationPreferencesDatabaseTest, PutDoNotDisturbDate_00100, Function | SmallTest | Level1) { - EXPECT_TRUE(preferncesDB_->PutDisturbMode(OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_ALARMS)); - EXPECT_TRUE(preferncesDB_->PutDisturbMode(OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_ALL)); - EXPECT_TRUE(preferncesDB_->PutDisturbMode(OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_NONE)); - EXPECT_TRUE(preferncesDB_->PutDisturbMode(OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_PRIORITY)); - EXPECT_TRUE(preferncesDB_->PutDisturbMode(OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_UNKNOWN)); + sptr date = + new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0); + EXPECT_TRUE(preferncesDB_->PutDoNotDisturbDate(date)); +} + +/** + * @tc.number : PutDoNotDisturbDate_00200 + * @tc.name : + * @tc.desc : Put disturbe mode into disturbe DB when DoNotDisturbType is ONCE, return is true. + */ +HWTEST_F(NotificationPreferencesDatabaseTest, PutDoNotDisturbDate_00200, Function | SmallTest | Level1) +{ + std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); + auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t beginDate = beginDuration.count(); + timePoint += std::chrono::hours(1); + auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t endDate = endDuration.count(); + sptr date = + new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate); + EXPECT_TRUE(preferncesDB_->PutDoNotDisturbDate(date)); +} + +/** + * @tc.number : PutDoNotDisturbDate_00300 + * @tc.name : + * @tc.desc : Put disturbe mode into disturbe DB when DoNotDisturbType is DAILY, return is true. + */ +HWTEST_F(NotificationPreferencesDatabaseTest, PutDoNotDisturbDate_00300, Function | SmallTest | Level1) +{ + std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); + auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t beginDate = beginDuration.count(); + timePoint += std::chrono::hours(1); + auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t endDate = endDuration.count(); + sptr date = + new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::DAILY, beginDate, endDate); + + EXPECT_TRUE(preferncesDB_->PutDoNotDisturbDate(date)); +} + +/** + * @tc.number : PutDoNotDisturbDate_00400 + * @tc.name : + * @tc.desc : Put disturbe mode into disturbe DB when DoNotDisturbType is CLEARLY, return is true. + */ +HWTEST_F(NotificationPreferencesDatabaseTest, PutDoNotDisturbDate_00400, Function | SmallTest | Level1) +{ + std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); + auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t beginDate = beginDuration.count(); + timePoint += std::chrono::hours(1); + auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t endDate = endDuration.count(); + sptr date = + new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::CLEARLY, beginDate, endDate); + + EXPECT_TRUE(preferncesDB_->PutDoNotDisturbDate(date)); } /** @@ -387,7 +441,7 @@ HWTEST_F(NotificationPreferencesDatabaseTest, GetKvStore_00100, Function | Small /** * @tc.name : CheckKvStore_00100 - * @tc.number : + * @tc.number : * @tc.desc : Check disturbe DB is exsit, return is true. */ HWTEST_F(NotificationPreferencesDatabaseTest, CheckKvStore_00100, Function | SmallTest | Level1) diff --git a/services/ans/test/unittest/notification_preferences_test.cpp b/services/ans/test/unittest/notification_preferences_test.cpp index f21215383..6c5353459 100644 --- a/services/ans/test/unittest/notification_preferences_test.cpp +++ b/services/ans/test/unittest/notification_preferences_test.cpp @@ -1036,29 +1036,46 @@ HWTEST_F(NotificationPreferencesTest, GetNotificationsEnabled_00100, Function | } /** - * @tc.number : SetDisturbMode_00100 + * @tc.number : SetDoNotDisturbDate_00100 * @tc.name : * @tc.desc : Set disturbe mode into disturbe DB, return is ERR_OK */ -HWTEST_F(NotificationPreferencesTest, SetDisturbMode_00100, Function | SmallTest | Level1) +HWTEST_F(NotificationPreferencesTest, SetDoNotDisturbDate_00100, Function | SmallTest | Level1) { - EXPECT_EQ((int)NotificationPreferences::GetInstance().SetDisturbMode(NotificationConstant::DisturbMode::ALLOW_ALL), - (int)ERR_OK); + std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); + auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t beginDate = beginDuration.count(); + timePoint += std::chrono::hours(1); + auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t endDate = endDuration.count(); + sptr date = + new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate); + + EXPECT_EQ((int)NotificationPreferences::GetInstance().SetDoNotDisturbDate(date), (int)ERR_OK); } /** - * @tc.number : GetDisturbMode_00100 + * @tc.number : GetDoNotDisturbDate_00100 * @tc.name : * @tc.desc : Get disturbe mode from disturbe DB, return is ERR_OK */ -HWTEST_F(NotificationPreferencesTest, GetDisturbMode_00100, Function | SmallTest | Level1) +HWTEST_F(NotificationPreferencesTest, GetDoNotDisturbDate_00100, Function | SmallTest | Level1) { - EXPECT_EQ((int)NotificationPreferences::GetInstance().SetDisturbMode(NotificationConstant::DisturbMode::ALLOW_ALL), - (int)ERR_OK); - NotificationConstant::DisturbMode mode; - EXPECT_EQ((int)NotificationPreferences::GetInstance().GetDisturbMode(mode), (int)ERR_OK); - EXPECT_EQ((int)NotificationConstant::DisturbMode::ALLOW_ALL, mode); -} + std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); + auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t beginDate = beginDuration.count(); + timePoint += std::chrono::hours(1); + auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t endDate = endDuration.count(); + sptr date = + new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::DAILY, beginDate, endDate); + EXPECT_EQ((int)NotificationPreferences::GetInstance().SetDoNotDisturbDate(date), (int)ERR_OK); + sptr getDate; + EXPECT_EQ((int)NotificationPreferences::GetInstance().GetDoNotDisturbDate(getDate), (int)ERR_OK); + EXPECT_EQ(getDate->GetDoNotDisturbType(), NotificationConstant::DoNotDisturbType::DAILY); + EXPECT_EQ(getDate->GetBeginDate(), beginDate); + EXPECT_EQ(getDate->GetEndDate(), endDate); +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/test/unittest/notification_slot_filter_test.cpp b/services/ans/test/unittest/notification_slot_filter_test.cpp index 1d8582a23..15e72a01e 100644 --- a/services/ans/test/unittest/notification_slot_filter_test.cpp +++ b/services/ans/test/unittest/notification_slot_filter_test.cpp @@ -32,7 +32,7 @@ public: /** * @tc.number : NotificationSlotFilterTest_00100 - * @tc.name : AMS_ANS_OnStart_0100 + * @tc.name : ANS_OnStart_0100 * @tc.desc : Test OnStart function */ HWTEST_F(NotificationSlotFilterTest, NotificationSlotFilterTest_00100, Function | SmallTest | Level1) @@ -43,7 +43,7 @@ HWTEST_F(NotificationSlotFilterTest, NotificationSlotFilterTest_00100, Function /** * @tc.number : NotificationSlotFilterTest_00200 - * @tc.name : AMS_ANS_OnStop_0100 + * @tc.name : ANS_OnStop_0100 * @tc.desc : Test OnStop function */ HWTEST_F(NotificationSlotFilterTest, NotificationSlotFilterTest_00200, Function | SmallTest | Level1) @@ -54,7 +54,7 @@ HWTEST_F(NotificationSlotFilterTest, NotificationSlotFilterTest_00200, Function /** * @tc.number : NotificationSlotFilterTest_00300 - * @tc.name : AMS_ANS_OnPublish_0100 + * @tc.name : ANS_OnPublish_0100 * @tc.desc : Test OnPublish function */ HWTEST_F(NotificationSlotFilterTest, NotificationSlotFilterTest_00300, Function | SmallTest | Level1) diff --git a/services/ans/test/unittest/notification_subscriber_manager_test.cpp b/services/ans/test/unittest/notification_subscriber_manager_test.cpp index 40b26ceca..6ce1eee99 100644 --- a/services/ans/test/unittest/notification_subscriber_manager_test.cpp +++ b/services/ans/test/unittest/notification_subscriber_manager_test.cpp @@ -44,7 +44,7 @@ private: {} void OnUpdate(const std::shared_ptr &sortingMap) override {} - void OnDisturbModeChanged(int disturbMode) override + void OnDoNotDisturbDateChange(const std::shared_ptr &date) override {} void OnCanceled(const std::shared_ptr &request) override {} @@ -92,7 +92,7 @@ void NotificationSubscriberManagerTest::TearDown() /** * @tc.number : NotificationSubscriberManagerTest_001 - * @tc.name : AMS_ANS_NotifyUpdated_0100 + * @tc.name : ANS_NotifyUpdated_0100 * @tc.desc : Test NotifyUpdated function. */ HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_001, Function | SmallTest | Level1) @@ -104,18 +104,19 @@ HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_00 /** * @tc.number : NotificationSubscriberManagerTest_002 - * @tc.name : AMS_ANS_NotifyDisturbModeChanged_0100 + * @tc.name : ANS_NotifyDisturbModeChanged_0100 * @tc.desc : Test NotifyDisturbModeChanged function. */ HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_002, Function | SmallTest | Level1) { - NotificationConstant::DisturbMode mode; - notificationSubscriberManager_->NotifyDisturbModeChanged(mode); + sptr date = + new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0); + notificationSubscriberManager_->NotifyDoNotDisturbDateChanged(date); } /** * @tc.number : NotificationSubscriberManagerTest_003 - * @tc.name : AMS_ANS_NotifyConsumed_0100 + * @tc.name : ANS_NotifyConsumed_0100 * @tc.desc : Test NotifyConsumed function. */ HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_003, Function | SmallTest | Level1) @@ -129,7 +130,7 @@ HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_00 /** * @tc.number : NotificationSubscriberManagerTest_004 - * @tc.name : AMS_ANS_NotifyCanceled_0100 + * @tc.name : ANS_NotifyCanceled_0100 * @tc.desc : Test NotifyCanceled function. */ HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_004, Function | SmallTest | Level1) @@ -144,7 +145,7 @@ HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_00 /** * @tc.number : NotificationSubscriberManagerTest_005 - * @tc.name : AMS_ANS_AddSubscriber_0100 + * @tc.name : ANS_AddSubscriber_0100 * @tc.desc : Test AddSubscriber function, return is ERR_OK. */ HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_005, Function | SmallTest | Level1) @@ -157,7 +158,7 @@ HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_00 /** * @tc.number : NotificationSubscriberManagerTest_006 - * @tc.name : AMS_ANS_AddSubscriber_0100 + * @tc.name : ANS_AddSubscriber_0100 * @tc.desc : Test AddSubscriber function when subscriber is nullptr, return is ERR_ANS_INVALID_PARAM. */ HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_006, Function | SmallTest | Level1) @@ -168,7 +169,7 @@ HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_00 /** * @tc.number : NotificationSubscriberManagerTest_007 - * @tc.name : AMS_ANS_RemoveSubscriber_0100 + * @tc.name : ANS_RemoveSubscriber_0100 * @tc.desc : Test RemoveSubscriber function, return is ERR_OK. */ HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_007, Function | SmallTest | Level1) @@ -180,7 +181,7 @@ HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_00 /** * @tc.number : NotificationSubscriberManagerTest_006 - * @tc.name : AMS_ANS_AddSubscriber_0100 + * @tc.name : ANS_AddSubscriber_0100 * @tc.desc : Test RemoveSubscriber function when subscriber is nullptr, return is ERR_ANS_INVALID_PARAM. */ HWTEST_F(NotificationSubscriberManagerTest, NotificationSubscriberManagerTest_008, Function | SmallTest | Level1) diff --git a/services/ans/test/unittest/permission_filter_test.cpp b/services/ans/test/unittest/permission_filter_test.cpp index 6472f5175..3aa2fa829 100644 --- a/services/ans/test/unittest/permission_filter_test.cpp +++ b/services/ans/test/unittest/permission_filter_test.cpp @@ -47,7 +47,7 @@ void PermissionFilterTest::TearDown() /** * @tc.number : PermissionFilterTest_00100 - * @tc.name : AMS_ANS_OnStop_0100 + * @tc.name : ANS_OnStop_0100 * @tc.desc : Test OnStart function */ HWTEST_F(PermissionFilterTest, PermissionFilterTest_00100, Function | SmallTest | Level1) @@ -58,7 +58,7 @@ HWTEST_F(PermissionFilterTest, PermissionFilterTest_00100, Function | SmallTest /** * @tc.number : PermissionFilterTest_00200 - * @tc.name : AMS_ANS_OnStop_0100 + * @tc.name : ANS_OnStop_0100 * @tc.desc : Test OnStop function */ HWTEST_F(PermissionFilterTest, PermissionFilterTest_00200, Function | SmallTest | Level1) diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index e98202874..02ebb5b1e 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -40,7 +40,6 @@ ohos_moduletest("ans_module_test") { "${services_path}/ans/src/advanced_notification_service.cpp", "${services_path}/ans/src/advanced_notification_service_ability.cpp", "${services_path}/ans/src/bundle_manager_helper.cpp", - "${services_path}/ans/src/disturb_filter.cpp", "${services_path}/ans/src/notification_preferences.cpp", "${services_path}/ans/src/notification_preferences_database.cpp", "${services_path}/ans/src/notification_preferences_info.cpp", @@ -58,6 +57,7 @@ ohos_moduletest("ans_module_test") { "mock/mock_event_handler.cpp", "mock/mock_ipc.cpp", "mock/mock_single_kv_store.cpp", + "mock/permission_kit.cpp", ] configs = [ "//utils/native/base:utils_config" ] @@ -86,6 +86,7 @@ ohos_moduletest("ans_module_test") { "ces_standard:cesfwk_innerkits", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", + "permission_standard:libpermissionsdk_standard", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", ] diff --git a/services/test/moduletest/ans_module_test.cpp b/services/test/moduletest/ans_module_test.cpp index 1a76cf30e..a967f8b00 100644 --- a/services/test/moduletest/ans_module_test.cpp +++ b/services/test/moduletest/ans_module_test.cpp @@ -33,8 +33,6 @@ sptr g_advancedNotificationService; bool passed = false; class TestAnsSubscriber : public NotificationSubscriber { public: - ~TestAnsSubscriber(){}; - void OnConnected() override { if (subscriberCb_ != nullptr) { @@ -51,7 +49,7 @@ public: {} void OnUpdate(const std::shared_ptr &sortingMap) override {} - void OnDisturbModeChanged(int disturbMode) override + void OnDoNotDisturbDateChange(const std::shared_ptr &date) override {} void OnCanceled(const std::shared_ptr &request) override {} @@ -124,7 +122,7 @@ void TestAddSlots() /** * @tc.number : AnsModuleTest_001 - * @tc.name : AMS_ANS_Subscribe_Publish_0100 + * @tc.name : ANS_Subscribe_Publish_0100 * @tc.desc : Test the functions of subscribing, publishing, and canceling */ HWTEST_F(AnsModuleTest, AnsModuleTest_001, Function | SmallTest | Level1) @@ -152,7 +150,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_001, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_002 - * @tc.name : AMS_ANS_GetActiveNotifications_0200 + * @tc.name : ANS_Module_Test_0200 * @tc.desc : Test the function of getting notifications and getting all notifications */ HWTEST_F(AnsModuleTest, AnsModuleTest_002, Function | SmallTest | Level1) @@ -184,7 +182,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_002, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_003 - * @tc.name : AMS_ANS_GetActiveNotifications_0300 + * @tc.name : ANS_Module_Test_0300 * @tc.desc : Test publish notifications when slot are not allowed publish. */ HWTEST_F(AnsModuleTest, AnsModuleTest_003, Function | SmallTest | Level1) @@ -216,44 +214,10 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_003, Function | SmallTest | Level1) g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo); } -/** - * @tc.number : AnsModuleTest_004 - * @tc.name : AMS_ANS_GetActiveNotifications_0400 - * @tc.desc : Test publish notifications when Disturb are not allowed publish. - */ -HWTEST_F(AnsModuleTest, AnsModuleTest_004, Function | SmallTest | Level1) -{ - // subscriber - auto subscriber = new TestAnsSubscriber(); - sptr subscriberInfo = new NotificationSubscribeInfo(); - g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); - subscriber->consumedCb_ = [](const std::shared_ptr, const std::shared_ptr) { - passed = true; - }; - - // add slot - std::vector> slots; - sptr slot0 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); - slots.push_back(slot0); - g_advancedNotificationService->AddSlots(slots); - - // create request - std::string label = "testLabel"; - sptr req = new NotificationRequest(0); - req->SetLabel(label); - req->SetStatusBarText("text"); - - g_advancedNotificationService->SetDisturbMode(NotificationConstant::DisturbMode::ALLOW_NONE); - - g_advancedNotificationService->Publish(label, req); - EXPECT_EQ(false, passed); - g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo); -} - /** * @tc.number : AnsModuleTest_005 - * @tc.name : AMS_ANS_GetActiveNotifications_0500 - * @tc.desc : Test publish notifications when Disturb are not allowed publish. + * @tc.name : ANS_Module_Test_0500 + * @tc.desc : Test publish notification when slot type is SERVICE_REMINDER. */ HWTEST_F(AnsModuleTest, AnsModuleTest_005, Function | SmallTest | Level1) { @@ -299,7 +263,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_005, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_006 - * @tc.name : AMS_ANS_GetActiveNotifications_0600 + * @tc.name : ANS_Module_Test_0600 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_006, Function | SmallTest | Level1) @@ -332,8 +296,8 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_006, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_007 - * @tc.name : AMS_ANS_GetActiveNotifications_0700 - * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. + * @tc.name : ANS_Module_Test_0700 + * @tc.desc : Test publish notification when slot type is OTHER. */ HWTEST_F(AnsModuleTest, AnsModuleTest_007, Function | SmallTest | Level1) { @@ -379,8 +343,8 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_007, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0013 - * @tc.name : AMS_ANS_GetActiveNotifications_01300 - * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. + * @tc.name : ANS_Module_Test_01300 + * @tc.desc : Test publish notification when slot type is SOCIAL_COMMUNICATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0013, Function | SmallTest | Level1) { @@ -412,8 +376,8 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0013, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0014 - * @tc.name : AMS_ANS_GetActiveNotifications_01400 - * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. + * @tc.name : ANS_Module_Test_01400 + * @tc.desc : Test publish notification when slot type is SOCIAL_COMMUNICATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0014, Function | SmallTest | Level1) { @@ -450,8 +414,8 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0014, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0015 - * @tc.name : AMS_ANS_GetActiveNotifications_01500 - * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. + * @tc.name : ANS_Module_Test_01500 + * @tc.desc : Test publish notification when slot type is SOCIAL_COMMUNICATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0015, Function | SmallTest | Level1) { @@ -488,8 +452,8 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0015, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0017 - * @tc.name : AMS_ANS_GetActiveNotifications_01700 - * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. + * @tc.name : ANS_Module_Test_01700 + * @tc.desc : Test publish notification when slot type is SOCIAL_COMMUNICATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0017, Function | SmallTest | Level1) { @@ -526,7 +490,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0017, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0019 - * @tc.name : AMS_ANS_GetActiveNotifications_01900 + * @tc.name : ANS_Module_Test_01900 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0019, Function | SmallTest | Level1) @@ -564,7 +528,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0019, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0021 - * @tc.name : AMS_ANS_GetActiveNotifications_02100 + * @tc.name : ANS_Module_Test_02100 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0021, Function | SmallTest | Level1) @@ -617,7 +581,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0021, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0023 - * @tc.name : AMS_ANS_GetActiveNotifications_02300 + * @tc.name : ANS_Module_Test_02300 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0023, Function | SmallTest | Level1) @@ -655,7 +619,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0023, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0031 - * @tc.name : AMS_ANS_GetActiveNotifications_03100 + * @tc.name : ANS_Module_Test_03100 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0031, Function | SmallTest | Level1) @@ -708,7 +672,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0031, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0033 - * @tc.name : AMS_ANS_GetActiveNotifications_03300 + * @tc.name : ANS_Module_Test_03300 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0033, Function | SmallTest | Level1) @@ -752,7 +716,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0033, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0034 - * @tc.name : AMS_ANS_GetActiveNotifications_03400 + * @tc.name : ANS_Module_Test_03400 * @tc.desc : Test publish notification when slot type is SOCIAL_COMMUNICATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0034, Function | SmallTest | Level1) @@ -796,7 +760,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0034, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0035 - * @tc.name : AMS_ANS_GetActiveNotifications_03500 + * @tc.name : ANS_Module_Test_03500 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0035, Function | SmallTest | Level1) @@ -836,7 +800,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0035, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0036 - * @tc.name : AMS_ANS_GetActiveNotifications_03600 + * @tc.name : ANS_Module_Test_03600 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0036, Function | SmallTest | Level1) @@ -876,7 +840,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0036, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0039 - * @tc.name : AMS_ANS_GetActiveNotifications_03900 + * @tc.name : ANS_Module_Test_03900 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0039, Function | SmallTest | Level1) @@ -930,7 +894,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0039, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0040 - * @tc.name : AMS_ANS_GetActiveNotifications_04000 + * @tc.name : ANS_Module_Test_04000 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0040, Function | SmallTest | Level1) @@ -968,7 +932,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0040, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0041 - * @tc.name : AMS_ANS_GetActiveNotifications_04100 + * @tc.name : ANS_Module_Test_04100 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0041, Function | SmallTest | Level1) @@ -1006,7 +970,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0041, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0042 - * @tc.name : AMS_ANS_GetActiveNotifications_04200 + * @tc.name : ANS_Module_Test_04200 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0042, Function | SmallTest | Level1) @@ -1044,7 +1008,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0042, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0043 - * @tc.name : AMS_ANS_GetActiveNotifications_04300 + * @tc.name : ANS_Module_Test_04300 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0043, Function | SmallTest | Level1) @@ -1082,7 +1046,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0043, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0049 - * @tc.name : AMS_ANS_GetActiveNotifications_04900 + * @tc.name : ANS_Module_Test_04900 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0049, Function | SmallTest | Level1) @@ -1103,7 +1067,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0049, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0051 - * @tc.name : AMS_ANS_GetActiveNotifications_05100 + * @tc.name : ANS_Module_Test_05100 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0051, Function | SmallTest | Level1) @@ -1129,7 +1093,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0051, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0052 - * @tc.name : AMS_ANS_GetActiveNotifications_05200 + * @tc.name : ANS_Module_Test_05200 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0052, Function | SmallTest | Level1) @@ -1154,7 +1118,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0052, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0054 - * @tc.name : AMS_ANS_GetActiveNotifications_05400 + * @tc.name : ANS_Module_Test_05400 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0054, Function | SmallTest | Level1) @@ -1186,7 +1150,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0054, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0055 - * @tc.name : AMS_ANS_GetActiveNotifications_05500 + * @tc.name : ANS_Module_Test_05500 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0055, Function | SmallTest | Level1) @@ -1204,7 +1168,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0055, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0056 - * @tc.name : AMS_ANS_GetActiveNotifications_05600 + * @tc.name : ANS_Module_Test_05600 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0056, Function | SmallTest | Level1) @@ -1228,7 +1192,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0056, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0058 - * @tc.name : AMS_ANS_GetActiveNotifications_05800 + * @tc.name : ANS_Module_Test_05800 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0058, Function | SmallTest | Level1) @@ -1269,7 +1233,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0058, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0060 - * @tc.name : AMS_ANS_GetActiveNotifications_06000 + * @tc.name : ANS_Module_Test_06000 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0060, Function | SmallTest | Level1) @@ -1316,7 +1280,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0060, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0061 - * @tc.name : AMS_ANS_GetActiveNotifications_06100 + * @tc.name : ANS_Module_Test_06100 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0061, Function | SmallTest | Level1) @@ -1363,7 +1327,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0061, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_062 - * @tc.name : AMS_ANS_GetActiveNotifications_06200 + * @tc.name : ANS_Module_Test_06200 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0062, Function | SmallTest | Level1) @@ -1410,7 +1374,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0062, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_063 - * @tc.name : AMS_ANS_GetActiveNotifications_06300 + * @tc.name : ANS_Module_Test_06300 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0063, Function | SmallTest | Level1) @@ -1455,7 +1419,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0063, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_064 - * @tc.name : AMS_ANS_GetActiveNotifications_06400 + * @tc.name : ANS_Module_Test_06400 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0064, Function | SmallTest | Level1) @@ -1472,7 +1436,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0064, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_065 - * @tc.name : AMS_ANS_GetActiveNotifications_06500 + * @tc.name : ANS_Module_Test_06500 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0065, Function | SmallTest | Level1) @@ -1487,7 +1451,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0065, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_066 - * @tc.name : AMS_ANS_GetActiveNotifications_06600 + * @tc.name : ANS_Module_Test_06600 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0066, Function | SmallTest | Level1) @@ -1515,7 +1479,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0066, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_100 - * @tc.name : AMS_ANS_GetActiveNotifications_10000 + * @tc.name : ANS_Module_Test_10000 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0100, Function | SmallTest | Level1) @@ -1558,7 +1522,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0100, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_101 - * @tc.name : AMS_ANS_GetActiveNotifications_10100 + * @tc.name : ANS_Module_Test_10100 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0101, Function | SmallTest | Level1) @@ -1589,7 +1553,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0101, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_102 - * @tc.name : AMS_ANS_GetActiveNotifications_10200 + * @tc.name : ANS_Module_Test_10200 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0102, Function | SmallTest | Level1) @@ -1620,7 +1584,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0102, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_103 - * @tc.name : AMS_ANS_GetActiveNotifications_10300 + * @tc.name : ANS_Module_Test_10300 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0103, Function | SmallTest | Level1) @@ -1649,44 +1613,9 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0103, Function | SmallTest | Level1) g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo); } -/** - * @tc.number : AnsModuleTest_104 - * @tc.name : AMS_ANS_GetActiveNotifications_10400 - * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. - */ -HWTEST_F(AnsModuleTest, AnsModuleTest_0104, Function | SmallTest | Level1) -{ - // subscriber - auto subscriber = new TestAnsSubscriber(); - sptr subscriberInfo = new NotificationSubscribeInfo(); - g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); - subscriber->consumedCb_ = [](const std::shared_ptr, const std::shared_ptr) { - passed = true; - }; - - // add slot - std::vector> slots; - sptr slot0 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); - slots.push_back(slot0); - g_advancedNotificationService->AddSlots(slots); - - // create request - std::string label = "testLabel"; - sptr req = new NotificationRequest(0); - req->SetLabel(label); - req->SetStatusBarText("text"); - req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); - - g_advancedNotificationService->SetDisturbMode(NotificationConstant::DisturbMode::ALLOW_NONE); - - g_advancedNotificationService->Publish(label, req); - EXPECT_EQ(false, passed); - g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo); -} - /** * @tc.number : AnsModuleTest_105 - * @tc.name : AMS_ANS_GetActiveNotifications_10500 + * @tc.name : ANS_Module_Test_10500 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0105, Function | SmallTest | Level1) @@ -1711,7 +1640,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0105, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_106 - * @tc.name : AMS_ANS_GetActiveNotifications_10600 + * @tc.name : ANS_Module_Test_10600 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0106, Function | SmallTest | Level1) @@ -1746,7 +1675,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0106, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_107 - * @tc.name : AMS_ANS_GetActiveNotifications_10700 + * @tc.name : ANS_Module_Test_10700 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0107, Function | SmallTest | Level1) @@ -1793,7 +1722,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0107, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_108 - * @tc.name : AMS_ANS_GetActiveNotifications_10800 + * @tc.name : ANS_Module_Test_10800 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0108, Function | SmallTest | Level1) @@ -1839,7 +1768,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0108, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_110 - * @tc.name : AMS_ANS_GetActiveNotifications_11000 + * @tc.name : ANS_Module_Test_11000 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0110, Function | SmallTest | Level1) @@ -1858,7 +1787,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0110, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_111 - * @tc.name : AMS_ANS_GetActiveNotifications_11100 + * @tc.name : ANS_Module_Test_11100 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0111, Function | SmallTest | Level1) @@ -1875,7 +1804,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0111, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_112 - * @tc.name : AMS_ANS_GetActiveNotifications_11200 + * @tc.name : ANS_Module_Test_11200 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0112, Function | SmallTest | Level1) @@ -1932,7 +1861,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0112, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_113 - * @tc.name : AMS_ANS_GetActiveNotifications_11300 + * @tc.name : ANS_Module_Test_11300 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0113, Function | SmallTest | Level1) @@ -1991,7 +1920,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0113, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_114 - * @tc.name : AMS_ANS_GetActiveNotifications_11400 + * @tc.name : ANS_Module_Test_11400 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0114, Function | SmallTest | Level1) @@ -2050,7 +1979,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0114, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_116 - * @tc.name : AMS_ANS_GetActiveNotifications_11600 + * @tc.name : ANS_Module_Test_11600 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0116, Function | SmallTest | Level1) @@ -2110,7 +2039,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0116, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_117 - * @tc.name : AMS_ANS_GetActiveNotifications_11700 + * @tc.name : ANS_Module_Test_11700 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0117, Function | SmallTest | Level1) @@ -2168,48 +2097,9 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0117, Function | SmallTest | Level1) g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr); } -/** - * @tc.number : AnsModuleTest_118 - * @tc.name : AMS_ANS_GetActiveNotifications_11800 - * @tc.desc : Test publish notifications when Disturb are not allowed publish. - */ -HWTEST_F(AnsModuleTest, AnsModuleTest_0118, Function | SmallTest | Level1) -{ - // subscriber - auto subscriber = new TestAnsSubscriber(); - sptr subscriberInfo = new NotificationSubscribeInfo(); - g_advancedNotificationService->Subscribe(subscriber->GetImpl(), subscriberInfo); - subscriber->consumedCb_ = [](const std::shared_ptr, const std::shared_ptr) { - passed = true; - }; - - // add slot - std::vector> slots; - sptr slot0 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); - slots.push_back(slot0); - g_advancedNotificationService->AddSlots(slots); - - // create request - std::string label = "testLabel"; - sptr req = new NotificationRequest(0); - req->SetLabel(label); - req->SetStatusBarText("text"); - std::shared_ptr contentImpl = std::make_shared(); - contentImpl->SetText("1"); - contentImpl->SetTitle("1"); - std::shared_ptr content = std::make_shared(contentImpl); - req->SetContent(content); - - g_advancedNotificationService->SetDisturbMode(NotificationConstant::DisturbMode::ALLOW_NONE); - - g_advancedNotificationService->Publish(label, req); - EXPECT_EQ(false, passed); - g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), subscriberInfo); -} - /** * @tc.number : AnsModuleTest_120 - * @tc.name : AMS_ANS_GetActiveNotifications_12000 + * @tc.name : ANS_Module_Test_12000 * @tc.desc : Test publish notifications when Disturb are not allowed publish. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0120, Function | SmallTest | Level1) @@ -2249,7 +2139,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0120, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0121 - * @tc.name : AMS_ANS_GetActiveNotifications_12100 + * @tc.name : ANS_Module_Test_12100 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0121, Function | SmallTest | Level1) @@ -2278,7 +2168,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0121, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0122 - * @tc.name : AMS_ANS_GetActiveNotifications_12200 + * @tc.name : ANS_Module_Test_12200 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0122, Function | SmallTest | Level1) @@ -2327,7 +2217,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0122, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0123 - * @tc.name : AMS_ANS_GetActiveNotifications_12300 + * @tc.name : ANS_Module_Test_12300 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0123, Function | SmallTest | Level1) @@ -2382,7 +2272,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0123, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0124 - * @tc.name : AMS_ANS_GetActiveNotifications_12400 + * @tc.name : ANS_Module_Test_12400 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0124, Function | SmallTest | Level1) @@ -2420,7 +2310,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0124, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0125 - * @tc.name : AMS_ANS_GetActiveNotifications_12500 + * @tc.name : ANS_Module_Test_12500 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0125, Function | SmallTest | Level1) @@ -2453,7 +2343,7 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0125, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0126 - * @tc.name : AMS_ANS_GetActiveNotifications_12600 + * @tc.name : ANS_Module_Test_12600 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0126, Function | SmallTest | Level1) @@ -2491,11 +2381,13 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0126, Function | SmallTest | Level1) /** * @tc.number : AnsModuleTest_0127 - * @tc.name : AMS_ANS_GetActiveNotifications_12700 + * @tc.name : ANS_Module_Test_12700 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0127, Function | SmallTest | Level1) { + const int EXPECT_REQUST_NUM = 2; + int ret = 0; // subscriber auto subscriber = new TestAnsSubscriber(); @@ -2542,17 +2434,21 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0127, Function | SmallTest | Level1) req1->SetSlotType(NotificationConstant::SlotType::SERVICE_REMINDER); // publish - EXPECT_EQ(0, ret); + EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK); + EXPECT_EQ(g_advancedNotificationService->Publish(label, req1), ERR_OK); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr); + EXPECT_EQ(ret, EXPECT_REQUST_NUM); } /** * @tc.number : AnsModuleTest_0128 - * @tc.name : AMS_ANS_GetActiveNotifications_12800 + * @tc.name : ANS_Module_Test_12800 * @tc.desc : Test publish notification when slot type is CONTENT_INFORMATION. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0128, Function | SmallTest | Level1) { + const int EXPECT_REQUST_NUM = 2; + int ret = 0; // subscriber auto subscriber = new TestAnsSubscriber(); @@ -2599,13 +2495,15 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0128, Function | SmallTest | Level1) req1->SetSlotType(NotificationConstant::SlotType::OTHER); // publish - EXPECT_EQ(0, ret); + EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK); + EXPECT_EQ(g_advancedNotificationService->Publish(label, req1), ERR_OK); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr); + EXPECT_EQ(ret, EXPECT_REQUST_NUM); } /** * @tc.number : AnsModuleTest_0130 - * @tc.name : AMS_ANS_GetActiveNotifications_13000 + * @tc.name : ANS_Module_Test_13000 * @tc.desc : Test publish notification when slot type is OTHER. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0130, Function | SmallTest | Level1) @@ -2615,8 +2513,8 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0130, Function | SmallTest | Level1) g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr); subscriber->consumedCb_ = [](const std::shared_ptr notification, const std::shared_ptr sortingMap) { - EXPECT_EQ(false, notification->EnableVibrate()); - EXPECT_EQ(NotificationConstant::VisiblenessType::PUBLIC, notification->GetLockscreenVisibleness()); + EXPECT_FALSE(notification->EnableVibrate()); + EXPECT_FALSE(notification->EnableSound()); }; // add slot @@ -2632,13 +2530,13 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0130, Function | SmallTest | Level1) req->SetSlotType(NotificationConstant::SlotType::OTHER); req->SetLabel(label); // publish - + EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK); g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr); } /** * @tc.number : AnsModuleTest_0131 - * @tc.name : AMS_ANS_GetActiveNotifications_13100 + * @tc.name : ANS_Module_Test_13100 * @tc.desc : Test publish notification when cancel a notification. */ HWTEST_F(AnsModuleTest, AnsModuleTest_0131, Function | SmallTest | Level1) @@ -2649,10 +2547,170 @@ HWTEST_F(AnsModuleTest, AnsModuleTest_0131, Function | SmallTest | Level1) subscriber->canceledCb_ = [](const std::shared_ptr &request, const std::shared_ptr &sortingMap, int deleteReason) { passed = true; }; - // g_advancedNotificationService->Cancel(1, "1"); + g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr); EXPECT_EQ(false, passed); } +/** + * @tc.number : AnsModuleTest_0132 + * @tc.name : ANS_Module_Test_13200 + * @tc.desc : Test publish notifications when Dnd type is NONE. + */ +HWTEST_F(AnsModuleTest, AnsModuleTest_0132, Function | SmallTest | Level1) +{ + // subscriber + auto subscriber = new TestAnsSubscriber(); + EXPECT_EQ(g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr), ERR_OK); + subscriber->consumedCb_ = [](const std::shared_ptr, const std::shared_ptr) { + passed = true; + }; + + // add slot + std::vector> slots; + sptr slot0 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); + slots.push_back(slot0); + g_advancedNotificationService->AddSlots(slots); + + // create request + std::string label = "testLabel"; + sptr req = new NotificationRequest(0); + req->SetLabel(label); + req->SetStatusBarText("text"); + + sptr date = + new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::NONE, 0, 0); + EXPECT_EQ(g_advancedNotificationService->SetDoNotDisturbDate(date), ERR_OK); + + EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK); + EXPECT_EQ(g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr), ERR_OK); + EXPECT_TRUE(passed); +} + +/** + * @tc.number : AnsModuleTest_0133 + * @tc.name : ANS_Module_Test_13300 + * @tc.desc : Test publish notifications when Dnd type is ONCE. + */ +HWTEST_F(AnsModuleTest, AnsModuleTest_0133, Function | SmallTest | Level1) +{ + // subscriber + auto subscriber = new TestAnsSubscriber(); + EXPECT_EQ(g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr), ERR_OK); + subscriber->consumedCb_ = [](const std::shared_ptr, const std::shared_ptr) { + passed = true; + }; + + // add slot + std::vector> slots; + sptr slot0 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); + slots.push_back(slot0); + g_advancedNotificationService->AddSlots(slots); + + // create request + std::string label = "testLabel"; + sptr req = new NotificationRequest(0); + req->SetLabel(label); + req->SetStatusBarText("text"); + req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); + + std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); + auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t beginDate = beginDuration.count(); + timePoint += std::chrono::hours(1); + auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t endDate = endDuration.count(); + sptr date = + new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::ONCE, beginDate, endDate); + EXPECT_EQ(g_advancedNotificationService->SetDoNotDisturbDate(date), ERR_OK); + + EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK); + EXPECT_EQ(g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr), ERR_OK); + EXPECT_TRUE(passed); +} + +/** + * @tc.number : AnsModuleTest_0134 + * @tc.name : ANS_Module_Test_13400 + * @tc.desc : Test publish notifications when Dnd type is DAILY. + */ +HWTEST_F(AnsModuleTest, AnsModuleTest_0134, Function | SmallTest | Level1) +{ + // subscriber + auto subscriber = new TestAnsSubscriber(); + g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr); + subscriber->consumedCb_ = [](const std::shared_ptr, const std::shared_ptr) { + passed = true; + }; + + // add slot + std::vector> slots; + sptr slot0 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); + slots.push_back(slot0); + g_advancedNotificationService->AddSlots(slots); + + // create request + std::string label = "testLabel"; + sptr req = new NotificationRequest(0); + req->SetLabel(label); + req->SetStatusBarText("text"); + req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); + + std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); + auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t beginDate = beginDuration.count(); + timePoint += std::chrono::hours(1); + auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t endDate = endDuration.count(); + sptr date = + new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::DAILY, beginDate, endDate); + EXPECT_EQ(g_advancedNotificationService->SetDoNotDisturbDate(date), ERR_OK); + + EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK); + EXPECT_EQ(g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr), ERR_OK); + EXPECT_TRUE(passed); +} + +/** + * @tc.number : AnsModuleTest_0135 + * @tc.name : ANS_Module_Test_13500 + * @tc.desc : Test publish notifications when Dnd type is CLEARLY. + */ +HWTEST_F(AnsModuleTest, AnsModuleTest_0135, Function | SmallTest | Level1) +{ + // subscriber + auto subscriber = new TestAnsSubscriber(); + g_advancedNotificationService->Subscribe(subscriber->GetImpl(), nullptr); + subscriber->consumedCb_ = [](const std::shared_ptr, const std::shared_ptr) { + passed = true; + }; + + // add slot + std::vector> slots; + sptr slot0 = new NotificationSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); + slots.push_back(slot0); + g_advancedNotificationService->AddSlots(slots); + + // create request + std::string label = "testLabel"; + sptr req = new NotificationRequest(0); + req->SetLabel(label); + req->SetStatusBarText("text"); + req->SetSlotType(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); + + std::chrono::system_clock::time_point timePoint = std::chrono::system_clock::now(); + auto beginDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t beginDate = beginDuration.count(); + timePoint += std::chrono::hours(1); + auto endDuration = std::chrono::duration_cast(timePoint.time_since_epoch()); + int64_t endDate = endDuration.count(); + sptr date = + new NotificationDoNotDisturbDate(NotificationConstant::DoNotDisturbType::CLEARLY, beginDate, endDate); + EXPECT_EQ(g_advancedNotificationService->SetDoNotDisturbDate(date), ERR_OK); + + EXPECT_EQ(g_advancedNotificationService->Publish(label, req), ERR_OK); + EXPECT_EQ(g_advancedNotificationService->Unsubscribe(subscriber->GetImpl(), nullptr), ERR_OK); + EXPECT_TRUE(passed); +} } // namespace Notification } // namespace OHOS diff --git a/services/test/moduletest/mock/permission_kit.cpp b/services/test/moduletest/mock/permission_kit.cpp new file mode 100644 index 000000000..36855b9de --- /dev/null +++ b/services/test/moduletest/mock/permission_kit.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "permission/permission_kit.h" + +namespace OHOS { +namespace Security { +namespace Permission { +using namespace std; + +int PermissionKit::VerifyPermission(const string &bundleName, const string &permissionName, int userId) +{ + return TypePermissionState::PERMISSION_GRANTED; +} + +bool PermissionKit::CanRequestPermission(const string &bundleName, const string &permissionName, int userId) +{ + return 0; +} + +int PermissionKit::GrantUserGrantedPermission(const string &bundleName, const string &permissionName, int userId) +{ + return 0; +} + +int PermissionKit::GrantSystemGrantedPermission(const string &bundleName, const string &permissionName) +{ + return 0; +} + +int PermissionKit::RevokeUserGrantedPermission(const string &bundleName, const string &permissionName, int userId) +{ + return 0; +} + +int PermissionKit::RevokeSystemGrantedPermission(const string &bundleName, const string &permissionName) +{ + return 0; +} + +int PermissionKit::AddUserGrantedReqPermissions( + const string &bundleName, const std::vector &permList, int userId) +{ + return 0; +} + +int PermissionKit::AddSystemGrantedReqPermissions(const string &bundleName, const std::vector &permList) +{ + return 0; +} + +int PermissionKit::RemoveUserGrantedReqPermissions(const string &bundleName, int userId) +{ + return 0; +} + +int PermissionKit::RemoveSystemGrantedReqPermissions(const string &bundleName) +{ + return 0; +} + +int PermissionKit::AddDefPermissions(const std::vector &permList) +{ + return 0; +} + +int PermissionKit::RemoveDefPermissions(const string &bundleName) +{ + return 0; +} + +int PermissionKit::GetDefPermission(const string &permissionName, PermissionDef &permissionDefResult) +{ + return 0; +} +} // namespace Permission +} // namespace Security +} // namespace OHOS \ No newline at end of file diff --git a/test/resource/notificationfuzztest/include/notificationgetparam.h b/test/resource/notificationfuzztest/include/notificationgetparam.h index 4fdcba8a0..2216a49f6 100644 --- a/test/resource/notificationfuzztest/include/notificationgetparam.h +++ b/test/resource/notificationfuzztest/include/notificationgetparam.h @@ -188,7 +188,6 @@ sptr GetParamNotificationSortingMapS OHOS::Notification::NotificationSlot::NotificationLevel GetParamNotificationLevel(); std::shared_ptr GetParamNotificationSubscriber(); std::shared_ptr GetParamNotificationSubscribeInfo(); -OHOS::Notification::NotificationConstant::DisturbMode GetParamDisturbMode(); std::shared_ptr GetParamWantAgentInfo(); OHOS::Notification::WantAgent::WantAgentConstant::OperationType GetParamOperationType(); @@ -223,6 +222,8 @@ OHOS::Notification::NotificationConstant::SubscribeResult GetParamSubscribeResul OHOS::AppExecFwk::MissionInformation GetParamMissionInformation(); std::shared_ptr GetParamAbilityLifecycleCallbacks(); std::shared_ptr GetParamIAbilityManager(); +std::shared_ptr GetParamNotificationDoNotDisturbDate(); +OHOS::Notification::NotificationConstant::DoNotDisturbType GetParamDoNotDisturbType(); class TestRemoteObject : public IRemoteObject { public: TestRemoteObject(); @@ -380,7 +381,7 @@ public: {} void OnUpdate(const std::shared_ptr &sortingMap) override {} - void OnDisturbModeChanged(int disturbMode) override + void OnDoNotDisturbDateChange(const std::shared_ptr &date) override {} void OnCanceled(const std::shared_ptr &request) override {} diff --git a/test/resource/notificationfuzztest/notificationfuzzconfig/config.json b/test/resource/notificationfuzztest/notificationfuzzconfig/config.json index ec41e6311..a7fc3f8c8 100644 --- a/test/resource/notificationfuzztest/notificationfuzzconfig/config.json +++ b/test/resource/notificationfuzztest/notificationfuzzconfig/config.json @@ -83,8 +83,8 @@ "SetShowBadgeEnabledForBundle": [], "GetShowBadgeEnabledForBundle": [], "GetShowBadgeEnabled": [], - "SetDisturbMode": [], - "GetDisturbMode": [] + "SetDoNotDisturbDate": [], + "GetDoNotDisturbDate": [] }, "WantAgentHelper": { "GetWantAgentOHOSAppExecFwkContextWantAgentInfo": [], diff --git a/test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp b/test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp index cef442c79..edb736b92 100644 --- a/test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp +++ b/test/resource/notificationfuzztest/src/notificationfuzztestmanager.cpp @@ -364,12 +364,12 @@ void NotificationFuzzTestManager::RegisterNotificationHelper() OHOS::Notification::NotificationHelper::GetShowBadgeEnabled(param); }); - callFunctionMap_.emplace("NotificationHelperSetDisturbMode", - []() { OHOS::Notification::NotificationHelper::SetDisturbMode(GetParamDisturbMode()); }); + callFunctionMap_.emplace("NotificationHelperSetDoNotDisturbDate", + []() { OHOS::Notification::NotificationHelper::SetDoNotDisturbDate(*GetParamNotificationDoNotDisturbDate()); }); - callFunctionMap_.emplace("NotificationHelperGetDisturbMode", []() { - OHOS::Notification::NotificationConstant::DisturbMode param = GetParamDisturbMode(); - OHOS::Notification::NotificationHelper::GetDisturbMode(param); + callFunctionMap_.emplace("NotificationHelperGetDoNotDisturbDate", []() { + OHOS::Notification::NotificationDoNotDisturbDate doNotDisturbDate; + OHOS::Notification::NotificationHelper::GetDoNotDisturbDate(doNotDisturbDate); }); } @@ -506,8 +506,7 @@ void NotificationFuzzTestManager::RegisterNotificationSubscriber() callFunctionMap_.emplace("NotificationSubscriberOnDisturbModeChanged", []() { std::shared_ptr temp = GetParamNotificationSubscriber(); - int disturbMode = GetIntParam(); - temp->OnDisturbModeChanged(disturbMode); + temp->OnDoNotDisturbDateChange(GetParamNotificationDoNotDisturbDate()); }); } diff --git a/test/resource/notificationfuzztest/src/notificationgetparam.cpp b/test/resource/notificationfuzztest/src/notificationgetparam.cpp index 48badd228..0ff93b73d 100644 --- a/test/resource/notificationfuzztest/src/notificationgetparam.cpp +++ b/test/resource/notificationfuzztest/src/notificationgetparam.cpp @@ -1091,29 +1091,6 @@ std::shared_ptr GetParamNotificat return std::make_shared(); } -OHOS::Notification::NotificationConstant::DisturbMode GetParamDisturbMode() -{ - switch (GetIntParam() % INDEX_FIVE) { - case INDEX_ZERO: - return OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_ALARMS; - break; - case INDEX_ONE: - return OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_ALL; - break; - case INDEX_TWO: - return OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_NONE; - break; - case INDEX_THREE: - return OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_PRIORITY; - break; - case INDEX_FOUR: - return OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_UNKNOWN; - break; - default: - return OHOS::Notification::NotificationConstant::DisturbMode::ALLOW_ALARMS; - break; - } -} std::shared_ptr GetParamWantAgentInfo() { switch (GetIntParam() % INDEX_THREE) { @@ -1445,5 +1422,36 @@ std::shared_ptr GetParamIAbilityManager() DelayedSingleton::GetInstance(); return param; } + +std::shared_ptr GetParamNotificationDoNotDisturbDate() +{ + if (GetBoolParam()) { + return std::make_shared(); + } else { + return std::make_shared( + GetParamDoNotDisturbType(), GetS64Param(), GetS64Param()); + } +} + +OHOS::Notification::NotificationConstant::DoNotDisturbType GetParamDoNotDisturbType() +{ + switch (GetIntParam() % INDEX_FOUR) { + case INDEX_ZERO: + return OHOS::Notification::NotificationConstant::DoNotDisturbType::NONE; + break; + case INDEX_ONE: + return OHOS::Notification::NotificationConstant::DoNotDisturbType::ONCE; + break; + case INDEX_TWO: + return OHOS::Notification::NotificationConstant::DoNotDisturbType::DAILY; + break; + case INDEX_THREE: + return OHOS::Notification::NotificationConstant::DoNotDisturbType::CLEARLY; + break; + default: + return OHOS::Notification::NotificationConstant::DoNotDisturbType::NONE; + break; + } +} } // namespace Notification } // namespace OHOS \ No newline at end of file -- Gitee From c64020eddffb613c597abed590a93efe6b7aee6f Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Mon, 22 Nov 2021 23:54:32 +0800 Subject: [PATCH 2/2] Fix codex Signed-off-by: zhaoyuan17 --- .../test/moduletest/ans_fw_module_test.cpp | 15 ++++++- .../ans/test/moduletest/ans_mt_constant.h | 39 ------------------- 2 files changed, 14 insertions(+), 40 deletions(-) delete mode 100644 frameworks/ans/test/moduletest/ans_mt_constant.h diff --git a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp index b4e5d98b8..c89d45290 100644 --- a/frameworks/ans/test/moduletest/ans_fw_module_test.cpp +++ b/frameworks/ans/test/moduletest/ans_fw_module_test.cpp @@ -26,7 +26,6 @@ #include "ans_const_define.h" #include "ans_inner_errors.h" #include "ans_manager_proxy.h" -#include "ans_mt_constant.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" #include "notification_content.h" @@ -40,6 +39,20 @@ using namespace OHOS::Media; namespace OHOS { namespace Notification { +namespace { +const std::string APP_NAME = "bundleName"; +const std::string NOTIFICATION_LABEL_0 = "Label0"; +const std::string NOTIFICATION_LABEL_1 = "Label1"; +const std::string NOTIFICATION_LABEL_2 = "Label2"; +const std::string AN_NOT_EXIST_KEY = "AN_NOT_EXIST_KEY"; +const std::string KEY_SPLITER = "_"; + +constexpr int UID = 1; +constexpr int CANCEL_REASON_DELETE = 2; +constexpr int APP_CANCEL_REASON_DELETE = 8; +constexpr int APP_CANCEL_ALL_REASON_DELETE = 9; +} // namespace + enum class SubscriberEventType { ON_SUBSCRIBERESULT, ON_UNSUBSCRIBERESULT, diff --git a/frameworks/ans/test/moduletest/ans_mt_constant.h b/frameworks/ans/test/moduletest/ans_mt_constant.h deleted file mode 100644 index 855cf4dff..000000000 --- a/frameworks/ans/test/moduletest/ans_mt_constant.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_TEST_MODULETEST_ANS_MT_CONSTANT_H -#define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_TEST_MODULETEST_ANS_MT_CONSTANT_H - -#include - -namespace OHOS { -namespace Notification { -namespace { -const std::string APP_NAME = "bundleName"; -const std::string NOTIFICATION_LABEL_0 = "Label0"; -const std::string NOTIFICATION_LABEL_1 = "Label1"; -const std::string NOTIFICATION_LABEL_2 = "Label2"; -const std::string AN_NOT_EXIST_KEY = "AN_NOT_EXIST_KEY"; -const std::string KEY_SPLITER = "_"; - -constexpr int UID = 1; -constexpr int CANCEL_REASON_DELETE = 2; -constexpr int APP_CANCEL_REASON_DELETE = 8; -constexpr int APP_CANCEL_ALL_REASON_DELETE = 9; -} // namespace -} // namespace Notification -} // namespace OHOS - -#endif -- Gitee