diff --git a/bundle.json b/bundle.json index f87567a63fd810b6c9d8b1e2548012cb9ea08af0..05d1d51173485ea6dc83595eb12ccbcaaeecab14 100644 --- a/bundle.json +++ b/bundle.json @@ -106,11 +106,14 @@ "//base/notification/distributed_notification_service/frameworks/ans:ans_client", "//base/notification/distributed_notification_service/frameworks/js/napi:napi_notification", "//base/notification/distributed_notification_service/frameworks/js/napi:napi_reminder", - "//base/notification/distributed_notification_service/interfaces/ndk:ohnotification" + "//base/notification/distributed_notification_service/interfaces/ndk:ohnotification", + "//base/notification/distributed_notification_service/frameworks/reminder:reminder_client" ], "service_group": [ "//base/notification/distributed_notification_service/sa_profile:ans_sa_profile", "//base/notification/distributed_notification_service/services:ans_service", + "//base/notification/distributed_notification_service/services/reminder/sa_profile:reminder_sa_profile", + "//base/notification/distributed_notification_service/services/reminder:reminder_service", "//base/notification/distributed_notification_service/tools:tools_shell" ] }, @@ -167,10 +170,12 @@ } ], "test": [ + "//base/notification/distributed_notification_service/services/reminder/test/unittest:unittest", "//base/notification/distributed_notification_service/services/ans/test/unittest:unittest", "//base/notification/distributed_notification_service/services/distributed/test/unittest:ans_unit_test", "//base/notification/distributed_notification_service/services/test/moduletest:moduletest", "//base/notification/distributed_notification_service/frameworks/test/moduletest:moduletest", + "//base/notification/distributed_notification_service/frameworks/reminder/test/unittest:unittest", "//base/notification/distributed_notification_service/frameworks/ans/test/unittest:unittest", "//base/notification/distributed_notification_service/frameworks/core/test/unittest:unittest", "//base/notification/distributed_notification_service/test:systemtest", diff --git a/frameworks/ans/BUILD.gn b/frameworks/ans/BUILD.gn index 837a2878d4270809877902f1ee5f946453ac301a..b82324819cd5a5562b2e333637f0503c8a7b5960 100644 --- a/frameworks/ans/BUILD.gn +++ b/frameworks/ans/BUILD.gn @@ -63,7 +63,6 @@ ohos_shared_library("ans_innerkits") { "${core_path}/src/manager/ans_manager_proxy_bundle.cpp", "${core_path}/src/manager/ans_manager_proxy_distributed.cpp", "${core_path}/src/manager/ans_manager_proxy_disturb.cpp", - "${core_path}/src/manager/ans_manager_proxy_reminder.cpp", "${core_path}/src/manager/ans_manager_proxy_slot.cpp", "${core_path}/src/manager/ans_manager_proxy_subscribe.cpp", "${core_path}/src/manager/ans_manager_proxy_utils.cpp", @@ -112,11 +111,6 @@ ohos_shared_library("ans_innerkits") { "${frameworks_module_ans_path}/src/notification_user_input.cpp", "${frameworks_module_ans_path}/src/push_callback_stub.cpp", "${frameworks_module_ans_path}/src/push_promise_callback.cpp", - "${frameworks_module_ans_path}/src/reminder_helper.cpp", - "${frameworks_module_ans_path}/src/reminder_request.cpp", - "${frameworks_module_ans_path}/src/reminder_request_alarm.cpp", - "${frameworks_module_ans_path}/src/reminder_request_calendar.cpp", - "${frameworks_module_ans_path}/src/reminder_request_timer.cpp", ] public_configs = [ ":ans_innerkits_public_config" ] diff --git a/frameworks/ans/src/notification_helper.cpp b/frameworks/ans/src/notification_helper.cpp index 45f7340a3b3bd95ce05685b44df567f3de445346..a98e65bd36c8ed41daf79345c03ecccffb53fb8e 100644 --- a/frameworks/ans/src/notification_helper.cpp +++ b/frameworks/ans/src/notification_helper.cpp @@ -587,5 +587,10 @@ ErrCode NotificationHelper::UpdateNotificationTimerByUid(const int32_t uid, cons { return DelayedSingleton::GetInstance()->UpdateNotificationTimerByUid(uid, isPaused); } + +ErrCode NotificationHelper::AllowUseReminder(const std::string& bundleName, bool& isAllowUseReminder) +{ + return DelayedSingleton::GetInstance()->AllowUseReminder(bundleName, isAllowUseReminder); +} } // namespace Notification } // namespace OHOS diff --git a/frameworks/ans/test/unittest/BUILD.gn b/frameworks/ans/test/unittest/BUILD.gn index d6a5b2f1e7025f8ae7e58ba2aa1fa7b313637558..095ac990a66d7b15e83184eb51c4b00363214b0c 100644 --- a/frameworks/ans/test/unittest/BUILD.gn +++ b/frameworks/ans/test/unittest/BUILD.gn @@ -17,7 +17,7 @@ import("//build/test.gni") module_output_path = "${component_name}/unittest" -ohos_unittest("ans_reminder_unit_test") { +ohos_unittest("ans_test") { module_out_path = module_output_path include_dirs = [ @@ -25,7 +25,6 @@ ohos_unittest("ans_reminder_unit_test") { "include", "/${services_path}/ans/include", "${services_path}/ans/test/unittest/mock/include", - "${ffrt_path}/interfaces/kits", ] sources = [ @@ -65,17 +64,11 @@ ohos_unittest("ans_reminder_unit_test") { "${frameworks_module_ans_path}/test/unittest/notification_unified_group_info_test.cpp", "${frameworks_module_ans_path}/test/unittest/notification_user_input_test.cpp", "${frameworks_module_ans_path}/test/unittest/push_promise_callback_test.cpp", - "${frameworks_module_ans_path}/test/unittest/reminder_helper_test.cpp", - "${frameworks_module_ans_path}/test/unittest/reminder_request_alarm_test.cpp", - "${frameworks_module_ans_path}/test/unittest/reminder_request_calendar_test.cpp", - "${frameworks_module_ans_path}/test/unittest/reminder_request_timer_test.cpp", - "${frameworks_module_ans_path}/test/unittest/reminder_store_test.cpp", ] deps = [ "${frameworks_module_ans_path}:ans_innerkits", "${services_path}/ans:libans", - "//third_party/googletest:gtest_main", ] defines = [] @@ -96,6 +89,7 @@ ohos_unittest("ans_reminder_unit_test") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hitrace:hitrace_meter", "image_framework:image_native", @@ -117,74 +111,9 @@ ohos_unittest("ans_reminder_unit_test") { branch_protector_ret = "pac_ret" } -ohos_unittest("reminder_request_test") { - module_out_path = module_output_path - - include_dirs = [ - ".", - "include", - "/${services_path}/ans/include", - "${services_path}/ans/test/unittest/mock/include", - ] - - sources = [ - "${frameworks_module_ans_path}/test/unittest/reminder_request_branch_test/mock_reminder_request.cpp", - "${frameworks_module_ans_path}/test/unittest/reminder_request_test.cpp", - ] - - deps = [ - "${frameworks_module_ans_path}:ans_innerkits", - "//third_party/googletest:gtest_main", - ] - - external_deps = [ - "ability_base:base", - "ability_base:want", - "ability_base:zuri", - "c_utils:utils", - "relational_store:native_rdb", - ] - - subsystem_name = "${subsystem_name}" - part_name = "${component_name}" -} - -ohos_unittest("reminder_request_branch_test") { - module_out_path = module_output_path - - include_dirs = [ - ".", - "include", - "/${services_path}/ans/include", - "${services_path}/ans/test/unittest/mock/include", - ] - - sources = [ - "${frameworks_module_ans_path}/test/unittest/reminder_request_branch_test/mock_reminder_request.cpp", - "${frameworks_module_ans_path}/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp", - ] - - deps = [ - "${frameworks_module_ans_path}:ans_innerkits", - "//third_party/googletest:gtest_main", - ] - - external_deps = [ - "ability_base:want", - "ability_base:zuri", - "c_utils:utils", - "relational_store:native_rdb", - ] - - subsystem_name = "${subsystem_name}" - part_name = "${component_name}" -} - group("unittest") { testonly = true deps = [ - ":ans_reminder_unit_test", - ":reminder_request_branch_test", - ":reminder_request_test", + ":ans_test", ] } diff --git a/frameworks/core/include/ans_manager_interface.h b/frameworks/core/include/ans_manager_interface.h index 831d1e6258498a3752f7b09d52e0f882b3f74d78..04909ffbba53dfce505ba7e921fc405a4b734b4b 100644 --- a/frameworks/core/include/ans_manager_interface.h +++ b/frameworks/core/include/ans_manager_interface.h @@ -652,63 +652,6 @@ public: */ virtual ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) = 0; - /** - * @brief Publishes a reminder notification. - * - * @param reminder Identifies the reminder notification request that needs to be published. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode PublishReminder(sptr &reminder) = 0; - - /** - * @brief Cancel a reminder notifications. - * - * @param reminderId Identifies the reminders id that needs to be canceled. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode CancelReminder(const int32_t reminderId) = 0; - - /** - * @brief Get all valid reminder notifications. - * - * @param reminders Identifies the list of all valid notifications. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode GetValidReminders(std::vector> &reminders) = 0; - - /** - * @brief Cancel all reminder notifications. - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode CancelAllReminders() = 0; - - /** - * @brief Add exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @param date exclude date - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) = 0; - - /** - * @brief Clear exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode DelExcludeDates(const int32_t reminderId) = 0; - - /** - * @brief Get exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @param dates exclude dates - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) = 0; - /** * @brief Checks whether this device is support template. * @@ -948,6 +891,15 @@ public: * @return Returns ERR_OK on success, others on failure. */ virtual ErrCode GetDoNotDisturbProfile(int32_t id, sptr &profile) = 0; + + /** + * @brief Whether reminders are allowed. + * + * @param bundleName bundleName + * @param isAllowUseReminder isAllowUseReminder + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode AllowUseReminder(const std::string& bundleName, bool& isAllowUseReminder) = 0; #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED /** * @brief Register Swing Callback. diff --git a/frameworks/core/include/ans_manager_proxy.h b/frameworks/core/include/ans_manager_proxy.h index 88078cae4364597ed2ddce136dc30fc471685e22..186c2efd5e5acba397012532337bfda1d549cd30 100644 --- a/frameworks/core/include/ans_manager_proxy.h +++ b/frameworks/core/include/ans_manager_proxy.h @@ -649,63 +649,6 @@ public: */ ErrCode IsSupportTemplate(const std::string &templateName, bool &support) override; - /** - * @brief Publishes a reminder notification. - * - * @param reminder Identifies the reminder notification request that needs to be published. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode PublishReminder(sptr &reminder) override; - - /** - * @brief Cancel a reminder notifications. - * - * @param reminderId Identifies the reminders id that needs to be canceled. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode CancelReminder(const int32_t reminderId) override; - - /** - * @brief Get all valid reminder notifications. - * - * @param reminders Identifies the list of all valid notifications. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode GetValidReminders(std::vector> &reminders) override; - - /** - * @brief Cancel all reminder notifications. - * - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode CancelAllReminders() override; - - /** - * @brief Add exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @param date exclude date - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) override; - - /** - * @brief Clear exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode DelExcludeDates(const int32_t reminderId) override; - - /** - * @brief Get exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @param dates exclude dates - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) override; - /** * @brief Checks Whether the specified users is allowed to publish notifications. * @@ -937,6 +880,15 @@ public: */ ErrCode GetDoNotDisturbProfile(int32_t id, sptr &profile) override; + /** + * @brief Whether reminders are allowed. + * + * @param bundleName bundleName + * @param isAllowUseReminder isAllowUseReminder + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode AllowUseReminder(const std::string& bundleName, bool& isAllowUseReminder) override; + #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED /** * @brief Register Swing Callback. diff --git a/frameworks/core/include/ans_manager_stub.h b/frameworks/core/include/ans_manager_stub.h index 470fbe583b7b79729f743c5543d1ea06d735c6e9..dd74da5e42e3c4dab6a8c75743d7a62c72533b4e 100644 --- a/frameworks/core/include/ans_manager_stub.h +++ b/frameworks/core/include/ans_manager_stub.h @@ -642,63 +642,6 @@ public: */ virtual ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) override; - /** - * @brief Publishes a reminder notification. - * - * @param reminder Identifies the reminder notification request that needs to be published. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode PublishReminder(sptr &reminder) override; - - /** - * @brief Cancel a reminder notifications. - * - * @param reminderId Identifies the reminders id that needs to be canceled. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode CancelReminder(const int32_t reminderId) override; - - /** - * @brief Get all valid reminder notifications. - * - * @param reminders Identifies the list of all valid notifications. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode GetValidReminders(std::vector> &reminders) override; - - /** - * @brief Cancel all reminder notifications. - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode CancelAllReminders() override; - - /** - * @brief Add exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @param date exclude date - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) override; - - /** - * @brief Clear exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode DelExcludeDates(const int32_t reminderId) override; - - /** - * @brief Get exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @param dates exclude dates - * @return Returns ERR_OK on success, others on failure. - */ - virtual ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) override; - /** * @brief Checks whether this device is support template. * @@ -939,6 +882,15 @@ public: */ virtual ErrCode GetDoNotDisturbProfile(int32_t id, sptr &profile) override; + /** + * @brief Whether reminders are allowed. + * + * @param bundleName bundleName + * @param isAllowUseReminder isAllowUseReminder + * @return Returns ERR_OK on success, others on failure. + */ + virtual ErrCode AllowUseReminder(const std::string& bundleName, bool& isAllowUseReminder) override; + #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED /** * @brief Register Swing Callback. @@ -1020,13 +972,6 @@ private: ErrCode HandleGetDeviceRemindType(MessageParcel &data, MessageParcel &reply); ErrCode HandlePublishContinuousTaskNotification(MessageParcel &data, MessageParcel &reply); ErrCode HandleCancelContinuousTaskNotification(MessageParcel &data, MessageParcel &reply); - ErrCode HandlePublishReminder(MessageParcel &data, MessageParcel &reply); - ErrCode HandleCancelReminder(MessageParcel &data, MessageParcel &reply); - ErrCode HandleGetValidReminders(MessageParcel &data, MessageParcel &reply); - ErrCode HandleCancelAllReminders(MessageParcel &data, MessageParcel &reply); - ErrCode HandleAddExcludeDate(MessageParcel &data, MessageParcel &reply); - ErrCode HandleDelExcludeDates(MessageParcel &data, MessageParcel &reply); - ErrCode HandleGetExcludeDates(MessageParcel &data, MessageParcel &reply); ErrCode HandleIsSupportTemplate(MessageParcel &data, MessageParcel &reply); ErrCode HandleIsSpecialUserAllowedNotifyByUser(MessageParcel &data, MessageParcel &reply); ErrCode HandleSetNotificationsEnabledByUser(MessageParcel &data, MessageParcel &reply); @@ -1058,6 +1003,7 @@ private: ErrCode HandleRemoveDoNotDisturbProfiles(MessageParcel &data, MessageParcel &reply); ErrCode HandleSetTargetDeviceStatus(MessageParcel &data, MessageParcel &reply); ErrCode HandleGetDoNotDisturbProfile(MessageParcel &data, MessageParcel &reply); + ErrCode HandleAllowUseReminder(MessageParcel &data, MessageParcel &reply); #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED ErrCode HandleRegisterSwingCallback(MessageParcel &data, MessageParcel &reply); #endif diff --git a/frameworks/core/include/ans_notification.h b/frameworks/core/include/ans_notification.h index fd332db0dc436d5a6b09e8c6d20f8dca4534d143..f79d62b09d265b90a720a18c126f08c9336adca7 100644 --- a/frameworks/core/include/ans_notification.h +++ b/frameworks/core/include/ans_notification.h @@ -876,64 +876,6 @@ public: * @brief try to reconnect ans SA when SA manager OnAddSystemAbility called. */ void Reconnect(); - - /** - * @brief Publishes a scheduled reminder. - * - * @param reminder Indicates a reminder. - * @return Returns publish result. - */ - ErrCode PublishReminder(ReminderRequest &reminder); - - /** - * @brief Cancels a specified reminder. - * - * @param reminderId Indicates reminder Id. - * @return Returns cancel result. - */ - ErrCode CancelReminder(const int32_t reminderId); - - /** - * @brief Cancels all reminders of current third part application. - * - * @return Returns cancel result. - */ - ErrCode CancelAllReminders(); - - /** - * @brief Obtains all valid reminder notifications set by the current application. - * - * @param[out] validReminders Indicates the vector to store the result. - * @return Returns get valid reminders result. - */ - ErrCode GetValidReminders(std::vector> &validReminders); - - /** - * @brief Add exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @param date exclude date - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date); - - /** - * @brief Clear exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode DelExcludeDates(const int32_t reminderId); - - /** - * @brief Get exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @param dates exclude dates - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates); - /** * @brief Checks whether this application has permission to publish notifications under the user. * @@ -1185,6 +1127,15 @@ public: */ ErrCode GetDoNotDisturbProfile(int32_t id, sptr &profile); + /** + * @brief Whether reminders are allowed. + * + * @param bundleName bundleName + * @param isAllowUseReminder isAllowUseReminder + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode AllowUseReminder(const std::string& bundleName, bool& isAllowUseReminder); + /** * @brief Ans service died, OnRemoteDied called. */ diff --git a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h index fc620668a10c95012a4736cd5e04e30abc1e5db4..70c5e62f396ec97956374be0047295776651842f 100644 --- a/frameworks/core/include/distributed_notification_service_ipc_interface_code.h +++ b/frameworks/core/include/distributed_notification_service_ipc_interface_code.h @@ -152,6 +152,7 @@ namespace Notification { GET_EXCLUDE_DATES_REMINDER, GET_DONOTDISTURB_PROFILE, UPDATE_NOTIFICATION_TIMER, + ALLOW_USE_REMINDER, }; } } diff --git a/frameworks/core/src/ans_notification.cpp b/frameworks/core/src/ans_notification.cpp index ea54d047d6c3fef95844e0c3c2b6f0a3a9b810ed..fb0f7a3daca9dbec7d117e45fc955c5b8a962b1d 100644 --- a/frameworks/core/src/ans_notification.cpp +++ b/frameworks/core/src/ans_notification.cpp @@ -24,9 +24,6 @@ #include "iservice_registry.h" #include "notification_button_option.h" #include "notification_local_live_view_subscriber.h" -#include "reminder_request_alarm.h" -#include "reminder_request_calendar.h" -#include "reminder_request_timer.h" #include "system_ability_definition.h" #include "unique_fd.h" @@ -1340,103 +1337,6 @@ void AnsNotification::Reconnect() } } -ErrCode AnsNotification::PublishReminder(ReminderRequest &reminder) -{ - sptr tarReminder = nullptr; - switch (reminder.GetReminderType()) { - case (ReminderRequest::ReminderType::TIMER): { - ANSR_LOGI("Publish timer"); - ReminderRequestTimer &timer = (ReminderRequestTimer &)reminder; - tarReminder = new (std::nothrow) ReminderRequestTimer(timer); - break; - } - case (ReminderRequest::ReminderType::ALARM): { - ANSR_LOGI("Publish alarm"); - ReminderRequestAlarm &alarm = (ReminderRequestAlarm &)reminder; - tarReminder = new (std::nothrow) ReminderRequestAlarm(alarm); - break; - } - case (ReminderRequest::ReminderType::CALENDAR): { - ANSR_LOGI("Publish calendar"); - ReminderRequestCalendar &calendar = (ReminderRequestCalendar &)reminder; - tarReminder = new (std::nothrow) ReminderRequestCalendar(calendar); - break; - } - default: { - ANSR_LOGW("PublishReminder fail."); - return ERR_ANS_INVALID_PARAM; - } - } - sptr proxy = GetAnsManagerProxy(); - if (!proxy) { - ANS_LOGE("GetAnsManagerProxy fail."); - return ERR_ANS_SERVICE_NOT_CONNECTED; - } - ErrCode code = proxy->PublishReminder(tarReminder); - reminder.SetReminderId(tarReminder->GetReminderId()); - return code; -} - -ErrCode AnsNotification::CancelReminder(const int32_t reminderId) -{ - sptr proxy = GetAnsManagerProxy(); - if (!proxy) { - ANS_LOGE("GetAnsManagerProxy fail."); - return ERR_ANS_SERVICE_NOT_CONNECTED; - } - return proxy->CancelReminder(reminderId); -} - -ErrCode AnsNotification::CancelAllReminders() -{ - sptr proxy = GetAnsManagerProxy(); - if (!proxy) { - ANS_LOGE("GetAnsManagerProxy fail."); - return ERR_ANS_SERVICE_NOT_CONNECTED; - } - return proxy->CancelAllReminders(); -} - -ErrCode AnsNotification::GetValidReminders(std::vector> &validReminders) -{ - sptr proxy = GetAnsManagerProxy(); - if (!proxy) { - ANS_LOGE("GetAnsManagerProxy fail."); - return ERR_ANS_SERVICE_NOT_CONNECTED; - } - return proxy->GetValidReminders(validReminders); -} - -ErrCode AnsNotification::AddExcludeDate(const int32_t reminderId, const uint64_t date) -{ - sptr proxy = GetAnsManagerProxy(); - if (!proxy) { - ANS_LOGE("GetAnsManagerProxy fail."); - return ERR_ANS_SERVICE_NOT_CONNECTED; - } - return proxy->AddExcludeDate(reminderId, date); -} - -ErrCode AnsNotification::DelExcludeDates(const int32_t reminderId) -{ - sptr proxy = GetAnsManagerProxy(); - if (!proxy) { - ANS_LOGE("GetAnsManagerProxy fail."); - return ERR_ANS_SERVICE_NOT_CONNECTED; - } - return proxy->DelExcludeDates(reminderId); -} - -ErrCode AnsNotification::GetExcludeDates(const int32_t reminderId, std::vector& dates) -{ - sptr proxy = GetAnsManagerProxy(); - if (!proxy) { - ANS_LOGE("GetAnsManagerProxy fail."); - return ERR_ANS_SERVICE_NOT_CONNECTED; - } - return proxy->GetExcludeDates(reminderId, dates); -} - sptr AnsNotification::GetAnsManagerProxy() { sptr systemAbilityManager = @@ -1982,6 +1882,18 @@ ErrCode AnsNotification::GetDoNotDisturbProfile(int32_t id, sptrGetDoNotDisturbProfile(id, profile); } +ErrCode AnsNotification::AllowUseReminder(const std::string& bundleName, bool& isAllowUseReminder) +{ + ANS_LOGD("enter"); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("AllowUseReminder fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + return proxy->AllowUseReminder(bundleName, isAllowUseReminder); +} + void AnsNotification::CreateSubscribeListener(const std::shared_ptr &subscriber, sptr &listener) { diff --git a/frameworks/core/src/manager/ans_manager_proxy_reminder.cpp b/frameworks/core/src/manager/ans_manager_proxy_reminder.cpp deleted file mode 100644 index f5256f48615ad1873ebdb8d6118d77ca10481ffd..0000000000000000000000000000000000000000 --- a/frameworks/core/src/manager/ans_manager_proxy_reminder.cpp +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Copyright (c) 2021-2023 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 - -#include "ans_const_define.h" -#include "ans_inner_errors.h" -#include "ans_log_wrapper.h" -#include "ans_subscriber_local_live_view_interface.h" -#include "distributed_notification_service_ipc_interface_code.h" -#include "message_option.h" -#include "message_parcel.h" -#include "parcel.h" -#include "reminder_request_alarm.h" -#include "reminder_request_calendar.h" -#include "reminder_request_timer.h" -#include "ans_manager_proxy.h" - -namespace OHOS { -namespace Notification { -ErrCode AnsManagerProxy::PublishReminder(sptr &reminder) -{ - ANSR_LOGI("PublishReminder"); - MessageParcel data; - if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { - ANSR_LOGE("[PublishReminder] fail: write interface token failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - if (reminder == nullptr) { - ANSR_LOGW("[PublishReminder] fail: reminder is null ptr."); - return ERR_ANS_INVALID_PARAM; - } - if (!data.WriteUint8(static_cast(reminder->GetReminderType()))) { - ANSR_LOGE("[PublishReminder] fail: write reminder type failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - if (!data.WriteParcelable(reminder)) { - ANSR_LOGE("[Publish] fail: write reminder parcelable failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::PUBLISH_REMINDER, option, data, reply); - if (result != ERR_OK) { - ANSR_LOGE("[PublishReminder] fail: transact ErrCode=%{public}d", result); - return ERR_ANS_TRANSACT_FAILED; - } - int32_t reminderId = -1; - if (!reply.ReadInt32(reminderId)) { - ANSR_LOGE("[PublishReminder] fail: read reminder id failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - reminder->SetReminderId(reminderId); - ANSR_LOGD("ReminderId=%{public}d", reminder->GetReminderId()); - if (!reply.ReadInt32(result)) { - ANSR_LOGE("[PublishReminder] fail: read result failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} - -ErrCode AnsManagerProxy::CancelReminder(const int32_t reminderId) -{ - ANSR_LOGI("[CancelReminder]"); - MessageParcel data; - if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { - ANSR_LOGE("[CancelReminder] fail: write interface token failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - if (!data.WriteInt32(reminderId)) { - ANSR_LOGE("[CancelReminder] fail: write reminder id failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::CANCEL_REMINDER, option, data, reply); - if (result != ERR_OK) { - ANSR_LOGE("[CancelReminder] fail: transact ErrCode=%{public}d", result); - return ERR_ANS_TRANSACT_FAILED; - } - if (!reply.ReadInt32(result)) { - ANSR_LOGE("[CancelReminder] fail: read result failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} - -ErrCode AnsManagerProxy::CancelAllReminders() -{ - ANSR_LOGI("[CancelAllReminders]"); - MessageParcel data; - if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { - ANSR_LOGE("[CancelAllReminders] fail: write interface token failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::CANCEL_ALL_REMINDERS, option, data, reply); - if (result != ERR_OK) { - ANSR_LOGE("[CancelAllReminders] fail: transact ErrCode=%{public}d", result); - return ERR_ANS_TRANSACT_FAILED; - } - if (!reply.ReadInt32(result)) { - ANSR_LOGE("[CancelAllReminders] fail: read result failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} - -ErrCode AnsManagerProxy::GetValidReminders(std::vector> &reminders) -{ - ANSR_LOGI("[GetValidReminders]"); - MessageParcel data; - if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { - ANSR_LOGE("[GetValidReminders] fail: write interface token failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::GET_ALL_VALID_REMINDERS, option, data, reply); - if (result != ERR_OK) { - ANSR_LOGE("[GetValidReminders] fail: transact ErrCode=%{public}d", result); - return ERR_ANS_TRANSACT_FAILED; - } - uint8_t count = 0; - if (!reply.ReadUint8(count)) { - ANSR_LOGE("[GetValidReminders] fail: read reminder count failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - ANSR_LOGD("[GetValidReminders] count=%{public}hhu", count); - reminders.clear(); - result = ReadReminders(count, reply, reminders); - if (result != ERR_OK) { - ANSR_LOGE("[GetValidReminders] fail: ReadReminders ErrCode=%{public}d", result); - return result; - } else { - ANSR_LOGD("[GetValidReminders], size=%{public}zu", reminders.size()); - } - if (!reply.ReadInt32(result)) { - ANSR_LOGE("[GetValidReminders] fail: read result failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} - -ErrCode AnsManagerProxy::AddExcludeDate(const int32_t reminderId, const uint64_t date) -{ - ANSR_LOGI("[AddExcludeDate]"); - MessageParcel data; - if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { - ANSR_LOGE("[AddExcludeDate] fail: write interface token failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - if (!data.WriteInt32(reminderId)) { - ANSR_LOGE("[AddExcludeDate] fail: write reminder id failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - if (!data.WriteUint64(date)) { - ANSR_LOGE("[AddExcludeDate] fail: write exclude date failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::ADD_EXCLUDE_DATE_REMINDER, option, data, reply); - if (result != ERR_OK) { - ANSR_LOGE("[AddExcludeDate] fail: transact ErrCode=%{public}d", result); - return ERR_ANS_TRANSACT_FAILED; - } - if (!reply.ReadInt32(result)) { - ANSR_LOGE("[AddExcludeDate] fail: read result failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} - -ErrCode AnsManagerProxy::DelExcludeDates(const int32_t reminderId) -{ - ANSR_LOGI("[DelExcludeDates]"); - MessageParcel data; - if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { - ANSR_LOGE("[DelExcludeDates] fail: write interface token failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - if (!data.WriteInt32(reminderId)) { - ANSR_LOGE("[DelExcludeDates] fail: write reminder id failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::DEL_EXCLUDE_DATES_REMINDER, option, data, reply); - if (result != ERR_OK) { - ANSR_LOGE("[DelExcludeDates] fail: transact ErrCode=%{public}d", result); - return ERR_ANS_TRANSACT_FAILED; - } - if (!reply.ReadInt32(result)) { - ANSR_LOGE("[DelExcludeDates] fail: read result failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} - -ErrCode AnsManagerProxy::GetExcludeDates(const int32_t reminderId, std::vector& dates) -{ - ANSR_LOGI("[GetExcludeDates]"); - MessageParcel data; - if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { - ANSR_LOGE("[GetExcludeDates] fail: write interface token failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - if (!data.WriteInt32(reminderId)) { - ANSR_LOGE("[GetExcludeDates] fail: write reminder id failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - ErrCode result = InnerTransact(NotificationInterfaceCode::GET_EXCLUDE_DATES_REMINDER, option, data, reply); - if (result != ERR_OK) { - ANSR_LOGE("[GetExcludeDates] fail: transact ErrCode=%{public}d", result); - return ERR_ANS_TRANSACT_FAILED; - } - uint8_t count = 0; - if (!reply.ReadUint8(count)) { - ANSR_LOGE("[GetExcludeDates] fail: read exclude date count failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - ANSR_LOGD("[GetExcludeDates] count=%{public}hhu", count); - dates.clear(); - for (uint8_t i = 0; i < count; i++) { - uint64_t date = 0; - if (!reply.ReadUint64(date)) { - ANSR_LOGE("[GetExcludeDates] fail: read exclude date"); - return ERR_ANS_PARCELABLE_FAILED; - } - dates.push_back(date); - } - if (!reply.ReadInt32(result)) { - ANSR_LOGE("[GetExcludeDates] fail: read result failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} - -ErrCode AnsManagerProxy::ReadReminders( - uint8_t &count, MessageParcel &reply, std::vector> &reminders) -{ - for (uint8_t i = 0; i < count; i++) { - uint8_t typeInfo = static_cast(ReminderRequest::ReminderType::INVALID); - if (!reply.ReadUint8(typeInfo)) { - ANSR_LOGE("Failed to read reminder type"); - return ERR_ANS_PARCELABLE_FAILED; - } - auto reminderType = static_cast(typeInfo); - sptr reminder; - if (ReminderRequest::ReminderType::ALARM == reminderType) { - ANSR_LOGD("[GetValidReminders] alarm"); - reminder = reply.ReadParcelable(); - } else if (ReminderRequest::ReminderType::TIMER == reminderType) { - ANSR_LOGD("[GetValidReminders] timer"); - reminder = reply.ReadParcelable(); - } else if (ReminderRequest::ReminderType::CALENDAR == reminderType) { - ANSR_LOGD("[GetValidReminders] calendar"); - reminder = reply.ReadParcelable(); - } else { - ANSR_LOGW("[GetValidReminders] type=%{public}hhu", typeInfo); - return ERR_ANS_INVALID_PARAM; - } - if (!reminder) { - ANSR_LOGE("[GetValidReminders] fail: Reminder ReadParcelable failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - reminders.push_back(reminder); - } - return ERR_OK; -} -} // namespace Notification -} // namespace OHOS diff --git a/frameworks/core/src/manager/ans_manager_proxy_utils.cpp b/frameworks/core/src/manager/ans_manager_proxy_utils.cpp index b0236fef5a61afe34918e51e8591f1a0eb2a85c3..b479d9b748982e140dec6b1b01cbe2f73c01c27f 100644 --- a/frameworks/core/src/manager/ans_manager_proxy_utils.cpp +++ b/frameworks/core/src/manager/ans_manager_proxy_utils.cpp @@ -278,6 +278,41 @@ ErrCode AnsManagerProxy::IsSmartReminderEnabled(const std::string &deviceType, b return result; } +ErrCode AnsManagerProxy::AllowUseReminder(const std::string& bundleName, bool& isAllowUseReminder) +{ + ANS_LOGD("enter"); + MessageParcel data; + if (!data.WriteInterfaceToken(AnsManagerProxy::GetDescriptor())) { + ANS_LOGE("[AllowUseReminder] fail: write interface token failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!data.WriteString(bundleName)) { + ANS_LOGE("[AllowUseReminder] fail: write deviceType failed"); + return ERR_ANS_PARCELABLE_FAILED; + } + + MessageParcel reply; + MessageOption option = {MessageOption::TF_SYNC}; + ErrCode result = InnerTransact(NotificationInterfaceCode::ALLOW_USE_REMINDER, option, data, reply); + if (result != ERR_OK) { + ANS_LOGE("[AllowUseReminder] fail: transact ErrCode=%{public}d", result); + return ERR_ANS_TRANSACT_FAILED; + } + + if (!reply.ReadInt32(result)) { + ANS_LOGE("[AllowUseReminder] fail: read result failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.ReadBool(isAllowUseReminder)) { + ANS_LOGE("[AllowUseReminder] fail: read enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + return result; +} + ErrCode AnsManagerProxy::ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, int32_t recvUserId, std::vector &dumpInfo) { diff --git a/frameworks/core/src/manager/ans_manager_stub.cpp b/frameworks/core/src/manager/ans_manager_stub.cpp index 1d01727132631ab19b48b643ef865d47725edf27..bde8fbdeb0251e83d9ca95a452b7e7f1ad9e357d 100644 --- a/frameworks/core/src/manager/ans_manager_stub.cpp +++ b/frameworks/core/src/manager/ans_manager_stub.cpp @@ -287,22 +287,6 @@ int32_t AnsManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Mess result = HandleCancelContinuousTaskNotification(data, reply); break; } - case static_cast(NotificationInterfaceCode::PUBLISH_REMINDER): { - result = HandlePublishReminder(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::CANCEL_REMINDER): { - result = HandleCancelReminder(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::CANCEL_ALL_REMINDERS): { - result = HandleCancelAllReminders(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::GET_ALL_VALID_REMINDERS): { - result = HandleGetValidReminders(data, reply); - break; - } case static_cast(NotificationInterfaceCode::IS_SUPPORT_TEMPLATE): { result = HandleIsSupportTemplate(data, reply); break; @@ -433,18 +417,6 @@ int32_t AnsManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Mess break; } #endif - case static_cast(NotificationInterfaceCode::ADD_EXCLUDE_DATE_REMINDER): { - result = HandleAddExcludeDate(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::DEL_EXCLUDE_DATES_REMINDER): { - result = HandleDelExcludeDates(data, reply); - break; - } - case static_cast(NotificationInterfaceCode::GET_EXCLUDE_DATES_REMINDER): { - result = HandleGetExcludeDates(data, reply); - break; - } case static_cast(NotificationInterfaceCode::GET_DONOTDISTURB_PROFILE): { result = HandleGetDoNotDisturbProfile(data, reply); break; @@ -453,6 +425,10 @@ int32_t AnsManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Mess result = HandleUpdateNotificationTimerByUid(data, reply); break; } + case static_cast(NotificationInterfaceCode::ALLOW_USE_REMINDER): { + result = HandleAllowUseReminder(data, reply); + break; + } default: { ANS_LOGE("[OnRemoteRequest] fail: unknown code!"); return IPCObjectStub::OnRemoteRequest(code, data, reply, flags); @@ -1865,175 +1841,6 @@ ErrCode AnsManagerStub::HandleShellDump(MessageParcel &data, MessageParcel &repl return ERR_OK; } -ErrCode AnsManagerStub::HandlePublishReminder(MessageParcel &data, MessageParcel &reply) -{ - ANSR_LOGI("HandlePublishReminder"); - uint8_t typeInfo = static_cast(ReminderRequest::ReminderType::INVALID); - if (!data.ReadUint8(typeInfo)) { - ANSR_LOGE("Failed to read reminder type"); - return ERR_ANS_PARCELABLE_FAILED; - } - ReminderRequest::ReminderType reminderType = static_cast(typeInfo); - sptr reminder; - if (ReminderRequest::ReminderType::ALARM == reminderType) { - ANSR_LOGD("Publish alarm"); - reminder = data.ReadParcelable(); - } else if (ReminderRequest::ReminderType::TIMER == reminderType) { - ANSR_LOGD("Publish timer"); - reminder = data.ReadParcelable(); - } else if (ReminderRequest::ReminderType::CALENDAR == reminderType) { - ANSR_LOGD("Publish calendar"); - reminder = data.ReadParcelable(); - } else { - ANSR_LOGE("Reminder type invalid"); - return ERR_ANS_INVALID_PARAM; - } - if (!reminder) { - ANSR_LOGE("Reminder ReadParcelable failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - ErrCode result = PublishReminder(reminder); - - if (!reply.WriteInt32(reminder->GetReminderId())) { - ANSR_LOGE("Write back reminderId failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - if (!reply.WriteInt32(result)) { - ANSR_LOGE("Write back result failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} - -ErrCode AnsManagerStub::HandleCancelReminder(MessageParcel &data, MessageParcel &reply) -{ - ANSR_LOGI("HandleCancelReminder"); - int32_t reminderId = -1; - if (!data.ReadInt32(reminderId)) { - ANSR_LOGE("Read reminder id failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - ErrCode result = CancelReminder(reminderId); - if (!reply.WriteInt32(result)) { - ANSR_LOGE("Write back result failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} - -ErrCode AnsManagerStub::HandleCancelAllReminders(MessageParcel &data, MessageParcel &reply) -{ - ErrCode result = CancelAllReminders(); - if (!reply.WriteInt32(result)) { - ANSR_LOGE("Write back result failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} - -ErrCode AnsManagerStub::HandleGetValidReminders(MessageParcel &data, MessageParcel &reply) -{ - ANSR_LOGI("HandleGetValidReminders"); - std::vector> validReminders; - ErrCode result = GetValidReminders(validReminders); - - ANSR_LOGD("Write back size=%{public}zu", validReminders.size()); - if (!reply.WriteUint8(static_cast(validReminders.size()))) { - ANSR_LOGE("Write back reminder count failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - for (auto it = validReminders.begin(); it != validReminders.end(); ++it) { - sptr reminder = (*it); - uint8_t reminderType = static_cast(reminder->GetReminderType()); - ANSR_LOGD("ReminderType=%{public}d", reminderType); - if (!reply.WriteUint8(reminderType)) { - ANSR_LOGW("Write reminder type failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - if (!reply.WriteParcelable(reminder)) { - ANSR_LOGW("Write reminder parcelable failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - } - if (!reply.WriteInt32(result)) { - ANSR_LOGE("Write back result failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} - -ErrCode AnsManagerStub::HandleAddExcludeDate(MessageParcel &data, MessageParcel &reply) -{ - ANSR_LOGI("HandleAddExcludeDate"); - int32_t reminderId = -1; - if (!data.ReadInt32(reminderId)) { - ANSR_LOGE("Read reminder id failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - uint64_t date = 0; - if (!data.ReadUint64(date)) { - ANSR_LOGE("Read exclude date failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - ErrCode result = AddExcludeDate(reminderId, date); - if (!reply.WriteInt32(result)) { - ANSR_LOGE("Write back result failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} - -ErrCode AnsManagerStub::HandleDelExcludeDates(MessageParcel &data, MessageParcel &reply) -{ - ANSR_LOGI("HandleDelExcludeDates"); - int32_t reminderId = -1; - if (!data.ReadInt32(reminderId)) { - ANSR_LOGE("Read reminder id failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - ErrCode result = DelExcludeDates(reminderId); - if (!reply.WriteInt32(result)) { - ANSR_LOGE("Write back result failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} - -ErrCode AnsManagerStub::HandleGetExcludeDates(MessageParcel &data, MessageParcel &reply) -{ - ANSR_LOGI("HandleGetExcludeDates"); - int32_t reminderId = -1; - if (!data.ReadInt32(reminderId)) { - ANSR_LOGE("Read reminder id failed."); - return ERR_ANS_PARCELABLE_FAILED; - } - - std::vector dates; - ErrCode result = GetExcludeDates(reminderId, dates); - ANSR_LOGD("Write back size=%{public}zu", dates.size()); - if (!reply.WriteUint8(static_cast(dates.size()))) { - ANSR_LOGE("Write back exclude date count failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - - for (const auto date : dates) { - if (!reply.WriteUint64(date)) { - ANSR_LOGW("Write exclude date failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - } - if (!reply.WriteInt32(result)) { - ANSR_LOGE("Write back result failed"); - return ERR_ANS_PARCELABLE_FAILED; - } - return result; -} - ErrCode AnsManagerStub::HandleIsSupportTemplate(MessageParcel &data, MessageParcel &reply) { std::string templateName; @@ -2666,5 +2473,28 @@ ErrCode AnsManagerStub::HandleUpdateNotificationTimerByUid(MessageParcel &data, } return ERR_OK; } + +ErrCode AnsManagerStub::HandleAllowUseReminder(MessageParcel &data, MessageParcel &reply) +{ + ANS_LOGD("enter"); + std::string bundleName; + if (!data.ReadString(bundleName)) { + ANS_LOGE("[HandleAllowUseReminder] fail: read deviceId failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + + bool isAllowUseReminder = false; + ErrCode result = AllowUseReminder(bundleName, isAllowUseReminder); + if (!reply.WriteInt32(result)) { + ANS_LOGE("[HandleAllowUseReminder] fail: write result failed, ErrCode=%{public}d", result); + return ERR_ANS_PARCELABLE_FAILED; + } + + if (!reply.WriteBool(isAllowUseReminder)) { + ANS_LOGE("[HandleAllowUseReminder] fail: write enabled failed."); + return ERR_ANS_PARCELABLE_FAILED; + } + return ERR_OK; +} } // namespace Notification } // namespace OHOS diff --git a/frameworks/core/src/manager/ans_manager_stub_invalid.cpp b/frameworks/core/src/manager/ans_manager_stub_invalid.cpp index 8d57b0365fc8cdb1598d1b4560c1bb5dde5b229e..4fd1383218fdb5316836315618a9494fcb1921b2 100644 --- a/frameworks/core/src/manager/ans_manager_stub_invalid.cpp +++ b/frameworks/core/src/manager/ans_manager_stub_invalid.cpp @@ -454,48 +454,6 @@ ErrCode AnsManagerStub::CancelContinuousTaskNotification(const std::string &labe return ERR_INVALID_OPERATION; } -ErrCode AnsManagerStub::PublishReminder(sptr &reminder) -{ - ANS_LOGE("AnsManagerStub::PublishReminder called!"); - return ERR_INVALID_OPERATION; -} - -ErrCode AnsManagerStub::CancelReminder(const int32_t reminderId) -{ - ANS_LOGE("AnsManagerStub::CancelReminder called!"); - return ERR_INVALID_OPERATION; -} - -ErrCode AnsManagerStub::GetValidReminders(std::vector> &reminders) -{ - ANS_LOGE("AnsManagerStub::getValidReminders called!"); - return ERR_INVALID_OPERATION; -} - -ErrCode AnsManagerStub::CancelAllReminders() -{ - ANS_LOGE("AnsManagerStub::cancelAllReminders called!"); - return ERR_INVALID_OPERATION; -} - -ErrCode AnsManagerStub::AddExcludeDate(const int32_t reminderId, const uint64_t date) -{ - ANS_LOGE("AnsManagerStub::AddExcludeDate called!"); - return ERR_INVALID_OPERATION; -} - -ErrCode AnsManagerStub::DelExcludeDates(const int32_t reminderId) -{ - ANS_LOGE("AnsManagerStub::DelExcludeDates called!"); - return ERR_INVALID_OPERATION; -} - -ErrCode AnsManagerStub::GetExcludeDates(const int32_t reminderId, std::vector& dates) -{ - ANS_LOGE("AnsManagerStub::GetExcludeDates called!"); - return ERR_INVALID_OPERATION; -} - ErrCode AnsManagerStub::IsSupportTemplate(const std::string &templateName, bool &support) { ANS_LOGE("AnsManagerStub::IsSupportTemplate called!"); @@ -652,6 +610,12 @@ ErrCode AnsManagerStub::GetDoNotDisturbProfile(int32_t id, sptr& swingCallback) { diff --git a/frameworks/core/test/unittest/ans_image_util_test/BUILD.gn b/frameworks/core/test/unittest/ans_image_util_test/BUILD.gn index 703d6cf0920b521b088fde03e6007bda7a55d6cb..ba78308bd70f3dee5568e870c7f137a5cf4453c6 100644 --- a/frameworks/core/test/unittest/ans_image_util_test/BUILD.gn +++ b/frameworks/core/test/unittest/ans_image_util_test/BUILD.gn @@ -33,16 +33,14 @@ ohos_unittest("ans_image_util_test") { "ans_image_util_unit_test.cpp", ] - deps = [ - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", - ] + deps = [] external_deps = [ "ability_base:want", "ability_base:zuri", "ability_runtime:wantagent_innerkits", "c_utils:utils", + "googletest:gmock_main", "hilog:libhilog", "image_framework:image_native", "relational_store:native_rdb", diff --git a/frameworks/core/test/unittest/ans_manager_proxy_test/BUILD.gn b/frameworks/core/test/unittest/ans_manager_proxy_test/BUILD.gn index 25e4772a3117d72e4d272cf0fcd1c1db59d8bb74..c627dc5806d0056235629ee9c8576d5c1a3b6d80 100644 --- a/frameworks/core/test/unittest/ans_manager_proxy_test/BUILD.gn +++ b/frameworks/core/test/unittest/ans_manager_proxy_test/BUILD.gn @@ -32,8 +32,6 @@ ohos_unittest("ans_manager_proxy_test") { deps = [ "${frameworks_module_ans_path}:ans_innerkits", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", ] external_deps = [ @@ -41,6 +39,7 @@ ohos_unittest("ans_manager_proxy_test") { "ability_base:zuri", "ability_runtime:wantagent_innerkits", "c_utils:utils", + "googletest:gmock_main", "hilog:libhilog", "image_framework:image_native", "ipc:ipc_core", diff --git a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp index 715472d49b1d6c121dd4431ad4460e8984057726..68368f4df472fbc4bf4609c71ceb8f78106e1eb7 100644 --- a/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_manager_proxy_test/ans_manager_proxy_unit_test.cpp @@ -7349,91 +7349,6 @@ HWTEST_F(AnsManagerProxyUnitTest, ShellDumpTest_0500, Function | MediumTest | Le EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, result); } -/* - * @tc.name: PublishReminder_0100 - * @tc.desc: test AnsManagerProxy's PublishReminder function - * @tc.type: FUNC - * @tc.require: #I5XO2O - */ -HWTEST_F(AnsManagerProxyUnitTest, PublishReminder_0100, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, PublishReminder_0100, TestSize.Level1"; - MockWriteInterfaceToken(false); - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - - sptr reminder = new ReminderRequest(); - ErrCode res = proxy->PublishReminder(reminder); - EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, res); -} - -/* - * @tc.name: PublishReminder_0200 - * @tc.desc: test AnsManagerProxy's PublishReminder function - * @tc.type: FUNC - * @tc.require: #I5XO2O - */ -HWTEST_F(AnsManagerProxyUnitTest, PublishReminder_0200, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, PublishReminder_0200, TestSize.Level1"; - MockWriteInterfaceToken(true); - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - - sptr reminder = nullptr; - ErrCode res = proxy->PublishReminder(reminder); - EXPECT_EQ(ERR_ANS_INVALID_PARAM, res); -} - -/* - * @tc.name: PublishReminder_0300 - * @tc.desc: test AnsManagerProxy's PublishReminder function - * @tc.type: FUNC - * @tc.require: #I5XO2O - */ -HWTEST_F(AnsManagerProxyUnitTest, PublishReminder_0300, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, PublishReminder_0300, TestSize.Level1"; - MockWriteInterfaceToken(true); - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - - sptr reminder = new ReminderRequest(); - ErrCode res = proxy->PublishReminder(reminder); - EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, res); -} - -/* - * @tc.name: ReadReminders_0100 - * @tc.desc: test AnsManagerProxy's ReadReminders function - * @tc.type: FUNC - * @tc.require: #I5XO2O - */ -HWTEST_F(AnsManagerProxyUnitTest, ReadReminders_0100, Function | MediumTest | Level1) -{ - GTEST_LOG_(INFO) - << "AnsManagerProxyUnitTest, ReadReminders_0100, TestSize.Level1"; - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - - uint8_t count = 10; - MessageParcel reply; - std::vector> reminders; - ErrCode res = proxy->ReadReminders(count, reply, reminders); - EXPECT_EQ(ERR_ANS_PARCELABLE_FAILED, res); -} - /* * @tc.name: SetBadgeNumberTest_0100 * @tc.desc: test SetBadgeNumber function diff --git a/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp b/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp index e73dd2d116d71ec060e75d6eb99643ddbfc7cee2..dba63a90d3da425aa6d8e47c3d7c6988ba81eab1 100644 --- a/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp +++ b/frameworks/core/test/unittest/ans_manager_stub_test/ans_manager_stub_test.cpp @@ -25,9 +25,6 @@ #define protected public #include "ans_manager_stub.h" #include "ans_subscriber_stub.h" -#include "reminder_request_alarm.h" -#include "reminder_request_timer.h" -#include "reminder_request_calendar.h" #include "ans_dialog_host_client.h" #include "notification_subscriber.h" #undef private @@ -3072,291 +3069,6 @@ HWTEST_F(AnsManagerStubTest, HandleShellDump04, Function | SmallTest | Level1) EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); } -/** - * @tc.name: HandlePublishReminder01 - * @tc.desc: Test Reminder type ALARM. - * @tc.type: FUNC - * @tc.require: issueI620XB - */ -HWTEST_F(AnsManagerStubTest, HandlePublishReminder01, Function | SmallTest | Level1) -{ - uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_REMINDER); - MessageParcel data; - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - - uint8_t typeInfo = static_cast(ReminderRequest::ReminderType::ALARM); - sptr reminder = new ReminderRequest(); - sptr reminderRequestAlarm = new ReminderRequestAlarm(); - - - data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); - data.WriteUint8(typeInfo); - data.WriteStrongParcelable(reminder); - data.WriteParcelable(reminderRequestAlarm); - - ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); -} - -/** - * @tc.name: HandlePublishReminder02 - * @tc.desc: Test Reminder type invalid. - * @tc.type: FUNC - * @tc.require: issueI620XB - */ -HWTEST_F(AnsManagerStubTest, HandlePublishReminder02, Function | SmallTest | Level1) -{ - uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_REMINDER); - MessageParcel data; - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - - uint8_t typeInfo = static_cast(ReminderRequest::ReminderType::INVALID); - sptr reminder = new ReminderRequest(); - - data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); - data.WriteUint8(typeInfo); - data.WriteParcelable(reminder); - - ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); -} - -/** - * @tc.name: HandlePublishReminder03 - * @tc.desc: Test reminder in date is null. - * @tc.type: FUNC - * @tc.require: issueI620XB - */ -HWTEST_F(AnsManagerStubTest, HandlePublishReminder03, Function | SmallTest | Level1) -{ - uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_REMINDER); - MessageParcel data; - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - - data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); - - ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); -} - -/** - * @tc.name: HandlePublishReminder04 - * @tc.desc: Test Reminder type TIMER. - * @tc.type: FUNC - * @tc.require: issueI620XB - */ -HWTEST_F(AnsManagerStubTest, HandlePublishReminder04, Function | SmallTest | Level1) -{ - uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_REMINDER); - MessageParcel data; - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - - uint8_t typeInfo = static_cast(ReminderRequest::ReminderType::TIMER); - sptr reminder = new ReminderRequest(); - sptr reminderRequestTimer = new ReminderRequestTimer(); - - - data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); - data.WriteUint8(typeInfo); - data.WriteStrongParcelable(reminder); - data.WriteParcelable(reminderRequestTimer); - - ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); -} - -/** - * @tc.name: HandlePublishReminder05 - * @tc.desc: Test Reminder type CALENDAR. - * @tc.type: FUNC - * @tc.require: issueI620XB - */ -HWTEST_F(AnsManagerStubTest, HandlePublishReminder05, Function | SmallTest | Level1) -{ - uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_REMINDER); - MessageParcel data; - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - - uint8_t typeInfo = static_cast(ReminderRequest::ReminderType::CALENDAR); - sptr reminder = new ReminderRequest(); - sptr reminderRequestCalendar = new ReminderRequestCalendar(); - - - data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); - data.WriteUint8(typeInfo); - data.WriteStrongParcelable(reminder); - data.WriteParcelable(reminderRequestCalendar); - - ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); -} - -/** - * @tc.name: HandlePublishReminder06 - * @tc.desc: Test typeInfo in date is null. - * @tc.type: FUNC - * @tc.require: issueI620XB - */ -HWTEST_F(AnsManagerStubTest, HandlePublishReminder06, Function | SmallTest | Level1) -{ - uint32_t code = static_cast(NotificationInterfaceCode::PUBLISH_REMINDER); - MessageParcel data; - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - - sptr reminder = new ReminderRequest(); - sptr reminderRequestCalendar = new ReminderRequestCalendar(); - - - data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); - data.WriteStrongParcelable(reminder); - data.WriteParcelable(reminderRequestCalendar); - - ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); -} - -/** - * @tc.name: HandleCancelReminder01 - * @tc.desc: Test HandleCancelReminder ERR_INVALID_OPERATION. - * @tc.type: FUNC - * @tc.require: issueI620XB - */ -HWTEST_F(AnsManagerStubTest, HandleCancelReminder01, Function | SmallTest | Level1) -{ - uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_REMINDER); - MessageParcel data; - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - - int32_t reminderId = 4; - - data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); - data.WriteInt32(reminderId); - - ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); -} - -/** - * @tc.name: HandleCancelReminder02 - * @tc.desc: Test reminderId in data is null. - * @tc.type: FUNC - * @tc.require: issueI620XB - */ -HWTEST_F(AnsManagerStubTest, HandleCancelReminder02, Function | SmallTest | Level1) -{ - uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_REMINDER); - MessageParcel data; - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - - data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); - - ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); -} - -/** - * @tc.name: HandleCancelAllReminders01 - * @tc.desc: Test HandleCancelAllReminders result ERR_INVALID_OPERATION. - * @tc.type: FUNC - * @tc.require: issueI620XB - */ -HWTEST_F(AnsManagerStubTest, HandleCancelAllReminders01, Function | SmallTest | Level1) -{ - uint32_t code = static_cast(NotificationInterfaceCode::CANCEL_ALL_REMINDERS); - MessageParcel data; - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - - data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); - - ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); -} - -/** - * @tc.name: HandleGetValidReminders01 - * @tc.desc: Test HandleGetValidReminders result ERR_INVALID_OPERATION. - * @tc.type: FUNC - * @tc.require: issueI620XB - */ -HWTEST_F(AnsManagerStubTest, HandleGetValidReminders01, Function | SmallTest | Level1) -{ - uint32_t code = static_cast(NotificationInterfaceCode::GET_ALL_VALID_REMINDERS); - MessageParcel data; - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - - data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); - - ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ret, (int)ERR_INVALID_OPERATION); -} - -/** - * @tc.name: HandleAddExcludeDate01 - * @tc.desc: Test HandleAddExcludeDate result ERR_INVALID_OPERATION. - * @tc.type: FUNC - * @tc.require: issueI620XB - */ -HWTEST_F(AnsManagerStubTest, HandleAddExcludeDate01, Function | SmallTest | Level1) -{ - uint32_t code = static_cast(NotificationInterfaceCode::ADD_EXCLUDE_DATE_REMINDER); - MessageParcel data; - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - - data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); - - ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); -} - -/** - * @tc.name: HandleDelExcludeDates01 - * @tc.desc: Test HandleDelExcludeDates result ERR_INVALID_OPERATION. - * @tc.type: FUNC - * @tc.require: issueI620XB - */ -HWTEST_F(AnsManagerStubTest, HandleDelExcludeDates01, Function | SmallTest | Level1) -{ - uint32_t code = static_cast(NotificationInterfaceCode::DEL_EXCLUDE_DATES_REMINDER); - MessageParcel data; - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - - data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); - - ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); -} - -/** - * @tc.name: HandleGetExcludeDates01 - * @tc.desc: Test HandleGetExcludeDates result ERR_INVALID_OPERATION. - * @tc.type: FUNC - * @tc.require: issueI620XB - */ -HWTEST_F(AnsManagerStubTest, HandleGetExcludeDates01, Function | SmallTest | Level1) -{ - uint32_t code = static_cast(NotificationInterfaceCode::GET_EXCLUDE_DATES_REMINDER); - MessageParcel data; - MessageParcel reply; - MessageOption option = {MessageOption::TF_SYNC}; - - data.WriteInterfaceToken(AnsManagerStub::GetDescriptor()); - - ErrCode ret = ansManagerStub_->OnRemoteRequest(code, data, reply, option); - EXPECT_EQ(ret, (int)ERR_ANS_PARCELABLE_FAILED); -} - /** * @tc.name: ReadParcelableVector01 * @tc.desc: Test ReadParcelableVector result. @@ -4540,103 +4252,6 @@ HWTEST_F(AnsManagerStubTest, CancelContinuousTaskNotification01, Function | Smal EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); } -/** - * @tc.name: PublishReminder01 - * @tc.desc: Test PublishReminder return. - * @tc.type: FUNC - * @tc.require: issueI620XB - */ -HWTEST_F(AnsManagerStubTest, PublishReminder01, Function | SmallTest | Level1) -{ - sptr reminder = new ReminderRequest(); - - ErrCode result = ansManagerStub_->PublishReminder(reminder); - EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); -} - -/** - * @tc.name: CancelReminder01 - * @tc.desc: Test CancelReminder return. - * @tc.type: FUNC - * @tc.require: issueI620XB - */ -HWTEST_F(AnsManagerStubTest, CancelReminder01, Function | SmallTest | Level1) -{ - int32_t reminderId = 5; - - ErrCode result = ansManagerStub_->CancelReminder(reminderId); - EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); -} - -/** - * @tc.name: GetValidReminders01 - * @tc.desc: Test GetValidReminders return. - * @tc.type: FUNC - * @tc.require: issueI620XB - */ -HWTEST_F(AnsManagerStubTest, GetValidReminders01, Function | SmallTest | Level1) -{ - std::vector> reminders; - sptr reminder = new ReminderRequest(); - reminders.emplace_back(reminder); - - ErrCode result = ansManagerStub_->GetValidReminders(reminders); - EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); -} - -/** - * @tc.name: CancelAllReminders01 - * @tc.desc: Test CancelAllReminders return. - * @tc.type: FUNC - * @tc.require: issueI620XB - */ -HWTEST_F(AnsManagerStubTest, CancelAllReminders01, Function | SmallTest | Level1) -{ - ErrCode result = ansManagerStub_->CancelAllReminders(); - EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); -} - -/** - * @tc.name: AddExcludeDate01 - * @tc.desc: Test AddExcludeDate return. - * @tc.type: FUNC - * @tc.require: issue#I9F24R - */ -HWTEST_F(AnsManagerStubTest, AddExcludeDate01, Function | SmallTest | Level1) -{ - int32_t reminderId = 5; - uint64_t date = 1713196800000; - ErrCode result = ansManagerStub_->AddExcludeDate(reminderId, date); - EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); -} - -/** - * @tc.name: DelExcludeDates01 - * @tc.desc: Test DelExcludeDates return. - * @tc.type: FUNC - * @tc.require: issue#I9F24R - */ -HWTEST_F(AnsManagerStubTest, DelExcludeDates01, Function | SmallTest | Level1) -{ - int32_t reminderId = 5; - ErrCode result = ansManagerStub_->DelExcludeDates(reminderId); - EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); -} - -/** - * @tc.name: GetExcludeDates01 - * @tc.desc: Test GetExcludeDates return. - * @tc.type: FUNC - * @tc.require: issue#I9F24R - */ -HWTEST_F(AnsManagerStubTest, GetExcludeDates01, Function | SmallTest | Level1) -{ - int32_t reminderId = 5; - std::vector dates; - ErrCode result = ansManagerStub_->GetExcludeDates(reminderId, dates); - EXPECT_EQ(result, (int)ERR_INVALID_OPERATION); -} - /** * @tc.name: IsSupportTemplate01 * @tc.desc: Test IsSupportTemplate return. diff --git a/frameworks/core/test/unittest/ans_notification_annex_test/ans_notification_annex_test.cpp b/frameworks/core/test/unittest/ans_notification_annex_test/ans_notification_annex_test.cpp index cf9e8fe2c2c388ff5ba6fa1089a1780689d9c295..09aacf0eb6c3bab7789be8b73360e224ca34ca21 100644 --- a/frameworks/core/test/unittest/ans_notification_annex_test/ans_notification_annex_test.cpp +++ b/frameworks/core/test/unittest/ans_notification_annex_test/ans_notification_annex_test.cpp @@ -25,9 +25,6 @@ #include "ans_inner_errors.h" #include "ipc_types.h" #include "notification.h" -#include "reminder_request_alarm.h" -#include "reminder_request_calendar.h" -#include "reminder_request_timer.h" #include "singleton.h" #include "notification_subscriber.h" @@ -260,54 +257,6 @@ HWTEST_F(AnsNotificationUnitAnnexTest, PublishContinuousTaskNotification_0200, F EXPECT_EQ(ret1, ERR_ANS_NOT_SYSTEM_SERVICE); } -/* - * @tc.name: PublishReminder_0100 - * @tc.desc: test PublishReminder ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. - * @tc.type: FUNC - * @tc.require: #I62SME - */ -HWTEST_F(AnsNotificationUnitAnnexTest, PublishReminder_0100, Function | MediumTest | Level1) -{ - uint64_t countDownTimeInSeconds = 0; - ReminderRequestTimer reminder = ReminderRequestTimer(countDownTimeInSeconds); - ErrCode ret = ans_->PublishReminder(reminder); - int errorcode = 201; - EXPECT_EQ(ret, errorcode); -} - -/* - * @tc.name: PublishReminder_0200 - * @tc.desc: test PublishReminder ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. - * @tc.type: FUNC - * @tc.require: #I62SME - */ -HWTEST_F(AnsNotificationUnitAnnexTest, PublishReminder_0200, Function | MediumTest | Level1) -{ - std::vector daysOfWeek; - ReminderRequestAlarm reminder = ReminderRequestAlarm(0, 0, daysOfWeek); - ErrCode ret = ans_->PublishReminder(reminder); - int errorcode = 201; - EXPECT_EQ(ret, errorcode); -} - -/* - * @tc.name: PublishReminder_0300 - * @tc.desc: test PublishReminder ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. - * @tc.type: FUNC - * @tc.require: #I62SME - */ -HWTEST_F(AnsNotificationUnitAnnexTest, PublishReminder_0300, Function | MediumTest | Level1) -{ - tm dateTime {}; - std::vector repeatMonths; - std::vector repeatDays; - std::vector daysOfWeek; - ReminderRequestCalendar reminder = ReminderRequestCalendar(dateTime, repeatMonths, repeatDays, daysOfWeek); - ErrCode ret = ans_->PublishReminder(reminder); - int errorcode = 201; - EXPECT_EQ(ret, errorcode); -} - /* * @tc.name: CheckImageSizeForContent_0100 * @tc.desc: test CheckImageSizeForContent. diff --git a/frameworks/core/test/unittest/ans_notification_branch_test/BUILD.gn b/frameworks/core/test/unittest/ans_notification_branch_test/BUILD.gn index c96bda5b6cc5d531d445638e4c39224a275f9313..a292326554abd39b7f4f1d63efca2dadb913b665 100755 --- a/frameworks/core/test/unittest/ans_notification_branch_test/BUILD.gn +++ b/frameworks/core/test/unittest/ans_notification_branch_test/BUILD.gn @@ -31,8 +31,6 @@ ohos_unittest("ans_notification_branch_test") { deps = [ "${frameworks_module_ans_path}:ans_innerkits", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", ] external_deps = [ @@ -40,6 +38,7 @@ ohos_unittest("ans_notification_branch_test") { "ability_base:zuri", "ability_runtime:wantagent_innerkits", "c_utils:utils", + "googletest:gmock_main", "hilog:libhilog", "image_framework:image_native", "ipc:ipc_single", diff --git a/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp b/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp index b3307a9f9cc42173a39e0e31bfefb57d7724841e..4fade4fc1143f8d53a6faa1bf612956973624d52 100644 --- a/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp +++ b/frameworks/core/test/unittest/ans_notification_branch_test/ans_notification_branch_test.cpp @@ -393,41 +393,6 @@ public: return ERR_ANS_INVALID_PARAM; } - ErrCode PublishReminder(sptr &reminder) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode CancelReminder(const int32_t reminderId) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetValidReminders(std::vector> &reminders) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode CancelAllReminders() override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode DelExcludeDates(const int32_t reminderId) override - { - return ERR_ANS_INVALID_PARAM; - } - - ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) override - { - return ERR_ANS_INVALID_PARAM; - } - ErrCode IsSupportTemplate(const std::string &templateName, bool &support) override { return ERR_ANS_INVALID_PARAM; @@ -588,6 +553,11 @@ public: { return ERR_ANS_INVALID_PARAM; } + + ErrCode AllowUseReminder(const std::string& bundleName, bool& isAllowUseReminder) override + { + return ERR_ANS_INVALID_PARAM; + } }; class AnsNotificationBranchTest : public testing::Test { diff --git a/frameworks/core/test/unittest/ans_notification_test/BUILD.gn b/frameworks/core/test/unittest/ans_notification_test/BUILD.gn index 0baa458dca49d6d6a8ad3131af1c57a32c254b9c..64aa04f127445ea81fc84db2462224e332962313 100644 --- a/frameworks/core/test/unittest/ans_notification_test/BUILD.gn +++ b/frameworks/core/test/unittest/ans_notification_test/BUILD.gn @@ -31,8 +31,6 @@ ohos_unittest("ans_notification_test") { deps = [ "${frameworks_module_ans_path}:ans_innerkits", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", ] external_deps = [ @@ -40,6 +38,7 @@ ohos_unittest("ans_notification_test") { "ability_base:zuri", "ability_runtime:wantagent_innerkits", "c_utils:utils", + "googletest:gmock_main", "hilog:libhilog", "image_framework:image_native", "ipc:ipc_single", diff --git a/frameworks/core/test/unittest/ans_notification_test/ans_notification_unit_test.cpp b/frameworks/core/test/unittest/ans_notification_test/ans_notification_unit_test.cpp index 6d499f03e89d90ccabfddd3dac3a65aeb44be4db..3fed63cffe5bada5f2274d50213047205431d2c8 100644 --- a/frameworks/core/test/unittest/ans_notification_test/ans_notification_unit_test.cpp +++ b/frameworks/core/test/unittest/ans_notification_test/ans_notification_unit_test.cpp @@ -873,37 +873,6 @@ HWTEST_F(AnsNotificationUnitTest, IsDistributedEnabled_0100, Function | MediumTe EXPECT_EQ(ret5, ERR_ANS_SERVICE_NOT_CONNECTED); } -/* - * @tc.name: GetDeviceRemindType_0100 - * @tc.desc: test GetDeviceRemindType ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. - * @tc.type: FUNC - * @tc.require: #I62SME - */ -HWTEST_F(AnsNotificationUnitTest, GetDeviceRemindType_0100, Function | MediumTest | Level1) -{ - MockWriteInterfaceToken(false); - sptr iremoteObject = new (std::nothrow) MockIRemoteObject(); - ASSERT_NE(nullptr, iremoteObject); - std::shared_ptr proxy = std::make_shared(iremoteObject); - ASSERT_NE(nullptr, proxy); - ans_->GetAnsManagerProxy(); - - NotificationConstant::RemindType remindType = NotificationConstant::RemindType::NONE; - ErrCode ret1 = ans_->GetDeviceRemindType(remindType); - EXPECT_EQ(ret1, ERR_ANS_SERVICE_NOT_CONNECTED); - ReminderRequest reminder; - ErrCode ret2 = ans_->PublishReminder(reminder); - EXPECT_EQ(ret2, ERR_ANS_INVALID_PARAM); - int32_t reminderId = 1; - ErrCode ret3 = ans_->CancelReminder(reminderId); - EXPECT_EQ(ret3, ERR_ANS_SERVICE_NOT_CONNECTED); - ErrCode ret4 = ans_->CancelAllReminders(); - EXPECT_EQ(ret4, ERR_ANS_SERVICE_NOT_CONNECTED); - std::vector> validReminders; - ErrCode ret5 = ans_->GetValidReminders(validReminders); - EXPECT_EQ(ret5, ERR_ANS_SERVICE_NOT_CONNECTED); -} - /* * @tc.name: IsSupportTemplate_0100 * @tc.desc: test IsSupportTemplate ErrCode ERR_ANS_SERVICE_NOT_CONNECTED. diff --git a/frameworks/core/test/unittest/ans_subscriber_proxy_branch_test/BUILD.gn b/frameworks/core/test/unittest/ans_subscriber_proxy_branch_test/BUILD.gn index c66a7869893e1e66d3f524f00842967996d65d44..a42d11e55691f0515ee5a95bd69cb7eb696be211 100755 --- a/frameworks/core/test/unittest/ans_subscriber_proxy_branch_test/BUILD.gn +++ b/frameworks/core/test/unittest/ans_subscriber_proxy_branch_test/BUILD.gn @@ -9,7 +9,7 @@ # 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. +# limitations under the License. import("//base/notification/distributed_notification_service/notification.gni") import("//build/ohos.gni") @@ -28,8 +28,6 @@ ohos_unittest("ans_subscriber_proxy_branch_test") { deps = [ "${frameworks_module_ans_path}:ans_innerkits", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", ] external_deps = [ @@ -37,6 +35,7 @@ ohos_unittest("ans_subscriber_proxy_branch_test") { "ability_base:zuri", "ability_runtime:wantagent_innerkits", "c_utils:utils", + "googletest:gmock_main", "hilog:libhilog", "image_framework:image_native", "ipc:ipc_single", diff --git a/frameworks/core/test/unittest/ans_subscriber_proxy_test/BUILD.gn b/frameworks/core/test/unittest/ans_subscriber_proxy_test/BUILD.gn index 9f5c0eaf56d29cd5d4dc6aacc5a1f1c67264eb16..f5d1007445f084d408a1152daf7695bac086fc4d 100644 --- a/frameworks/core/test/unittest/ans_subscriber_proxy_test/BUILD.gn +++ b/frameworks/core/test/unittest/ans_subscriber_proxy_test/BUILD.gn @@ -28,8 +28,6 @@ ohos_unittest("ans_subscriber_proxy_test") { deps = [ "${frameworks_module_ans_path}:ans_innerkits", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", ] external_deps = [ @@ -37,6 +35,7 @@ ohos_unittest("ans_subscriber_proxy_test") { "ability_base:zuri", "ability_runtime:wantagent_innerkits", "c_utils:utils", + "googletest:gmock_main", "hilog:libhilog", "image_framework:image_native", "ipc:ipc_single", diff --git a/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn b/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn index fc967ba2c6e7aa0bc28e28a684c5a32713c096c5..46417089e0f78901a942a8983229e27cc8f23cc5 100644 --- a/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn +++ b/frameworks/core/test/unittest/ans_subscriber_stub_test/BUILD.gn @@ -28,8 +28,6 @@ ohos_unittest("ans_subscriber_stub_test") { deps = [ "${frameworks_module_ans_path}:ans_innerkits", - "//third_party/googletest:gmock_main", - "//third_party/googletest:gtest_main", ] external_deps = [ @@ -37,6 +35,7 @@ ohos_unittest("ans_subscriber_stub_test") { "ability_base:zuri", "ability_runtime:wantagent_innerkits", "c_utils:utils", + "googletest:gmock_main", "hilog:libhilog", "image_framework:image_native", "ipc:ipc_single", diff --git a/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index 7e11b49298e54eb36a5767a6f8b65bd663c7143f..a410ebc6ed9600885e8bbf1d6dd70838a4b7cf15 100644 --- a/frameworks/js/napi/BUILD.gn +++ b/frameworks/js/napi/BUILD.gn @@ -96,7 +96,10 @@ ohos_shared_library("notification") { "src/unsubscribe.cpp", ] - deps = [ "${frameworks_module_ans_path}:ans_innerkits" ] + deps = [ + "${frameworks_module_ans_path}:ans_innerkits", + "${frameworks_module_reminder_path}:reminder_innerkits", + ] external_deps = [ "ability_base:want", diff --git a/frameworks/js/napi/src/manager/BUILD.gn b/frameworks/js/napi/src/manager/BUILD.gn index 3cfda893b7af5a4cc5b1f1ba6c9cca4be73aace7..0081f8b8bc2625be13ec34093f544fbcb4c90831 100644 --- a/frameworks/js/napi/src/manager/BUILD.gn +++ b/frameworks/js/napi/src/manager/BUILD.gn @@ -94,7 +94,10 @@ ohos_shared_library("notificationmanager") { "napi_template.cpp", ] - deps = [ "${frameworks_module_ans_path}:ans_innerkits" ] + deps = [ + "${frameworks_module_ans_path}:ans_innerkits", + "${frameworks_module_reminder_path}:reminder_innerkits", + ] external_deps = [ "ability_base:want", diff --git a/frameworks/js/napi/src/reminder/BUILD.gn b/frameworks/js/napi/src/reminder/BUILD.gn index 3bdbdddb193f63ffa574053ba0904ce4300a19bb..365b4d2d07e3e3e0ff8c37a05db145800772155d 100644 --- a/frameworks/js/napi/src/reminder/BUILD.gn +++ b/frameworks/js/napi/src/reminder/BUILD.gn @@ -58,7 +58,10 @@ ohos_shared_library("reminderagent") { "reminder_common.cpp", ] - deps = [ "${frameworks_module_ans_path}:ans_innerkits" ] + deps = [ + "${frameworks_module_ans_path}:ans_innerkits", + "${frameworks_module_reminder_path}:reminder_innerkits", + ] external_deps = [ "ability_base:want", @@ -112,7 +115,10 @@ ohos_shared_library("reminderagentmanager") { "reminder_common.cpp", ] - deps = [ "${frameworks_module_ans_path}:ans_innerkits" ] + deps = [ + "${frameworks_module_ans_path}:ans_innerkits", + "${frameworks_module_reminder_path}:reminder_innerkits", + ] external_deps = [ "ability_base:want", diff --git a/frameworks/js/napi/src/reminder/publish.cpp b/frameworks/js/napi/src/reminder/publish.cpp index f45edf5d2a872a1beed29b1f0e762a20601dbb7d..9b2a9b4ddf4cd7a5b0bb8039aa95f81d35fa7795 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -53,19 +53,19 @@ struct AsyncCallbackInfo { napi_ref callback = nullptr; napi_value result = nullptr; int32_t reminderId = -1; - uint64_t excludeDate = 0; + int64_t excludeDate = 0; bool isThrow = false; NotificationNapi::NotificationConstant::SlotType inType = NotificationNapi::NotificationConstant::SlotType::CONTENT_INFORMATION; std::shared_ptr reminder = nullptr; - std::vector> validReminders; - std::vector excludeDates; + std::vector validReminders; + std::vector excludeDates; CallbackPromiseInfo info; }; struct Parameters { int32_t reminderId = -1; - uint64_t excludeDate = 0; + int64_t excludeDate = 0; int32_t errCode = ERR_OK; NotificationNapi::NotificationConstant::SlotType inType = NotificationNapi::NotificationConstant::SlotType::CONTENT_INFORMATION; @@ -632,7 +632,7 @@ void ParseButtonDataShareUpdate(const napi_env &env, ParseValueBucket(env, valuesBucketVector, buttonDataShareUpdate, BUTTON_DATA_SHARE_UPDATE_VALUE); } -void ParseActionButtons(const napi_env &env, ReminderRequest &reminder, napi_value &result) +void ParseActionButtons(const napi_env &env, const ReminderRequest &reminder, napi_value &result) { auto actionButtonsMap = reminder.GetActionButtons(); @@ -679,7 +679,7 @@ void ParseActionButtons(const napi_env &env, ReminderRequest &reminder, napi_val } } -void ParseWantAgent(const napi_env &env, ReminderRequest &reminder, napi_value &result) +void ParseWantAgent(const napi_env &env, const ReminderRequest &reminder, napi_value &result) { // create obj napi_value wantAgentInfo = nullptr; @@ -699,7 +699,7 @@ void ParseWantAgent(const napi_env &env, ReminderRequest &reminder, napi_value & napi_set_named_property(env, wantAgentInfo, WANT_AGENT_PARAMETERS, params); } -void ParseMaxScreenWantAgent(const napi_env &env, ReminderRequest &reminder, napi_value &result) +void ParseMaxScreenWantAgent(const napi_env &env, const ReminderRequest &reminder, napi_value &result) { // create obj napi_value maxScreenWantAgentInfo = nullptr; @@ -713,7 +713,7 @@ void ParseMaxScreenWantAgent(const napi_env &env, ReminderRequest &reminder, nap napi_set_named_property(env, maxScreenWantAgentInfo, MAX_SCREEN_WANT_AGENT_ABILITY, info); } -napi_value SetValidReminder(const napi_env &env, ReminderRequest &reminder, napi_value &result) +napi_value SetValidReminder(const napi_env &env, const ReminderRequest &reminder, napi_value &result) { ANSR_LOGI("enter"); napi_value value = nullptr; @@ -805,18 +805,14 @@ napi_value SetValidReminder(const napi_env &env, ReminderRequest &reminder, napi return NotificationNapi::Common::NapiGetBoolean(env, true); } -void GetValidRemindersInner(napi_env env, const std::vector>& validReminders, napi_value& arr) +void GetValidRemindersInner(napi_env env, const std::vector& validReminders, napi_value& arr) { int32_t count = 0; napi_create_array(env, &arr); - for (auto reminder : validReminders) { - if (reminder == nullptr) { - ANSR_LOGW("reminder is null"); - continue; - } + for (auto& reminder : validReminders) { napi_value result = nullptr; napi_create_object(env, &result); - if (!SetValidReminder(env, *reminder, result)) { + if (!SetValidReminder(env, reminder, result)) { ANSR_LOGW("Set reminder object failed"); continue; } @@ -826,26 +822,22 @@ void GetValidRemindersInner(napi_env env, const std::vector>& validReminders, napi_value& arr) +void GetAllValidRemindersInner(napi_env env, const std::vector& validReminders, napi_value& arr) { int32_t count = 0; napi_create_array(env, &arr); - for (auto reminder : validReminders) { - if (reminder == nullptr) { - ANSR_LOGW("reminder is null"); - continue; - } + for (auto& reminder : validReminders) { napi_value result = nullptr; napi_create_object(env, &result); napi_value reminderReq = nullptr; napi_create_object(env, &reminderReq); napi_set_named_property(env, result, REMINDER_INFO_REMINDER_REQ, reminderReq); - if (!SetValidReminder(env, *reminder, reminderReq)) { + if (!SetValidReminder(env, reminder, reminderReq)) { ANSR_LOGW("Set reminder object failed"); continue; } napi_value reminderId = nullptr; - napi_create_int32(env, reminder->GetReminderId(), &reminderId); + napi_create_int32(env, reminder.GetReminderId(), &reminderId); napi_set_named_property(env, result, REMINDER_INFO_REMINDER_ID, reminderId); napi_set_element(env, arr, count, result); count++; @@ -1033,8 +1025,9 @@ napi_value PublishReminderInner(napi_env env, napi_callback_info info, bool isTh ANSR_LOGI("Publish napi_create_async_work start"); AsyncCallbackInfo *asynccallbackinfo = static_cast(data); if (asynccallbackinfo) { - asynccallbackinfo->info.errorCode = ReminderHelper::PublishReminder(*(asynccallbackinfo->reminder)); - ANSR_LOGD("Return reminderId=%{public}d", asynccallbackinfo->reminder->GetReminderId()); + asynccallbackinfo->info.errorCode = + ReminderHelper::PublishReminder(*(asynccallbackinfo->reminder), asynccallbackinfo->reminderId); + ANSR_LOGD("Return reminderId=%{public}d", asynccallbackinfo->reminderId); } }, [](napi_env env, napi_status status, void *data) { @@ -1045,7 +1038,7 @@ napi_value PublishReminderInner(napi_env env, napi_callback_info info, bool isTh // reminderId if (asynccallbackinfo) { if (asynccallbackinfo->info.errorCode == ERR_OK) { - napi_create_int32(env, asynccallbackinfo->reminder->GetReminderId(), &(asynccallbackinfo->result)); + napi_create_int32(env, asynccallbackinfo->reminderId, &(asynccallbackinfo->result)); } else { napi_create_int32(env, -1, &(asynccallbackinfo->result)); } @@ -1187,7 +1180,7 @@ napi_value ParseAddExcludeDateParameter(const napi_env &env, const napi_callback ReminderCommon::HandleErrCode(env, ERR_REMINDER_INVALID_PARAM); return nullptr; } - params.excludeDate = static_cast(date); + params.excludeDate = static_cast(date); return NotificationNapi::Common::NapiGetNull(env); } @@ -1335,7 +1328,7 @@ napi_value DelExcludeDates(napi_env env, napi_callback_info info) return isCallback ? NotificationNapi::Common::NapiGetNull(env) : promise; } -void GetExcludeDatesInner(napi_env env, const std::vector& dates, napi_value& arr) +void GetExcludeDatesInner(napi_env env, const std::vector& dates, napi_value& arr) { int32_t count = 0; napi_create_array(env, &arr); diff --git a/frameworks/reminder/BUILD.gn b/frameworks/reminder/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6041dea060a16dd565b226b41755fb435e97864e --- /dev/null +++ b/frameworks/reminder/BUILD.gn @@ -0,0 +1,114 @@ +# Copyright (c) 2024 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. + +import("//build/ohos.gni") +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/components/idl_tool/idl.gni") + +group("reminder_client") { + deps = [ ":reminder_innerkits" ] +} + +idl_interface_sources = [ + "${target_gen_dir}/reminder_service_proxy.cpp", + "${target_gen_dir}/reminder_service_stub.cpp", +] + +idl_gen_interface("reminder_service_interface") { + src_idl = rebase_path("IReminderService.idl") + dst_file = string_join(",", idl_interface_sources) + hitrace = "HITRACE_TAG_ABILITY_MANAGER" + log_domainid = "0xD003900" + log_tag = "ReminderServiceService" +} + +config("reminder_innerkits_public_config") { + visibility = [ "./../../*" ] + + include_dirs = [ + "${inner_api_path}", + "${core_path}/common/include", + "${core_path}/include", + "${target_gen_dir}", + ] +} + +ohos_shared_library("reminder_innerkits") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + + include_dirs = [ "${inner_api_path}" ] + public_configs = [ ":reminder_innerkits_public_config" ] + output_values = get_target_outputs(":reminder_service_interface") + sources = [ + "${frameworks_module_reminder_path}/src/reminder_request_factory.cpp", + "${frameworks_module_reminder_path}/src/reminder_request_client.cpp", + "${frameworks_module_reminder_path}/src/reminder_service_load_callback.cpp", + "${frameworks_module_reminder_path}/src/reminder_helper.cpp", + "${frameworks_module_reminder_path}/src/reminder_request.cpp", + "${frameworks_module_reminder_path}/src/reminder_request_alarm.cpp", + "${frameworks_module_reminder_path}/src/reminder_request_calendar.cpp", + "${frameworks_module_reminder_path}/src/reminder_request_timer.cpp", + ] + sources += filter_include(output_values, [ "*.cpp" ]) + defines = [] + deps = [ + ":reminder_service_interface", + "${frameworks_path}/ans:ans_client", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:appkit_native", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "eventhandler:libeventhandler", + "hicollie:libhicollie", + "hilog:libhilog", + "i18n:intl_util", + "ipc:ipc_core", + "samgr:samgr_proxy", + "time_service:time_client", + ] + + public_external_deps = [ + "ability_runtime:wantagent_innerkits", + "ffrt:libffrt", + "image_framework:image_native", + ] + + if (is_double_framework) { + cflags = [ "-DCONFIG_DUAL_FRAMEWORK" ] + } + + if (ans_hitrace_usage) { + external_deps += [ "hitrace:hitrace_meter" ] + defines += [ "HITRACE_METER_ENABLE" ] + } + + if (notification_smart_reminder_supported) { + defines += [ "NOTIFICATION_SMART_REMINDER_SUPPORTED" ] + } + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} diff --git a/frameworks/reminder/IReminderService.idl b/frameworks/reminder/IReminderService.idl new file mode 100644 index 0000000000000000000000000000000000000000..b384c516c44e19a9cfcc68add08f9e84a3dacd7c --- /dev/null +++ b/frameworks/reminder/IReminderService.idl @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024 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. + */ + +sequenceable OHOS.Notification.ReminderRequest; +interface OHOS.Notification.IReminderService { + void PublishReminder([in] ReminderRequest reminder, [out] int reminderId); + void CancelReminder([in] int reminderId); + void CancelAllReminders(); + void GetValidReminders([out] ReminderRequest[] reminders); + void AddExcludeDate([in] int reminderId, [in] long date); + void DelExcludeDates([in] int reminderId); + void GetExcludeDates([in] int reminderId, [out] long[] dates); +} \ No newline at end of file diff --git a/frameworks/ans/src/reminder_helper.cpp b/frameworks/reminder/src/reminder_helper.cpp similarity index 56% rename from frameworks/ans/src/reminder_helper.cpp rename to frameworks/reminder/src/reminder_helper.cpp index 49298a0725ee03697fe820d84bb9069b4532534b..b82b35a37443971335fd88772e8e2ab90df76677 100644 --- a/frameworks/ans/src/reminder_helper.cpp +++ b/frameworks/reminder/src/reminder_helper.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -16,65 +16,63 @@ #include "reminder_helper.h" #include "ans_log_wrapper.h" -#include "ans_notification.h" -#include "notification_helper.h" +#include "reminder_request_client.h" #include "singleton.h" namespace OHOS { namespace Notification { -ErrCode ReminderHelper::PublishReminder(ReminderRequest &reminder) +ErrCode ReminderHelper::PublishReminder(const ReminderRequest& reminder, int32_t& reminderId) { ANSR_LOGI("PublishReminder start"); - NotificationHelper::AddSlotByType(reminder.GetSlotType()); - return DelayedSingleton::GetInstance()->PublishReminder(reminder); + return DelayedSingleton::GetInstance()->PublishReminder(reminder, reminderId); } ErrCode ReminderHelper::CancelReminder(const int32_t reminderId) { ANSR_LOGI("CancelReminder start"); - return DelayedSingleton::GetInstance()->CancelReminder(reminderId); + return DelayedSingleton::GetInstance()->CancelReminder(reminderId); } ErrCode ReminderHelper::CancelAllReminders() { ANSR_LOGI("CancelAllReminders start"); - return DelayedSingleton::GetInstance()->CancelAllReminders(); + return DelayedSingleton::GetInstance()->CancelAllReminders(); } -ErrCode ReminderHelper::GetValidReminders(std::vector> &validReminders) +ErrCode ReminderHelper::GetValidReminders(std::vector &validReminders) { ANSR_LOGI("GetValidReminders start"); - return DelayedSingleton::GetInstance()->GetValidReminders(validReminders); + return DelayedSingleton::GetInstance()->GetValidReminders(validReminders); } ErrCode ReminderHelper::AddNotificationSlot(const NotificationSlot &slot) { ANSR_LOGI("AddNotificationSlot start"); - return DelayedSingleton::GetInstance()->AddNotificationSlot(slot); + return DelayedSingleton::GetInstance()->AddNotificationSlot(slot); } ErrCode ReminderHelper::RemoveNotificationSlot(const NotificationConstant::SlotType &slotType) { ANSR_LOGI("RemoveNotificationSlot start"); - return DelayedSingleton::GetInstance()->RemoveNotificationSlot(slotType); + return DelayedSingleton::GetInstance()->RemoveNotificationSlot(slotType); } -ErrCode ReminderHelper::AddExcludeDate(const int32_t reminderId, const uint64_t date) +ErrCode ReminderHelper::AddExcludeDate(const int32_t reminderId, const int64_t date) { ANSR_LOGI("AddExcludeDate start"); - return DelayedSingleton::GetInstance()->AddExcludeDate(reminderId, date); + return DelayedSingleton::GetInstance()->AddExcludeDate(reminderId, date); } ErrCode ReminderHelper::DelExcludeDates(const int32_t reminderId) { ANSR_LOGI("DelExcludeDates start"); - return DelayedSingleton::GetInstance()->DelExcludeDates(reminderId); + return DelayedSingleton::GetInstance()->DelExcludeDates(reminderId); } -ErrCode ReminderHelper::GetExcludeDates(const int32_t reminderId, std::vector& dates) +ErrCode ReminderHelper::GetExcludeDates(const int32_t reminderId, std::vector& dates) { ANSR_LOGI("GetExcludeDates start"); - return DelayedSingleton::GetInstance()->GetExcludeDates(reminderId, dates); + return DelayedSingleton::GetInstance()->GetExcludeDates(reminderId, dates); } } } \ No newline at end of file diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/reminder/src/reminder_request.cpp similarity index 91% rename from frameworks/ans/src/reminder_request.cpp rename to frameworks/reminder/src/reminder_request.cpp index 2420f77b29b9a345832bca082b6648818b4448e0..42c9453e19be8aab99935d1883dec45c40f4277a 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/reminder/src/reminder_request.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -14,6 +14,7 @@ */ #include "reminder_request.h" +#include "reminder_request_factory.h" #include "ans_const_define.h" #include "ans_log_wrapper.h" @@ -43,6 +44,7 @@ const int32_t BUTTON_PKG_INDEX = 2; const int32_t BUTTON_ABILITY_INDEX = 3; const int32_t WANT_AGENT_URI_INDEX = 2; const int32_t INDENT = -1; +const int32_t FOUDATION_UID = 5523; const char* const PARAM_EXTRA_KEY = "NotificationRequest_extraInfo"; } @@ -69,6 +71,7 @@ const std::string ReminderRequest::REMINDER_EVENT_CLICK_ALERT = "ohos.event.noti const std::string ReminderRequest::REMINDER_EVENT_ALERT_TIMEOUT = "ohos.event.notification.reminder.ALERT_TIMEOUT"; const std::string ReminderRequest::REMINDER_EVENT_REMOVE_NOTIFICATION = "ohos.event.notification.reminder.REMOVE_NOTIFICATION"; +const std::string ReminderRequest::REMINDER_EVENT_LOAD_REMINDER = "ohos.event.notification.reminder.LOAD_REMINDER"; const std::string ReminderRequest::PARAM_REMINDER_ID = "REMINDER_ID"; const std::string ReminderRequest::SEP_BUTTON_SINGLE = ""; const std::string ReminderRequest::SEP_BUTTON_MULTI = ""; @@ -135,7 +138,6 @@ ReminderRequest::ReminderRequest(const ReminderRequest &other) this->reminderType_ = other.reminderType_; this->slotType_ = other.slotType_; this->snoozeSlotType_ = other.snoozeSlotType_; - this->notificationRequest_ = other.notificationRequest_; this->wantAgentInfo_ = other.wantAgentInfo_; this->maxScreenWantAgentInfo_ = other.maxScreenWantAgentInfo_; this->actionButtonMap_ = other.actionButtonMap_; @@ -400,7 +402,6 @@ void ReminderRequest::OnShow(bool isPlaySoundOrVibration, bool isSysTimeChanged, if (isPlaySoundOrVibration) { SetState(true, REMINDER_STATUS_ALERTING, "OnShow"); } - UpdateNotificationStateForAlert(); } } @@ -422,7 +423,6 @@ bool ReminderRequest::OnSnooze() if (!UpdateNextReminder(true)) { return false; } - UpdateNotificationStateForSnooze(); if (timeIntervalInMilli_ > 0) { SetState(true, REMINDER_STATUS_SNOOZE, "onSnooze()"); } @@ -460,7 +460,6 @@ bool ReminderRequest::OnTerminate() return false; } SetState(false, REMINDER_STATUS_ALERTING, "onTerminate"); - UpdateNotificationStateForAlert(); return true; } @@ -792,11 +791,6 @@ std::string ReminderRequest::GetGroupId() const return groupId_; } -sptr ReminderRequest::GetNotificationRequest() const -{ - return notificationRequest_; -} - int32_t ReminderRequest::GetReminderId() const { return reminderId_; @@ -949,16 +943,6 @@ std::string ReminderRequest::GetCustomRingUri() const return customRingUri_; } -sptr ReminderRequest::GetNotificationBundleOption() const -{ - return notificationOption_; -} - -void ReminderRequest::SetNotificationBundleOption(const sptr& option) -{ - notificationOption_ = option; -} - std::shared_ptr ReminderRequest::GetWantAgentInfo() const { return wantAgentInfo_; @@ -1004,50 +988,48 @@ std::string ReminderRequest::GetMaxWantAgentStr() return maxWantAgentStr_; } -void ReminderRequest::UpdateNotificationRequest(UpdateNotificationType type, std::string extra) +NotificationRequest ReminderRequest::CreateNotificationRequest() { - switch (type) { - case UpdateNotificationType::COMMON: { - ANSR_LOGI("UpdateNotification common information"); - if (extra == "snooze") { - UpdateNotificationCommon(true); - } else { - UpdateNotificationCommon(false); - } - break; - } - case UpdateNotificationType::REMOVAL_WANT_AGENT: { - ANSR_LOGI("UpdateNotification removal_want_agent"); - AddRemovalWantAgent(); - break; - } - case UpdateNotificationType::WANT_AGENT: { - ANSR_LOGI("UpdateNotification want_agent"); - AppExecFwk::ElementName wantAgent("", wantAgentInfo_->pkgName, wantAgentInfo_->abilityName); - SetWantAgent(wantAgent); - SetExtraInfo(wantAgentInfo_->parameters); - break; - } - case UpdateNotificationType::MAX_SCREEN_WANT_AGENT: { - ANSR_LOGI("UpdateNotification max_screen_want_agent"); - AppExecFwk::ElementName maxScreenWantAgent( - "", maxScreenWantAgentInfo_->pkgName, maxScreenWantAgentInfo_->abilityName); - SetMaxScreenWantAgent(maxScreenWantAgent); - break; - } - case UpdateNotificationType::BUNDLE_INFO: { - ANSR_LOGI("UpdateNotification hap information"); - UpdateNotificationBundleInfo(); - break; - } - case UpdateNotificationType::CONTENT: { - break; - } - default: - break; + NotificationRequest notificationRequest(notificationId_); + return notificationRequest; +} + +void ReminderRequest::UpdateNotificationRequest(NotificationRequest& notificationRequest, const bool isSnooze) +{ + if (isSnooze) { + UpdateNotificationStateForSnooze(notificationRequest); + UpdateNotificationCommon(notificationRequest, true); + } else { + UpdateNotificationStateForAlert(notificationRequest); + UpdateNotificationCommon(notificationRequest, false); + } + UpdateNotificationAddRemovalWantAgent(notificationRequest); + UpdateNotificationWantAgent(notificationRequest); + UpdateNotificationMaxScreenWantAgent(notificationRequest); + UpdateNotificationBundleInfo(notificationRequest); +} + +void ReminderRequest::UpdateNotificationWantAgent(NotificationRequest& notificationRequest) +{ + ANSR_LOGI("UpdateNotification want_agent"); + AppExecFwk::ElementName element("", wantAgentInfo_->pkgName, wantAgentInfo_->abilityName); + std::shared_ptr wantAgent = CreateWantAgent(element); + notificationRequest.SetWantAgent(wantAgent); + if (wantAgentInfo_->parameters.HasParam(PARAM_EXTRA_KEY)) { + std::shared_ptr extras = std::make_shared( + wantAgentInfo_->parameters.GetWantParams(PARAM_EXTRA_KEY)); + notificationRequest.SetAdditionalData(extras); } } +void ReminderRequest::UpdateNotificationMaxScreenWantAgent(NotificationRequest& notificationRequest) +{ + AppExecFwk::ElementName element( + "", maxScreenWantAgentInfo_->pkgName, maxScreenWantAgentInfo_->abilityName); + std::shared_ptr wantAgent = CreateMaxWantAgent(element); + notificationRequest.SetMaxScreenWantAgent(wantAgent); +} + bool ReminderRequest::MarshallingActionButton(Parcel& parcel) const { // write map @@ -1100,6 +1082,9 @@ bool ReminderRequest::MarshallingWantParameters(Parcel& parcel, const AAFwk::Wan bool ReminderRequest::Marshalling(Parcel &parcel) const { + // write enum + uint8_t reminderType = static_cast(reminderType_); + WRITE_UINT8_RETURN_FALSE_LOG(parcel, reminderType, "reminderType"); // write string WRITE_STRING_RETURN_FALSE_LOG(parcel, content_, "content"); WRITE_STRING_RETURN_FALSE_LOG(parcel, expiredContent_, "expiredContent"); @@ -1136,10 +1121,6 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const WRITE_UINT8_RETURN_FALSE_LOG(parcel, snoozeTimesDynamic_, "snoozeTimesDynamic"); WRITE_UINT8_RETURN_FALSE_LOG(parcel, state_, "state"); - // write enum - uint8_t reminderType = static_cast(reminderType_); - WRITE_UINT8_RETURN_FALSE_LOG(parcel, reminderType, "reminderType"); - int32_t slotType = static_cast(slotType_); WRITE_INT32_RETURN_FALSE_LOG(parcel, slotType, "slotType"); @@ -1152,18 +1133,28 @@ bool ReminderRequest::Marshalling(Parcel &parcel) const return true; } +bool ReminderRequest::ReadReminderTypeFormParcel(Parcel &parcel, ReminderType& tarReminderType) +{ + uint8_t reminderType = static_cast(ReminderType::INVALID); + READ_UINT8_RETURN_FALSE_LOG(parcel, reminderType, "reminderType"); + tarReminderType = static_cast(reminderType); + return true; +} + ReminderRequest *ReminderRequest::Unmarshalling(Parcel &parcel) { - auto objptr = new (std::nothrow) ReminderRequest(); - if (objptr == nullptr) { + ReminderType tarReminderType = ReminderType::INVALID; + ReadReminderTypeFormParcel(parcel, tarReminderType); + auto reminderRequest = ReminderRequestFactory::CreateReminderRequest(tarReminderType); + if (reminderRequest == nullptr) { ANSR_LOGE("Failed to create reminder due to no memory."); - return objptr; + return reminderRequest; } - if (!objptr->ReadFromParcel(parcel)) { - delete objptr; - objptr = nullptr; + if (!reminderRequest->ReadFromParcel(parcel)) { + delete reminderRequest; + reminderRequest = nullptr; } - return objptr; + return reminderRequest; } bool ReminderRequest::ReadActionButtonFromParcel(Parcel& parcel) @@ -1262,11 +1253,6 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) READ_UINT8_RETURN_FALSE_LOG(parcel, snoozeTimes_, "snoozeTimes"); READ_UINT8_RETURN_FALSE_LOG(parcel, snoozeTimesDynamic_, "snoozeTimesDynamic"); READ_UINT8_RETURN_FALSE_LOG(parcel, state_, "state"); - - uint8_t reminderType = static_cast(ReminderType::INVALID); - READ_UINT8_RETURN_FALSE_LOG(parcel, reminderType, "reminderType"); - reminderType_ = static_cast(reminderType); - int32_t slotType = static_cast(NotificationConstant::SlotType::OTHER); READ_INT32_RETURN_FALSE_LOG(parcel, slotType, "slotType"); slotType_ = static_cast(slotType); @@ -1279,20 +1265,6 @@ bool ReminderRequest::ReadFromParcel(Parcel &parcel) return false; } - if (!InitNotificationRequest()) { - return false; - } - return true; -} - -bool ReminderRequest::InitNotificationRequest() -{ - notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); - if (notificationRequest_ == nullptr) { - ANSR_LOGE("Failed to create notification."); - return false; - } - displayContent_ = content_; return true; } @@ -1317,7 +1289,7 @@ uint64_t ReminderRequest::GetDurationSinceEpochInMilli(const time_t target) ANSR_LOGW("tarDuration is less than 0."); return INVALID_LONG_LONG_VALUE; } - return static_cast(tarDate); + return tarDate; } std::string ReminderRequest::GetDateTimeInfo(const time_t &timeInSecond) const @@ -1443,7 +1415,7 @@ std::string ReminderRequest::GetState(const uint8_t state) const return stateInfo; } -void ReminderRequest::AddActionButtons(const bool includeSnooze) +void ReminderRequest::AddActionButtons(NotificationRequest& notificationRequest, const bool includeSnooze) { int32_t requestCode = 10; std::vector flags; @@ -1493,12 +1465,13 @@ void ReminderRequest::AddActionButtons(const bool includeSnooze) std::shared_ptr actionButton = NotificationActionButton::Create(nullptr, title, buttonWantAgent); - notificationRequest_->AddActionButton(actionButton); + notificationRequest.AddActionButton(actionButton); } } -void ReminderRequest::AddRemovalWantAgent() +void ReminderRequest::UpdateNotificationAddRemovalWantAgent(NotificationRequest& notificationRequest) { + ANSR_LOGI("UpdateNotification removal_want_agent"); int32_t requestCode = 10; std::vector flags; flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); @@ -1520,7 +1493,7 @@ void ReminderRequest::AddRemovalWantAgent() AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, userId_); IPCSkeleton::SetCallingIdentity(identity); - notificationRequest_->SetRemovalWantAgent(wantAgent); + notificationRequest.SetRemovalWantAgent(wantAgent); } std::shared_ptr ReminderRequest::CreateWantAgent( @@ -1570,27 +1543,6 @@ std::shared_ptr ReminderRequest::CreateMax return wantAgent; } -void ReminderRequest::SetMaxScreenWantAgent(AppExecFwk::ElementName &element) -{ - std::shared_ptr wantAgent = CreateMaxWantAgent(element); - notificationRequest_->SetMaxScreenWantAgent(wantAgent); -} - -void ReminderRequest::SetWantAgent(AppExecFwk::ElementName &element) -{ - std::shared_ptr wantAgent = CreateWantAgent(element); - notificationRequest_->SetWantAgent(wantAgent); -} - -void ReminderRequest::SetExtraInfo(const AAFwk::WantParams& params) -{ - if (params.HasParam(PARAM_EXTRA_KEY)) { - std::shared_ptr extras = std::make_shared( - params.GetWantParams(PARAM_EXTRA_KEY)); - notificationRequest_->SetAdditionalData(extras); - } -} - void ReminderRequest::SetState(bool deSet, const uint8_t newState, std::string function) { uint8_t oldState = state_; @@ -1609,17 +1561,13 @@ void ReminderRequest::SetStateToInActive() "SetStateToInActive"); } -void ReminderRequest::UpdateActionButtons(const bool &setSnooze) +void ReminderRequest::UpdateActionButtons(NotificationRequest& notificationRequest, const bool &setSnooze) { - if (notificationRequest_ == nullptr) { - ANSR_LOGE("updateActionButtons failed, the notificationRequest is null"); - return; - } - notificationRequest_->ClearActionButtons(); + notificationRequest.ClearActionButtons(); if (setSnooze) { - AddActionButtons(false); + AddActionButtons(notificationRequest, false); } else { - AddActionButtons(true); + AddActionButtons(notificationRequest, true); } } @@ -1647,61 +1595,50 @@ bool ReminderRequest::UpdateNextReminder(const bool &force) return result; } -void ReminderRequest::UpdateNotificationCommon(bool isSnooze) +void ReminderRequest::UpdateNotificationCommon(NotificationRequest& notificationRequest, bool isSnooze) { + ANSR_LOGI("UpdateNotification common information"); time_t now; (void)time(&now); // unit is seconds. - notificationRequest_->SetDeliveryTime(GetDurationSinceEpochInMilli(now)); - notificationRequest_->SetLabel(NOTIFICATION_LABEL); - notificationRequest_->SetShowDeliveryTime(true); + notificationRequest.SetDeliveryTime(GetDurationSinceEpochInMilli(now)); + notificationRequest.SetLabel(NOTIFICATION_LABEL); + notificationRequest.SetShowDeliveryTime(true); if (isSnooze) { if (snoozeSlotType_ == NotificationConstant::SlotType::OTHER) { - notificationRequest_->SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION); + notificationRequest.SetSlotType(NotificationConstant::SlotType::CONTENT_INFORMATION); } else { - notificationRequest_->SetSlotType(snoozeSlotType_); + notificationRequest.SetSlotType(snoozeSlotType_); } } else { - notificationRequest_->SetSlotType(slotType_); + notificationRequest.SetSlotType(slotType_); } - notificationRequest_->SetTapDismissed(tapDismissed_); - notificationRequest_->SetAutoDeletedTime(autoDeletedTime_); + notificationRequest.SetTapDismissed(tapDismissed_); + notificationRequest.SetAutoDeletedTime(autoDeletedTime_); auto notificationNormalContent = std::make_shared(); notificationNormalContent->SetText(displayContent_); notificationNormalContent->SetTitle(title_); auto notificationContent = std::make_shared(notificationNormalContent); - notificationRequest_->SetContent(notificationContent); + notificationRequest.SetContent(notificationContent); if ((reminderType_ == ReminderRequest::ReminderType::TIMER) || (reminderType_ == ReminderRequest::ReminderType::ALARM)) { - notificationRequest_->SetUnremovable(true); + notificationRequest.SetUnremovable(true); } } -void ReminderRequest::UpdateNotificationBundleInfo() +void ReminderRequest::UpdateNotificationBundleInfo(NotificationRequest& notificationRequest) { - std::string ownerBundleName = notificationRequest_->GetOwnerBundleName(); - if (!(ownerBundleName.empty())) { - return; - } - ANSR_LOGD("ownerBundleName=%{public}s, bundleName_=%{public}s", - ownerBundleName.c_str(), bundleName_.c_str()); - notificationRequest_->SetOwnerBundleName(bundleName_); - notificationRequest_->SetCreatorBundleName(bundleName_); - notificationRequest_->SetCreatorUid(uid_); - notificationRequest_->SetCreatorUserId(userId_); + notificationRequest.SetOwnerUid(uid_); + notificationRequest.SetCreatorUid(FOUDATION_UID); } -void ReminderRequest::UpdateNotificationContent(const bool &setSnooze) +void ReminderRequest::UpdateNotificationContent(NotificationRequest& notificationRequest, const bool &setSnooze) { - if (notificationRequest_ == nullptr) { - ANSR_LOGE("updateNotificationContent failed, the notificationRequest is null"); - return; - } std::string extendContent = ""; if (setSnooze) { if (timeIntervalInMilli_ != 0) { // snooze the reminder by manual extendContent = snoozeContent_; - notificationRequest_->SetTapDismissed(false); + notificationRequest.SetTapDismissed(false); } else { // the reminder is expired now, when timeInterval is 0 extendContent = expiredContent_; @@ -1712,7 +1649,7 @@ void ReminderRequest::UpdateNotificationContent(const bool &setSnooze) } else if (snoozeTimesDynamic_ != snoozeTimes_) { // the reminder is snoozing by period artithmetic, when the ring duration is over. extendContent = snoozeContent_; - notificationRequest_->SetTapDismissed(false); + notificationRequest.SetTapDismissed(false); } else { // the reminder has already snoozed by period arithmetic, when the ring duration is over. extendContent = expiredContent_; @@ -1725,18 +1662,18 @@ void ReminderRequest::UpdateNotificationContent(const bool &setSnooze) ANSR_LOGD("Display content=%{public}s", displayContent_.c_str()); } -void ReminderRequest::UpdateNotificationStateForAlert() +void ReminderRequest::UpdateNotificationStateForAlert(NotificationRequest& notificationRequest) { ANSR_LOGD("UpdateNotification content and buttons"); - UpdateNotificationContent(false); - UpdateActionButtons(false); + UpdateNotificationContent(notificationRequest, false); + UpdateActionButtons(notificationRequest, false); } -void ReminderRequest::UpdateNotificationStateForSnooze() +void ReminderRequest::UpdateNotificationStateForSnooze(NotificationRequest& notificationRequest) { ANSR_LOGD("UpdateNotification content and buttons"); - UpdateNotificationContent(true); - UpdateActionButtons(true); + UpdateNotificationContent(notificationRequest, true); + UpdateActionButtons(notificationRequest, true); } int32_t ReminderRequest::GetActualTime(const TimeTransferType &type, int32_t cTime) diff --git a/frameworks/ans/src/reminder_request_alarm.cpp b/frameworks/reminder/src/reminder_request_alarm.cpp similarity index 99% rename from frameworks/ans/src/reminder_request_alarm.cpp rename to frameworks/reminder/src/reminder_request_alarm.cpp index 8fd928b2b89b5221952eb2cf9e365915d289218b..3a384fc22d521520f955f0d7ec4d010da1e630ba 100644 --- a/frameworks/ans/src/reminder_request_alarm.cpp +++ b/frameworks/reminder/src/reminder_request_alarm.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 diff --git a/frameworks/ans/src/reminder_request_calendar.cpp b/frameworks/reminder/src/reminder_request_calendar.cpp similarity index 98% rename from frameworks/ans/src/reminder_request_calendar.cpp rename to frameworks/reminder/src/reminder_request_calendar.cpp index df26f548ccc0977ec839176fbbb85216b8152b4b..f6aff4d9229987a0bfc75ce89b9b4ff6d6c4008d 100644 --- a/frameworks/ans/src/reminder_request_calendar.cpp +++ b/frameworks/reminder/src/reminder_request_calendar.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 @@ -69,7 +69,7 @@ void ReminderRequestCalendar::SetRRuleWantAgentInfo(const std::shared_ptr(date / MILLI_SECONDS); struct tm dateTime; @@ -90,9 +90,9 @@ void ReminderRequestCalendar::DelExcludeDates() excludeDates_.clear(); } -std::vector ReminderRequestCalendar::GetExcludeDates() const +std::vector ReminderRequestCalendar::GetExcludeDates() const { - std::vector excludeDates; + std::vector excludeDates; for (auto date : excludeDates_) { excludeDates.push_back(date); } @@ -112,7 +112,7 @@ bool ReminderRequestCalendar::IsInExcludeDate() const ANSR_LOGW("error start date time"); return false; } - uint64_t notificationTime = ReminderRequest::GetDurationSinceEpochInMilli(target); + int64_t notificationTime = ReminderRequest::GetDurationSinceEpochInMilli(target); if (excludeDates_.find(notificationTime) != excludeDates_.end()) { ANSR_LOGI("Reminder[%{public}d] trigger time is in exclude date", GetReminderId()); return true; @@ -862,7 +862,7 @@ void ReminderRequestCalendar::DeserializationExcludeDates(const std::string& str excludeDates_.clear(); for (auto date : root["excludeDates"]) { if (date.is_number()) { - excludeDates_.insert(date.get()); + excludeDates_.insert(date.get()); } } } diff --git a/frameworks/reminder/src/reminder_request_client.cpp b/frameworks/reminder/src/reminder_request_client.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d1594fee824c2a642b1d13ff8d1ab5108a459d50 --- /dev/null +++ b/frameworks/reminder/src/reminder_request_client.cpp @@ -0,0 +1,268 @@ +/* + * Copyright (c) 2024 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 "reminder_request_client.h" +#include "reminder_service_load_callback.h" +#include "ans_manager_proxy.h" +#include "reminder_service_proxy.h" +#include "ans_const_define.h" +#include "ans_inner_errors.h" +#include "ans_log_wrapper.h" + +#include "ipc_skeleton.h" +#include "iservice_registry.h" +#include "reminder_request_alarm.h" +#include "reminder_request_calendar.h" +#include "reminder_request_timer.h" +#include "system_ability_definition.h" +#include "unique_fd.h" + +#include +#include + +namespace OHOS { +namespace Notification { +constexpr int32_t REMINDER_SERVICE_LOADSA_TIMEOUT_MS = 10000; +ErrCode ReminderRequestClient::AddSlotByType(const NotificationConstant::SlotType &slotType) +{ + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->AddSlotByType(slotType); +} + +ErrCode ReminderRequestClient::AddNotificationSlot(const NotificationSlot &slot) +{ + std::vector slots; + slots.push_back(slot); + return AddNotificationSlots(slots); +} + +ErrCode ReminderRequestClient::AddNotificationSlots(const std::vector &slots) +{ + if (slots.size() == 0) { + ANS_LOGE("Failed to add notification slots because input slots size is 0."); + return ERR_ANS_INVALID_PARAM; + } + + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + + std::vector> slotsSptr; + for (auto it = slots.begin(); it != slots.end(); ++it) { + sptr slot = new (std::nothrow) NotificationSlot(*it); + if (slot == nullptr) { + ANS_LOGE("Failed to create NotificationSlot ptr."); + return ERR_ANS_NO_MEMORY; + } + slotsSptr.emplace_back(slot); + } + + return proxy->AddSlots(slotsSptr); +} + +ErrCode ReminderRequestClient::RemoveNotificationSlot(const NotificationConstant::SlotType &slotType) +{ + ANS_LOGI("enter RemoveNotificationSlot,slotType:%{public}d", slotType); + sptr proxy = GetAnsManagerProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->RemoveSlotByType(slotType); +} + +ErrCode ReminderRequestClient::PublishReminder(const ReminderRequest& reminder, int32_t& reminderId) +{ + AddSlotByType(reminder.GetSlotType()); + sptr proxy = GetReminderServiceProxy(); + if (!proxy) { + ANS_LOGE("GetReminderServiceProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->PublishReminder(reminder, reminderId); +} + +ErrCode ReminderRequestClient::CancelReminder(const int32_t reminderId) +{ + sptr proxy = GetReminderServiceProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->CancelReminder(reminderId); +} + +ErrCode ReminderRequestClient::CancelAllReminders() +{ + sptr proxy = GetReminderServiceProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->CancelAllReminders(); +} + +ErrCode ReminderRequestClient::GetValidReminders(std::vector &validReminders) +{ + sptr proxy = GetReminderServiceProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->GetValidReminders(validReminders); +} + +ErrCode ReminderRequestClient::AddExcludeDate(const int32_t reminderId, const uint64_t date) +{ + sptr proxy = GetReminderServiceProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->AddExcludeDate(reminderId, date); +} + +ErrCode ReminderRequestClient::DelExcludeDates(const int32_t reminderId) +{ + sptr proxy = GetReminderServiceProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->DelExcludeDates(reminderId); +} + +ErrCode ReminderRequestClient::GetExcludeDates(const int32_t reminderId, std::vector& dates) +{ + sptr proxy = GetReminderServiceProxy(); + if (!proxy) { + ANS_LOGE("GetAnsManagerProxy fail."); + return ERR_ANS_SERVICE_NOT_CONNECTED; + } + return proxy->GetExcludeDates(reminderId, dates); +} + +sptr ReminderRequestClient::GetAnsManagerProxy() +{ + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + ANS_LOGE("Failed to get system ability mgr."); + return nullptr; + } + + sptr remoteObject = + systemAbilityManager->GetSystemAbility(ADVANCED_NOTIFICATION_SERVICE_ABILITY_ID); + if (!remoteObject) { + ANS_LOGE("Failed to get notification Manager."); + return nullptr; + } + + sptr proxy = iface_cast(remoteObject); + if ((!proxy) || (!proxy->AsObject())) { + ANS_LOGE("Failed to get notification Manager's proxy"); + return nullptr; + } + return proxy; +} + +sptr ReminderRequestClient::GetReminderServiceProxy() +{ + { + std::lock_guard lock(serviceLock_); + if (proxy_ != nullptr) { + return proxy_; + } + auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgrProxy == nullptr) { + ANS_LOGE("get samgr failed"); + return nullptr; + } + auto object = samgrProxy->CheckSystemAbility(1930); + if (object != nullptr) { + ANS_LOGE("get service succeeded"); + proxy_ = iface_cast(object); + return proxy_; + } + } + + ANS_LOGE("object is null"); + if (LoadReminderService()) { + std::lock_guard lock(serviceLock_); + if (proxy_ != nullptr) { + return proxy_; + } else { + ANS_LOGE("load reminder service failed"); + return nullptr; + } + } + ANS_LOGE("load reminder service failed"); + return nullptr; +} + +bool ReminderRequestClient::LoadReminderService() +{ + std::unique_lock lock(serviceLock_); + sptr loadCallback = sptr(new ReminderServiceCallback()); + if (loadCallback == nullptr) { + ANS_LOGE("loadCallback is nullptr."); + return false; + } + + auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgrProxy == nullptr) { + ANS_LOGE("get samgr failed"); + return false; + } + + int32_t ret = samgrProxy->LoadSystemAbility(1930, loadCallback); + if (ret != ERR_OK) { + ANS_LOGE("Failed to Load systemAbility"); + return false; + } + + auto waitStatus = proxyConVar_.wait_for(lock, std::chrono::milliseconds(REMINDER_SERVICE_LOADSA_TIMEOUT_MS), + [this]() { return proxy_ != nullptr; }); + if (!waitStatus) { + ANS_LOGE("reminder service load sa timeout"); + return false; + } + return true; +} + +void ReminderRequestClient::LoadSystemAbilitySuccess(const sptr &remoteObject) +{ + ANS_LOGE("ReminderRequestClient FinishStartSA"); + std::lock_guard lock(serviceLock_); + if (remoteObject != nullptr) { + proxy_ = iface_cast(remoteObject); + proxyConVar_.notify_one(); + } +} + +void ReminderRequestClient::LoadSystemAbilityFail() +{ + std::lock_guard lock(serviceLock_); + proxy_ = nullptr; +} + +} // namespace Notification +} // namespace OHOS diff --git a/frameworks/reminder/src/reminder_request_factory.cpp b/frameworks/reminder/src/reminder_request_factory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5e580f44dd3b6cd8d7784d4017e735a7cf51d59d --- /dev/null +++ b/frameworks/reminder/src/reminder_request_factory.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024 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 "reminder_request_factory.h" + +#include "ans_inner_errors.h" +#include "ans_log_wrapper.h" +#include "reminder_request_alarm.h" +#include "reminder_request_calendar.h" +#include "reminder_request_timer.h" + + +#include +#include + +namespace OHOS { +namespace Notification { +ReminderRequest* ReminderRequestFactory::CreateReminderRequest(ReminderRequest::ReminderType reminderType) +{ + ReminderRequest* reminderRequest = nullptr; + switch (reminderType) { + case (ReminderRequest::ReminderType::TIMER): { + ANSR_LOGI("Create timer"); + reminderRequest = new (std::nothrow) ReminderRequestTimer(); + break; + } + case (ReminderRequest::ReminderType::ALARM): { + ANSR_LOGI("Create alarm"); + reminderRequest = new (std::nothrow) ReminderRequestAlarm(); + break; + } + case (ReminderRequest::ReminderType::CALENDAR): { + ANSR_LOGI("Create calendar"); + reminderRequest = new (std::nothrow) ReminderRequestCalendar(); + break; + } + default: { + ANSR_LOGW("PublishReminder fail."); + return nullptr; + } + } + reminderRequest->SetReminderType(reminderType); + return reminderRequest; +} + +} // namespace Notification +} // namespace OHOS diff --git a/frameworks/ans/src/reminder_request_timer.cpp b/frameworks/reminder/src/reminder_request_timer.cpp similarity index 99% rename from frameworks/ans/src/reminder_request_timer.cpp rename to frameworks/reminder/src/reminder_request_timer.cpp index 867f26ae9266e07d45dfbef647b9779336bb7d17..621c6681a02b1abd56f0a52531d94804000eb6d6 100644 --- a/frameworks/ans/src/reminder_request_timer.cpp +++ b/frameworks/reminder/src/reminder_request_timer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2024 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 diff --git a/frameworks/reminder/src/reminder_service_load_callback.cpp b/frameworks/reminder/src/reminder_service_load_callback.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dae18f59df43ee6e568605c9559767cb633e882d --- /dev/null +++ b/frameworks/reminder/src/reminder_service_load_callback.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 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 "reminder_service_load_callback.h" + +#include "ans_log_wrapper.h" +#include "reminder_request_client.h" +#include "singleton.h" + +namespace OHOS { class IRemoteObject; } +namespace OHOS { +namespace Notification { + +const std::string TAG = "ReminderServiceLoadCallback"; + +void ReminderServiceCallback::OnLoadSystemAbilitySuccess( + int32_t systemAbilityId, const sptr &remoteObject) +{ + DelayedSingleton::GetInstance()->LoadSystemAbilitySuccess(remoteObject); + ANS_LOGI("on load system ability success!"); +} + +void ReminderServiceCallback::OnLoadSystemAbilityFail(int32_t systemAbilityId) +{ + DelayedSingleton::GetInstance()->LoadSystemAbilityFail(); + ANS_LOGI("on load system ability failed!"); +} +} +} \ No newline at end of file diff --git a/frameworks/reminder/test/unittest/BUILD.gn b/frameworks/reminder/test/unittest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e669f2a86c9b16ed19ca69d0aa6cc8b51c640af2 --- /dev/null +++ b/frameworks/reminder/test/unittest/BUILD.gn @@ -0,0 +1,155 @@ +# Copyright (c) 2021-2024 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. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "${component_name}/unittest" + +ohos_unittest("reminder_test") { + module_out_path = module_output_path + + include_dirs = [ + ".", + "include", + "/${services_path}/ans/include", + "/${services_path}/reminder/include", + "${services_path}/ans/test/unittest/mock/include", + ] + + sources = [ + "${frameworks_module_reminder_path}/test/unittest/reminder_helper_test.cpp", + "${frameworks_module_reminder_path}/test/unittest/reminder_request_alarm_test.cpp", + "${frameworks_module_reminder_path}/test/unittest/reminder_request_calendar_test.cpp", + "${frameworks_module_reminder_path}/test/unittest/reminder_request_timer_test.cpp", + ] + + deps = [ + "${frameworks_module_ans_path}:ans_innerkits", + "${frameworks_module_reminder_path}:reminder_innerkits", + "${services_path}/reminder:libreminder", + ] + + defines = [] + if (distributed_notification_supported) { + defines += [ "DISTRIBUTED_NOTIFICATION_SUPPORTED" ] + deps += [ "${services_path}/distributed:libans_distributed" ] + } + + external_deps = [ + "ability_base:base", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:wantagent_innerkits", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "hilog:libhilog", + "hitrace:hitrace_meter", + "image_framework:image_native", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" + + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" +} + +ohos_unittest("reminder_request_test") { + module_out_path = module_output_path + + include_dirs = [ + ".", + "include", + "/${services_path}/ans/include", + "/${services_path}/reminder/include", + "${services_path}/reminder/test/unittest/mock/include", + ] + + sources = [ + "${frameworks_module_reminder_path}/test/unittest/reminder_request_branch_test/mock_reminder_request.cpp", + "${frameworks_module_reminder_path}/test/unittest/reminder_request_test.cpp", + ] + + deps = [ + "${frameworks_module_ans_path}:ans_innerkits", + "${frameworks_module_reminder_path}:reminder_innerkits", + ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "relational_store:native_rdb", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +ohos_unittest("reminder_request_branch_test") { + module_out_path = module_output_path + + include_dirs = [ + ".", + "include", + "/${services_path}/reminder/include", + "${services_path}/reminder/test/unittest/mock/include", + ] + + sources = [ + "${frameworks_module_reminder_path}/test/unittest/reminder_request_branch_test/mock_reminder_request.cpp", + "${frameworks_module_reminder_path}/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp", + ] + + deps = [ + "${frameworks_module_ans_path}:ans_innerkits", + "${frameworks_module_reminder_path}:reminder_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "relational_store:native_rdb", + ] + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [ + ":reminder_test", + ":reminder_request_branch_test", + ":reminder_request_test", + ] +} diff --git a/frameworks/ans/test/unittest/reminder_helper_test.cpp b/frameworks/reminder/test/unittest/reminder_helper_test.cpp similarity index 93% rename from frameworks/ans/test/unittest/reminder_helper_test.cpp rename to frameworks/reminder/test/unittest/reminder_helper_test.cpp index a97c0ed63e6e0f2673d3ea4477599aff791631a7..799caa049fcaeb12006ecc21ca2e0564664e8daa 100644 --- a/frameworks/ans/test/unittest/reminder_helper_test.cpp +++ b/frameworks/reminder/test/unittest/reminder_helper_test.cpp @@ -45,7 +45,8 @@ HWTEST_F(ReminderHelperTest, PublishReminder_00001, Function | SmallTest | Level { ReminderRequest reminder; ReminderHelper reminderHelper; - ErrCode ret = reminderHelper.PublishReminder(reminder); + int32_t reminderId = -1; + ErrCode ret = reminderHelper.PublishReminder(reminder, reminderId); EXPECT_EQ(ret, (int)ERR_ANS_INVALID_PARAM); } @@ -84,7 +85,7 @@ HWTEST_F(ReminderHelperTest, CancelAllReminders_00001, Function | SmallTest | Le */ HWTEST_F(ReminderHelperTest, GetValidReminders_00001, Function | SmallTest | Level1) { - std::vector> validReminders; + std::vector validReminders; ReminderHelper reminderHelper; ErrCode ret = reminderHelper.GetValidReminders(validReminders); EXPECT_NE(ret, (int)ERR_OK); @@ -156,7 +157,7 @@ HWTEST_F(ReminderHelperTest, DelExcludeDates_00001, Function | SmallTest | Level HWTEST_F(ReminderHelperTest, GetExcludeDates_00001, Function | SmallTest | Level1) { int32_t reminderId = 1; - std::vector dates; + std::vector dates; ReminderHelper reminderHelper; ErrCode ret = reminderHelper.GetExcludeDates(reminderId, dates); EXPECT_NE(ret, (int)ERR_ANS_INVALID_BUNDLE); diff --git a/frameworks/ans/test/unittest/reminder_request_alarm_test.cpp b/frameworks/reminder/test/unittest/reminder_request_alarm_test.cpp similarity index 100% rename from frameworks/ans/test/unittest/reminder_request_alarm_test.cpp rename to frameworks/reminder/test/unittest/reminder_request_alarm_test.cpp diff --git a/frameworks/ans/test/unittest/reminder_request_branch_test/mock_reminder_request.cpp b/frameworks/reminder/test/unittest/reminder_request_branch_test/mock_reminder_request.cpp similarity index 100% rename from frameworks/ans/test/unittest/reminder_request_branch_test/mock_reminder_request.cpp rename to frameworks/reminder/test/unittest/reminder_request_branch_test/mock_reminder_request.cpp diff --git a/frameworks/ans/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp b/frameworks/reminder/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp similarity index 83% rename from frameworks/ans/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp rename to frameworks/reminder/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp index 4d4e655f8b45ecee7252c06f23c7e1d4a4e656d8..7f0708b63a0d56d3606eabe073fed8e59dafba97 100644 --- a/frameworks/ans/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp +++ b/frameworks/reminder/test/unittest/reminder_request_branch_test/reminder_request_branch_test.cpp @@ -178,10 +178,9 @@ HWTEST_F(ReminderRequestBranchTest, UpdateNotificationRequest_00100, Function | auto reminderRequest = std::make_shared(); EXPECT_NE(reminderRequest, nullptr); int32_t notificationId_ = 0; - reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); - ReminderRequest::UpdateNotificationType type = ReminderRequest::UpdateNotificationType::COMMON; - std::string extra = "aa"; - reminderRequest->UpdateNotificationRequest(type, extra); + auto notificationRequest = reminderRequest->CreateNotificationRequest(); + bool isSnooze = true; + reminderRequest->UpdateNotificationRequest(notificationRequest, isSnooze); } /** @@ -196,10 +195,9 @@ HWTEST_F(ReminderRequestBranchTest, UpdateNotificationRequest_00200, Function | auto reminderRequest = std::make_shared(); EXPECT_NE(reminderRequest, nullptr); int32_t notificationId_ = 0; - reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); - ReminderRequest::UpdateNotificationType type = ReminderRequest::UpdateNotificationType::REMOVAL_WANT_AGENT; - std::string extra = "aa"; - reminderRequest->UpdateNotificationRequest(type, extra); + auto notificationRequest = reminderRequest->CreateNotificationRequest(); + bool isSnooze = false; + reminderRequest->UpdateNotificationRequest(notificationRequest, false); } /** @@ -214,11 +212,10 @@ HWTEST_F(ReminderRequestBranchTest, UpdateNotificationRequest_00300, Function | auto reminderRequest = std::make_shared(); EXPECT_NE(reminderRequest, nullptr); int32_t notificationId_ = 0; - reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); + auto notificationRequest = reminderRequest->CreateNotificationRequest(); reminderRequest->wantAgentInfo_ = std::make_shared(); - ReminderRequest::UpdateNotificationType type = ReminderRequest::UpdateNotificationType::WANT_AGENT; - std::string extra = "aa"; - reminderRequest->UpdateNotificationRequest(type, extra); + bool isSnooze = true; + reminderRequest->UpdateNotificationRequest(notificationRequest, isSnooze); } /** @@ -233,11 +230,10 @@ HWTEST_F(ReminderRequestBranchTest, UpdateNotificationRequest_00400, Function | auto reminderRequest = std::make_shared(); EXPECT_NE(reminderRequest, nullptr); int32_t notificationId_ = 0; - reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); reminderRequest->maxScreenWantAgentInfo_ = std::make_shared(); - ReminderRequest::UpdateNotificationType type = ReminderRequest::UpdateNotificationType::MAX_SCREEN_WANT_AGENT; - std::string extra = "aa"; - reminderRequest->UpdateNotificationRequest(type, extra); + auto notificationRequest = reminderRequest->CreateNotificationRequest(); + bool isSnooze = true; + reminderRequest->UpdateNotificationRequest(notificationRequest, isSnooze); } /** @@ -252,10 +248,9 @@ HWTEST_F(ReminderRequestBranchTest, UpdateNotificationRequest_00500, Function | auto reminderRequest = std::make_shared(); EXPECT_NE(reminderRequest, nullptr); int32_t notificationId_ = 0; - reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); - ReminderRequest::UpdateNotificationType type = ReminderRequest::UpdateNotificationType::BUNDLE_INFO; - std::string extra = "aa"; - reminderRequest->UpdateNotificationRequest(type, extra); + auto notificationRequest = reminderRequest->CreateNotificationRequest(); + bool isSnooze = true; + reminderRequest->UpdateNotificationRequest(notificationRequest, isSnooze); } /** @@ -269,9 +264,9 @@ HWTEST_F(ReminderRequestBranchTest, UpdateNotificationRequest_00600, Function | { auto reminderRequest = std::make_shared(); EXPECT_NE(reminderRequest, nullptr); - ReminderRequest::UpdateNotificationType type = ReminderRequest::UpdateNotificationType::CONTENT; - std::string extra = "aa"; - reminderRequest->UpdateNotificationRequest(type, extra); + auto notificationRequest = reminderRequest->CreateNotificationRequest(); + bool isSnooze = true; + reminderRequest->UpdateNotificationRequest(notificationRequest, isSnooze); } /** @@ -286,7 +281,6 @@ HWTEST_F(ReminderRequestBranchTest, GetButtonInfo_00100, Function | SmallTest | auto reminderRequest = std::make_shared(); EXPECT_NE(reminderRequest, nullptr); int32_t notificationId_ = 0; - reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); std::string title = "aa"; ReminderRequest::ActionButtonType actionButtonType = ReminderRequest::ActionButtonType::CLOSE; ReminderRequest::ActionButtonInfo info; @@ -310,7 +304,6 @@ HWTEST_F(ReminderRequestBranchTest, GetButtonInfo_00200, Function | SmallTest | auto reminderRequest = std::make_shared(); EXPECT_NE(reminderRequest, nullptr); int32_t notificationId_ = 0; - reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); std::string title = "aa"; std::string pkgName = "bb"; std::string abilityName = "cc"; @@ -338,7 +331,7 @@ HWTEST_F(ReminderRequestBranchTest, AddActionButtons_00100, Function | SmallTest auto reminderRequest = std::make_shared(); EXPECT_NE(reminderRequest, nullptr); int32_t notificationId = 0; - reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId); + auto notificationRequest = reminderRequest->CreateNotificationRequest(); std::string stringData = "aa"; ReminderRequest::ActionButtonType buttonType = ReminderRequest::ActionButtonType::CLOSE; ReminderRequest::ActionButtonInfo info; @@ -348,7 +341,7 @@ HWTEST_F(ReminderRequestBranchTest, AddActionButtons_00100, Function | SmallTest reminderRequest->actionButtonMap_.insert( std::pair(buttonType, info)); bool includeSnooze = true; - reminderRequest->AddActionButtons(includeSnooze); + reminderRequest->AddActionButtons(notificationRequest, includeSnooze); } /** @@ -363,7 +356,7 @@ HWTEST_F(ReminderRequestBranchTest, AddActionButtons_00200, Function | SmallTest auto reminderRequest = std::make_shared(); EXPECT_NE(reminderRequest, nullptr); int32_t notificationId_ = 0; - reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); + auto notificationRequest = reminderRequest->CreateNotificationRequest(); std::string title = "aa"; ReminderRequest::ActionButtonType actionButtonType = ReminderRequest::ActionButtonType::SNOOZE; ReminderRequest::ActionButtonInfo info; @@ -373,7 +366,7 @@ HWTEST_F(ReminderRequestBranchTest, AddActionButtons_00200, Function | SmallTest reminderRequest->actionButtonMap_.insert( std::pair(actionButtonType, info)); bool includeSnooze = true; - reminderRequest->AddActionButtons(includeSnooze); + reminderRequest->AddActionButtons(notificationRequest, includeSnooze); } /** @@ -388,7 +381,7 @@ HWTEST_F(ReminderRequestBranchTest, AddActionButtons_00300, Function | SmallTest auto reminderRequest = std::make_shared(); EXPECT_NE(reminderRequest, nullptr); int32_t notificationIds = 0; - reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationIds); + auto notificationRequest = reminderRequest->CreateNotificationRequest(); std::string title = "title"; ReminderRequest::ActionButtonType actionButtonType_ = ReminderRequest::ActionButtonType::SNOOZE; ReminderRequest::ActionButtonInfo info; @@ -398,7 +391,7 @@ HWTEST_F(ReminderRequestBranchTest, AddActionButtons_00300, Function | SmallTest reminderRequest->actionButtonMap_.insert( std::pair(actionButtonType_, info)); bool includeSnooze = false; - reminderRequest->AddActionButtons(includeSnooze); + reminderRequest->AddActionButtons(notificationRequest, includeSnooze); } /** @@ -413,7 +406,7 @@ HWTEST_F(ReminderRequestBranchTest, AddActionButtons_00400, Function | SmallTest auto reminderRequest = std::make_shared(); EXPECT_NE(reminderRequest, nullptr); int32_t notificationId_ = 0; - reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); + auto notificationRequest = reminderRequest->CreateNotificationRequest(); std::string title = "aa"; ReminderRequest::ActionButtonType actionButtonType = ReminderRequest::ActionButtonType::CUSTOM; ReminderRequest::ActionButtonInfo info; @@ -423,7 +416,7 @@ HWTEST_F(ReminderRequestBranchTest, AddActionButtons_00400, Function | SmallTest reminderRequest->actionButtonMap_.insert( std::pair(actionButtonType, info)); bool includeSnooze = false; - reminderRequest->AddActionButtons(includeSnooze); + reminderRequest->AddActionButtons(notificationRequest, includeSnooze); } /** @@ -438,7 +431,7 @@ HWTEST_F(ReminderRequestBranchTest, AddActionButtons_00500, Function | SmallTest auto reminderRequest = std::make_shared(); EXPECT_NE(reminderRequest, nullptr); int32_t notificationId_ = 0; - reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); + auto notificationRequest = reminderRequest->CreateNotificationRequest(); std::string title = "aa"; std::string pkgName = "bb"; std::string abilityName = "cc"; @@ -452,7 +445,7 @@ HWTEST_F(ReminderRequestBranchTest, AddActionButtons_00500, Function | SmallTest reminderRequest->actionButtonMap_.insert( std::pair(actionButtonType, info)); bool includeSnooze = false; - reminderRequest->AddActionButtons(includeSnooze); + reminderRequest->AddActionButtons(notificationRequest, includeSnooze); } /** @@ -467,7 +460,7 @@ HWTEST_F(ReminderRequestBranchTest, AddActionButtons_00600, Function | SmallTest auto reminderRequest = std::make_shared(); EXPECT_NE(reminderRequest, nullptr); int32_t notificationId_ = 0; - reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); + auto notificationRequest = reminderRequest->CreateNotificationRequest(); std::string title = "aa"; ReminderRequest::ActionButtonType actionButtonType = ReminderRequest::ActionButtonType::INVALID; ReminderRequest::ActionButtonInfo info; @@ -477,7 +470,7 @@ HWTEST_F(ReminderRequestBranchTest, AddActionButtons_00600, Function | SmallTest reminderRequest->actionButtonMap_.insert( std::pair(actionButtonType, info)); bool includeSnooze = false; - reminderRequest->AddActionButtons(includeSnooze); + reminderRequest->AddActionButtons(notificationRequest, includeSnooze); } /** @@ -492,9 +485,9 @@ HWTEST_F(ReminderRequestBranchTest, UpdateNotificationCommon_00100, Function | S auto reminderRequest = std::make_shared(); EXPECT_NE(reminderRequest, nullptr); int32_t notificationId_ = 0; - reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); + auto notificationRequest = reminderRequest->CreateNotificationRequest(); reminderRequest->reminderType_ = ReminderRequest::ReminderType::TIMER; - reminderRequest->UpdateNotificationCommon(false); + reminderRequest->UpdateNotificationCommon(notificationRequest, false); } /** @@ -509,9 +502,9 @@ HWTEST_F(ReminderRequestBranchTest, UpdateNotificationCommon_00200, Function | S auto reminderRequest = std::make_shared(); EXPECT_NE(reminderRequest, nullptr); int32_t notificationId_ = 0; - reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); + auto notificationRequest = reminderRequest->CreateNotificationRequest(); reminderRequest->reminderType_ = ReminderRequest::ReminderType::ALARM; - reminderRequest->UpdateNotificationCommon(false); + reminderRequest->UpdateNotificationCommon(notificationRequest, false); } /** @@ -526,9 +519,9 @@ HWTEST_F(ReminderRequestBranchTest, UpdateNotificationCommon_00300, Function | S auto reminderRequest = std::make_shared(); EXPECT_NE(reminderRequest, nullptr); int32_t notificationId_ = 0; - reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); + auto notificationRequest = reminderRequest->CreateNotificationRequest(); reminderRequest->reminderType_ = ReminderRequest::ReminderType::INVALID; - reminderRequest->UpdateNotificationCommon(false); + reminderRequest->UpdateNotificationCommon(notificationRequest, false); } /** @@ -543,10 +536,10 @@ HWTEST_F(ReminderRequestBranchTest, UpdateNotificationBundleInfo_00100, Function auto reminderRequest = std::make_shared(); EXPECT_NE(reminderRequest, nullptr); int32_t notificationId_ = 0; - reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); + auto notificationRequest = reminderRequest->CreateNotificationRequest(); std::string ownerName = ""; - reminderRequest->notificationRequest_->SetOwnerBundleName(ownerName); - reminderRequest->UpdateNotificationBundleInfo(); + notificationRequest.SetOwnerBundleName(ownerName); + reminderRequest->UpdateNotificationBundleInfo(notificationRequest); } /** @@ -561,10 +554,10 @@ HWTEST_F(ReminderRequestBranchTest, UpdateNotificationBundleInfo_00200, Function auto reminderRequest = std::make_shared(); EXPECT_NE(reminderRequest, nullptr); int32_t notificationId_ = 0; - reminderRequest->notificationRequest_ = new (std::nothrow) NotificationRequest(notificationId_); + auto notificationRequest = reminderRequest->CreateNotificationRequest(); std::string ownerName = "aa"; - reminderRequest->notificationRequest_->SetOwnerBundleName(ownerName); - reminderRequest->UpdateNotificationBundleInfo(); + notificationRequest.SetOwnerBundleName(ownerName); + reminderRequest->UpdateNotificationBundleInfo(notificationRequest); } } } diff --git a/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp b/frameworks/reminder/test/unittest/reminder_request_calendar_test.cpp similarity index 100% rename from frameworks/ans/test/unittest/reminder_request_calendar_test.cpp rename to frameworks/reminder/test/unittest/reminder_request_calendar_test.cpp diff --git a/frameworks/ans/test/unittest/reminder_request_test.cpp b/frameworks/reminder/test/unittest/reminder_request_test.cpp similarity index 95% rename from frameworks/ans/test/unittest/reminder_request_test.cpp rename to frameworks/reminder/test/unittest/reminder_request_test.cpp index 0489d7cbbab32cb918b7b6616775891a68d25ba1..c37376f1db9bb62e8987984cc0a1563b04a7f06b 100644 --- a/frameworks/ans/test/unittest/reminder_request_test.cpp +++ b/frameworks/reminder/test/unittest/reminder_request_test.cpp @@ -931,28 +931,28 @@ HWTEST_F(ReminderRequestTest, Unmarshalling_00001, Function | SmallTest | Level1 } /** - * @tc.name: InitNotificationRequest_00001 - * @tc.desc: Test InitNotificationRequest parameters. + * @tc.name: CreateNotificationRequest_00001 + * @tc.desc: Test CreateNotificationRequest parameters. * @tc.type: FUNC * @tc.require: issueI5VB6V */ -HWTEST_F(ReminderRequestTest, InitNotificationRequest_00001, Function | SmallTest | Level1) +HWTEST_F(ReminderRequestTest, CreateNotificationRequest_00001, Function | SmallTest | Level1) { auto rrc = std::make_shared(); - EXPECT_EQ(rrc->InitNotificationRequest(), true); + EXPECT_EQ(rrc->CreateNotificationRequest().GetNotificationId(), 0); } /** - * @tc.name: InitNotificationRequest_00002 - * @tc.desc: Test InitNotificationRequest parameters. + * @tc.name: CreateNotificationRequest_00002 + * @tc.desc: Test CreateNotificationRequest parameters. * @tc.type: FUNC * @tc.require: issueI5VB6V */ -HWTEST_F(ReminderRequestTest, InitNotificationRequest_00002, Function | SmallTest | Level1) +HWTEST_F(ReminderRequestTest, CreateNotificationRequest_00002, Function | SmallTest | Level1) { auto rrc = std::make_shared(); rrc->SetNotificationId(100); - EXPECT_EQ(rrc->InitNotificationRequest(), true); + EXPECT_EQ(rrc->CreateNotificationRequest().GetNotificationId(), 100); } /** @@ -1112,9 +1112,10 @@ HWTEST_F(ReminderRequestTest, SetActionButton_00005, Function | SmallTest | Leve HWTEST_F(ReminderRequestTest, AddActionButtons_00001, Function | SmallTest | Level1) { std::shared_ptr reminderRequestChild = std::make_shared(); + NotificationRequest notificationRequest = reminderRequestChild->CreateNotificationRequest(); ASSERT_NE(nullptr, reminderRequestChild); - reminderRequestChild->AddActionButtons(true); - reminderRequestChild->AddActionButtons(false); + reminderRequestChild->AddActionButtons(notificationRequest, true); + reminderRequestChild->AddActionButtons(notificationRequest, false); } /** @@ -1206,10 +1207,9 @@ HWTEST_F(ReminderRequestTest, UpdateNotificationContent_00002, Function | SmallT { auto rrc = std::make_shared(); rrc->SetNotificationId(100); - EXPECT_EQ(rrc->InitNotificationRequest(), true); - - rrc->UpdateNotificationContent(true); - rrc->UpdateNotificationContent(false); + auto notification = rrc->CreateNotificationRequest(); + rrc->UpdateNotificationContent(notification, true); + rrc->UpdateNotificationContent(notification, false); Notification::ReminderRequest::TimeTransferType type = Notification::ReminderRequest::TimeTransferType::WEEK; int32_t actualTime = 1; @@ -1428,14 +1428,13 @@ HWTEST_F(ReminderRequestTest, RecoverWantAgent_00006, Function | SmallTest | Lev HWTEST_F(ReminderRequestTest, UpdateActionButtons_00001, Function | SmallTest | Level1) { auto rrc = std::make_shared(); - EXPECT_EQ(rrc->InitNotificationRequest(), true); - sptr ret = rrc->GetNotificationRequest(); + NotificationRequest notificationRequest = rrc->CreateNotificationRequest(); bool setSnooze = true; rrc->SetSnoozeTimes(1); EXPECT_EQ(rrc->GetSnoozeTimes(), 1); rrc->SetSnoozeTimesDynamic(1); EXPECT_EQ(rrc->GetSnoozeTimesDynamic(), 1); - rrc->UpdateActionButtons(setSnooze); + rrc->UpdateActionButtons(notificationRequest, setSnooze); } /** @@ -1447,14 +1446,13 @@ HWTEST_F(ReminderRequestTest, UpdateActionButtons_00001, Function | SmallTest | HWTEST_F(ReminderRequestTest, UpdateActionButtons_00002, Function | SmallTest | Level1) { auto rrc = std::make_shared(); - EXPECT_EQ(rrc->InitNotificationRequest(), true); - sptr ret = rrc->GetNotificationRequest(); + NotificationRequest notificationRequest = rrc->CreateNotificationRequest(); bool setSnooze = true; rrc->SetSnoozeTimes(0); EXPECT_EQ(rrc->GetSnoozeTimes(), 0); rrc->SetSnoozeTimesDynamic(1); EXPECT_EQ(rrc->GetSnoozeTimesDynamic(), 1); - rrc->UpdateActionButtons(setSnooze); + rrc->UpdateActionButtons(notificationRequest, setSnooze); } /** @@ -1466,14 +1464,13 @@ HWTEST_F(ReminderRequestTest, UpdateActionButtons_00002, Function | SmallTest | HWTEST_F(ReminderRequestTest, UpdateActionButtons_00003, Function | SmallTest | Level1) { auto rrc = std::make_shared(); - EXPECT_EQ(rrc->InitNotificationRequest(), true); - sptr ret = rrc->GetNotificationRequest(); + NotificationRequest notificationRequest = rrc->CreateNotificationRequest(); bool setSnooze = false; rrc->SetSnoozeTimes(1); EXPECT_EQ(rrc->GetSnoozeTimes(), 1); rrc->SetSnoozeTimesDynamic(1); EXPECT_EQ(rrc->GetSnoozeTimesDynamic(), 1); - rrc->UpdateActionButtons(setSnooze); + rrc->UpdateActionButtons(notificationRequest, setSnooze); } /** @@ -1485,14 +1482,13 @@ HWTEST_F(ReminderRequestTest, UpdateActionButtons_00003, Function | SmallTest | HWTEST_F(ReminderRequestTest, UpdateActionButtons_00004, Function | SmallTest | Level1) { auto rrc = std::make_shared(); - EXPECT_EQ(rrc->InitNotificationRequest(), true); - sptr ret = rrc->GetNotificationRequest(); + NotificationRequest notificationRequest = rrc->CreateNotificationRequest(); bool setSnooze = true; rrc->SetSnoozeTimes(1); EXPECT_EQ(rrc->GetSnoozeTimes(), 1); rrc->SetSnoozeTimesDynamic(0); EXPECT_EQ(rrc->GetSnoozeTimesDynamic(), 0); - rrc->UpdateActionButtons(setSnooze); + rrc->UpdateActionButtons(notificationRequest, setSnooze); } /** @@ -1504,14 +1500,13 @@ HWTEST_F(ReminderRequestTest, UpdateActionButtons_00004, Function | SmallTest | HWTEST_F(ReminderRequestTest, UpdateNotificationContent_00300, Function | SmallTest | Level1) { auto rrc = std::make_shared(); - EXPECT_EQ(rrc->InitNotificationRequest(), true); - sptr ret = rrc->GetNotificationRequest(); + NotificationRequest notificationRequest = rrc->CreateNotificationRequest(); uint32_t minTimeIntervalInSecond = 5 * 60; rrc->SetTimeInterval(1); EXPECT_EQ(rrc->GetTimeInterval(), minTimeIntervalInSecond); bool setSnooze = true; - rrc->UpdateNotificationContent(setSnooze); + rrc->UpdateNotificationContent(notificationRequest, setSnooze); } @@ -1524,8 +1519,7 @@ HWTEST_F(ReminderRequestTest, UpdateNotificationContent_00300, Function | SmallT HWTEST_F(ReminderRequestTest, UpdateNotificationContent_00400, Function | SmallTest | Level1) { auto rrc = std::make_shared(); - EXPECT_EQ(rrc->InitNotificationRequest(), true); - sptr ret = rrc->GetNotificationRequest(); + NotificationRequest notificationRequest = rrc->CreateNotificationRequest(); bool deSet = true; uint8_t newState = 2; @@ -1535,7 +1529,7 @@ HWTEST_F(ReminderRequestTest, UpdateNotificationContent_00400, Function | SmallT EXPECT_EQ(result1, 2); EXPECT_EQ(rrc->IsAlerting(), true); bool setSnooze = false; - rrc->UpdateNotificationContent(setSnooze); + rrc->UpdateNotificationContent(notificationRequest, setSnooze); } /** @@ -1548,8 +1542,7 @@ HWTEST_F(ReminderRequestTest, UpdateNotificationContent_00600, Function | SmallT { // given auto rrc = std::make_shared(); - EXPECT_EQ(rrc->InitNotificationRequest(), true); - sptr ret = rrc->GetNotificationRequest(); + NotificationRequest notificationRequest = rrc->CreateNotificationRequest(); rrc->snoozeContent_ = "snooze"; rrc->content_ = "content"; rrc->expiredContent_ = "expiredContent"; @@ -1557,7 +1550,7 @@ HWTEST_F(ReminderRequestTest, UpdateNotificationContent_00600, Function | SmallT // when bool setSnooze = true; - rrc->UpdateNotificationContent(setSnooze); + rrc->UpdateNotificationContent(notificationRequest, setSnooze); // then EXPECT_EQ(rrc->displayContent_, "snooze"); @@ -1573,8 +1566,7 @@ HWTEST_F(ReminderRequestTest, UpdateNotificationContent_00800, Function | SmallT { // given auto rrc = std::make_shared(); - EXPECT_EQ(rrc->InitNotificationRequest(), true); - sptr ret = rrc->GetNotificationRequest(); + NotificationRequest notificationRequest = rrc->CreateNotificationRequest(); rrc->snoozeContent_ = "snooze"; rrc->content_ = "content"; rrc->expiredContent_ = "expiredContent"; @@ -1582,7 +1574,7 @@ HWTEST_F(ReminderRequestTest, UpdateNotificationContent_00800, Function | SmallT // when bool setSnooze = true; - rrc->UpdateNotificationContent(setSnooze); + rrc->UpdateNotificationContent(notificationRequest, setSnooze); // then EXPECT_EQ(rrc->displayContent_, "expiredContent"); @@ -1597,8 +1589,7 @@ HWTEST_F(ReminderRequestTest, UpdateNotificationContent_00800, Function | SmallT HWTEST_F(ReminderRequestTest, UpdateNotificationContent_00500, Function | SmallTest | Level1) { auto rrc = std::make_shared(); - EXPECT_EQ(rrc->InitNotificationRequest(), true); - sptr ret = rrc->GetNotificationRequest(); + NotificationRequest notificationRequest = rrc->CreateNotificationRequest(); bool deSet = false; uint8_t newState = 0; @@ -1614,7 +1605,7 @@ HWTEST_F(ReminderRequestTest, UpdateNotificationContent_00500, Function | SmallT EXPECT_EQ(rrc->GetSnoozeTimesDynamic(), 1); bool setSnooze = false; - rrc->UpdateNotificationContent(setSnooze); + rrc->UpdateNotificationContent(notificationRequest, setSnooze); } /** @@ -1761,16 +1752,15 @@ HWTEST_F(ReminderRequestTest, UpdateNotificationCommon_00100, Function | SmallTe { // given auto rrc = std::make_shared(); - EXPECT_EQ(rrc->InitNotificationRequest(), true); - sptr ret = rrc->GetNotificationRequest(); + NotificationRequest notificationRequest = rrc->CreateNotificationRequest(); rrc->snoozeSlotType_ = NotificationConstant::SlotType::OTHER; bool isSnooze = true; // when - rrc->UpdateNotificationCommon(isSnooze); + rrc->UpdateNotificationCommon(notificationRequest, isSnooze); // then - EXPECT_EQ(ret->GetSlotType(), NotificationConstant::SlotType::CONTENT_INFORMATION); + EXPECT_EQ(notificationRequest.GetSlotType(), NotificationConstant::SlotType::CONTENT_INFORMATION); } /** @@ -1783,16 +1773,15 @@ HWTEST_F(ReminderRequestTest, UpdateNotificationCommon_00200, Function | SmallTe { // given auto rrc = std::make_shared(); - EXPECT_EQ(rrc->InitNotificationRequest(), true); - sptr ret = rrc->GetNotificationRequest(); + NotificationRequest notificationRequest = rrc->CreateNotificationRequest(); rrc->snoozeSlotType_ = NotificationConstant::SlotType::SERVICE_REMINDER; bool isSnooze = true; // when - rrc->UpdateNotificationCommon(isSnooze); + rrc->UpdateNotificationCommon(notificationRequest, isSnooze); // then - EXPECT_EQ(ret->GetSlotType(), NotificationConstant::SlotType::SERVICE_REMINDER); + EXPECT_EQ(notificationRequest.GetSlotType(), NotificationConstant::SlotType::SERVICE_REMINDER); } /** @@ -1805,17 +1794,17 @@ HWTEST_F(ReminderRequestTest, UpdateNotificationCommon_00300, Function | SmallTe { // given auto rrc = std::make_shared(); - EXPECT_EQ(rrc->InitNotificationRequest(), true); - sptr ret = rrc->GetNotificationRequest(); + + NotificationRequest notificationRequest = rrc->CreateNotificationRequest(); rrc->snoozeSlotType_ = NotificationConstant::SlotType::SERVICE_REMINDER; rrc->slotType_ = NotificationConstant::SlotType::SOCIAL_COMMUNICATION; bool isSnooze = false; // when - rrc->UpdateNotificationCommon(isSnooze); + rrc->UpdateNotificationCommon(notificationRequest, isSnooze); // then - EXPECT_EQ(ret->GetSlotType(), NotificationConstant::SlotType::SOCIAL_COMMUNICATION); + EXPECT_EQ(notificationRequest.GetSlotType(), NotificationConstant::SlotType::SOCIAL_COMMUNICATION); } /** diff --git a/frameworks/ans/test/unittest/reminder_request_timer_test.cpp b/frameworks/reminder/test/unittest/reminder_request_timer_test.cpp similarity index 100% rename from frameworks/ans/test/unittest/reminder_request_timer_test.cpp rename to frameworks/reminder/test/unittest/reminder_request_timer_test.cpp diff --git a/frameworks/test/moduletest/BUILD.gn b/frameworks/test/moduletest/BUILD.gn index c37703db69c8720a60baf1f58438cbf156bab196..ead308c2a25d6bb917201d75f91c238f09ee1c72 100644 --- a/frameworks/test/moduletest/BUILD.gn +++ b/frameworks/test/moduletest/BUILD.gn @@ -40,7 +40,6 @@ ohos_moduletest("ans_fw_module_test") { "${core_path}/include", "${inner_api_path}", "${frameworks_path}/test/moduletest/mock/include", - "${ffrt_path}/interfaces/kits", ] sources = [ @@ -118,7 +117,6 @@ ohos_moduletest("ans_innerkits_module_publish_test") { "${core_path}/include", "${inner_api_path}", "${frameworks_path}/test/moduletest/mock/include", - "${ffrt_path}/interfaces/kits", ] sources = [ @@ -186,7 +184,6 @@ ohos_moduletest("ans_innerkits_module_slot_test") { "${core_path}/include", "${inner_api_path}", "${frameworks_path}/test/moduletest/mock/include", - "${ffrt_path}/interfaces/kits", ] sources = [ @@ -263,7 +260,6 @@ ohos_moduletest("ans_innerkits_module_setting_test") { "${core_path}/include", "${inner_api_path}", "${frameworks_path}/test/moduletest/mock/include", - "${ffrt_path}/interfaces/kits", ] sources = [ diff --git a/interfaces/inner_api/notification_helper.h b/interfaces/inner_api/notification_helper.h index 6b021c8754bc3c610ef439957f1336e6b076cf7a..0dc96c34c56994701b66967952b9e50dd553dfc8 100644 --- a/interfaces/inner_api/notification_helper.h +++ b/interfaces/inner_api/notification_helper.h @@ -1109,6 +1109,15 @@ public: * @return Returns Update result. */ static ErrCode UpdateNotificationTimerByUid(const int32_t uid, const bool isPaused); + + /** + * @brief Whether reminders are allowed. + * + * @param bundleName bundleName + * @param isAllowUseReminder isAllowUseReminder + * @return Returns ERR_OK on success, others on failure. + */ + static ErrCode AllowUseReminder(const std::string& bundleName, bool& isAllowUseReminder); }; } // namespace Notification } // namespace OHOS diff --git a/interfaces/inner_api/reminder_helper.h b/interfaces/inner_api/reminder_helper.h index 553dea0c9f1ab73ad62f82c212b59a9024ac70a3..77f79f4b38a910dfd72ac83f4f90da0c18dc4541 100644 --- a/interfaces/inner_api/reminder_helper.h +++ b/interfaces/inner_api/reminder_helper.h @@ -48,7 +48,7 @@ public: * Reminder id will be set with a number >= 0 if publishing the reminder successfully, Otherwise * reminder id is -1. You can call reminder.GetReminderId() to get the reminder id. */ - static ErrCode PublishReminder(ReminderRequest &reminder); + static ErrCode PublishReminder(const ReminderRequest &reminder, int32_t& reminderId); /** * Cancels a specified reminder. @@ -72,7 +72,7 @@ public: * @param[out] validReminders Indicates an initial vector to receive the result. * @return Returns an array list containing all valid reminder notifications set by the current application. */ - static ErrCode GetValidReminders(std::vector> &validReminders); + static ErrCode GetValidReminders(std::vector &validReminders); /** * Creates a NotificationSlot. @@ -104,7 +104,7 @@ public: * @param date exclude date * @return Returns ERR_OK on success, others on failure. */ - static ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date); + static ErrCode AddExcludeDate(const int32_t reminderId, const int64_t date); /** * @brief Clear exclude date for reminder @@ -121,7 +121,7 @@ public: * @param dates exclude dates * @return Returns ERR_OK on success, others on failure. */ - static ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates); + static ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates); private: static bool CheckPermission(); diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index eb5c2de5406585bb5846599c48c16ce876dd3ec7..42eea4fe65eb8ee6b56d2ec7bd17763ecbffe254 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -355,13 +355,6 @@ public: */ std::string GetGroupId() const; - /** - * @brief Obtains notification request. - * - * @return notification request instance. - */ - sptr GetNotificationRequest() const; - /** * @brief Obtains reminder id. * @@ -870,16 +863,6 @@ public: */ void SetCustomRingUri(const std::string &uri); - /** - * @brief Gets notification bundle option. - */ - sptr GetNotificationBundleOption() const; - - /** - * @brief Sets notification bundle option. - */ - void SetNotificationBundleOption(const sptr& option); - /** * @brief Update notification attributes. * @@ -887,10 +870,10 @@ public: * For example, action button should not init until the reminder is published successfully, as the reminder id is * assigned after that. * - * @param type Indicates the update type. - * @param extra Indicates the extra content. + * @param notificationRequest notificationRequest. + * @param isSnooze isSnooze */ - void UpdateNotificationRequest(UpdateNotificationType type, std::string extra); + void UpdateNotificationRequest(NotificationRequest& notificationRequest, bool isSnooze); /** * @brief Get repeated days of the week. @@ -899,12 +882,6 @@ public: */ std::vector GetDaysOfWeek() const; - /** - * @brief Create notification request struct when recover from rdb or - * recv reminder info from ipc. - */ - bool InitNotificationRequest(); - /** * @brief Gets repeat days of week */ @@ -917,6 +894,8 @@ public: */ void OnLanguageChange(const std::shared_ptr &resMgr); + NotificationRequest CreateNotificationRequest(); + public: /** * @brief Serialize want agent info and max want agent info to string. @@ -947,6 +926,8 @@ public: static uint64_t GetDurationSinceEpochInMilli(const time_t target); static std::vector StringSplit(std::string source, const std::string &split); + static bool ReadReminderTypeFormParcel(Parcel &parcel, ReminderType& tarReminderType); + static int32_t GLOBAL_ID; static const uint64_t INVALID_LONG_LONG_VALUE; static const uint16_t INVALID_U16_VALUE; @@ -991,6 +972,7 @@ public: * @brief Update the reminder when remove notification from the systemUI. */ static const std::string REMINDER_EVENT_REMOVE_NOTIFICATION; + static const std::string REMINDER_EVENT_LOAD_REMINDER; static const std::string PARAM_REMINDER_ID; static const uint8_t REMINDER_STATUS_INACTIVE; static const uint8_t REMINDER_STATUS_ACTIVE; @@ -1045,8 +1027,7 @@ protected: uint64_t GetNowInstantMilli() const; private: - void AddActionButtons(const bool includeSnooze); - void AddRemovalWantAgent(); + std::shared_ptr CreateWantAgent(AppExecFwk::ElementName &element) const; std::shared_ptr CreateMaxWantAgent(AppExecFwk::ElementName &element) const; std::string GetShowTime(const uint64_t showTime) const; @@ -1059,10 +1040,15 @@ private: void SetState(bool deSet, const uint8_t newState, std::string function); void SetWantAgent(AppExecFwk::ElementName &element); void SetExtraInfo(const AAFwk::WantParams& params); - void UpdateActionButtons(const bool &setSnooze); + void UpdateActionButtons(NotificationRequest& notificationRequest, const bool &setSnooze); bool UpdateNextReminder(const bool &force); - void UpdateNotificationContent(const bool &setSnooze); - void UpdateNotificationCommon(bool isSnooze); + void AddActionButtons(NotificationRequest& notificationRequest, const bool includeSnooze); + void UpdateNotificationContent(NotificationRequest& notificationRequest, const bool &setSnooze); + void UpdateNotificationCommon(NotificationRequest& notificationRequest, bool isSnooze); + void UpdateNotificationAddRemovalWantAgent(NotificationRequest& notificationRequest); + void UpdateNotificationWantAgent(NotificationRequest& notificationRequest); + void UpdateNotificationMaxScreenWantAgent(NotificationRequest& notificationRequest); + void UpdateNotificationBundleInfo(NotificationRequest& notificationRequest); /** * @brief Determine whether it is repeated every week. @@ -1071,26 +1057,19 @@ private: */ bool IsRepeatDaysOfWeek(int32_t day) const; - /** - * @brief Used for reminder recovery from database. - * - * @param bundleName Indicates the third part bundle name. - */ - void UpdateNotificationBundleInfo(); - /** * @brief Update the notification, which will be shown for the "Alerting" reminder. * 1. Update the notification label/content. * 2. Restore the snooze action button. */ - void UpdateNotificationStateForAlert(); + void UpdateNotificationStateForAlert(NotificationRequest& notificationRequest); /** * @brief Update the notification, which will be shown when user do a snooze. * 1. Update the notification label/content. * 2. Remove the snooze action button. */ - void UpdateNotificationStateForSnooze(); + void UpdateNotificationStateForSnooze(NotificationRequest& notificationRequest); bool MarshallingWantParameters(Parcel& parcel, const AAFwk::WantParams& params) const; bool MarshallingActionButton(Parcel& parcel) const; @@ -1137,16 +1116,14 @@ private: ReminderType reminderType_ {ReminderType::INVALID}; NotificationConstant::SlotType slotType_ {NotificationConstant::SlotType::SOCIAL_COMMUNICATION}; NotificationConstant::SlotType snoozeSlotType_ {NotificationConstant::SlotType::OTHER}; - sptr notificationRequest_ = nullptr; std::shared_ptr wantAgentInfo_ = nullptr; std::shared_ptr maxScreenWantAgentInfo_ = nullptr; std::map actionButtonMap_ {}; + std::vector> actionButtons_ {}; std::string wantAgentStr_{}; std::string maxWantAgentStr_{}; - - sptr notificationOption_ {nullptr}; }; -} // namespace Reminder +} // namespace Notification } // namespace OHOS #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_H \ No newline at end of file diff --git a/interfaces/inner_api/reminder_request_alarm.h b/interfaces/inner_api/reminder_request_alarm.h index e9f01d9222a073e8987584492e035b904faabf51..8a8d39a74cffe32bca9992e3c2980b87ca809493 100644 --- a/interfaces/inner_api/reminder_request_alarm.h +++ b/interfaces/inner_api/reminder_request_alarm.h @@ -110,11 +110,12 @@ public: */ bool ReadFromParcel(Parcel &parcel) override; + ReminderRequestAlarm() : ReminderRequest(ReminderType::ALARM) {}; + protected: virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) override; private: - ReminderRequestAlarm() : ReminderRequest() {}; void CheckParamValid() const; /** diff --git a/interfaces/inner_api/reminder_request_calendar.h b/interfaces/inner_api/reminder_request_calendar.h index 6e2ff9dbc1229028ca81f5d539003bc851562e2b..dcdd4a9111716585ed34391ef3711fd9435b4e67 100644 --- a/interfaces/inner_api/reminder_request_calendar.h +++ b/interfaces/inner_api/reminder_request_calendar.h @@ -68,9 +68,9 @@ public: std::shared_ptr GetRRuleWantAgentInfo(); - void AddExcludeDate(const uint64_t date); + void AddExcludeDate(const int64_t date); void DelExcludeDates(); - std::vector GetExcludeDates() const; + std::vector GetExcludeDates() const; bool IsInExcludeDate() const; inline uint16_t GetYear() const @@ -313,6 +313,8 @@ public: */ uint64_t GetLastStartDateTime() const; + ReminderRequestCalendar() : ReminderRequest(ReminderType::CALENDAR) {}; + public: static constexpr uint8_t MAX_MONTHS_OF_YEAR = 12; static constexpr uint8_t MAX_DAYS_OF_MONTH = 31; @@ -321,7 +323,6 @@ protected: virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) override; private: - ReminderRequestCalendar() : ReminderRequest() {} uint8_t GetNextDay(const uint16_t &settedYear, const uint8_t &settedMonth, const tm &now, const tm &target) const; uint64_t GetNextTriggerTime(const bool updateLast = false); @@ -378,7 +379,7 @@ private: uint64_t durationTime_{0}; uint64_t lastStartDateTime_{0}; - std::set excludeDates_; + std::set excludeDates_; // repeat calendar std::shared_ptr rruleWantAgentInfo_ = nullptr; diff --git a/interfaces/inner_api/reminder_request_client.h b/interfaces/inner_api/reminder_request_client.h new file mode 100644 index 0000000000000000000000000000000000000000..dc85c7ecd3978cd66de43d9b36a943bd0c17b4c6 --- /dev/null +++ b/interfaces/inner_api/reminder_request_client.h @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2024 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_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_CLIENT_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_CLIENT_H +#include +#include + +#include "reminder_request.h" +#include "notification_slot.h" +#include "notification_constant.h" +#include "ans_manager_interface.h" +#include "ireminder_service.h" +#include "ffrt.h" + +namespace OHOS { +namespace Notification { +class ReminderRequestClient { +public: + /** + * @brief Publishes a scheduled reminder. + * + * @param reminder Indicates a reminder. + * @return Returns publish result. + */ + ErrCode PublishReminder(const ReminderRequest& reminder, int32_t& reminderId); + + /** + * @brief Cancels a specified reminder. + * + * @param reminderId Indicates reminder Id. + * @return Returns cancel result. + */ + ErrCode CancelReminder(const int32_t reminderId); + + /** + * @brief Cancels all reminders of current third part application. + * + * @return Returns cancel result. + */ + ErrCode CancelAllReminders(); + + /** + * @brief Obtains all valid reminder notifications set by the current application. + * + * @param[out] validReminders Indicates the vector to store the result. + * @return Returns get valid reminders result. + */ + ErrCode GetValidReminders(std::vector &validReminders); + + /** + * @brief Add exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param date exclude date + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date); + + /** + * @brief Clear exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode DelExcludeDates(const int32_t reminderId); + + /** + * @brief Get exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param dates exclude dates + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates); + + /** + * @brief Creates a notification slot. + * @note You can call the NotificationRequest::SetSlotType(NotificationConstant::SlotType) method to bind the slot + * for publishing. A NotificationSlot instance cannot be used directly after being initialized. Instead, you have to + * call this method to create a notification slot and bind the slot ID to a NotificationRequest object so that the + * notification published can have all the characteristics set in the NotificationSlot. After a notification slot is + * created by using this method, only the name and description of the notification slot can be changed. Changes to + * the other attributes, such as the vibration status and notification tone, will no longer take effect. + * + * @param slot Indicates the notification slot to be created, which is set by NotificationSlot. + * This parameter must be specified. + * @return Returns add notification slot result. + */ + ErrCode AddNotificationSlot(const NotificationSlot &slot); + + /** + * @brief Deletes a created notification slot based on the slot ID. + * + * @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot + * This parameter must be specified. + * @return Returns remove notification slot result. + */ + ErrCode RemoveNotificationSlot(const NotificationConstant::SlotType &slotType); + + void LoadSystemAbilitySuccess(const sptr &remoteObject); + + void LoadSystemAbilityFail(); + +private: + + /** + * @brief Adds a notification slot by type. + * + * @param slotType Indicates the notification slot type to be added. + * @return Returns add notification slot result. + */ + ErrCode AddSlotByType(const NotificationConstant::SlotType &slotType); + + ErrCode AddNotificationSlots(const std::vector &slots); + + sptr GetAnsManagerProxy(); + + sptr GetReminderServiceProxy(); + + bool LoadReminderService(); + + std::mutex serviceLock_; + + std::condition_variable proxyConVar_; + + sptr proxy_; +}; +} // namespace Notification +} // namespace OHOS +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_CLIENT_H + diff --git a/interfaces/inner_api/reminder_request_factory.h b/interfaces/inner_api/reminder_request_factory.h new file mode 100644 index 0000000000000000000000000000000000000000..fb33ebbcb22cac56738e8945ee67e8d5c9a16fea --- /dev/null +++ b/interfaces/inner_api/reminder_request_factory.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021-2022 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_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_FACTORY_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_FACTORY_H + +#include "reminder_request.h" +#include "string" + +namespace OHOS { +namespace Notification { +class ReminderRequestFactory { +public: + static ReminderRequest* CreateReminderRequest(ReminderRequest::ReminderType reminderType); +}; +} // namespace Notification +} // namespace OHOS +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_FACTORY_H \ No newline at end of file diff --git a/interfaces/inner_api/reminder_request_timer.h b/interfaces/inner_api/reminder_request_timer.h index 527b65cbe0235cf5a63ca83521615b2756666347..a3e39351a469d620846804e0d606c2d6c2657326 100644 --- a/interfaces/inner_api/reminder_request_timer.h +++ b/interfaces/inner_api/reminder_request_timer.h @@ -71,11 +71,12 @@ public: bool ReadFromParcel(Parcel &parcel) override; + ReminderRequestTimer() : ReminderRequest(ReminderType::TIMER) {}; + protected: virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) override; private: - ReminderRequestTimer() {}; void CheckParamsValid(const uint64_t countDownTimeInSeconds) const; void UpdateTimeInfo(const std::string &description); uint64_t countDownTimeInSeconds_ {0}; diff --git a/interfaces/inner_api/reminder_service_load_callback.h b/interfaces/inner_api/reminder_service_load_callback.h new file mode 100644 index 0000000000000000000000000000000000000000..4aa59c1f3321c6ce8f76933ebf7597ea3578e9fb --- /dev/null +++ b/interfaces/inner_api/reminder_service_load_callback.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024 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 OHOS_REMINDER_SERVICE_CALLBACK_H +#define OHOS_REMINDER_SERVICE_CALLBACK_H + +#include +#include + +#include "refbase.h" +#include "system_ability_load_callback_stub.h" + +namespace OHOS { class IRemoteObject; } +namespace OHOS { +namespace Notification { +class ReminderServiceCallback : public SystemAbilityLoadCallbackStub { +public: + void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, + const sptr &remoteObject) override; + void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; +}; +} +} +#endif \ No newline at end of file diff --git a/notification.gni b/notification.gni index 77e6889af1527d2dc7f8db4070f8d18b36c2a8f4..e0622f0f0658c771c79e83f31b4d203456833b72 100644 --- a/notification.gni +++ b/notification.gni @@ -17,14 +17,15 @@ ability_runtime_services_path = "${ability_runtime_path}/services" ability_runtime_kits_path = "${ability_runtime_path}/frameworks/kits" ability_runtime_napi_path = "${ability_runtime_path}/frameworks/js/napi" access_token_path = "//base/security/access_token" -ffrt_path = "//foundation/resourceschedule/ffrt" component_name = "distributed_notification_service" component_path = "//base/notification/distributed_notification_service" multimedia_path = "//foundation/multimedia/image_framework" commonlibrary_utils_path = "//commonlibrary/c_utils" services_path = "${component_path}/services" +reminder_services_path = "${component_path}/services/reminder" frameworks_path = "${component_path}/frameworks" frameworks_module_ans_path = "${frameworks_path}/ans" +frameworks_module_reminder_path = "${frameworks_path}/reminder" interfaces_path = "${component_path}/interfaces" inner_api_path = "${interfaces_path}/inner_api" notification_ndk_path = "${interfaces_path}/ndk" diff --git a/services/ans/BUILD.gn b/services/ans/BUILD.gn index c44e54ab6d2539c97e5c9d180966767353d5eb77..060444e328964b8021c4e9443e28e00903ccd814 100644 --- a/services/ans/BUILD.gn +++ b/services/ans/BUILD.gn @@ -22,6 +22,7 @@ config("public_ans_config") { include_dirs = [ "${services_path}/ans/include", "${core_path}/include", + "${frameworks_module_reminder_path}/include", ] } @@ -99,16 +100,7 @@ ohos_source_set("ans_service_sources") { "src/notification_timer_info.cpp", "src/os_account_manager_helper.cpp", "src/permission_filter.cpp", - "src/reminder_config_change_observer.cpp", - "src/reminder_data_manager.cpp", - "src/reminder_data_manager_inner.cpp", - "src/reminder_event_manager.cpp", - "src/reminder_store.cpp", - "src/reminder_store_strategy.cpp", "src/reminder_swing_decision_center.cpp", - "src/reminder_table.cpp", - "src/reminder_table_old.cpp", - "src/reminder_timer_info.cpp", "src/report_time_info.cpp", "src/system_dialog_connect_stb.cpp", "src/system_event_observer.cpp", diff --git a/services/ans/include/advanced_notification_service.h b/services/ans/include/advanced_notification_service.h index d84de77f65c65f697d6ec1b90eb0ed5631573a62..a543cfcaae78c6c22daf1ce14989d324a0aa3125 100644 --- a/services/ans/include/advanced_notification_service.h +++ b/services/ans/include/advanced_notification_service.h @@ -702,63 +702,6 @@ public: */ bool CheckReminderPermission(); - /** - * @brief Publishes a reminder notification. - * - * @param reminder Identifies the reminder notification request that needs to be published. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode PublishReminder(sptr &reminder) override; - - /** - * @brief Cancel a reminder notifications. - * - * @param reminderId Identifies the reminders id that needs to be canceled. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode CancelReminder(const int32_t reminderId) override; - - /** - * @brief Get all valid reminder notifications. - * - * @param reminders Identifies the list of all valid notifications. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode GetValidReminders(std::vector> &reminders) override; - - /** - * @brief Cancel all reminder notifications. - * - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode CancelAllReminders() override; - - /** - * @brief Add exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @param date exclude date - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) override; - - /** - * @brief Clear exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode DelExcludeDates(const int32_t reminderId) override; - - /** - * @brief Get exclude date for reminder - * - * @param reminderId Identifies the reminders id. - * @param dates exclude dates - * @return Returns ERR_OK on success, others on failure. - */ - ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) override; - /** * @brief Checks whether this device is support template. * @@ -1132,6 +1075,15 @@ public: */ bool AllowUseReminder(const std::string& bundleName); + /** + * @brief Whether reminders are allowed. + * + * @param bundleName bundleName + * @param isAllowUseReminder isAllowUseReminder + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode AllowUseReminder(const std::string& bundleName, bool& isAllowUseReminder) override; + /** * @brief Get do not disturb profile by id. * diff --git a/services/ans/include/advanced_notification_service_ability.h b/services/ans/include/advanced_notification_service_ability.h index 229e57197d78441ad7928b5660a2714d611f776f..682b0dbc8e5dace3c21e922adaee72f4a6e45fd1 100644 --- a/services/ans/include/advanced_notification_service_ability.h +++ b/services/ans/include/advanced_notification_service_ability.h @@ -20,7 +20,6 @@ #include "advanced_datashare_observer.h" #include "advanced_notification_service.h" -#include "reminder_data_manager.h" #include "system_ability_definition.h" #include "notification_extension_wrapper.h" @@ -55,7 +54,6 @@ private: private: std::atomic isDatashaReready_ {false}; sptr service_; - std::shared_ptr reminderAgent_; std::shared_ptr subscriber_ = nullptr; }; } // namespace Notification diff --git a/services/ans/src/advanced_notification_reminder_service.cpp b/services/ans/src/advanced_notification_reminder_service.cpp index c6ff8843a75e5333d1e24ec853467b232c5bc5bf..98afa721263dde0b66c43a2634891bce28573d63 100644 --- a/services/ans/src/advanced_notification_reminder_service.cpp +++ b/services/ans/src/advanced_notification_reminder_service.cpp @@ -30,7 +30,6 @@ #include "notification_request.h" #include "os_account_manager.h" #include "hitrace_meter_adapter.h" -#include "reminder_data_manager.h" #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED #include "distributed_notification_manager.h" #include "distributed_preferences.h" @@ -41,207 +40,6 @@ namespace OHOS { namespace Notification { -inline bool AdvancedNotificationService::CheckReminderPermission() -{ - Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID(); - ErrCode result = Security::AccessToken::AccessTokenKit::VerifyAccessToken( - callerToken, "ohos.permission.PUBLISH_AGENT_REMINDER"); - return result == Security::AccessToken::PermissionState::PERMISSION_GRANTED; -} - -ErrCode AdvancedNotificationService::PublishReminder(sptr &reminder) -{ - HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); - ANSR_LOGI("Publish reminder"); - if (!reminder) { - ANSR_LOGE("ReminderRequest object is nullptr"); - return ERR_ANS_INVALID_PARAM; - } - - std::string bundle = GetClientBundleName(); - if (!CheckReminderPermission()) { - ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); - return ERR_REMINDER_PERMISSION_DENIED; - } - if (!AllowUseReminder(bundle)) { - ANSR_LOGW("The number of reminders exceeds the limit[0]."); - return ERR_REMINDER_NUMBER_OVERLOAD; - } - ANSR_LOGD("is system app: %{public}d", AccessTokenHelper::IsSystemApp()); - reminder->SetSystemApp(AccessTokenHelper::IsSystemApp()); - sptr notificationRequest = reminder->GetNotificationRequest(); - reminder->InitCreatorBundleName(bundle); - reminder->InitCreatorUid(IPCSkeleton::GetCallingUid()); - if (reminder->GetWantAgentInfo() == nullptr || reminder->GetMaxScreenWantAgentInfo() == nullptr) { - ANSR_LOGE("wantagent info is nullptr"); - return ERR_ANS_INVALID_PARAM; - } - std::string wantAgentName = reminder->GetWantAgentInfo()->pkgName; - std::string msWantAgentName = reminder->GetMaxScreenWantAgentInfo()->pkgName; - if (wantAgentName != msWantAgentName && wantAgentName != "" && msWantAgentName != "") { - ANSR_LOGE("wantAgentName is not same to msWantAgentName, wantAgentName:%{public}s, msWantAgentName:%{public}s", - wantAgentName.c_str(), msWantAgentName.c_str()); - return ERR_ANS_INVALID_PARAM; - } - if (wantAgentName != bundle && wantAgentName != "") { - ANSR_LOGI("Set agent reminder, bundle:%{public}s, wantAgentName:%{public}s", bundle.c_str(), - wantAgentName.c_str()); - SetAgentNotification(notificationRequest, wantAgentName); - } else if (msWantAgentName != bundle && msWantAgentName != "") { - ANSR_LOGI("Set agent reminder, bundle:%{public}s, msWantAgentName:%{public}s", bundle.c_str(), - msWantAgentName.c_str()); - SetAgentNotification(notificationRequest, msWantAgentName); - } - sptr bundleOption = nullptr; - ErrCode result = PrepareNotificationInfo(notificationRequest, bundleOption); - if (result != ERR_OK) { - ANSR_LOGW("PrepareNotificationInfo fail"); - return result; - } - bool allowedNotify = false; - result = IsAllowedNotifySelf(bundleOption, allowedNotify); - if (!reminder->IsSystemApp() && (result != ERR_OK || !allowedNotify)) { - ANSR_LOGW("The application does not request enable notification"); - return ERR_REMINDER_NOTIFICATION_NOT_ENABLE; - } - auto rdm = ReminderDataManager::GetInstance(); - if (rdm == nullptr) { - return ERR_NO_INIT; - } - return rdm->PublishReminder(reminder, bundleOption); -} - -ErrCode AdvancedNotificationService::CancelReminder(const int32_t reminderId) -{ - HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); - ANSR_LOGI("Cancel Reminder"); - if (!CheckReminderPermission()) { - ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); - return ERR_REMINDER_PERMISSION_DENIED; - } - - sptr bundleOption = GenerateBundleOption(); - if (bundleOption == nullptr) { - return ERR_ANS_INVALID_BUNDLE; - } - auto rdm = ReminderDataManager::GetInstance(); - if (rdm == nullptr) { - return ERR_NO_INIT; - } - return rdm->CancelReminder(reminderId, bundleOption); -} - -ErrCode AdvancedNotificationService::CancelAllReminders() -{ - HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); - ANSR_LOGI("Cancel all reminders"); - if (!CheckReminderPermission()) { - ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); - return ERR_REMINDER_PERMISSION_DENIED; - } - - sptr bundleOption = GenerateBundleOption(); - if (bundleOption == nullptr) { - return ERR_ANS_INVALID_BUNDLE; - } - int32_t userId = -1; - AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(bundleOption->GetUid(), userId); - auto rdm = ReminderDataManager::GetInstance(); - if (rdm == nullptr) { - return ERR_NO_INIT; - } - return rdm->CancelAllReminders(bundleOption->GetBundleName(), userId, bundleOption->GetUid()); -} - - -ErrCode AdvancedNotificationService::GetValidReminders(std::vector> &reminders) -{ - HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); - ANSR_LOGI("GetValidReminders"); - if (!CheckReminderPermission()) { - ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); - return ERR_REMINDER_PERMISSION_DENIED; - } - - reminders.clear(); - sptr bundleOption = GenerateBundleOption(); - if (bundleOption == nullptr) { - return ERR_ANS_INVALID_BUNDLE; - } - auto rdm = ReminderDataManager::GetInstance(); - if (rdm == nullptr) { - return ERR_NO_INIT; - } - rdm->GetValidReminders(bundleOption, reminders); - ANSR_LOGD("Valid reminders size=%{public}zu", reminders.size()); - return ERR_OK; -} - -ErrCode AdvancedNotificationService::AddExcludeDate(const int32_t reminderId, const uint64_t date) -{ - HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); - ANSR_LOGI("Add Exclude Date"); - if (!CheckReminderPermission()) { - ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); - return ERR_REMINDER_PERMISSION_DENIED; - } - - sptr bundleOption = GenerateBundleOption(); - if (bundleOption == nullptr) { - ANSR_LOGW("Generate bundle option failed!"); - return ERR_ANS_INVALID_BUNDLE; - } - auto rdm = ReminderDataManager::GetInstance(); - if (rdm == nullptr) { - ANSR_LOGW("Reminder data manager not init!"); - return ERR_NO_INIT; - } - return rdm->AddExcludeDate(reminderId, date, bundleOption); -} - -ErrCode AdvancedNotificationService::DelExcludeDates(const int32_t reminderId) -{ - HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); - ANSR_LOGI("Del Exclude Dates"); - if (!CheckReminderPermission()) { - ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); - return ERR_REMINDER_PERMISSION_DENIED; - } - - sptr bundleOption = GenerateBundleOption(); - if (bundleOption == nullptr) { - ANSR_LOGW("Generate bundle option failed!"); - return ERR_ANS_INVALID_BUNDLE; - } - auto rdm = ReminderDataManager::GetInstance(); - if (rdm == nullptr) { - ANSR_LOGW("Reminder data manager not init!"); - return ERR_NO_INIT; - } - return rdm->DelExcludeDates(reminderId, bundleOption); -} - -ErrCode AdvancedNotificationService::GetExcludeDates(const int32_t reminderId, std::vector& dates) -{ - HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); - ANSR_LOGI("Get Exclude Dates"); - if (!CheckReminderPermission()) { - ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); - return ERR_REMINDER_PERMISSION_DENIED; - } - - sptr bundleOption = GenerateBundleOption(); - if (bundleOption == nullptr) { - ANSR_LOGW("Generate bundle option failed!"); - return ERR_ANS_INVALID_BUNDLE; - } - auto rdm = ReminderDataManager::GetInstance(); - if (rdm == nullptr) { - ANSR_LOGW("Reminder data manager not init!"); - return ERR_NO_INIT; - } - return rdm->GetExcludeDates(reminderId, bundleOption, dates); -} #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED NotificationConstant::RemindType AdvancedNotificationService::GetRemindType() diff --git a/services/ans/src/advanced_notification_service_ability.cpp b/services/ans/src/advanced_notification_service_ability.cpp index 2b444241a2e6d3cb298c6d39dd569cc081ad2325..3326601fd9c0d9906c64717cab310afebd07fb5b 100644 --- a/services/ans/src/advanced_notification_service_ability.cpp +++ b/services/ans/src/advanced_notification_service_ability.cpp @@ -46,7 +46,6 @@ void AdvancedNotificationServiceAbility::OnStart() } service_->CreateDialogManager(); service_->InitPublishProcess(); - reminderAgent_ = ReminderDataManager::InitInstance(service_); #ifdef ENABLE_ANS_EXT_WRAPPER EXTENTION_WRAPPER->InitExtentionWrapper(); @@ -64,7 +63,6 @@ void AdvancedNotificationServiceAbility::OnStart() void AdvancedNotificationServiceAbility::OnStop() { service_ = nullptr; - reminderAgent_ = nullptr; } void AdvancedNotificationServiceAbility::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) diff --git a/services/ans/src/advanced_notification_utils.cpp b/services/ans/src/advanced_notification_utils.cpp index e05796ebe3fc0b47e8eabd43a511226897cff67b..87cbeb26e0dedc87e203ba472ec10a43d28d7a0a 100644 --- a/services/ans/src/advanced_notification_utils.cpp +++ b/services/ans/src/advanced_notification_utils.cpp @@ -2019,6 +2019,12 @@ bool AdvancedNotificationService::AllowUseReminder(const std::string& bundleName #endif } +ErrCode AdvancedNotificationService::AllowUseReminder(const std::string& bundleName, bool& isAllowUseReminder) +{ + isAllowUseReminder = AllowUseReminder(bundleName); + return ERR_OK; +} + void AdvancedNotificationService::ResetDistributedEnabled() { if (notificationSvrQueue_ == nullptr) { diff --git a/services/ans/test/unittest/BUILD.gn b/services/ans/test/unittest/BUILD.gn index 86637a419d37288eb7b163d38b64d6bf600dfc3b..9d8b3d2888b19f8aa14d8e3e817c7e5aded94c89 100644 --- a/services/ans/test/unittest/BUILD.gn +++ b/services/ans/test/unittest/BUILD.gn @@ -17,90 +17,6 @@ import("//build/test.gni") module_output_path = "${component_name}/unittest" -ohos_unittest("reminder_unit_test") { - module_out_path = module_output_path - include_dirs = [ - ".", - "include", - "/${services_path}/ans/include", - "${services_path}/ans/test/unittest/mock/include", - ] - - defines = [] - - sources = [ - "mock/blob.cpp", - "mock/distributed_kv_data_manager.cpp", - "mock/mock_access_token_helper.cpp", - "mock/mock_bundle_manager_helper.cpp", - "mock/mock_event_handler.cpp", - "mock/mock_ipc.cpp", - "mock/mock_single_kv_store.cpp", - "reminder_data_manager_test.cpp", - ] - - deps = [ - "${frameworks_module_ans_path}:ans_innerkits", - "${services_path}/ans:libans", - "//third_party/googletest:gtest_main", - ] - - if (distributed_notification_supported) { - defines += [ "DISTRIBUTED_NOTIFICATION_SUPPORTED" ] - deps += [ "${services_path}/distributed:libans_distributed" ] - include_dirs += [ "${services_path}/distributed/include" ] - } - - external_deps = [ - "ability_base:want", - "ability_base:zuri", - "ability_runtime:ability_manager", - "ability_runtime:abilitykit_native", - "ability_runtime:app_manager", - "ability_runtime:wantagent_innerkits", - "access_token:libaccesstoken_sdk", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "common_event_service:cesfwk_innerkits", - "data_share:datashare_common", - "data_share:datashare_consumer", - "device_manager:devicemanagersdk", - "eventhandler:libeventhandler", - "ffrt:libffrt", - "hilog:libhilog", - "hitrace:hitrace_meter", - "hitrace:libhitracechain", - "image_framework:image_native", - "ipc:ipc_core", - "kv_store:distributeddata_inner", - "os_account:os_account_innerkits", - "relational_store:native_rdb", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - "time_service:time_client", - ] - - if (device_usage) { - external_deps += [ "device_usage_statistics:usagestatsinner" ] - defines += [ "DEVICE_USAGE_STATISTICS_ENABLE" ] - } - - if (player_framework) { - external_deps += [ "player_framework:media_client" ] - defines += [ "PLAYER_FRAMEWORK_ENABLE" ] - } - - cflags = [] - if (hisysevent_usage) { - external_deps += [ "hisysevent:libhisysevent" ] - cflags += [ "-DHAS_HISYSEVENT_PART" ] - } - - subsystem_name = "${subsystem_name}" - part_name = "${component_name}" -} - ohos_unittest("ans_unit_test") { module_out_path = module_output_path include_dirs = [ @@ -913,7 +829,6 @@ ohos_unittest("notification_subscriber_manager_branch_test") { "include", "/${services_path}/ans/include", "${services_path}/ans/test/unittest/mock/include", - "${ffrt_path}/interfaces/kits", ] defines = [] @@ -983,7 +898,6 @@ ohos_unittest("advanced_notification_service_branch_test") { "include", "/${services_path}/ans/include", "${services_path}/ans/test/unittest/mock/include", - "${ffrt_path}/interfaces/kits", ] defines = [] @@ -1057,7 +971,6 @@ ohos_unittest("notification_preferences_database_branch_test") { "include", "/${services_path}/ans/include", "${services_path}/ans/test/unittest/mock/include", - "${ffrt_path}/interfaces/kits", ] sources = [ @@ -1091,6 +1004,7 @@ ohos_unittest("notification_preferences_database_branch_test") { "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", + "ffrt:libffrt", "hilog:libhilog", "hitrace:hitrace_meter", "hitrace:libhitracechain", @@ -1338,6 +1252,5 @@ group("unittest") { ":notification_subscriber_manager_test", ":os_account_manager_helper_test", ":push_callback_stub_test", - ":reminder_unit_test", ] } diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index 1aae93d2efbd100125217cddb3549f5b7f34a895..210211dec1e875f60587f51965fd961c048a5d00 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -993,18 +993,6 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13100, (int)ERR_ANS_INVALID_PARAM); } -/** - * @tc.number : AdvancedNotificationServiceTest_13500 - * @tc.name : ANS_GetValidReminders_0100 - * @tc.desc : Test GetValidReminders function when the result is ERR_NO_INIT - * @tc.require : issueI5S4VP - */ -HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13500, Function | SmallTest | Level1) -{ - std::vector> reminders; - ASSERT_EQ(advancedNotificationService_->GetValidReminders(reminders), (int)ERR_NO_INIT); -} - /** * @tc.number : AdvancedNotificationServiceTest_13600 * @tc.name : ANS_ActiveNotificationDump_0100 @@ -1429,14 +1417,6 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_16900, ASSERT_EQ(advancedNotificationService_->GetAppTargetBundle(bundleOption, bundleOption), ERR_ANS_INVALID_BUNDLE); - int32_t reminderId = 1; - ASSERT_EQ(advancedNotificationService_->CancelReminder(reminderId), ERR_ANS_INVALID_BUNDLE); - - ASSERT_EQ(advancedNotificationService_->CancelAllReminders(), ERR_ANS_INVALID_BUNDLE); - - std::vector> reminders; - ASSERT_EQ(advancedNotificationService_->GetValidReminders(reminders), ERR_ANS_INVALID_BUNDLE); - ASSERT_EQ(advancedNotificationService_->RemoveAllSlots(), ERR_ANS_INVALID_BUNDLE); ASSERT_EQ(advancedNotificationService_->AddSlotByType(NotificationConstant::SlotType::OTHER), @@ -3738,68 +3718,9 @@ HWTEST_F(AdvancedNotificationServiceTest, RegisterSwingCallback_00002, Function #endif /** - * @tc.number : AddExcludeDate_00001 - * @tc.name : Test AddExcludeDate - * @tc.desc : Test AddExcludeDate function when the result is ERR_NO_INIT - * @tc.require : issueI5S4VP - */ -HWTEST_F(AdvancedNotificationServiceTest, AddExcludeDate_00001, Function | SmallTest | Level1) -{ - int32_t reminderId = 10; - uint64_t time = 124325; - MockIsVerfyPermisson(false); - ASSERT_EQ(advancedNotificationService_->AddExcludeDate(reminderId, time), (int)ERR_REMINDER_PERMISSION_DENIED); - TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); - MockIsNonBundleName(true); - ASSERT_EQ(advancedNotificationService_->AddExcludeDate(reminderId, time), (int)ERR_ANS_INVALID_BUNDLE); - MockIsNonBundleName(false); - ASSERT_EQ(advancedNotificationService_->AddExcludeDate(reminderId, time), (int)ERR_NO_INIT); - MockIsVerfyPermisson(false); -} - -/** - * @tc.number : DelExcludeDates_00002 - * @tc.name : Test DelExcludeDates - * @tc.desc : Test DelExcludeDates function when the result is ERR_NO_INIT - * @tc.require : issueI5S4VP - */ -HWTEST_F(AdvancedNotificationServiceTest, DelExcludeDates_00002, Function | SmallTest | Level1) -{ - int32_t reminderId = 10; - MockIsVerfyPermisson(false); - ASSERT_EQ(advancedNotificationService_->DelExcludeDates(reminderId), (int)ERR_REMINDER_PERMISSION_DENIED); - TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); - MockIsNonBundleName(true); - ASSERT_EQ(advancedNotificationService_->DelExcludeDates(reminderId), (int)ERR_ANS_INVALID_BUNDLE); - MockIsNonBundleName(false); - ASSERT_EQ(advancedNotificationService_->DelExcludeDates(reminderId), (int)ERR_NO_INIT); - MockIsVerfyPermisson(false); -} - -/** - * @tc.number : GetExcludeDates_00001 - * @tc.name : Test GetExcludeDates - * @tc.desc : Test GetExcludeDates function when the result is ERR_NO_INIT - * @tc.require : issueI5S4VP - */ -HWTEST_F(AdvancedNotificationServiceTest, GetExcludeDates_00001, Function | SmallTest | Level1) -{ - int32_t reminderId = 10; - std::vector times; - MockIsVerfyPermisson(false); - ASSERT_EQ(advancedNotificationService_->GetExcludeDates(reminderId, times), (int)ERR_REMINDER_PERMISSION_DENIED); - TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); - MockIsNonBundleName(true); - ASSERT_EQ(advancedNotificationService_->GetExcludeDates(reminderId, times), (int)ERR_ANS_INVALID_BUNDLE); - MockIsNonBundleName(false); - ASSERT_EQ(advancedNotificationService_->GetExcludeDates(reminderId, times), (int)ERR_NO_INIT); - MockIsVerfyPermisson(false); -} - -/** - * @tc.number : PublishInNotificationList_00001 - * @tc.name : Test PublishInNotificationList - * @tc.desc : Test PublishInNotificationList function when the record->slot is nullptr + * @tc.number : PublishFlowControl_00001 + * @tc.name : Test PublishFlowControl + * @tc.desc : Test PublishFlowControl function when the record->slot is nullptr * @tc.require : issueI5S4VP */ HWTEST_F(AdvancedNotificationServiceTest, PublishInNotificationList_00001, Function | SmallTest | Level1) diff --git a/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_service_publish_test.cpp b/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_service_publish_test.cpp index 5e164addcb93dc042928d839a63bd5e7b5bc4866..cb03c49b9df0a569a64b510a068e7c03ceb9316e 100644 --- a/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_service_publish_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test/advanced_notification_service_publish_test.cpp @@ -1284,48 +1284,6 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_12800, ASSERT_EQ(advancedNotificationService_->PublishAsBundle(notification, representativeBundle), result); } - -/** - * @tc.number : AdvancedNotificationServiceTest_13200 - * @tc.name : ANS_PublishReminder_0100 - * @tc.desc : Test PublishReminder function - * @tc.require : issueI5S4VP - */ -HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13200, Function | SmallTest | Level1) -{ - sptr reminder = nullptr; - ASSERT_EQ(advancedNotificationService_->PublishReminder(reminder), ERR_ANS_INVALID_PARAM); -} - -/** - * @tc.number : AdvancedNotificationServiceTest_13300 - * @tc.name : ANS_CancelReminder_0100 - * @tc.desc : Test CancelReminder function when the result is ERR_NO_INIT - * @tc.require : issueI5S4VP - */ -HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13300, Function | SmallTest | Level1) -{ - TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); - sptr req = new NotificationRequest(); - EXPECT_NE(req, nullptr); - int32_t reminderId = 1; - ASSERT_EQ(advancedNotificationService_->CancelReminder(reminderId), (int)ERR_NO_INIT); -} - -/** - * @tc.number : AdvancedNotificationServiceTest_13400 - * @tc.name : ANS_CancelAllReminders_0100 - * @tc.desc : Test CancelAllReminders function when the result is ERR_NO_INIT - * @tc.require : issueI5S4VP - */ -HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_13400, Function | SmallTest | Level1) -{ - TestAddSlot(NotificationConstant::SlotType::SOCIAL_COMMUNICATION); - sptr req = new NotificationRequest(); - EXPECT_NE(req, nullptr); - ASSERT_EQ(advancedNotificationService_->CancelAllReminders(), (int)ERR_NO_INIT); -} - /** * @tc.number : AdvancedNotificationServiceTest_21500 * @tc.name : PublishPreparedNotification_1000 @@ -1346,43 +1304,6 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_21500, GTEST_LOG_(INFO) << "PublishPreparedNotification_1000 test end"; } -/** - * @tc.number : AdvancedNotificationServiceTest_17900 - * @tc.name : PublishReminder_1000 - * @tc.desc : Test PublishReminder function. - * @tc.require : #I61RF2 - */ -HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_17900, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "GetAppTargetBundle_1000 test start"; - - int32_t reminderId = 1; - sptr reminder = new ReminderRequest(reminderId); - reminder->InitNotificationRequest(); - ASSERT_EQ(advancedNotificationService_->PublishReminder(reminder), ERR_REMINDER_NOTIFICATION_NOT_ENABLE); - - GTEST_LOG_(INFO) << "GetAppTargetBundle_1000 test end"; -} - -/** - * @tc.number : AdvancedNotificationServiceTest_18000 - * @tc.name : PublishReminder_2000 - * @tc.desc : Test PublishReminder function. - * @tc.require : #I61RF2 - */ -HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_18000, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "GetAppTargetBundle_2000 test start"; - - MockIsNonBundleName(true); - int32_t reminderId = 1; - sptr reminder = new ReminderRequest(reminderId); - reminder->InitNotificationRequest(); - ASSERT_EQ(advancedNotificationService_->PublishReminder(reminder), ERR_ANS_INVALID_BUNDLE); - MockIsNonBundleName(false); - GTEST_LOG_(INFO) << "GetAppTargetBundle_2000 test end"; -} - /** * @tc.number : AdvancedNotificationServiceTest_19000 * @tc.name : ANS_Publish_With_PixelMap diff --git a/services/distributed/BUILD.gn b/services/distributed/BUILD.gn index 07554f3a34e2eda1899a4efd6c005a9758fa1eb3..b0ca637dd776c2f5b2cbfa59008108f572d886a6 100644 --- a/services/distributed/BUILD.gn +++ b/services/distributed/BUILD.gn @@ -17,7 +17,6 @@ import("//build/ohos.gni") config("ans_distributed_config") { include_dirs = [ "${services_path}/distributed/include", - "${ffrt_path}/interfaces/kits", ] } diff --git a/services/distributed/test/unittest/BUILD.gn b/services/distributed/test/unittest/BUILD.gn index 0dd4677ed185032607fdea95039ff89bcf35c959..7ff0808239442b7059938be8a547d757bae71bd2 100644 --- a/services/distributed/test/unittest/BUILD.gn +++ b/services/distributed/test/unittest/BUILD.gn @@ -37,7 +37,6 @@ ohos_unittest("ans_distributed_unit_test") { module_out_path = "${component_name}/unittest" include_dirs = [ "/${services_path}/distributed/include", - "${ffrt_path}/interfaces/kits", ] sources = [ @@ -382,7 +381,6 @@ ohos_unittest("distributed_notification_manager_branch_test") { module_out_path = "${component_name}/unittest" include_dirs = [ "/${services_path}/distributed/include", - "${ffrt_path}/interfaces/kits", ] sources = [ diff --git a/services/reminder/BUILD.gn b/services/reminder/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f4d1518a54c23fa441f6c20f911e6cfde43cc202 --- /dev/null +++ b/services/reminder/BUILD.gn @@ -0,0 +1,281 @@ +# Copyright (c) 2021-2024 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. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") + +group("reminder_service") { + deps = [ ":libreminder" ] +} + +config("public_reminder_config") { + include_dirs = [ + "${services_path}/reminder/include", + "${core_path}/include", + ] +} + +ohos_source_set("reminder_service_sources") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + + cflags = [ + "-fno-math-errno", + "-fno-unroll-loops", + "-fmerge-all-constants", + "-fno-ident", + "-Oz", + "-flto", + "-ffunction-sections", + "-fdata-sections", + ] + + include_dirs = [ "${services_path}/reminder/include" ] + + defines = [] + + sources = [ + "src/reminder_notification_inline.cpp", + "src/reminder_access_token_helper.cpp", + "src/reminder_os_account_manager_helper.cpp", + "src/reminder_bundle_manager_helper.cpp", + "src/reminder_service.cpp", + "src/reminder_service_ability.cpp", + "src/reminder_config_change_observer.cpp", + "src/reminder_data_manager.cpp", + "src/reminder_data_manager_inner.cpp", + "src/reminder_event_manager.cpp", + "src/reminder_store.cpp", + "src/reminder_store_strategy.cpp", + "src/reminder_table.cpp", + "src/reminder_table_old.cpp", + "src/reminder_timer_info.cpp", + ] + + deps = [ + "${frameworks_module_reminder_path}:reminder_innerkits", + "${frameworks_module_ans_path}:ans_innerkits" + ] + + if (is_double_framework) { + cflags += [ "-DCONFIG_DUAL_FRAMEWORK" ] + } + + if (distributed_notification_supported) { + defines += [ "DISTRIBUTED_NOTIFICATION_SUPPORTED" ] + deps += [ "${services_path}/distributed:libans_distributed" ] + include_dirs += [ "${services_path}/distributed/include" ] + } + + if (notification_smart_reminder_supported) { + defines += [ "NOTIFICATION_SMART_REMINDER_SUPPORTED" ] + } + + external_deps = [ + "ability_base:configuration", + "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "ability_runtime:appkit_native", + "ability_runtime:dataobs_manager", + "ability_runtime:extension_manager", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "config_policy:configpolicy_util", + "data_share:datashare_common", + "data_share:datashare_consumer", + "data_share:datashare_permission", + "device_manager:devicemanagersdk", + "ffrt:libffrt", + "i18n:intl_util", + "image_framework:image_native", + "init:libbegetutil", + "kv_store:distributeddata_inner", + "openssl:libcrypto_shared", + "os_account:os_account_innerkits", + "relational_store:native_rdb", + "resource_management:global_resmgr", + "time_service:time_client", + ] + external_deps += component_external_deps + + if (device_usage) { + external_deps += [ "device_usage_statistics:usagestatsinner" ] + defines += [ "DEVICE_USAGE_STATISTICS_ENABLE" ] + } + + if (hisysevent_usage) { + cflags += [ "-DHAS_HISYSEVENT_PART" ] + external_deps += [ "hisysevent:libhisysevent" ] + } + + if (standby_enable) { + external_deps += [ "device_standby:standby_innerkits" ] + defines += [ "DEVICE_STANDBY_ENABLE" ] + } + + if (player_framework) { + external_deps += [ "player_framework:media_client" ] + defines += [ "PLAYER_FRAMEWORK_ENABLE" ] + } + + if (ans_hitrace_usage) { + external_deps += [ "hitrace:hitrace_meter" ] + defines += [ "HITRACE_METER_ENABLE" ] + } + + if (ans_config_policy_enable) { + external_deps += [ "config_policy:configpolicy_util" ] + defines += [ "CONFIG_POLICY_ENABLE" ] + } + + if (screenlock_mgr_enable) { + external_deps += [ "screenlock_mgr:screenlock_client" ] + defines += [ "SCREENLOCK_MGR_ENABLE" ] + } + + if (distributed_notification_service_feature_summary) { + defines += [ "ENABLE_ANS_EXT_WRAPPER" ] + } + + if (telephony_cust) { + defines += [ "ENABLE_ANS_TELEPHONY_CUST_WRAPPER" ] + } + + if (distributed_notification_service_feature_disable_fa_model) { + defines += [ "ANS_DISABLE_FA_MODEL" ] + } + + if (is_emulator) { + defines += [ "IS_EMULATOR" ] + } + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +ohos_shared_library("libreminder") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + + shlib_type = "sa" + version_script = "libreminder.map" + cflags = [ + "-fno-math-errno", + "-fno-unroll-loops", + "-fmerge-all-constants", + "-fno-ident", + "-Oz", + "-flto", + "-ffunction-sections", + "-fdata-sections", + ] + sources = [] + + configs = [ ":public_reminder_config" ] + + defines = [] + + if (is_double_framework) { + cflags += [ "-DCONFIG_DUAL_FRAMEWORK" ] + } + + deps = [ + "${services_path}/reminder:reminder_service_sources", + ] + + if (distributed_notification_supported) { + deps += [ "${services_path}/distributed:libans_distributed" ] + } + + external_deps = [ + "ability_base:configuration", + "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "ability_runtime:appkit_native", + "ability_runtime:dataobs_manager", + "ability_runtime:extension_manager", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "config_policy:configpolicy_util", + "data_share:datashare_common", + "data_share:datashare_consumer", + "data_share:datashare_permission", + "device_manager:devicemanagersdk", + "ffrt:libffrt", + "i18n:intl_util", + "image_framework:image_native", + "init:libbegetutil", + "kv_store:distributeddata_inner", + "openssl:libcrypto_shared", + "os_account:os_account_innerkits", + "relational_store:native_rdb", + "resource_management:global_resmgr", + "time_service:time_client", + ] + external_deps += component_external_deps + + if (device_usage) { + external_deps += [ "device_usage_statistics:usagestatsinner" ] + } + + if (hisysevent_usage) { + cflags += [ "-DHAS_HISYSEVENT_PART" ] + external_deps += [ "hisysevent:libhisysevent" ] + } + + if (standby_enable) { + external_deps += [ "device_standby:standby_innerkits" ] + } + + if (player_framework) { + external_deps += [ "player_framework:media_client" ] + } + + if (ans_hitrace_usage) { + external_deps += [ "hitrace:hitrace_meter" ] + } + + if (ans_config_policy_enable) { + external_deps += [ "config_policy:configpolicy_util" ] + } + + if (screenlock_mgr_enable) { + external_deps += [ "screenlock_mgr:screenlock_client" ] + } + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + diff --git a/services/reminder/include/reminder_access_token_helper.h b/services/reminder/include/reminder_access_token_helper.h new file mode 100644 index 0000000000000000000000000000000000000000..ea0afa2257250858bbf2f22409b53da9eb55ac5b --- /dev/null +++ b/services/reminder/include/reminder_access_token_helper.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022 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_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_ACCESS_TOKEN_HELPER_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_ACCESS_TOKEN_HELPER_H + +#include +#include "refbase.h" + +#include "accesstoken_kit.h" + +namespace OHOS { +namespace Notification { +class ReminderAccessTokenHelper { +public: + static bool IsSystemApp(); + static bool VerifyNativeToken(const OHOS::Security::AccessToken::AccessTokenID &callerToken); +private: +}; +} // namespace Notification +} // namespace OHOS +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_REMINDER_ACCESS_TOKEN_HELPER_H \ No newline at end of file diff --git a/services/reminder/include/reminder_bundle_manager_helper.h b/services/reminder/include/reminder_bundle_manager_helper.h new file mode 100644 index 0000000000000000000000000000000000000000..9763f19e8b70d0f984612957b566fc383f2db4ff --- /dev/null +++ b/services/reminder/include/reminder_bundle_manager_helper.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2021-2023 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 NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_BUNDLE_MANAGER_HELPER_H +#define NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_BUNDLE_MANAGER_HELPER_H + +#include +#include +#include + +#include "bundle_mgr_interface.h" +#include "ipc_skeleton.h" +#include "iremote_object.h" +#include "refbase.h" +#include "remote_death_recipient.h" +#include "singleton.h" + +namespace OHOS { +namespace Notification { +class ReminderBundleManagerHelper : public DelayedSingleton { +public: + /** + * @brief Obtains the bundle name base on the specified uid. + * + * @param uid Indicates the specified uid. + * @return Returns the bundle name. + */ + std::string GetBundleNameByUid(int32_t uid); + + /** + * @brief Obtains the default uid. + * + * @param bundle Indicates the bundle name. + * @param userId Indicates the user id. + * @return Returns the uid. + */ + int32_t GetDefaultUidByBundleName(const std::string &bundle, const int32_t userId); + + /** + * @brief Obtains bundle info by bundle name. + * + * @param bundleName Indicates the bundle name. + * @param flag Indicates the bundle flag. + * @param bundleInfo Indicates the bundle info. + * @param userId Indicates the user id. + * @return Returns the check result. + */ + bool GetBundleInfo(const std::string &bundleName, const AppExecFwk::BundleFlag flag, + int32_t userId, AppExecFwk::BundleInfo &bundleInfo); + + /** + * @brief Obtains the app index by uid. + * @param uid Indicates uid. + * @return Returns the query result if succeed, retrun 0(main index) otherwise. + */ + int32_t GetAppIndexByUid(const int32_t uid); + +private: + void Connect(); + void Disconnect(); + + void OnRemoteDied(const wptr &object); + +private: + sptr bundleMgr_ = nullptr; + std::mutex connectionMutex_; + sptr deathRecipient_ = nullptr; + + DECLARE_DELAYED_SINGLETON(ReminderBundleManagerHelper) +}; +} // namespace Notification +} // namespace OHOS +#endif // NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_BUNDLE_MANAGER_HELPER_H diff --git a/services/ans/include/reminder_config_change_observer.h b/services/reminder/include/reminder_config_change_observer.h similarity index 92% rename from services/ans/include/reminder_config_change_observer.h rename to services/reminder/include/reminder_config_change_observer.h index c7981b0b8578495789a70b7747b616224cf59b84..982b7ddb1fffef61c9ae26bd9daf4fa2ffdc938c 100644 --- a/services/ans/include/reminder_config_change_observer.h +++ b/services/reminder/include/reminder_config_change_observer.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_REMINDER_CONFIG_CHANGE_OBSERVER_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_REMINDER_CONFIG_CHANGE_OBSERVER_H +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_CONFIG_CHANGE_OBSERVER_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_CONFIG_CHANGE_OBSERVER_H #include "configuration_observer_stub.h" diff --git a/services/ans/include/reminder_data_manager.h b/services/reminder/include/reminder_data_manager.h similarity index 88% rename from services/ans/include/reminder_data_manager.h rename to services/reminder/include/reminder_data_manager.h index ee4f53f3ec45fcc3270a0456941b05cf0a791fda..db3d427ae16fce8360c8468d05dbfa036eeba3de 100644 --- a/services/ans/include/reminder_data_manager.h +++ b/services/reminder/include/reminder_data_manager.h @@ -13,13 +13,13 @@ * limitations under the License. */ -#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_REMINDER_DATA_MANAGER_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_REMINDER_DATA_MANAGER_H +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_DATA_MANAGER_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_DATA_MANAGER_H #include #include -#include "advanced_notification_service.h" +#include "reminder_service.h" #include "ans_inner_errors.h" #ifdef PLAYER_FRAMEWORK_ENABLE #include "player.h" @@ -56,8 +56,7 @@ public: * @param uid Indicates the uid which the bundle belong to. * @return ERR_OK if success, else not. */ - ErrCode CancelAllReminders(const std::string& packageName, const int32_t userId, - const int32_t uid); + ErrCode CancelAllReminders(const std::string& packageName, const int32_t userId, const int32_t uid); /** * @brief Cancels the target reminder relative to the reminder id and bundle option. @@ -66,10 +65,10 @@ public: * @param bundleOption Indicates the bundle option. * @return ERR_OK if success, else not. */ - ErrCode CancelReminder(const int32_t &reminderId, const sptr &bundleOption); + ErrCode CancelReminder(const int32_t &reminderId, const int32_t callingUid); sptr CheckExcludeDateParam(const int32_t reminderId, - const sptr &bundleOption); + const int32_t callingUid); /** * @brief Add exclude date for reminder @@ -78,8 +77,8 @@ public: * @param date exclude date * @return Returns ERR_OK on success, others on failure. */ - ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date, - const sptr &bundleOption); + ErrCode AddExcludeDate(const int32_t reminderId, const int64_t date, + const int32_t callingUid); /** * @brief Clear exclude date for reminder @@ -87,7 +86,7 @@ public: * @param reminderId Identifies the reminders id. * @return Returns ERR_OK on success, others on failure. */ - ErrCode DelExcludeDates(const int32_t reminderId, const sptr &bundleOption); + ErrCode DelExcludeDates(const int32_t reminderId, const int32_t callingUid); /** * @brief Get exclude date for reminder @@ -96,8 +95,8 @@ public: * @param dates exclude dates * @return Returns ERR_OK on success, others on failure. */ - ErrCode GetExcludeDates(const int32_t reminderId, const sptr &bundleOption, - std::vector& dates); + ErrCode GetExcludeDates(const int32_t reminderId, const int32_t callingUid, + std::vector& dates); /** * @brief Close the target reminder which is showing on panel. @@ -121,8 +120,7 @@ public: * @return Single instance of ReminderDataManager. */ static std::shared_ptr GetInstance(); - static std::shared_ptr InitInstance( - const sptr &advancedNotificationService); + static std::shared_ptr InitInstance(); /** * Obtains all the valid reminders (which are not expired) relative to the bundle option. @@ -131,7 +129,7 @@ public: * @param[out] reminders return the valid reminders. */ void GetValidReminders( - const sptr &bundleOption, std::vector> &reminders); + const int32_t callingUid, std::vector &reminders); /** * @brief Inits and recovery data from database. @@ -174,7 +172,7 @@ public: * * @param bundleOption Indicates the bundleOption of third party application. */ - void OnProcessDiedLocked(const sptr &bundleOption); + void OnProcessDiedLocked(const int32_t callingUid); /** * Publishs a scheduled reminder. @@ -184,7 +182,7 @@ public: * @return ERR_OK if success, else not. */ ErrCode PublishReminder(const sptr &reminder, - const sptr &bundleOption); + const int32_t callingUid); /** * @brief Refresh all reminders when date/time or timeZone of device changed by user. @@ -193,13 +191,6 @@ public: */ void RefreshRemindersDueToSysTimeChange(uint8_t type); - /** - * @brief Indicates the single instance of ans that used to execute operations in service. - * - * @param Indicates the single instance of ans notification service. - */ - void SetService(sptr &advancedNotificationService); - bool ShouldAlert(const sptr &reminder) const; /** @@ -275,6 +266,12 @@ public: */ bool IsSystemReady(); + int32_t QueryActiveReminderCount(); + + void ReceiveLoadReminderEvent(); + + void StartReminderLoadTimer(); + static constexpr uint8_t TIME_ZONE_CHANGE = 0; static constexpr uint8_t DATE_TIME_CHANGE = 1; @@ -361,7 +358,8 @@ private: * @param packageName Indicates the packageName need to cancel. * @param userId Indicates the userId to cancel. */ - void CancelRemindersImplLocked(const std::string &packageName, const int32_t userId, const int32_t uid); + void CancelRemindersImplLocked(const std::string& bundleName, + const int32_t userId, const int32_t uid, bool isCancelAllPackage = false); /** * @brief Close reminders with the same group id. @@ -386,8 +384,8 @@ private: * @param bundleName Indicates the target bundle. * @return true if number limit is exceeded. */ - bool CheckReminderLimitExceededLocked(const sptr &bundleOption, - const sptr &reminder) const; + bool CheckReminderLimitExceededLocked(const int32_t callingUid, + const sptr& reminder) const; void CloseReminder(const sptr &reminder, bool cancelNotification); /** @@ -404,8 +402,6 @@ private: void GetImmediatelyShowRemindersLocked(std::vector> &reminders) const; - std::string GetSoundUri(const sptr &reminder); - /** * Find the reminder from reminderVector_ by reminder id. * @@ -414,16 +410,6 @@ private: */ sptr FindReminderRequestLocked(const int32_t &reminderId); - /** - * Find the reminder from {@link reminderVector_} and - * {@link notificationBundleOptionMap_} by reminder id and pkgName. - * - * @param reminderId Indicates the reminder id. - * @param pkgName Indicates the package name. - * @return pointer of reminder request or nullptr. - */ - sptr FindReminderRequestLocked(const int32_t &reminderId, const std::string &pkgName); - /** * Obtains the recent reminder which is not expired from reminder vector. * @@ -462,9 +448,8 @@ private: * @param other Indicates the bundleOption of second reminder. * @return true if the two reminders belong to the same application. */ - bool IsBelongToSameApp(const sptr &bundleOption, - const sptr &other) const; - bool CheckIsSameApp(const sptr &reminder, const sptr &other) const; + bool IsBelongToSameApp(const int32_t uidSrc, const int32_t uidTar) const; + bool CheckIsSameApp(const sptr &reminder, const int32_t callingUid) const; /** * @brief Judges whether the reminder is matched with the bundleOption or userId. @@ -475,8 +460,8 @@ private: * @param uid Indicates the uid. * @return true If the reminder is matched with the bundleOption or userId. */ - bool IsMatched(const sptr &reminder, const std::string &packageName, - const int32_t userId, const int32_t uid) const; + bool IsMatched(const sptr &reminder, const int32_t userId, const int32_t uid, + bool isCancelAllPackage = false) const; /** * @brief Judges whether the reminder is matched with the packageName or groupId. @@ -605,12 +590,10 @@ private: * @brief Assign unique reminder id and save reminder in memory. * * @param reminder Indicates a reminder. - * @param bundleOption Indicates bundle option relative to the reminder. */ - void UpdateAndSaveReminderLocked( - const sptr &reminder, const sptr &bundleOption); + void UpdateAndSaveReminderLocked(const sptr &reminder); - void UpdateNotification(const sptr &reminder, bool isSnooze); + NotificationRequest CreateNotificationRequest(const sptr &reminder, bool isSnooze); static bool cmp(sptr &reminderRequest, sptr &other); @@ -662,6 +645,8 @@ private: */ void ReportSysEvent(const sptr& reminder); + int64_t CreateReminderLoadTimer(const sptr timer); + /** * Single instance. */ @@ -734,7 +719,6 @@ private: */ int16_t totalCount_ {0}; int currentUserId_ {0}; - sptr advancedNotificationService_ = nullptr; std::shared_ptr store_ = nullptr; /** @@ -757,7 +741,10 @@ private: * Sa ready flag */ std::atomic saReadyFlag_{ 0 }; + + std::mutex timeLoadMutex_; + int32_t reminderLoadtimerId_ {0}; }; } // namespace OHOS } // namespace Notification -#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_REMINDER_DATA_MANAGER_H +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_DATA_MANAGER_H diff --git a/services/ans/include/reminder_event_manager.h b/services/reminder/include/reminder_event_manager.h similarity index 91% rename from services/ans/include/reminder_event_manager.h rename to services/reminder/include/reminder_event_manager.h index 415d0a5c091be7c72e2c304e70c1c90ce71ca2f2..b6e875d4267c533f410e9d6f0afdbc3d56891659 100644 --- a/services/ans/include/reminder_event_manager.h +++ b/services/reminder/include/reminder_event_manager.h @@ -13,9 +13,10 @@ * limitations under the License. */ -#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_REMINDER_EVENT_MANAGER_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_REMINDER_EVENT_MANAGER_H +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_EVENT_MANAGER_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_EVENT_MANAGER_H +#include "reminder_service.h" #include "common_event_subscriber.h" #include "reminder_data_manager.h" #include "system_ability_status_change_stub.h" @@ -44,6 +45,7 @@ public: private: sptr GetBundleOption(const OHOS::EventFwk::Want &want) const; + int32_t GetUid(const OHOS::EventFwk::Want &want) const; void HandlePackageRemove(const EventFwk::Want &want) const; void HandleProcessDied(const EventFwk::Want &want) const; std::shared_ptr reminderDataManager_ = nullptr; @@ -97,4 +99,4 @@ private: }; } // namespace OHOS } // namespace Notification -#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_REMINDER_EVENT_MANAGER_H +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_EVENT_MANAGER_H diff --git a/services/reminder/include/reminder_os_account_manager_helper.h b/services/reminder/include/reminder_os_account_manager_helper.h new file mode 100644 index 0000000000000000000000000000000000000000..16f4433571cb3da9c08a4c50b219f10b6a085a09 --- /dev/null +++ b/services/reminder/include/reminder_os_account_manager_helper.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 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 DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_OS_ACCOUNT_MANAGER_HELPER_H +#define DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_OS_ACCOUNT_MANAGER_HELPER_H + +#include "errors.h" +#include "singleton.h" +#include + +namespace OHOS { +namespace Notification { +class ReminderOsAccountManagerHelper : public DelayedSingleton { +public: + + ReminderOsAccountManagerHelper() = default; + ~ReminderOsAccountManagerHelper() = default; + + /** + * @brief Get OsAccountManagerHelper instance object. + */ + static ReminderOsAccountManagerHelper &GetInstance(); + + /** + * Gets operating system account local ID from uid. + * + * @param uid Indicates the uid. + * @param id Indicates the account ID. + * @return Returns result code. + */ + ErrCode GetOsAccountLocalIdFromUid(const int32_t uid, int32_t &id); + + /** + * Gets operating system account local ID from current active. + * + * @param id Indicates the current active account ID. + * @return Returns result code. + */ + ErrCode GetCurrentActiveUserId(int32_t &id); +}; +} // namespace OHOS +} // namespace Notification +#endif // DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_OS_ACCOUNT_MANAGER_HELPER_H \ No newline at end of file diff --git a/services/reminder/include/reminder_service.h b/services/reminder/include/reminder_service.h new file mode 100644 index 0000000000000000000000000000000000000000..781c42db3b5e7f5bcab1dadfec9adeb8ddb19440 --- /dev/null +++ b/services/reminder/include/reminder_service.h @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2021-2024 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_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_SERVICE_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_SERVICE_H + +#include +#include +#include +#include +#include + +#include "event_handler.h" +#include "event_runner.h" +#include "ffrt.h" +#include "refbase.h" + +#include "ans_const_define.h" +#include "reminder_service_stub.h" + +namespace OHOS { +namespace Notification { + +static const uint32_t DEFAULT_SLOT_FLAGS = 59; // 0b111011 +class ReminderService final : public ReminderServiceStub, + public std::enable_shared_from_this { +public: + + ~ReminderService() override = default; + + DISALLOW_COPY_AND_MOVE(ReminderService); + + /** + * @brief Get the instance of service. + * + * @return Returns the instance. + */ + static sptr GetInstance(); + + /** + * @brief Check reminder permission + */ + bool CheckReminderPermission(); + + /** + * @brief Publishes a reminder notification. + * + * @param reminder Identifies the reminder notification request that needs to be published. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode PublishReminder(const ReminderRequest &reminder, int32_t& reminderId) override; + + /** + * @brief Cancel a reminder notifications. + * + * @param reminderId Identifies the reminders id that needs to be canceled. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode CancelReminder(const int32_t reminderId) override; + + /** + * @brief Get all valid reminder notifications. + * + * @param reminders Identifies the list of all valid notifications. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode GetValidReminders(std::vector &reminders) override; + + /** + * @brief Cancel all reminder notifications. + * + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode CancelAllReminders() override; + + /** + * @brief Add exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param date exclude date + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode AddExcludeDate(const int32_t reminderId, const int64_t date) override; + + /** + * @brief Clear exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode DelExcludeDates(const int32_t reminderId) override; + + /** + * @brief Get exclude date for reminder + * + * @param reminderId Identifies the reminders id. + * @param dates exclude dates + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode GetExcludeDates(const int32_t reminderId, std::vector& dates) override; + + void TryPostDelayUnloadTask(int64_t delayTime); +private: + ReminderService() = default; + + void PostDelayUnloadTask(); + + sptr CreateTarReminderRequest(const ReminderRequest &reminder); + + ErrCode InitReminderRequest(sptr& tarReminder, const std::string& bundle, + const int32_t callingUid); +private: + ffrt::task_handle tryUnloadTask_ = nullptr; + static sptr instance_; + static std::mutex instanceMutex_; + + static std::mutex unloadMutex_; +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_SERVICE_H diff --git a/services/reminder/include/reminder_service_ability.h b/services/reminder/include/reminder_service_ability.h new file mode 100644 index 0000000000000000000000000000000000000000..22251347c13366e55694abf3155642bd0b183803 --- /dev/null +++ b/services/reminder/include/reminder_service_ability.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 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_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_SERVICE_ABILITY_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_SERVICE_ABILITY_H + +#include "system_ability.h" + +#include "reminder_service.h" +#include "reminder_data_manager.h" +#include "system_ability_definition.h" + +namespace OHOS { +namespace Notification { +class ReminderServiceAbility final : public SystemAbility { +public: + /** + * @brief The constructor of service ability. + * + * @param systemAbilityId Indicates the system ability id. + * @param runOnCreate Run the system ability on created. + */ + ReminderServiceAbility(const int32_t systemAbilityId, bool runOnCreate); + + /** + * @brief The deconstructor. + */ + ~ReminderServiceAbility() final; + + DISALLOW_COPY_AND_MOVE(ReminderServiceAbility); + DECLARE_SYSTEM_ABILITY(ReminderServiceAbility); + +private: + void OnStart() final; + void OnStop() final; + +private: + sptr service_; + std::shared_ptr reminderAgent_; +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_SERVICE_ABILITY_H diff --git a/services/ans/include/reminder_store.h b/services/reminder/include/reminder_store.h similarity index 88% rename from services/ans/include/reminder_store.h rename to services/reminder/include/reminder_store.h index ac81e8e25d1b448cec5f4f4d8a590378338f4eb1..b80fb1c5932293b806893d044cffc8165ed76934 100644 --- a/services/ans/include/reminder_store.h +++ b/services/reminder/include/reminder_store.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_STORE_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_STORE_H +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_STORE_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_STORE_H #include @@ -37,8 +37,10 @@ public: int32_t Delete(const int32_t reminderId); int32_t Delete(const std::string& pkg, const int32_t userId, const int32_t uid); int32_t DeleteUser(const int32_t userId); - int32_t UpdateOrInsert(const sptr& reminder, const sptr& bundleOption); + int32_t UpdateOrInsert(const sptr& reminder); int32_t GetMaxId(); + int32_t QueryActiveReminderCount(); + std::vector> GetHalfHourReminders(); std::vector> GetAllValidReminders(); public: @@ -74,8 +76,8 @@ private: int32_t InitData(); int32_t DeleteBase(const std::string& deleteCondition); int32_t Delete(const std::string& baseCondition, const std::string& assoConditon); - int32_t Insert(const sptr& reminder, const sptr& bundleOption); - int32_t Update(const sptr& reminder, const sptr& bundleOption); + int32_t Insert(const sptr& reminder); + int32_t Update(const sptr& reminder); bool IsReminderExist(const sptr& reminder); std::vector> GetReminders(const std::string& queryCondition); @@ -106,4 +108,4 @@ private: }; } // namespace Notification } // namespace OHOS -#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_STORE_H \ No newline at end of file +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_STORE_H \ No newline at end of file diff --git a/services/ans/include/reminder_store_strategy.h b/services/reminder/include/reminder_store_strategy.h similarity index 97% rename from services/ans/include/reminder_store_strategy.h rename to services/reminder/include/reminder_store_strategy.h index 0d0ccefb6af063a12c980bddde7af739176e9f5c..daadfdd925ed915a6e60b8db0487fdcf9cd0a73d 100644 --- a/services/ans/include/reminder_store_strategy.h +++ b/services/reminder/include/reminder_store_strategy.h @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_REMINDER_STORE_STRATEGY_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_REMINDER_STORE_STRATEGY_H +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_STORE_STRATEGY_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_STORE_STRATEGY_H #include #include @@ -190,4 +190,4 @@ void ReminderStrategy::GetRdbValue(const std::shared_ptr& } } // namespace Notification } // namespace OHOS -#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_REMINDER_STORE_STRATEGY_H \ No newline at end of file +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_STORE_STRATEGY_H \ No newline at end of file diff --git a/services/ans/include/reminder_table.h b/services/reminder/include/reminder_table.h similarity index 94% rename from services/ans/include/reminder_table.h rename to services/reminder/include/reminder_table.h index 4542000cd648a97c81f51a5c299c73dc0f09f072..7a174f87bb67de5a3e38bab7ba3a8b10763da75f 100644 --- a/services/ans/include/reminder_table.h +++ b/services/reminder/include/reminder_table.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_TABLE_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_TABLE_H +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_TABLE_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_TABLE_H #include #include @@ -269,4 +269,4 @@ public: }; } // namespace Notification } // namespace OHOS -#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_TABLE_H +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_TABLE_H diff --git a/services/ans/include/reminder_table_old.h b/services/reminder/include/reminder_table_old.h similarity index 93% rename from services/ans/include/reminder_table_old.h rename to services/reminder/include/reminder_table_old.h index 172541b490fa9265a5dab16416d00fffa2e7274b..77c228fd1fd062db79cb93786d10b6cc9c961abf 100644 --- a/services/ans/include/reminder_table_old.h +++ b/services/reminder/include/reminder_table_old.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_TABLE_OLD_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_TABLE_OLD_H +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_TABLE_OLD_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_TABLE_OLD_H #include #include @@ -236,4 +236,4 @@ private: }; } // namespace Notification } // namespace OHOS -#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_TABLE_OLD_H +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_TABLE_OLD_H diff --git a/services/ans/include/reminder_timer_info.h b/services/reminder/include/reminder_timer_info.h similarity index 85% rename from services/ans/include/reminder_timer_info.h rename to services/reminder/include/reminder_timer_info.h index 5ffc5b34a568c9801e28f40b4288b94e31e84230..28c05a7ba6a18b5f7bb9785033a9478999035551 100644 --- a/services/ans/include/reminder_timer_info.h +++ b/services/reminder/include/reminder_timer_info.h @@ -13,10 +13,10 @@ * limitations under the License. */ -#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_REMINDER_TIMER_INFO_H -#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_REMINDER_TIMER_INFO_H +#ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_TIMER_INFO_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_TIMER_INFO_H -#include "advanced_notification_service.h" +#include "reminder_service.h" #include "itimer_info.h" #include "notification_request.h" #include "reminder_request.h" @@ -85,4 +85,4 @@ private: } // namespace OHOS } // namespace Notification -#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_REMINDER_TIMER_INFO_H +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_TIMER_INFO_H diff --git a/services/reminder/include/remote_death_recipient.h b/services/reminder/include/remote_death_recipient.h new file mode 100644 index 0000000000000000000000000000000000000000..4c7cddcbe2821a27ce647c0ec810930138061214 --- /dev/null +++ b/services/reminder/include/remote_death_recipient.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2021-2022 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_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMOTE_DEATH_RECIPIENT_H +#define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMOTE_DEATH_RECIPIENT_H + +#include + +#include "iremote_object.h" +#include "refbase.h" + +namespace OHOS { +namespace Notification { +class RemoteDeathRecipient : public IRemoteObject::DeathRecipient { +public: + /** + * The constructor. + * @param callback Indicates the callback. + */ + explicit RemoteDeathRecipient(std::function &)> callback) + { + callback_ = callback; + } + + /** + * The deconstructor. + */ + ~RemoteDeathRecipient() + { + callback_ = nullptr; + } + + /** + * Obtains the death event. Inherited from IRemoteObject::DeathRecipient. + * @param object Indicates the death object. + */ + void OnRemoteDied(const wptr &object) + { + if (callback_ != nullptr) { + callback_(object); + } + } + +private: + std::function &)> callback_; +}; +} // namespace Notification +} // namespace OHOS + +#endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMOTE_DEATH_RECIPIENT_H \ No newline at end of file diff --git a/services/reminder/libreminder.map b/services/reminder/libreminder.map new file mode 100644 index 0000000000000000000000000000000000000000..d9c548487a15f912895df07304a1fc3c57dae4c7 --- /dev/null +++ b/services/reminder/libreminder.map @@ -0,0 +1,38 @@ +# Copyright (c) 2023 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. + +1.0 { + global: + *BundleInfo*; + *BundleManagerHelper*; + *Connect*; + *Delete*; + *Disconnect*; + *GetBundle*; + *GetDefaultUidByBundleName*; + *GetDoNotDisturb*; + *GetInstance*; + *Init*; + *IsAllowedNotify*; + *IsSystemApp*; + *Notification*; + *Notify*; + *OnRemoteDied*; + *Publish*; + *Put*; + *Query*; + *Remove*; + *Subscribe*; + local: + *; +}; diff --git a/services/reminder/sa_profile/1930.json b/services/reminder/sa_profile/1930.json new file mode 100644 index 0000000000000000000000000000000000000000..e2a78eb6b876edd34a911c7adce8ecc45e650195 --- /dev/null +++ b/services/reminder/sa_profile/1930.json @@ -0,0 +1,17 @@ +{ + "process": "foundation", + "systemability": [ + { + "name": 1930, + "libpath": "libreminder.z.so", + "run-on-create": false, + "distributed": false, + "dump_level": 1, + "commonevent":[ + { + "name":"usual.event.BOOT_COMPLETED" + } + ] + } + ] +} diff --git a/services/reminder/sa_profile/BUILD.gn b/services/reminder/sa_profile/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..bd8f445ce751835d8ddd5457aba165cd6ff84a05 --- /dev/null +++ b/services/reminder/sa_profile/BUILD.gn @@ -0,0 +1,19 @@ +# 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. +import("//build/ohos/sa_profile/sa_profile.gni") + +ohos_sa_profile("reminder_sa_profile") { + sources = [ "1930.json" ] + + part_name = "distributed_notification_service" +} diff --git a/services/reminder/src/reminder_access_token_helper.cpp b/services/reminder/src/reminder_access_token_helper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..473427b17c06ac5fc5dd2e4bde79164a77794ca8 --- /dev/null +++ b/services/reminder/src/reminder_access_token_helper.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 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 "reminder_access_token_helper.h" + +#include "ans_log_wrapper.h" +#include "ipc_skeleton.h" +#include "tokenid_kit.h" +#include "reminder_notification_inline.cpp" + +using namespace OHOS::Security::AccessToken; + +namespace OHOS { +namespace Notification { +bool ReminderAccessTokenHelper::IsSystemApp() +{ + AccessTokenID tokenId = IPCSkeleton::GetCallingTokenID(); + ATokenTypeEnum type = AccessTokenKit::GetTokenTypeFlag(tokenId); + if (type == ATokenTypeEnum::TOKEN_HAP) { + uint64_t fullTokenId = IPCSkeleton::GetCallingFullTokenID(); + if (Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(fullTokenId)) { + return true; + } + } + return false; +} + +bool ReminderAccessTokenHelper::VerifyNativeToken(const AccessTokenID &callerToken) +{ + ATokenTypeEnum tokenType = AccessTokenKit::GetTokenTypeFlag(callerToken); + return (tokenType == ATokenTypeEnum::TOKEN_NATIVE); +} +} // namespace Notification +} // namespace OHOS diff --git a/services/reminder/src/reminder_bundle_manager_helper.cpp b/services/reminder/src/reminder_bundle_manager_helper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c9cb370236944ff18551197e482e28227d1bd731 --- /dev/null +++ b/services/reminder/src/reminder_bundle_manager_helper.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2021-2023 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 "reminder_bundle_manager_helper.h" + +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "os_account_manager.h" +#include "system_ability_definition.h" + +#include "ans_const_define.h" +#include "ans_log_wrapper.h" + +namespace OHOS { +namespace Notification { +ReminderBundleManagerHelper::ReminderBundleManagerHelper() +{ + deathRecipient_ = new (std::nothrow) + RemoteDeathRecipient(std::bind(&ReminderBundleManagerHelper::OnRemoteDied, this, std::placeholders::_1)); + if (deathRecipient_ == nullptr) { + ANS_LOGE("Failed to create RemoteDeathRecipient instance"); + } +} + +ReminderBundleManagerHelper::~ReminderBundleManagerHelper() +{ + std::lock_guard lock(connectionMutex_); + Disconnect(); +} + +void ReminderBundleManagerHelper::OnRemoteDied(const wptr &object) +{ + std::lock_guard lock(connectionMutex_); + Disconnect(); +} + +void ReminderBundleManagerHelper::Connect() +{ + if (bundleMgr_ != nullptr) { + return; + } + + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemAbilityManager == nullptr) { + return; + } + + sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (remoteObject == nullptr) { + return; + } + + bundleMgr_ = iface_cast(remoteObject); + if (bundleMgr_ != nullptr) { + bundleMgr_->AsObject()->AddDeathRecipient(deathRecipient_); + } +} + +void ReminderBundleManagerHelper::Disconnect() +{ + if (bundleMgr_ != nullptr) { + bundleMgr_->AsObject()->RemoveDeathRecipient(deathRecipient_); + bundleMgr_ = nullptr; + } +} + +std::string ReminderBundleManagerHelper::GetBundleNameByUid(int32_t uid) +{ + std::string bundle; + + std::lock_guard lock(connectionMutex_); + + Connect(); + + if (bundleMgr_ != nullptr) { + std::string identity = IPCSkeleton::ResetCallingIdentity(); + bundleMgr_->GetNameForUid(uid, bundle); + IPCSkeleton::SetCallingIdentity(identity); + } + + return bundle; +} + +int32_t ReminderBundleManagerHelper::GetDefaultUidByBundleName(const std::string &bundle, const int32_t userId) +{ + int32_t uid = -1; + + std::lock_guard lock(connectionMutex_); + + Connect(); + + if (bundleMgr_ != nullptr) { + std::string identity = IPCSkeleton::ResetCallingIdentity(); + uid = bundleMgr_->GetUidByBundleName(bundle, userId); + if (uid < 0) { + ANS_LOGW("get invalid uid of bundle %{public}s in userId %{public}d", bundle.c_str(), userId); + } + IPCSkeleton::SetCallingIdentity(identity); + } + + return uid; +} + +bool ReminderBundleManagerHelper::GetBundleInfo(const std::string &bundleName, const AppExecFwk::BundleFlag flag, + int32_t userId, AppExecFwk::BundleInfo &bundleInfo) +{ + std::lock_guard lock(connectionMutex_); + + Connect(); + + if (bundleMgr_ == nullptr) { + return false; + } + int32_t callingUserId; + AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(userId, callingUserId); + std::string identity = IPCSkeleton::ResetCallingIdentity(); + bool ret = bundleMgr_->GetBundleInfo(bundleName, flag, bundleInfo, callingUserId); + IPCSkeleton::SetCallingIdentity(identity); + return ret; +} + +int32_t ReminderBundleManagerHelper::GetAppIndexByUid(const int32_t uid) +{ + int32_t appIndex = 0; + std::lock_guard lock(connectionMutex_); + Connect(); + if (nullptr == bundleMgr_) { + return appIndex; + } + std::string bundleName; + std::string identity = IPCSkeleton::ResetCallingIdentity(); + bundleMgr_->GetNameAndIndexForUid(uid, bundleName, appIndex); + IPCSkeleton::SetCallingIdentity(identity); + return appIndex; +} + +} // namespace Notification +} // namespace OHOS diff --git a/services/ans/src/reminder_config_change_observer.cpp b/services/reminder/src/reminder_config_change_observer.cpp similarity index 100% rename from services/ans/src/reminder_config_change_observer.cpp rename to services/reminder/src/reminder_config_change_observer.cpp diff --git a/services/ans/src/reminder_data_manager.cpp b/services/reminder/src/reminder_data_manager.cpp similarity index 84% rename from services/ans/src/reminder_data_manager.cpp rename to services/reminder/src/reminder_data_manager.cpp index 126f393b184c57ea926060943d65e6332745adbd..f9825adf965985e2d571ef6abe490438fe6d74f4 100644 --- a/services/ans/src/reminder_data_manager.cpp +++ b/services/reminder/src/reminder_data_manager.cpp @@ -16,7 +16,6 @@ #include "reminder_data_manager.h" #include "ability_manager_client.h" -#include "access_token_helper.h" #include "ans_log_wrapper.h" #include "ans_const_define.h" #include "common_event_support.h" @@ -30,12 +29,12 @@ #include "ipc_skeleton.h" #include "notification_slot.h" #include "os_account_manager.h" -#include "os_account_manager_helper.h" +#include "reminder_os_account_manager_helper.h" #include "reminder_event_manager.h" #include "time_service_client.h" #include "singleton.h" #include "locale_config.h" -#include "bundle_manager_helper.h" +#include "reminder_bundle_manager_helper.h" #include "datashare_predicates_object.h" #include "datashare_value_object.h" #include "datashare_helper.h" @@ -50,6 +49,8 @@ #ifdef HAS_HISYSEVENT_PART #include "hisysevent.h" #endif +#include "reminder_notification_inline.cpp" +#include "notification_helper.h" namespace OHOS { namespace Notification { @@ -62,6 +63,8 @@ const int REASON_APP_API = 1; const int INDEX_KEY = 0; const int INDEX_TYPE = 1; const int INDEX_VALUE = 2; +const int64_t ONE_MIN_TIME = 60 * 1000; +const int64_t HALF_HOUR = 30 * ONE_MIN_TIME; } /** @@ -82,7 +85,7 @@ std::shared_ptr ReminderDataManager::serviceQueue_ = nullptr; ReminderDataManager::~ReminderDataManager() = default; ErrCode ReminderDataManager::PublishReminder(const sptr &reminder, - const sptr &bundleOption) + const int32_t callingUid) { HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); uint32_t callerTokenId = IPCSkeleton::GetCallingTokenID(); @@ -95,10 +98,10 @@ ErrCode ReminderDataManager::PublishReminder(const sptr &remind return ERR_REMINDER_DATA_SHARE_PERMISSION_DENIED; } - if (CheckReminderLimitExceededLocked(bundleOption, reminder)) { + if (CheckReminderLimitExceededLocked(callingUid, reminder)) { return ERR_REMINDER_NUMBER_OVERLOAD; } - UpdateAndSaveReminderLocked(reminder, bundleOption); + UpdateAndSaveReminderLocked(reminder); queue_->submit([this, reminder]() { StartRecentReminder(); }); @@ -106,16 +109,16 @@ ErrCode ReminderDataManager::PublishReminder(const sptr &remind } ErrCode ReminderDataManager::CancelReminder( - const int32_t &reminderId, const sptr &bundleOption) + const int32_t &reminderId, const int32_t callingUid) { HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); ANSR_LOGI("cancel reminder id: %{public}d", reminderId); - sptr reminder = FindReminderRequestLocked(reminderId, bundleOption->GetBundleName()); + sptr reminder = FindReminderRequestLocked(reminderId); if (reminder == nullptr) { ANSR_LOGW("Cancel reminder, not find the reminder"); return ERR_REMINDER_NOT_EXIST; } - if (!CheckIsSameApp(reminder, bundleOption)) { + if (!CheckIsSameApp(reminder, callingUid)) { ANSR_LOGW("Not find the reminder due to not match"); return ERR_REMINDER_NOT_EXIST; } @@ -137,24 +140,24 @@ ErrCode ReminderDataManager::CancelReminder( return ERR_OK; } -ErrCode ReminderDataManager::CancelAllReminders(const std::string& packageName, const int32_t userId, - const int32_t uid) +ErrCode ReminderDataManager::CancelAllReminders(const std::string& bundleName, + const int32_t userId, const int32_t callingUid) { HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); - ANSR_LOGD("CancelAllReminders, userId=%{private}d, pkgName=%{public}s", userId, packageName.c_str()); - CancelRemindersImplLocked(packageName, userId, uid); + ANSR_LOGD("CancelAllReminders, userId=%{private}d", userId); + CancelRemindersImplLocked(bundleName, userId, callingUid); return ERR_OK; } sptr ReminderDataManager::CheckExcludeDateParam(const int32_t reminderId, - const sptr &bundleOption) + const int32_t callingUid) { sptr reminder = FindReminderRequestLocked(reminderId); if (reminder == nullptr) { ANSR_LOGW("Check reminder failed, not find the reminder"); return nullptr; } - if (!CheckIsSameApp(reminder, bundleOption)) { + if (!CheckIsSameApp(reminder, callingUid)) { ANSR_LOGW("Check reminder failed, due to not match"); return nullptr; } @@ -166,11 +169,11 @@ sptr ReminderDataManager::CheckExcludeDateParam(const int32_t r return reminder; } -ErrCode ReminderDataManager::AddExcludeDate(const int32_t reminderId, const uint64_t date, - const sptr &bundleOption) +ErrCode ReminderDataManager::AddExcludeDate(const int32_t reminderId, const int64_t date, + const int32_t callingUid) { HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); - sptr reminder = CheckExcludeDateParam(reminderId, bundleOption); + sptr reminder = CheckExcludeDateParam(reminderId, callingUid); if (reminder == nullptr) { return ERR_REMINDER_NOT_EXIST; } @@ -178,16 +181,16 @@ ErrCode ReminderDataManager::AddExcludeDate(const int32_t reminderId, const uint std::lock_guard locker(ReminderDataManager::MUTEX); ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); calendar->AddExcludeDate(date); - store_->UpdateOrInsert(reminder, bundleOption); + store_->UpdateOrInsert(reminder); } return ERR_OK; } ErrCode ReminderDataManager::DelExcludeDates(const int32_t reminderId, - const sptr &bundleOption) + const int32_t callingUid) { HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); - sptr reminder = CheckExcludeDateParam(reminderId, bundleOption); + sptr reminder = CheckExcludeDateParam(reminderId, callingUid); if (reminder == nullptr) { return ERR_REMINDER_NOT_EXIST; } @@ -195,16 +198,16 @@ ErrCode ReminderDataManager::DelExcludeDates(const int32_t reminderId, std::lock_guard locker(ReminderDataManager::MUTEX); ReminderRequestCalendar* calendar = static_cast(reminder.GetRefPtr()); calendar->DelExcludeDates(); - store_->UpdateOrInsert(reminder, bundleOption); + store_->UpdateOrInsert(reminder); } return ERR_OK; } ErrCode ReminderDataManager::GetExcludeDates(const int32_t reminderId, - const sptr &bundleOption, std::vector& dates) + const int32_t callingUid, std::vector& dates) { HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); - sptr reminder = CheckExcludeDateParam(reminderId, bundleOption); + sptr reminder = CheckExcludeDateParam(reminderId, callingUid); if (reminder == nullptr) { return ERR_REMINDER_NOT_EXIST; } @@ -217,17 +220,18 @@ ErrCode ReminderDataManager::GetExcludeDates(const int32_t reminderId, } void ReminderDataManager::GetValidReminders( - const sptr &bundleOption, std::vector> &reminders) + const int32_t callingUid, std::vector &reminders) { HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); std::lock_guard lock(ReminderDataManager::MUTEX); - for (auto& eachReminder : reminderVector_) { + auto reminderVector = store_->GetAllValidReminders(); + for (auto& eachReminder : reminderVector) { if (eachReminder->IsExpired()) { continue; } - if (CheckIsSameApp(eachReminder, bundleOption)) { - reminders.push_back(eachReminder); + if (CheckIsSameApp(eachReminder, callingUid)) { + reminders.push_back(*eachReminder); } } } @@ -235,23 +239,23 @@ void ReminderDataManager::GetValidReminders( void ReminderDataManager::CancelAllReminders(const int32_t userId) { ANSR_LOGD("CancelAllReminders, userId=%{private}d", userId); - CancelRemindersImplLocked(ALL_PACKAGES, userId, -1); + CancelRemindersImplLocked(ALL_PACKAGES, userId, -1, true); } -void ReminderDataManager::CancelRemindersImplLocked(const std::string &packageName, const int32_t userId, - const int32_t uid) +void ReminderDataManager::CancelRemindersImplLocked(const std::string& packageName, const int32_t userId, + const int32_t uid, bool isCancelAllPackage) { MUTEX.lock(); { std::lock_guard locker(ReminderDataManager::ACTIVE_MUTEX); - if (activeReminderId_ != -1 && IsMatched(activeReminder_, packageName, userId, uid)) { + if (activeReminderId_ != -1 && IsMatched(activeReminder_, userId, uid, isCancelAllPackage)) { activeReminder_->OnStop(); StopTimer(TimerType::TRIGGER_TIMER); ANSR_LOGD("Stop active reminder, reminderId=%{public}d", activeReminderId_.load()); } } for (auto vit = reminderVector_.begin(); vit != reminderVector_.end();) { - if (IsMatched(*vit, packageName, userId, uid)) { + if (IsMatched(*vit, userId, uid, isCancelAllPackage)) { if ((*vit)->IsAlerting()) { StopAlertingReminder(*vit); } @@ -263,7 +267,7 @@ void ReminderDataManager::CancelRemindersImplLocked(const std::string &packageNa } ++vit; } - if (packageName == ALL_PACKAGES) { + if (isCancelAllPackage) { store_->DeleteUser(userId); } else { store_->Delete(packageName, userId, uid); @@ -287,17 +291,14 @@ bool ReminderDataManager::IsMatchedForGroupIdAndPkgName(const sptr &reminder, - const std::string &packageName, const int32_t userId, const int32_t uid) const + const int32_t userId, const int32_t uid, bool isCancelAllPackage) const { if (reminder->GetUserId() != userId) { return false; } - if (packageName == ALL_PACKAGES) { + if (isCancelAllPackage) { return true; } - if (reminder->GetBundleName() != packageName) { - return false; - } if (uid != -1 && reminder->GetUid() == uid) { return true; } @@ -310,23 +311,14 @@ void ReminderDataManager::CancelNotification(const sptr &remind ANSR_LOGD("No need to cancel notification"); return; } - sptr notification = reminder->GetNotificationRequest(); - if (notification == nullptr) { - ANSR_LOGW("Cancel notification fail"); - return; - } ANSR_LOGD("Cancel notification"); - if (advancedNotificationService_ == nullptr) { - ANSR_LOGE("Cancel notification fail"); - return; - } - sptr bundleOption = reminder->GetNotificationBundleOption(); - advancedNotificationService_->CancelPreparedNotification(notification->GetNotificationId(), - ReminderRequest::NOTIFICATION_LABEL, bundleOption, NotificationConstant::APP_CANCEL_REMINDER_REASON_DELETE); + std::string identity = IPCSkeleton::ResetCallingIdentity(); + NotificationHelper::CancelNotification(ReminderRequest::NOTIFICATION_LABEL, reminder->GetNotificationId()); + IPCSkeleton::SetCallingIdentity(identity); } -bool ReminderDataManager::CheckReminderLimitExceededLocked(const sptr &bundleOption, - const sptr &reminder) const +bool ReminderDataManager::CheckReminderLimitExceededLocked(const int32_t callingUid, + const sptr& reminder) const { std::lock_guard lock(ReminderDataManager::MUTEX); if (totalCount_ >= ReminderDataManager::MAX_NUM_REMINDER_LIMIT_SYSTEM) { @@ -339,7 +331,7 @@ bool ReminderDataManager::CheckReminderLimitExceededLocked(const sptrIsExpired()) { continue; } - if (CheckIsSameApp(eachReminder, bundleOption)) { + if (CheckIsSameApp(eachReminder, callingUid)) { count++; } } @@ -383,15 +375,13 @@ void ReminderDataManager::OnUserSwitch(const int32_t& userId) } } -void ReminderDataManager::OnProcessDiedLocked(const sptr &bundleOption) +void ReminderDataManager::OnProcessDiedLocked(const int32_t callingUid) { - std::string bundleName = bundleOption->GetBundleName(); - int32_t uid = bundleOption->GetUid(); - ANSR_LOGD("OnProcessDiedLocked, bundleName=%{public}s, uid=%{public}d", bundleName.c_str(), uid); + ANSR_LOGD("OnProcessDiedLocked, uid=%{public}d", callingUid); std::lock_guard locker(ReminderDataManager::MUTEX); std::lock_guard lock(ReminderDataManager::SHOW_MUTEX); for (auto it = showedReminderVector_.begin(); it != showedReminderVector_.end(); ++it) { - if ((*it)->GetBundleName() != bundleName || (*it)->GetUid() != uid) { + if ((*it)->GetUid() != callingUid) { continue; } if ((*it)->IsAlerting()) { @@ -402,7 +392,7 @@ void ReminderDataManager::OnProcessDiedLocked(const sptrUpdateOrInsert((*it), bundleOption); + store_->UpdateOrInsert((*it)); } } @@ -485,21 +475,6 @@ sptr ReminderDataManager::FindReminderRequestLocked(const int32 return nullptr; } -sptr ReminderDataManager::FindReminderRequestLocked( - const int32_t &reminderId, const std::string &pkgName) -{ - sptr reminder = FindReminderRequestLocked(reminderId); - std::lock_guard lock(ReminderDataManager::MUTEX); - if (reminder == nullptr) { - return nullptr; - } - if (reminder->GetCreatorBundleName() != pkgName) { - ANSR_LOGW("Not find the reminder due to package name not match"); - return nullptr; - } - return reminder; -} - bool ReminderDataManager::cmp(sptr &reminderRequest, sptr &other) { return reminderRequest->GetTriggerTimeInMilli() < other->GetTriggerTimeInMilli(); @@ -549,7 +524,7 @@ void ReminderDataManager::CloseRemindersByGroupId(const int32_t &oldReminderId, if (IsMatchedForGroupIdAndPkgName(reminder, packageName, groupId)) { reminder->SetExpired(true); reminder->SetStateToInActive(); - store_->UpdateOrInsert(reminder, reminder->GetNotificationBundleOption()); + store_->UpdateOrInsert(reminder); ResetStates(TimerType::TRIGGER_TIMER); ANSR_LOGD("Cancel reminders by groupid, reminder is %{public}s", reminder->Dump().c_str()); } @@ -573,7 +548,7 @@ void ReminderDataManager::CloseReminder(const sptr &reminder, b } reminder->OnClose(true); RemoveFromShowedReminders(reminder); - store_->UpdateOrInsert(reminder, reminder->GetNotificationBundleOption()); + store_->UpdateOrInsert(reminder); if (cancelNotification) { CancelNotification(reminder); } @@ -584,17 +559,62 @@ std::shared_ptr ReminderDataManager::GetInstance() return REMINDER_DATA_MANAGER; } -std::shared_ptr ReminderDataManager::InitInstance( - const sptr &advancedNotificationService) +std::shared_ptr ReminderDataManager::InitInstance() { if (REMINDER_DATA_MANAGER == nullptr) { REMINDER_DATA_MANAGER = std::make_shared(); - REMINDER_DATA_MANAGER->advancedNotificationService_ = advancedNotificationService; ReminderEventManager reminderEventManager(REMINDER_DATA_MANAGER); } return REMINDER_DATA_MANAGER; } +void ReminderDataManager::StartReminderLoadTimer() +{ + sptr timer = MiscServices::TimeServiceClient::GetInstance(); + REMINDER_CHECK_NULL_VOID(timer, "Get timeServiceClient failed"); + std::lock_guard locker(timeLoadMutex_); + if (reminderLoadtimerId_ == 0) { + reminderLoadtimerId_ = CreateReminderLoadTimer(timer); + } + timer->StopTimer(reminderLoadtimerId_); + uint64_t nowMilli = GetCurrentTime() + HALF_HOUR; + timer->StartTimer(reminderLoadtimerId_, nowMilli); +} + +int64_t ReminderDataManager::CreateReminderLoadTimer(const sptr timer) +{ + auto sharedTimerInfo = std::make_shared(); + sharedTimerInfo->SetRepeat(false); + sharedTimerInfo->SetInterval(0); + uint8_t timerTypeWakeup = static_cast(sharedTimerInfo->TIMER_TYPE_WAKEUP); + uint8_t timerTypeExact = static_cast(sharedTimerInfo->TIMER_TYPE_EXACT); + int32_t timerType = static_cast(timerTypeWakeup | timerTypeExact); + sharedTimerInfo->SetType(timerType); + + int32_t requestCode = 10; + std::vector flags; + flags.push_back(AbilityRuntime::WantAgent::WantAgentConstant::Flags::UPDATE_PRESENT_FLAG); + + auto want = std::make_shared(); + want->SetAction(ReminderRequest::REMINDER_EVENT_LOAD_REMINDER); + std::vector> wants; + wants.push_back(want); + AbilityRuntime::WantAgent::WantAgentInfo wantAgentInfo( + requestCode, + AbilityRuntime::WantAgent::WantAgentConstant::OperationType::SEND_COMMON_EVENT, + flags, wants, nullptr); + + std::string identity = IPCSkeleton::ResetCallingIdentity(); + std::shared_ptr wantAgent = + AbilityRuntime::WantAgent::WantAgentHelper::GetWantAgent(wantAgentInfo, 0); + IPCSkeleton::SetCallingIdentity(identity); + + sharedTimerInfo->SetWantAgent(wantAgent); + return timer->CreateTimer(sharedTimerInfo); +} + + + bool ReminderDataManager::CheckUpdateConditions(const sptr &reminder, const ReminderRequest::ActionButtonType &actionButtonType, const std::map &actionButtonMap) @@ -801,48 +821,25 @@ void ReminderDataManager::TerminateAlerting(const sptr &reminde return; } int32_t reminderId = reminder->GetReminderId(); - sptr bundleOption = reminder->GetNotificationBundleOption(); - sptr notificationRequest = reminder->GetNotificationRequest(); - if (bundleOption == nullptr) { - ANSR_LOGE("Get bundle option fail, reminderId=%{public}d", reminderId); - return; - } + int32_t uid = reminder->GetUid(); ANSR_LOGD("publish(update) notification.(reminderId=%{public}d)", reminder->GetReminderId()); - UpdateNotification(reminder, false); - if (advancedNotificationService_ == nullptr) { - ANSR_LOGE("Ans instance is null."); - return; - } - // Set the notification SoundEnabled and VibrationEnabled by soltType - advancedNotificationService_->SetRequestBySlotType(notificationRequest, bundleOption); - advancedNotificationService_->PublishPreparedNotification(notificationRequest, bundleOption); - store_->UpdateOrInsert(reminder, bundleOption); + NotificationRequest notificationRequest = CreateNotificationRequest(reminder, false); + NotificationHelper::PublishNotification(ReminderRequest::NOTIFICATION_LABEL, notificationRequest); + store_->UpdateOrInsert(reminder); } -void ReminderDataManager::UpdateAndSaveReminderLocked( - const sptr &reminder, const sptr &bundleOption) +void ReminderDataManager::UpdateAndSaveReminderLocked(const sptr& reminder) { std::lock_guard lock(ReminderDataManager::MUTEX); reminder->InitReminderId(); - int32_t userId = -1; - OsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(bundleOption->GetUid(), userId); - reminder->InitUserId(userId); - reminder->InitUid(bundleOption->GetUid()); - reminder->InitBundleName(bundleOption->GetBundleName()); if (reminder->GetTriggerTimeInMilli() == ReminderRequest::INVALID_LONG_LONG_VALUE) { ANSR_LOGW("now publish reminder is expired. reminder is =%{public}s", reminder->Dump().c_str()); reminder->SetExpired(true); } - reminder->SetNotificationBundleOption(bundleOption); reminderVector_.push_back(reminder); totalCount_++; - store_->UpdateOrInsert(reminder, bundleOption); -} - -void ReminderDataManager::SetService(sptr &advancedNotificationService) -{ - advancedNotificationService_ = advancedNotificationService; + store_->UpdateOrInsert(reminder); } bool ReminderDataManager::ShouldAlert(const sptr &reminder) const @@ -851,30 +848,26 @@ bool ReminderDataManager::ShouldAlert(const sptr &reminder) con return false; } int32_t reminderId = reminder->GetReminderId(); - sptr bundleOption = reminder->GetNotificationBundleOption(); - if (bundleOption == nullptr) { - ANSR_LOGD("The reminder (reminderId=%{public}d) is silent", reminderId); - return false; - } int32_t userId = -1; - OsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(bundleOption->GetUid(), userId); + ReminderOsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(reminder->GetUid(), userId); if (currentUserId_ != userId) { ANSR_LOGD("The reminder (reminderId=%{public}d) is silent for not in active user, " \ "current user id: %{private}d, reminder user id: %{private}d", reminderId, currentUserId_, userId); return false; } - sptr date; - ErrCode errCode = advancedNotificationService_->GetDoNotDisturbDate(date); + NotificationDoNotDisturbDate date; + ErrCode errCode = NotificationHelper::GetDoNotDisturbDate(date); if (errCode != ERR_OK) { ANSR_LOGE("The reminder (reminderId=%{public}d) is silent for get disturbDate error", reminderId); return true; } - if (date->GetDoNotDisturbType() == NotificationConstant::DoNotDisturbType::NONE) { + if (date.GetDoNotDisturbType() == NotificationConstant::DoNotDisturbType::NONE) { return true; } + auto bundleOption = CreateBundleOption(reminder->GetBundleName(), reminder->GetUid()); std::vector> slots; - errCode = advancedNotificationService_->GetSlotsByBundle(bundleOption, slots); + errCode = NotificationHelper::GetNotificationSlotsForBundle(bundleOption, slots); if (errCode != ERR_OK) { ANSR_LOGE("The reminder (reminderId=%{public}d) is silent for get slots error", reminderId); return false; @@ -1037,36 +1030,23 @@ void ReminderDataManager::ShowReminder(const sptr &reminder, co ANSR_LOGD("Show the reminder(Play sound: %{public}d), %{public}s", static_cast(isNeedToPlaySound), reminder->Dump().c_str()); int32_t reminderId = reminder->GetReminderId(); - sptr bundleOption = reminder->GetNotificationBundleOption(); - sptr notificationRequest = reminder->GetNotificationRequest(); - if (bundleOption == nullptr) { - ANSR_LOGE("Get bundle option fail, reminderId=%{public}d", reminderId); - return; - } - if (advancedNotificationService_ == nullptr) { - ANSR_LOGE("ShowReminder fail"); - reminder->OnShow(false, isSysTimeChanged, false); - store_->UpdateOrInsert(reminder, bundleOption); - return; - } if (!IsAllowedNotify(reminder)) { ANSR_LOGE("Not allow to notify."); reminder->OnShow(false, isSysTimeChanged, false); - store_->UpdateOrInsert(reminder, bundleOption); + store_->UpdateOrInsert(reminder); return; } ReportSysEvent(reminder); bool toPlaySound = isNeedToPlaySound && ShouldAlert(reminder) ? true : false; reminder->OnShow(toPlaySound, isSysTimeChanged, true); AddToShowedReminders(reminder); - UpdateNotification(reminder, false); // this should be called after OnShow + NotificationRequest notificationRequest = CreateNotificationRequest(reminder, false); // this should be called after OnShow if (alertingReminderId_ != -1) { TerminateAlerting(alertingReminder_, "PlaySoundAndVibration"); } - // Set the notification SoundEnabled and VibrationEnabled by soltType - advancedNotificationService_->SetRequestBySlotType(notificationRequest, bundleOption); - ErrCode errCode = advancedNotificationService_->PublishPreparedNotification(notificationRequest, bundleOption); + ErrCode errCode = NotificationHelper::PublishNotification(ReminderRequest::NOTIFICATION_LABEL, + notificationRequest); if (errCode != ERR_OK) { reminder->OnShowFail(); RemoveFromShowedReminders(reminder); @@ -1081,24 +1061,18 @@ void ReminderDataManager::ShowReminder(const sptr &reminder, co } HandleSameNotificationIdShowing(reminder); } - store_->UpdateOrInsert(reminder, bundleOption); + store_->UpdateOrInsert(reminder); if (isNeedToStartNext) { StartRecentReminder(); } } -void ReminderDataManager::UpdateNotification(const sptr &reminder, bool isSnooze) +NotificationRequest ReminderDataManager::CreateNotificationRequest(const sptr &reminder, bool isSnooze) { - if (isSnooze) { - reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::COMMON, "snooze"); - } else { - reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::COMMON, ""); - } - reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::REMOVAL_WANT_AGENT, ""); - reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::WANT_AGENT, ""); - reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::MAX_SCREEN_WANT_AGENT, ""); - reminder->UpdateNotificationRequest(ReminderRequest::UpdateNotificationType::BUNDLE_INFO, ""); + NotificationRequest notificationRequest = reminder->CreateNotificationRequest(); + reminder->UpdateNotificationRequest(notificationRequest, isSnooze); + return notificationRequest; } void ReminderDataManager::SnoozeReminder(const OHOS::EventFwk::Want &want) @@ -1133,24 +1107,12 @@ void ReminderDataManager::SnoozeReminderImpl(sptr &reminder) StopTimerLocked(TimerType::ALERTING_TIMER); } reminder->OnSnooze(); - store_->UpdateOrInsert(reminder, reminder->GetNotificationBundleOption()); + store_->UpdateOrInsert(reminder); // 2) Show the notification dialog in the systemUI - sptr bundleOption = reminder->GetNotificationBundleOption(); - sptr notificationRequest = reminder->GetNotificationRequest(); - if (bundleOption == nullptr) { - ANSR_LOGW("snoozeReminder, invalid bundle option"); - return; - } ANSR_LOGD("publish(update) notification.(reminderId=%{public}d)", reminder->GetReminderId()); - UpdateNotification(reminder, true); - if (advancedNotificationService_ == nullptr) { - ANSR_LOGE("Ans instance is null"); - return; - } - // Set the notification SoundEnabled and VibrationEnabled by soltType - advancedNotificationService_->SetRequestBySlotType(notificationRequest, bundleOption); - advancedNotificationService_->PublishPreparedNotification(notificationRequest, bundleOption); + NotificationRequest notificationRequest = CreateNotificationRequest(reminder, true); + NotificationHelper::PublishNotification(ReminderRequest::NOTIFICATION_LABEL, notificationRequest); StartRecentReminder(); } @@ -1170,14 +1132,14 @@ void ReminderDataManager::StartRecentReminder() { std::lock_guard locker(ReminderDataManager::ACTIVE_MUTEX); activeReminder_->OnStop(); - store_->UpdateOrInsert(activeReminder_, activeReminder_->GetNotificationBundleOption()); + store_->UpdateOrInsert(activeReminder_); } StopTimerLocked(TimerType::TRIGGER_TIMER); } ANSR_LOGI("Start recent reminder"); StartTimerLocked(reminder, TimerType::TRIGGER_TIMER); reminder->OnStart(); - store_->UpdateOrInsert(reminder, reminder->GetNotificationBundleOption()); + store_->UpdateOrInsert(reminder); } void ReminderDataManager::StopAlertingReminder(const sptr &reminder) @@ -1310,10 +1272,10 @@ sptr ReminderDataManager::HandleRefreshReminder(const uint8_t & if (triggerTimeBefore != triggerTimeAfter || reminder->GetReminderId() == alertingReminderId_) { CloseReminder(reminder, true); } - store_->UpdateOrInsert(reminder, reminder->GetNotificationBundleOption()); + store_->UpdateOrInsert(reminder); return nullptr; } - store_->UpdateOrInsert(reminder, reminder->GetNotificationBundleOption()); + store_->UpdateOrInsert(reminder); return reminder; } @@ -1323,11 +1285,6 @@ void ReminderDataManager::HandleSameNotificationIdShowing(const sptrGetNotificationId(); ANSR_LOGD("HandleSameNotificationIdShowing notificationId=%{public}d", notificationId); int32_t curReminderId = reminder->GetReminderId(); - sptr option1 = reminder->GetNotificationBundleOption(); - if (option1 == nullptr) { - ANSR_LOGE("Error occur when get bundle option, reminderId=%{public}d", curReminderId); - return; - } for (auto it = reminderVector_.begin(); it != reminderVector_.end(); ++it) { int32_t tmpId = (*it)->GetReminderId(); @@ -1337,18 +1294,13 @@ void ReminderDataManager::HandleSameNotificationIdShowing(const sptrIsShowing()) { continue; } - sptr bundleOption = (*it)->GetNotificationBundleOption(); - if (bundleOption == nullptr) { - ANSR_LOGW("Get notificationBundleOption(reminderId=%{public}d) fail", tmpId); - continue; - } - if (notificationId == (*it)->GetNotificationId() && IsBelongToSameApp(bundleOption, option1)) { + if (notificationId == (*it)->GetNotificationId() && IsBelongToSameApp((*it)->GetUid(), reminder->GetUid())) { if ((*it)->IsAlerting()) { StopAlertingReminder(*it); } (*it)->OnSameNotificationIdCovered(); RemoveFromShowedReminders(*it); - store_->UpdateOrInsert((*it), bundleOption); + store_->UpdateOrInsert((*it)); } } } @@ -1427,7 +1379,7 @@ void ReminderDataManager::CheckReminderTime(std::vector>& void ReminderDataManager::InitUserId() { currentUserId_ = MAIN_USER_ID; - OsAccountManagerHelper::GetInstance().GetCurrentActiveUserId(currentUserId_); + ReminderOsAccountManagerHelper::GetInstance().GetCurrentActiveUserId(currentUserId_); } bool ReminderDataManager::RegisterConfigurationObserver() @@ -1465,15 +1417,12 @@ bool ReminderDataManager::IsAllowedNotify(const sptr &reminder) if (reminder == nullptr) { return false; } - auto option = reminder->GetNotificationBundleOption(); - if (option == nullptr) { - ANSR_LOGE("Get bundle option occur error, reminderId=%{public}d", reminder->GetReminderId()); - return false; - } bool isAllowed = false; - ErrCode errCode = advancedNotificationService_->IsSpecialBundleAllowedNotify(option, isAllowed); + auto bundleOption = CreateBundleOption(reminder->GetBundleName(), reminder->GetUid()); + + ErrCode errCode = NotificationHelper::IsAllowedNotify(bundleOption, isAllowed); if (errCode != ERR_OK) { - ANSR_LOGE("Failed to call IsSpecialBundleAllowedNotify, errCode=%{public}d", errCode); + ANSR_LOGE("Failed to call IsAllowedNotify, errCode=%{public}d", errCode); return false; } return isAllowed; @@ -1485,47 +1434,38 @@ bool ReminderDataManager::IsReminderAgentReady() const } bool ReminderDataManager::CheckIsSameApp(const sptr &reminder, - const sptr &other) const + const int32_t callingUid) const { std::string bundleName = reminder->GetCreatorBundleName(); int32_t uid = reminder->GetCreatorUid(); if (uid == -1) { - uid = BundleManagerHelper::GetInstance()->GetDefaultUidByBundleName(bundleName, reminder->GetUserId()); + uid = ReminderBundleManagerHelper::GetInstance()->GetDefaultUidByBundleName(bundleName, reminder->GetUserId()); } - return bundleName == other->GetBundleName() && uid == other->GetUid(); + return uid == callingUid; } -bool ReminderDataManager::IsBelongToSameApp(const sptr &bundleOption, - const sptr &other) const +bool ReminderDataManager::IsBelongToSameApp(const int32_t uidSrc, + const int32_t uidTar) const { - int32_t uidSrc = bundleOption->GetUid(); - int32_t uidTar = other->GetUid(); bool result = uidSrc == uidTar; int32_t userIdSrc = -1; - OsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(uidSrc, userIdSrc); + ReminderOsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(uidSrc, userIdSrc); int32_t userIdTar = -1; - OsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(uidTar, userIdTar); + ReminderOsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(uidTar, userIdTar); result = result && (userIdSrc == userIdTar); - result = result && (bundleOption->GetBundleName() == other->GetBundleName()); return result; } +void ReminderDataManager::ReceiveLoadReminderEvent() +{ + LoadReminderFromDb(); +} + void ReminderDataManager::LoadReminderFromDb() { std::lock_guard lock(ReminderDataManager::MUTEX); - std::vector> existReminders = store_->GetAllValidReminders(); + std::vector> existReminders = store_->GetHalfHourReminders(); reminderVector_ = existReminders; - ANSR_LOGD("LoadReminderFromDb, reminder size=%{public}zu", reminderVector_.size()); - for (auto it = reminderVector_.begin(); it != reminderVector_.end(); ++it) { - sptr bundleOption = new (std::nothrow) NotificationBundleOption(); - if (bundleOption == nullptr) { - ANS_LOGE("Failed to create bundle option due to low memory."); - return; - } - bundleOption->SetBundleName((*it)->GetBundleName()); - bundleOption->SetUid((*it)->GetUid()); - (*it)->SetNotificationBundleOption(bundleOption); - } totalCount_ = static_cast(reminderVector_.size()); ReminderRequest::GLOBAL_ID = store_->GetMaxId() + 1; } @@ -1600,29 +1540,6 @@ void ReminderDataManager::PlaySoundAndVibration(const sptr &rem SetAlertingReminder(reminder); } -std::string ReminderDataManager::GetSoundUri(const sptr &reminder) -{ - Uri uri = DEFAULT_NOTIFICATION_SOUND; - if (advancedNotificationService_ == nullptr) { - ANSR_LOGE("Ans instance is null."); - return uri.GetSchemeSpecificPart(); - } - sptr bundle = reminder->GetNotificationBundleOption(); - std::vector> slots; - ErrCode errCode = advancedNotificationService_->GetSlotsByBundle(bundle, slots); - if (errCode != ERR_OK) { - ANSR_LOGW("Get sound uri fail, use default sound instead."); - return uri.GetSchemeSpecificPart(); - } - for (auto it = slots.begin(); it != slots.end(); ++it) { - if ((*it)->GetType() == reminder->GetSlotType()) { - uri = (*it)->GetSound(); - break; - } - } - return uri.GetSchemeSpecificPart(); -} - void ReminderDataManager::StopSoundAndVibrationLocked(const sptr &reminder) { std::lock_guard lock(ReminderDataManager::ALERT_MUTEX); @@ -1904,7 +1821,7 @@ void ReminderDataManager::ClickReminder(const OHOS::EventFwk::Want &want) abilityWant.SetElement(element); abilityWant.SetUri(wantInfo->uri); abilityWant.SetParams(wantInfo->parameters); - int32_t appIndex = BundleManagerHelper::GetInstance()->GetAppIndexByUid(reminder->GetUid()); + int32_t appIndex = ReminderBundleManagerHelper::GetInstance()->GetAppIndexByUid(reminder->GetUid()); abilityWant.SetParam("ohos.extra.param.key.appCloneIndex", appIndex); auto client = AppExecFwk::AbilityManagerClient::GetInstance(); @@ -1923,7 +1840,7 @@ std::shared_ptr ReminderDataManager::GetResou const int32_t uid) { AppExecFwk::BundleInfo bundleInfo; - if (!BundleManagerHelper::GetInstance()->GetBundleInfo(bundleName, + if (!ReminderBundleManagerHelper::GetInstance()->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, uid, bundleInfo)) { ANSR_LOGE("GetBundleInfo[%{public}s][%{public}d] fail.", bundleName.c_str(), uid); return nullptr; @@ -2069,5 +1986,10 @@ void ReminderDataManager::CheckNeedNotifyStatus(const sptr &rem ANSR_LOGI("notify reminder status change %{public}s", bundleName.c_str()); } } + +int32_t ReminderDataManager::QueryActiveReminderCount() +{ + return store_->QueryActiveReminderCount(); +} } } diff --git a/services/ans/src/reminder_data_manager_inner.cpp b/services/reminder/src/reminder_data_manager_inner.cpp similarity index 98% rename from services/ans/src/reminder_data_manager_inner.cpp rename to services/reminder/src/reminder_data_manager_inner.cpp index 46284fe3a4f6d10c8f7cef2e48153b27b24f37a6..261f4d745effab466d94d8041bcfce6519925a7e 100644 --- a/services/ans/src/reminder_data_manager_inner.cpp +++ b/services/reminder/src/reminder_data_manager_inner.cpp @@ -16,7 +16,6 @@ #include "reminder_data_manager.h" #include "ability_manager_client.h" -#include "access_token_helper.h" #include "ans_log_wrapper.h" #include "ans_const_define.h" #include "common_event_support.h" @@ -34,7 +33,6 @@ #include "time_service_client.h" #include "singleton.h" #include "locale_config.h" -#include "bundle_manager_helper.h" #include "datashare_predicates_object.h" #include "datashare_value_object.h" #include "datashare_helper.h" diff --git a/services/ans/src/reminder_event_manager.cpp b/services/reminder/src/reminder_event_manager.cpp similarity index 94% rename from services/ans/src/reminder_event_manager.cpp rename to services/reminder/src/reminder_event_manager.cpp index 6b8b629b11e79d4f062e114b4822ca4c2b2cd9ec..3ce88f932abfeddbdaed62be4353d9bbd4a8cb15 100644 --- a/services/ans/src/reminder_event_manager.cpp +++ b/services/reminder/src/reminder_event_manager.cpp @@ -20,7 +20,7 @@ #include "bundle_mgr_interface.h" #include "common_event_manager.h" #include "common_event_support.h" -#include "bundle_manager_helper.h" +#include "reminder_bundle_manager_helper.h" #include "if_system_ability_manager.h" #include "ipc_skeleton.h" #include "iservice_registry.h" @@ -78,7 +78,7 @@ void ReminderEventManager::init(std::shared_ptr &reminderDa IPCSkeleton::SetCallingIdentity(identity); subscriber_ = std::make_shared(reminderDataManager); - if (NotificationHelper::SubscribeNotification(*subscriber_) != ERR_OK) { + if (NotificationHelper::SubscribeNotificationSelf(*subscriber_) != ERR_OK) { ANSR_LOGD("SubscribeNotification failed"); } @@ -174,6 +174,10 @@ void ReminderEventManager::ReminderEventCustomSubscriber::OnReceiveEvent(const E reminderDataManager_->ClickReminder(want); return; } + if (action == ReminderRequest::REMINDER_EVENT_LOAD_REMINDER) { + reminderDataManager_->ReceiveLoadReminderEvent(); + return; + } } void ReminderEventManager::ReminderEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data) @@ -226,27 +230,19 @@ void ReminderEventManager::ReminderEventSubscriber::HandlePackageRemove(const Ev void ReminderEventManager::ReminderEventSubscriber::HandleProcessDied(const EventFwk::Want &want) const { - sptr bundleOption = GetBundleOption(want); - if (bundleOption == nullptr) { - ANSR_LOGE("Get bundle option error."); - return; - } - reminderDataManager_->OnProcessDiedLocked(bundleOption); + int32_t uid = GetUid(want); + reminderDataManager_->OnProcessDiedLocked(uid); } -sptr ReminderEventManager::ReminderEventSubscriber::GetBundleOption( +int32_t ReminderEventManager::ReminderEventSubscriber::GetUid( const OHOS::EventFwk::Want &want) const { OHOS::AppExecFwk::ElementName ele = want.GetElement(); std::string bundleName = ele.GetBundleName(); int32_t userId = want.GetIntParam(OHOS::AppExecFwk::Constants::USER_ID, -1); - int32_t uid = BundleManagerHelper::GetInstance()->GetDefaultUidByBundleName(bundleName, userId); + int32_t uid = ReminderBundleManagerHelper::GetInstance()->GetDefaultUidByBundleName(bundleName, userId); ANSR_LOGD("bundleName=%{public}s, userId=%{private}d, uid=%{public}d", bundleName.c_str(), userId, uid); - sptr bundleOption = new (std::nothrow) NotificationBundleOption(bundleName, uid); - if (bundleOption == nullptr) { - ANSR_LOGE("new NotificationBundleOption fail due to no memory."); - } - return bundleOption; + return uid; } ReminderEventManager::SystemAbilityStatusChangeListener::SystemAbilityStatusChangeListener( diff --git a/services/reminder/src/reminder_notification_inline.cpp b/services/reminder/src/reminder_notification_inline.cpp new file mode 100644 index 0000000000000000000000000000000000000000..aa66101d46f9caa3ec4efd2f01fb9ef3a9c95f50 --- /dev/null +++ b/services/reminder/src/reminder_notification_inline.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2021-2023 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 +#include +#include + +#include "ans_inner_errors.h" +#include "ans_log_wrapper.h" +#include "reminder_access_token_helper.h" +#include "ans_permission_def.h" +#include "reminder_bundle_manager_helper.h" +#include "errors.h" +#include "ipc_skeleton.h" +#include "notification_constant.h" +#include "notification_bundle_option.h" +#include "reminder_request.h" +#include "notification_request.h" +#include + +namespace OHOS { +namespace Notification { +#define REMINDER_CHECK_NULL_VOID(ptr, msg) \ + do { \ + if ((ptr) == nullptr) { \ + ANSR_LOGW("%{public}s", msg); \ + return; \ + } \ + } while (0) + +#define REMINDER_CHECK_NULL_RETURN(ptr, msg, ret) \ + do { \ + if ((ptr) == nullptr) { \ + ANSR_LOGW("%{public}s", msg); \ + return ret; \ + } \ + } while (0) + +inline std::string GetClientBundleNameByUid(int32_t callingUid) +{ + std::string bundle; + + std::shared_ptr bundleManager = ReminderBundleManagerHelper::GetInstance(); + if (bundleManager != nullptr) { + bundle = bundleManager->GetBundleNameByUid(callingUid); + } + + return bundle; +} + +inline std::string GetClientBundleName() +{ + return GetClientBundleNameByUid(IPCSkeleton::GetCallingUid()); +} + +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) +{ + struct tm ret = {0}; + localtime_r(&time, &ret); + return ret; +} + +inline NotificationBundleOption CreateBundleOption(const std::string& bundleName, const int32_t uid) +{ + return NotificationBundleOption(bundleName, uid); +} + +} // namespace Notification +} // namespace OHOS diff --git a/services/reminder/src/reminder_os_account_manager_helper.cpp b/services/reminder/src/reminder_os_account_manager_helper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..87646810e0c19ad44f25a0f4c4851c0324502a35 --- /dev/null +++ b/services/reminder/src/reminder_os_account_manager_helper.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2022 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 "reminder_os_account_manager_helper.h" +#include "ans_log_wrapper.h" +#include "ans_inner_errors.h" +#include "errors.h" +#include "ipc_skeleton.h" + +#include "os_account_constants.h" +#include "os_account_info.h" +#include "os_account_manager.h" +#include + +namespace OHOS { +namespace Notification { +ReminderOsAccountManagerHelper &ReminderOsAccountManagerHelper::GetInstance() +{ + return DelayedRefSingleton::GetInstance(); +} +ErrCode ReminderOsAccountManagerHelper::GetOsAccountLocalIdFromUid(const int32_t uid, int32_t &userId) +{ + int32_t ret = AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, userId); + if (ret != ERR_OK) { + ANS_LOGE("Get userId failed, uid = <%{public}d>, code is %{public}d", uid, ret); + return ret; + } + ANS_LOGD("Get userId Success, uid = <%{public}d> userId = <%{public}d>", uid, userId); + return ret; +} + +ErrCode ReminderOsAccountManagerHelper::GetCurrentActiveUserId(int32_t &id) +{ + int32_t ret = OHOS::AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(id); + if (ret != ERR_OK) { + ANS_LOGE("Failed to call OsAccountManager::GetForegroundOsAccountLocalId, code is %{public}d", ret); + } + return ret; +} +} +} diff --git a/services/reminder/src/reminder_service.cpp b/services/reminder/src/reminder_service.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6e7e457c37706e7977efddd179496064bbccfdad --- /dev/null +++ b/services/reminder/src/reminder_service.cpp @@ -0,0 +1,344 @@ +/* + * Copyright (c) 2021-2023 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 "reminder_service.h" + +#include "reminder_request_timer.h" +#include "reminder_request_calendar.h" +#include "reminder_request_alarm.h" +#include "reminder_bundle_manager_helper.h" +#include "reminder_access_token_helper.h" +#include "reminder_notification_inline.cpp" +#include "ffrt_inner.h" + + +#include +#include +#include + +#include "accesstoken_kit.h" +#include "ans_inner_errors.h" +#include "ans_log_wrapper.h" +#include "errors.h" + +#include "ipc_skeleton.h" +#include "notification_constant.h" +#include "notification_request.h" +#include "os_account_manager.h" +#include "hitrace_meter_adapter.h" +#include "reminder_data_manager.h" +#include "notification_helper.h" +#include "reminder_os_account_manager_helper.h" +#ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED +#include "distributed_notification_manager.h" +#include "distributed_preferences.h" +#include "distributed_screen_status_manager.h" +#endif + +namespace OHOS { +namespace Notification { +constexpr int64_t DELAY_TIME = 60 * 1000 * 1000; +sptr ReminderService::instance_; +std::mutex ReminderService::instanceMutex_; +std::mutex ReminderService::unloadMutex_; +sptr ReminderService::GetInstance() +{ + std::lock_guard lock(instanceMutex_); + + if (instance_ == nullptr) { + instance_ = new (std::nothrow) ReminderService(); + if (instance_ == nullptr) { + ANS_LOGE("Failed to create AdvancedNotificationService instance"); + return nullptr; + } + } + + return instance_; +} + +inline bool ReminderService::CheckReminderPermission() +{ + Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID(); + ErrCode result = Security::AccessToken::AccessTokenKit::VerifyAccessToken( + callerToken, "ohos.permission.PUBLISH_AGENT_REMINDER"); + return result == Security::AccessToken::PermissionState::PERMISSION_GRANTED; +} + +ErrCode ReminderService::PublishReminder(const ReminderRequest &reminder, int32_t& reminderId) +{ + HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); + ANSR_LOGI("Publish reminder"); + sptr tarReminder = CreateTarReminderRequest(reminder); + if (!tarReminder) { + ANSR_LOGE("ReminderRequest object is nullptr"); + return ERR_ANS_INVALID_PARAM; + } + int32_t callingUid = IPCSkeleton::GetCallingUid(); + std::string bundle = GetClientBundleName(); + if (!CheckReminderPermission()) { + ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); + return ERR_REMINDER_PERMISSION_DENIED; + } + bool isAllowUseReminder = false; + NotificationHelper::AllowUseReminder(bundle, isAllowUseReminder); + if (isAllowUseReminder) { + ANSR_LOGW("The number of reminders exceeds the limit[0]."); + return ERR_REMINDER_NUMBER_OVERLOAD; + } + InitReminderRequest(tarReminder, bundle, callingUid); + auto bundleOption = CreateBundleOption(tarReminder->GetBundleName(), tarReminder->GetUid()); + bool allowedNotify = false; + ErrCode result = NotificationHelper::IsAllowedNotify(bundleOption, allowedNotify); + if (!tarReminder->IsSystemApp() && (result != ERR_OK || !allowedNotify)) { + ANSR_LOGW("The application does not request enable notification"); + return ERR_REMINDER_NOTIFICATION_NOT_ENABLE; + } + auto rdm = ReminderDataManager::GetInstance(); + if (rdm == nullptr) { + return ERR_NO_INIT; + } + int32_t ret = rdm->PublishReminder(tarReminder, callingUid); + if (ret == ERR_OK) { + reminderId = tarReminder->GetReminderId(); + } + TryPostDelayUnloadTask(DELAY_TIME); + return ret; +} + +sptr ReminderService::CreateTarReminderRequest(const ReminderRequest &reminder) +{ + sptr tarReminder = nullptr; + switch (reminder.GetReminderType()) { + case (ReminderRequest::ReminderType::TIMER): { + ANSR_LOGI("Publish timer"); + ReminderRequestTimer &timer = (ReminderRequestTimer &)reminder; + tarReminder = new (std::nothrow) ReminderRequestTimer(timer); + break; + } + case (ReminderRequest::ReminderType::ALARM): { + ANSR_LOGI("Publish alarm"); + ReminderRequestAlarm &alarm = (ReminderRequestAlarm &)reminder; + tarReminder = new (std::nothrow) ReminderRequestAlarm(alarm); + break; + } + case (ReminderRequest::ReminderType::CALENDAR): { + ANSR_LOGI("Publish calendar"); + ReminderRequestCalendar &calendar = (ReminderRequestCalendar &)reminder; + tarReminder = new (std::nothrow) ReminderRequestCalendar(calendar); + break; + } + default: { + ANSR_LOGW("PublishReminder fail."); + } + } + return tarReminder; +} + +ErrCode ReminderService::InitReminderRequest(sptr& tarReminder, + const std::string& bundle, const int32_t callingUid) +{ + ANSR_LOGD("is system app: %{public}d", ReminderAccessTokenHelper::IsSystemApp()); + tarReminder->SetSystemApp(ReminderAccessTokenHelper::IsSystemApp()); + tarReminder->InitCreatorBundleName(bundle); + tarReminder->InitCreatorUid(callingUid); + if (tarReminder->GetWantAgentInfo() == nullptr || tarReminder->GetMaxScreenWantAgentInfo() == nullptr) { + ANSR_LOGE("wantagent info is nullptr"); + return ERR_ANS_INVALID_PARAM; + } + std::string wantAgentName = tarReminder->GetWantAgentInfo()->pkgName; + std::string msWantAgentName = tarReminder->GetMaxScreenWantAgentInfo()->pkgName; + if (wantAgentName != msWantAgentName && wantAgentName != "" && msWantAgentName != "") { + ANSR_LOGE("wantAgentName is not same to msWantAgentName, wantAgentName:%{public}s, msWantAgentName:%{public}s", + wantAgentName.c_str(), msWantAgentName.c_str()); + return ERR_ANS_INVALID_PARAM; + } + std::string bundleName = bundle; + if (wantAgentName != bundle && wantAgentName != "") { + ANSR_LOGI("Set agent reminder, bundle:%{public}s, wantAgentName:%{public}s", bundle.c_str(), + wantAgentName.c_str()); + bundleName = wantAgentName; + } else if (msWantAgentName != bundle && msWantAgentName != "") { + ANSR_LOGI("Set agent reminder, bundle:%{public}s, msWantAgentName:%{public}s", bundle.c_str(), + msWantAgentName.c_str()); + bundleName = msWantAgentName; + } + tarReminder->InitBundleName(bundleName); + int32_t activeUserId = -1; + if (ReminderOsAccountManagerHelper::GetInstance().GetCurrentActiveUserId(activeUserId) != ERR_OK) { + ANSR_LOGE("failed to get active user id"); + return ERR_ANS_INVALID_BUNDLE; + } + tarReminder->InitUserId(activeUserId); + tarReminder->InitUid(ReminderBundleManagerHelper::GetInstance()->GetDefaultUidByBundleName( + tarReminder->GetBundleName(), tarReminder->GetUserId())); + return ERR_OK; +} + +ErrCode ReminderService::CancelReminder(const int32_t reminderId) +{ + HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); + ANSR_LOGI("Cancel Reminder"); + if (!CheckReminderPermission()) { + ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); + return ERR_REMINDER_PERMISSION_DENIED; + } + int32_t callingUid = IPCSkeleton::GetCallingUid(); + auto rdm = ReminderDataManager::GetInstance(); + if (rdm == nullptr) { + return ERR_NO_INIT; + } + ErrCode result = rdm->CancelReminder(reminderId, callingUid); + TryPostDelayUnloadTask(DELAY_TIME); + return result; +} + +ErrCode ReminderService::CancelAllReminders() +{ + HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); + ANSR_LOGI("Cancel all reminders"); + if (!CheckReminderPermission()) { + ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); + return ERR_REMINDER_PERMISSION_DENIED; + } + int32_t callingUid = IPCSkeleton::GetCallingUid(); + std::string bundleName = GetClientBundleName(); + int32_t userId = -1; + AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, userId); + auto rdm = ReminderDataManager::GetInstance(); + if (rdm == nullptr) { + return ERR_NO_INIT; + } + ErrCode result = rdm->CancelAllReminders(bundleName, userId, callingUid); + TryPostDelayUnloadTask(DELAY_TIME); + return result; +} + + +ErrCode ReminderService::GetValidReminders(std::vector &reminders) +{ + HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); + ANSR_LOGI("GetValidReminders"); + if (!CheckReminderPermission()) { + ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); + return ERR_REMINDER_PERMISSION_DENIED; + } + + reminders.clear(); + int32_t callingUid = IPCSkeleton::GetCallingUid(); + auto rdm = ReminderDataManager::GetInstance(); + if (rdm == nullptr) { + return ERR_NO_INIT; + } + rdm->GetValidReminders(callingUid, reminders); + ANSR_LOGD("Valid reminders size=%{public}zu", reminders.size()); + TryPostDelayUnloadTask(DELAY_TIME); + return ERR_OK; +} + +ErrCode ReminderService::AddExcludeDate(const int32_t reminderId, const int64_t date) +{ + HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); + ANSR_LOGI("Add Exclude Date"); + if (!CheckReminderPermission()) { + ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); + return ERR_REMINDER_PERMISSION_DENIED; + } + int32_t callingUid = IPCSkeleton::GetCallingUid(); + auto rdm = ReminderDataManager::GetInstance(); + if (rdm == nullptr) { + ANSR_LOGW("Reminder data manager not init!"); + return ERR_NO_INIT; + } + ErrCode result = rdm->AddExcludeDate(reminderId, date, callingUid); + TryPostDelayUnloadTask(DELAY_TIME); + return result; +} + +ErrCode ReminderService::DelExcludeDates(const int32_t reminderId) +{ + HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); + ANSR_LOGI("Del Exclude Dates"); + if (!CheckReminderPermission()) { + ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); + return ERR_REMINDER_PERMISSION_DENIED; + } + + int32_t callingUid = IPCSkeleton::GetCallingUid(); + auto rdm = ReminderDataManager::GetInstance(); + if (rdm == nullptr) { + ANSR_LOGW("Reminder data manager not init!"); + return ERR_NO_INIT; + } + ErrCode result = rdm->DelExcludeDates(reminderId, callingUid); + TryPostDelayUnloadTask(DELAY_TIME); + return result; +} + +ErrCode ReminderService::GetExcludeDates(const int32_t reminderId, std::vector& dates) +{ + HITRACE_METER_NAME(HITRACE_TAG_OHOS, __PRETTY_FUNCTION__); + ANSR_LOGI("Get Exclude Dates"); + if (!CheckReminderPermission()) { + ANSR_LOGW("Permission denied: ohos.permission.PUBLISH_AGENT_REMINDER"); + return ERR_REMINDER_PERMISSION_DENIED; + } + int32_t callingUid = IPCSkeleton::GetCallingUid(); + auto rdm = ReminderDataManager::GetInstance(); + if (rdm == nullptr) { + ANSR_LOGW("Reminder data manager not init!"); + return ERR_NO_INIT; + } + ErrCode result = rdm->GetExcludeDates(reminderId, callingUid, dates); + TryPostDelayUnloadTask(DELAY_TIME); + return result; +} + +void ReminderService::TryPostDelayUnloadTask(int64_t delayTime) +{ + std::lock_guard lock(unloadMutex_); + if (tryUnloadTask_) { + ffrt::skip(tryUnloadTask_); + } + tryUnloadTask_ = ffrt::submit_h([this]() { + auto rdm = ReminderDataManager::GetInstance(); + if (rdm == nullptr) { + ANSR_LOGW("Reminder data manager not init!"); + return; + } + int32_t reminderCount = rdm->QueryActiveReminderCount(); + if (reminderCount > 0) { + return; + } + PostDelayUnloadTask(); + }, {}, {}, ffrt::task_attr().delay(delayTime)); + +} + +void ReminderService::PostDelayUnloadTask() +{ + ANSR_LOGI("do unload task"); + auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgrProxy == nullptr) { + ANSR_LOGE("get samgr failed"); + return; + } + int32_t ret = samgrProxy->UnloadSystemAbility(1930); + if (ret != ERR_OK) { + ANSR_LOGE("remove system ability failed"); + return; + } +} +} // namespace Notification +} // namespace OHOS diff --git a/services/reminder/src/reminder_service_ability.cpp b/services/reminder/src/reminder_service_ability.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b6d3edabe983fff21a0eef23f559f71dcc435301 --- /dev/null +++ b/services/reminder/src/reminder_service_ability.cpp @@ -0,0 +1,57 @@ +/* + * 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 "reminder_service_ability.h" + +namespace OHOS { +namespace Notification { +namespace { +REGISTER_SYSTEM_ABILITY_BY_ID(ReminderServiceAbility, 1930, true); +} + +const std::string EXTENSION_BACKUP = "backup"; +const std::string EXTENSION_RESTORE = "restore"; +constexpr int64_t INIT_DELAY_TIME = 0; + +ReminderServiceAbility::ReminderServiceAbility(const int32_t systemAbilityId, bool runOnCreate) + : SystemAbility(systemAbilityId, runOnCreate), service_(nullptr) +{} + +ReminderServiceAbility::~ReminderServiceAbility() +{} + +void ReminderServiceAbility::OnStart() +{ + if (service_ != nullptr) { + return; + } + + service_ = ReminderService::GetInstance(); + if (!Publish(service_)) { + return; + } + reminderAgent_ = ReminderDataManager::InitInstance(); + reminderAgent_->StartReminderLoadTimer(); + ReminderService::GetInstance()->TryPostDelayUnloadTask(INIT_DELAY_TIME); +} + +void ReminderServiceAbility::OnStop() +{ + service_ = nullptr; + reminderAgent_ = nullptr; +} + +} // namespace Notification +} // namespace OHOS diff --git a/services/ans/src/reminder_store.cpp b/services/reminder/src/reminder_store.cpp similarity index 91% rename from services/ans/src/reminder_store.cpp rename to services/reminder/src/reminder_store.cpp index 3a8b0867729c6ce6427bbc48a7b788cc666976f3..2dd53d4ef12d9108127dc95739f14fbb68ccbeba 100644 --- a/services/ans/src/reminder_store.cpp +++ b/services/reminder/src/reminder_store.cpp @@ -28,6 +28,7 @@ #include "reminder_request_timer.h" #include "reminder_request_calendar.h" #include "reminder_store_strategy.h" +#include "reminder_notification_inline.cpp" namespace OHOS { namespace Notification { @@ -39,6 +40,8 @@ const int32_t REMINDER_RDB_VERSION_V4 = 4; const int32_t REMINDER_RDB_VERSION_V5 = 5; const int32_t REMINDER_RDB_VERSION_V6 = 6; const int32_t REMINDER_RDB_VERSION = 7; +const int64_t ONE_MIN_TIME = 60 * 1000; +const int64_t HALF_HOUR = 30 * ONE_MIN_TIME; } const int32_t ReminderStore::STATE_OK = 0; @@ -208,11 +211,6 @@ void ReminderStore::ReminderStoreDataCallBack::InsertNewReminders(NativeRdb::Rdb { for (auto reminder : reminders) { int64_t rowId = STATE_FAIL; - sptr bundleOption = new (std::nothrow) NotificationBundleOption(); - if (bundleOption == nullptr) { - continue; - } - bundleOption->SetBundleName(reminder->GetBundleName()); NativeRdb::ValuesBucket baseValues; ReminderStrategy::AppendValuesBucket(reminder, baseValues, true); @@ -376,20 +374,16 @@ __attribute__((no_sanitize("cfi"))) int32_t ReminderStore::DeleteUser(const int3 } int32_t ReminderStore::UpdateOrInsert( - const sptr& reminder, const sptr& bundleOption) + const sptr& reminder) { if (rdbStore_ == nullptr) { ANSR_LOGE("Rdb store is not initialized."); return STATE_FAIL; } - if (bundleOption == nullptr) { - ANSR_LOGE("BundleOption is null."); - return STATE_FAIL; - } if (IsReminderExist(reminder)) { - return Update(reminder, bundleOption); + return Update(reminder); } else { - return Insert(reminder, bundleOption); + return Insert(reminder); } } @@ -433,6 +427,26 @@ __attribute__((no_sanitize("cfi"))) std::vector> ReminderS return GetReminders(sql); } +__attribute__((no_sanitize("cfi"))) std::vector> ReminderStore::GetHalfHourReminders() +{ + int64_t nowTime = GetCurrentTime(); + std::string sql = "SELECT * FROM " + + ReminderBaseTable::TABLE_NAME + " WHERE (" + + ReminderBaseTable::TABLE_NAME + "." + ReminderBaseTable::IS_EXPIRED + " = 'false' AND " + + ReminderBaseTable::TABLE_NAME + "." + ReminderBaseTable::REMINDER_TYPE + " != 1 AND " + + ReminderBaseTable::TABLE_NAME + "." + ReminderBaseTable::TRIGGER_TIME + " < " + + std::to_string(nowTime + HALF_HOUR) + ") OR " + + ReminderBaseTable::TABLE_NAME + "." + ReminderBaseTable::REMINDER_ID + " IN " + + "(SELECT" + ReminderBaseTable::REMINDER_ID + " FROM " + ReminderCalendarTable::TABLE_NAME + + ReminderCalendarTable::TABLE_NAME + "." + ReminderCalendarTable::CALENDAR_DATE_TIME + " < " + + std::to_string(nowTime + HALF_HOUR) + " AND " + + ReminderCalendarTable::TABLE_NAME + "." + ReminderCalendarTable::CALENDAR_DATE_TIME + " > " + + std::to_string(nowTime) +") ORDER BY " + + ReminderBaseTable::TRIGGER_TIME + " ASC"; + ANSR_LOGD("GetHalfHourReminders sql =%{public}s", sql.c_str()); + return GetReminders(sql); +} + void ReminderStore::GetUInt8Val(const std::shared_ptr& resultSet, const std::string& name, uint8_t& value) { @@ -590,8 +604,7 @@ __attribute__((no_sanitize("cfi"))) int32_t ReminderStore::Delete(const std::str return STATE_OK; } -int32_t ReminderStore::Insert( - const sptr& reminder, const sptr& bundleOption) +int32_t ReminderStore::Insert(const sptr& reminder) { if (rdbStore_ == nullptr) { ANSR_LOGE("Rdb store is not initialized."); @@ -648,7 +661,7 @@ int32_t ReminderStore::Insert( } int32_t ReminderStore::Update( - const sptr& reminder, const sptr& bundleOption) + const sptr& reminder) { if (rdbStore_ == nullptr) { ANSR_LOGE("Rdb store is not initialized."); @@ -813,5 +826,29 @@ std::shared_ptr ReminderStore::Query(const std::string& qu std::vector whereArgs; return rdbStore_->QuerySql(queryCondition, whereArgs); } + +int32_t ReminderStore::QueryActiveReminderCount() +{ + REMINDER_CHECK_NULL_RETURN(rdbStore_, "Rdb store is not initialized.", 0); + std::string queryCondition = "SELECT * FROM "; + queryCondition.append(ReminderBaseTable::TABLE_NAME).append(" WHERE ").append(ReminderBaseTable::IS_EXPIRED) + .append(" = 'true' AND ").append(ReminderTable::REMINDER_TYPE).append(" != 1"); + std::vector whereArgs; + auto resultSet = rdbStore_->QuerySql(queryCondition, whereArgs); + int32_t baseTableNum = 0; + resultSet->GetRowCount(baseTableNum); + + queryCondition = "SELECT * FROM "; + int64_t nowTime = GetCurrentTime(); + queryCondition.append(ReminderCalendarTable::TABLE_NAME).append(" WHERE (") + .append(ReminderCalendarTable::CALENDAR_DATE_TIME).append(" < ").append(std::to_string(nowTime)).append(" AND ") + .append(ReminderCalendarTable::CALENDAR_END_DATE_TIME) + .append(" > ").append(std::to_string(nowTime)).append(" ) OR ") + .append(ReminderCalendarTable::CALENDAR_DATE_TIME).append("> ").append(std::to_string(nowTime)); + resultSet = rdbStore_->QuerySql(queryCondition, whereArgs); + int32_t calenderTableNum = 0; + resultSet->GetRowCount(calenderTableNum); + return baseTableNum + calenderTableNum; +} } // namespace Notification } // namespace OHOS diff --git a/services/ans/src/reminder_store_strategy.cpp b/services/reminder/src/reminder_store_strategy.cpp similarity index 99% rename from services/ans/src/reminder_store_strategy.cpp rename to services/reminder/src/reminder_store_strategy.cpp index 2fefeb129595b30c2d4569500c2165af05e7d8f1..adf3c0085fb751907aa8028e48b26b7e9fc809c3 100644 --- a/services/ans/src/reminder_store_strategy.cpp +++ b/services/reminder/src/reminder_store_strategy.cpp @@ -355,7 +355,6 @@ void ReminderStrategy::RecoverFromDb(sptr& reminder, ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::ACTION_BUTTON_INFO, actionButtons); reminder->DeserializeButtonInfo(actionButtons); - reminder->InitNotificationRequest(); // must set before wantAgent & maxScreenWantAgent std::string wantAgent; ReminderStrategy::GetRdbValue(resultSet, ReminderBaseTable::WANT_AGENT, wantAgent); reminder->DeserializeWantAgent(wantAgent, 0); diff --git a/services/ans/src/reminder_table.cpp b/services/reminder/src/reminder_table.cpp similarity index 100% rename from services/ans/src/reminder_table.cpp rename to services/reminder/src/reminder_table.cpp diff --git a/services/ans/src/reminder_table_old.cpp b/services/reminder/src/reminder_table_old.cpp similarity index 100% rename from services/ans/src/reminder_table_old.cpp rename to services/reminder/src/reminder_table_old.cpp diff --git a/services/ans/src/reminder_timer_info.cpp b/services/reminder/src/reminder_timer_info.cpp similarity index 100% rename from services/ans/src/reminder_timer_info.cpp rename to services/reminder/src/reminder_timer_info.cpp diff --git a/services/reminder/test/unittest/BUILD.gn b/services/reminder/test/unittest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f9aafd57c52ea929b69e11b998ad2e0851da5f65 --- /dev/null +++ b/services/reminder/test/unittest/BUILD.gn @@ -0,0 +1,444 @@ +# Copyright (c) 2022-2023 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. + +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/ohos.gni") +import("//build/test.gni") + +module_output_path = "${component_name}/unittest" + +ohos_unittest("reminder_unit_test") { + module_out_path = module_output_path + include_dirs = [ + ".", + "include", + "/${services_path}/ans/include", + "/${services_path}/reminder/include", + "${services_path}/reminder/test/unittest/mock/include", + ] + + defines = [] + + sources = [ + "mock/mock_access_token_helper.cpp", + "mock/mock_bundle_manager_helper.cpp", + "mock/mock_ipc.cpp", + "reminder_data_manager_test.cpp", + ] + + deps = [ + "${frameworks_module_ans_path}:ans_innerkits", + "${frameworks_module_reminder_path}:reminder_innerkits", + "${services_path}/reminder:libreminder", + ] + + if (distributed_notification_supported) { + defines += [ "DISTRIBUTED_NOTIFICATION_SUPPORTED" ] + deps += [ "${services_path}/distributed:libans_distributed" ] + include_dirs += [ "${services_path}/distributed/include" ] + } + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_manager", + "ability_runtime:abilitykit_native", + "ability_runtime:app_manager", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "data_share:datashare_common", + "data_share:datashare_consumer", + "device_manager:devicemanagersdk", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "hilog:libhilog", + "hitrace:hitrace_meter", + "hitrace:libhitracechain", + "image_framework:image_native", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "os_account:os_account_innerkits", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "time_service:time_client", + ] + + if (device_usage) { + external_deps += [ "device_usage_statistics:usagestatsinner" ] + defines += [ "DEVICE_USAGE_STATISTICS_ENABLE" ] + } + + if (player_framework) { + external_deps += [ "player_framework:media_client" ] + defines += [ "PLAYER_FRAMEWORK_ENABLE" ] + } + + cflags = [] + if (hisysevent_usage) { + external_deps += [ "hisysevent:libhisysevent" ] + cflags += [ "-DHAS_HISYSEVENT_PART" ] + } + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +ohos_unittest("reminder_service_publish_test") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path + include_dirs = [ + ".", + "include", + "/${services_path}/reminder/include", + "${services_path}/reminder/test/unittest/mock/include", + ] + + defines = [] + + sources = [ + "${test_path}/mock/mock_tokenid_kit.cpp", + "reminder_service_test/reminder_service_publish_test.cpp", + "mock/mock_access_token_helper.cpp", + "mock/mock_accesstoken_kit.cpp", + "mock/mock_bundle_manager_helper.cpp", + "mock/mock_bundle_mgr.cpp", + "mock/mock_ipc.cpp", + "mock/mock_os_account_manager_annex.cpp", + ] + + deps = [ + "${frameworks_module_reminder_path}:reminder_innerkits", + "${services_path}/reminder:libreminder", + ] + + if (distributed_notification_supported) { + defines += [ "DISTRIBUTED_NOTIFICATION_SUPPORTED" ] + deps += [ "${services_path}/distributed:libans_distributed" ] + include_dirs += [ "${services_path}/distributed/include" ] + } + + external_deps = [ + "ability_base:base", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:abilitykit_native", + "ability_runtime:app_manager", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "device_manager:devicemanagersdk", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "hilog:libhilog", + "hitrace:hitrace_meter", + "hitrace:libhitracechain", + "image_framework:image_native", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "os_account:os_account_innerkits", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "time_service:time_client", + ] + + if (device_usage) { + external_deps += [ "device_usage_statistics:usagestatsinner" ] + defines += [ "DEVICE_USAGE_STATISTICS_ENABLE" ] + } + + if (player_framework) { + external_deps += [ "player_framework:media_client" ] + defines += [ "PLAYER_FRAMEWORK_ENABLE" ] + } + + cflags = [] + if (hisysevent_usage) { + external_deps += [ "hisysevent:libhisysevent" ] + cflags += [ "-DHAS_HISYSEVENT_PART" ] + } + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +ohos_unittest("reminder_access_token_helper_test") { + module_out_path = module_output_path + include_dirs = [ + ".", + "include", + "/${services_path}/reminder/include", + "${services_path}/reminder/test/unittest/mock/include", + ] + + sources = [ + "${services_path}/reminder/src/reminder_access_token_helper.cpp", + "${services_path}/reminder/test/unittest/mock/mock_accesstoken_kit.cpp", + "${test_path}/mock/mock_tokenid_kit.cpp", + "access_token_helper_test/access_token_helper_test.cpp", + ] + + deps = [ "${frameworks_module_reminder_path}:reminder_innerkits" ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:abilitykit_native", + "ability_runtime:app_manager", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "hitrace:libhitracechain", + "image_framework:image_native", + "init:libbegetutil", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "os_account:os_account_innerkits", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "time_service:time_client", + ] + + if (player_framework) { + external_deps += [ "player_framework:media_client" ] + defines = [ "PLAYER_FRAMEWORK_ENABLE" ] + } + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +ohos_unittest("reminder_bundle_manager_helper_branch_test") { + module_out_path = module_output_path + include_dirs = [ + ".", + "include", + "/${services_path}/reminder/include", + "${services_path}/reminder/test/unittest/mock/include", + ] + + sources = [ + "bundle_manager_helper_branch_test/bundle_manager_helper_branch_test.cpp", + "bundle_manager_helper_branch_test/mock_service_registry.cpp", + ] + + deps = [ + "${frameworks_module_reminder_path}:reminder_innerkits", + "${services_path}/reminder:libreminder", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:abilitykit_native", + "ability_runtime:app_manager", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "hitrace:libhitracechain", + "image_framework:image_native", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "os_account:os_account_innerkits", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "time_service:time_client", + ] + + if (player_framework) { + external_deps += [ "player_framework:media_client" ] + defines = [ "PLAYER_FRAMEWORK_ENABLE" ] + } + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +ohos_unittest("reminder_os_account_manager_helper_test") { + module_out_path = module_output_path + include_dirs = [ + ".", + "include", + "/${services_path}/reminder/include", + "${services_path}/reminder/test/unittest/mock/include", + ] + + sources = [ "os_account_manager_helper_test.cpp" ] + + deps = [ + "${frameworks_module_reminder_path}:reminder_innerkits", + "${services_path}/reminder:libreminder", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:abilitykit_native", + "ability_runtime:app_manager", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "hitrace:libhitracechain", + "image_framework:image_native", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "os_account:os_account_innerkits", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "time_service:time_client", + ] + + if (player_framework) { + external_deps += [ "player_framework:media_client" ] + defines = [ "PLAYER_FRAMEWORK_ENABLE" ] + } + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +ohos_unittest("reminder_service_test") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + module_out_path = module_output_path + include_dirs = [ + ".", + "include", + "/${services_path}/reminder/include", + "${services_path}/reminder/test/unittest/mock/include", + ] + + defines = [] + + sources = [ + "${test_path}/mock/mock_tokenid_kit.cpp", + "reminder_service_test.cpp", + "reminder_store_test.cpp", + "mock/mock_access_token_helper.cpp", + "mock/mock_accesstoken_kit.cpp", + "mock/mock_bundle_manager_helper.cpp", + "mock/mock_bundle_mgr.cpp", + "mock/mock_ipc.cpp", + "mock/mock_os_account_manager_annex.cpp", + ] + + deps = [ + "${frameworks_module_reminder_path}:reminder_innerkits", + "${services_path}/reminder:libreminder", + ] + + if (distributed_notification_supported) { + defines += [ "DISTRIBUTED_NOTIFICATION_SUPPORTED" ] + deps += [ "${services_path}/distributed:libans_distributed" ] + include_dirs += [ "${services_path}/distributed/include" ] + } + + external_deps = [ + "ability_base:base", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:abilitykit_native", + "ability_runtime:app_manager", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "device_manager:devicemanagersdk", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "hilog:libhilog", + "hitrace:hitrace_meter", + "hitrace:libhitracechain", + "image_framework:image_native", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "os_account:os_account_innerkits", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "time_service:time_client", + ] + + if (device_usage) { + external_deps += [ "device_usage_statistics:usagestatsinner" ] + defines += [ "DEVICE_USAGE_STATISTICS_ENABLE" ] + } + + if (player_framework) { + external_deps += [ "player_framework:media_client" ] + defines += [ "PLAYER_FRAMEWORK_ENABLE" ] + } + + cflags = [] + if (hisysevent_usage) { + external_deps += [ "hisysevent:libhisysevent" ] + cflags += [ "-DHAS_HISYSEVENT_PART" ] + } + + subsystem_name = "${subsystem_name}" + part_name = "${component_name}" +} + +group("unittest") { + testonly = true + deps = [ + ":reminder_access_token_helper_test", + ":reminder_bundle_manager_helper_branch_test", + ":reminder_service_publish_test", + ":reminder_service_test", + ":reminder_os_account_manager_helper_test", + ":reminder_unit_test", + ] +} diff --git a/services/reminder/test/unittest/access_token_helper_test/access_token_helper_test.cpp b/services/reminder/test/unittest/access_token_helper_test/access_token_helper_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cc6b5482d952731507cdf48f2a5c97fe46449fa5 --- /dev/null +++ b/services/reminder/test/unittest/access_token_helper_test/access_token_helper_test.cpp @@ -0,0 +1,97 @@ +/* + * 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 +#include +#include "accesstoken_kit.h" +#define private public +#define protected public +#include "reminder_access_token_helper.h" +#include "ans_log_wrapper.h" +#include "ipc_skeleton.h" +#undef private +#undef protected +using namespace testing::ext; +using namespace OHOS::Security::AccessToken; + +namespace OHOS { +namespace Notification { + +extern void MockGetTokenTypeFlag(ATokenTypeEnum mockRet); +extern void MockDlpType(DlpType mockRet); +extern void MockApl(ATokenAplEnum mockRet); +class AccessTokenHelperTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + + std::shared_ptr stub_; +}; + +void AccessTokenHelperTest::SetUpTestCase() +{ +} + +void AccessTokenHelperTest::TearDownTestCase() +{ +} + +void AccessTokenHelperTest::SetUp() +{ + stub_ = std::make_shared(); +} + +void AccessTokenHelperTest::TearDown() +{ +} + +/** + * @tc.number : AccessTokenHelperTest + * @tc.name : VerifyNativeToken_00100 + * @tc.desc : VerifyNativeToken success + */ +HWTEST_F(AccessTokenHelperTest, VerifyNativeToken_00100, Function | SmallTest | Level1) +{ + AccessTokenID tokenID = 0; + MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE); + EXPECT_TRUE(stub_->VerifyNativeToken(tokenID)); +} + +/** + * @tc.number : AccessTokenHelperTest + * @tc.name : IsSystemApp_00100 + * @tc.desc : IsSystemApp Token Type TOKEN_NATIVE + */ +HWTEST_F(AccessTokenHelperTest, IsSystemApp_00100, Function | SmallTest | Level1) +{ + MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_NATIVE); + EXPECT_FALSE(stub_->IsSystemApp()); +} + +/** + * @tc.number : AccessTokenHelperTest + * @tc.name : IsSystemApp_00200 + * @tc.desc : IsSystemApp Token Type TOKEN_HAP + */ +HWTEST_F(AccessTokenHelperTest, IsSystemApp_00200, Function | SmallTest | Level1) +{ + MockGetTokenTypeFlag(ATokenTypeEnum::TOKEN_HAP); + EXPECT_TRUE(stub_->IsSystemApp()); +} + +} // namespace Notification +} // namespace OHOS diff --git a/services/reminder/test/unittest/advanced_notification_service_ability_test.cpp b/services/reminder/test/unittest/advanced_notification_service_ability_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4cc27724b53b5ff844cf0d7d498c215a2a4a8115 --- /dev/null +++ b/services/reminder/test/unittest/advanced_notification_service_ability_test.cpp @@ -0,0 +1,76 @@ +/* + * 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 +#include +#define private public +#define protected public +#include "reminder_service_ability.h" + +using namespace testing::ext; + +namespace OHOS { +namespace Notification { +class ReminderServiceAbilityTest : public testing::Test { +public: + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.number : ReminderServiceAbilityTest_00100 + * @tc.name : ReminderServiceAbility_0100 + * @tc.desc : Structure ReminderServiceAbility with systemAbilityId and runOnCreate + */ +HWTEST_F( + ReminderServiceAbilityTest, ReminderServiceAbilityTest_00100, Function | SmallTest | Level1) +{ + int32_t systemAbilityId = 1; + bool runOnCreate = true; + ReminderServiceAbility(systemAbilityId, runOnCreate); +} + +/** + * @tc.number : ReminderServiceAbilityTest_00200 + * @tc.name : ReminderServiceAbility_0200 + * @tc.desc : Structure ReminderServiceAbility with systemAbilityId and runOnCreate + */ +HWTEST_F( + ReminderServiceAbilityTest, ReminderServiceAbilityTest_00200, Function | SmallTest | Level1) +{ + int32_t systemAbilityId = 1; + bool runOnCreate = true; + ReminderServiceAbility test(systemAbilityId, runOnCreate); + test.OnStart(); +} + +/** + * @tc.number : ReminderServiceAbilityTest_00300 + * @tc.name : ReminderServiceAbility_0300 + * @tc.desc : Structure ReminderServiceAbility with systemAbilityId and runOnCreate + */ +HWTEST_F( + ReminderServiceAbilityTest, ReminderServiceAbilityTest_00300, Function | SmallTest | Level1) +{ + int32_t systemAbilityId = 1; + bool runOnCreate = true; + ReminderServiceAbility test(systemAbilityId, runOnCreate); + test.OnStop(); + test.OnStart(); +} +} // namespace Notification +} // namespace OHOS diff --git a/services/reminder/test/unittest/bundle_manager_helper_branch_test/bundle_manager_helper_branch_test.cpp b/services/reminder/test/unittest/bundle_manager_helper_branch_test/bundle_manager_helper_branch_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..6cfa18810f9087c226e8769cdacb207407ab1f8c --- /dev/null +++ b/services/reminder/test/unittest/bundle_manager_helper_branch_test/bundle_manager_helper_branch_test.cpp @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2022 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 +#include + +#include "reminder_ut_constant.h" +#define private public +#define protected public +#include "reminder_bundle_manager_helper.h" +#undef private +#undef protected + +extern void MockGetSystemAbilityManager(bool mockRet); + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class BundleManagerHelperBranchTest : public testing::Test { +public: + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.number : BundleManagerHelper_00100 + * @tc.name : BundleManagerHelper_00100 + * @tc.desc : test GetBundleNameByUid function and bundleMgr_ != nullptr + */ +HWTEST_F(BundleManagerHelperBranchTest, BundleManagerHelperTest_00100, Function | SmallTest | Level1) +{ + ReminderBundleManagerHelper bundleManagerHelper; + MockGetSystemAbilityManager(false); + int32_t uid = 1; + ASSERT_EQ("", bundleManagerHelper.GetBundleNameByUid(uid)); +} + +/** + * @tc.number : BundleManagerHelper_00200 + * @tc.name : BundleManagerHelper_00200 + * @tc.desc : test GetBundleNameByUid function and bundleMgr_ == nullptr + */ +HWTEST_F(BundleManagerHelperBranchTest, BundleManagerHelper_00200, Function | SmallTest | Level1) +{ + ReminderBundleManagerHelper bundleManagerHelper; + MockGetSystemAbilityManager(true); + int32_t uid = 1; + ASSERT_EQ("", bundleManagerHelper.GetBundleNameByUid(uid)); +} + +/** + * @tc.number : BundleManagerHelper_00800 + * @tc.name : BundleManagerHelper_00800 + * @tc.desc : test Connect function and systemAbilityManager is nullptr + */ +HWTEST_F(BundleManagerHelperBranchTest, BundleManagerHelper_00800, Function | SmallTest | Level1) +{ + std::shared_ptr bundleManagerHelper = std::make_shared(); + ASSERT_NE(nullptr, bundleManagerHelper); + MockGetSystemAbilityManager(true); + bundleManagerHelper->Connect(); +} + +/** + * @tc.number : BundleManagerHelper_00900 + * @tc.name : BundleManagerHelper_00900 + * @tc.desc : test Connect function and systemAbilityManager is not nullptr + */ +HWTEST_F(BundleManagerHelperBranchTest, BundleManagerHelper_00900, Function | SmallTest | Level1) +{ + std::shared_ptr bundleManagerHelper = std::make_shared(); + ASSERT_NE(nullptr, bundleManagerHelper); + MockGetSystemAbilityManager(false); + // test Connect and bundleMgr_ == nullptr + bundleManagerHelper->Connect(); +} + +/** + * @tc.number : BundleManagerHelper_01000 + * @tc.name : BundleManagerHelper_01000 + * @tc.desc : test Connect function and bundleMgr_ != nullptr + */ +HWTEST_F(BundleManagerHelperBranchTest, BundleManagerHelper_01000, Function | SmallTest | Level1) +{ + std::shared_ptr bundleManagerHelper = std::make_shared(); + ASSERT_NE(nullptr, bundleManagerHelper); + MockGetSystemAbilityManager(false); + bundleManagerHelper->Connect(); + // test Connect and bundleMgr_ != nullptr + bundleManagerHelper->Connect(); +} + +/** + * @tc.number : BundleManagerHelper_01100 + * @tc.name : BundleManagerHelper_01100 + * @tc.desc : test Disconnect function and bundleMgr_ != nullptr + */ +HWTEST_F(BundleManagerHelperBranchTest, BundleManagerHelper_01100, Function | SmallTest | Level1) +{ + std::shared_ptr bundleManagerHelper = std::make_shared(); + ASSERT_NE(nullptr, bundleManagerHelper); + MockGetSystemAbilityManager(false); + bundleManagerHelper->Connect(); + bundleManagerHelper->Disconnect(); +} + +/** + * @tc.number : BundleManagerHelper_01200 + * @tc.name : BundleManagerHelper_01200 + * @tc.desc : test Disconnect function and bundleMgr_ == nullptr + */ +HWTEST_F(BundleManagerHelperBranchTest, BundleManagerHelper_01200, Function | SmallTest | Level1) +{ + std::shared_ptr bundleManagerHelper = std::make_shared(); + ASSERT_NE(nullptr, bundleManagerHelper); + bundleManagerHelper->Disconnect(); +} + +/** + * @tc.number : BundleManagerHelper_01300 + * @tc.name : BundleManagerHelper_01300 + * @tc.desc : test GetDefaultUidByBundleName function and bundleMgr_ == nullptr + */ +HWTEST_F(BundleManagerHelperBranchTest, BundleManagerHelper_01300, Function | SmallTest | Level1) +{ + ReminderBundleManagerHelper bundleManagerHelper; + MockGetSystemAbilityManager(true); + std::string bundle = "aa"; + int32_t userId = 1; + ASSERT_EQ(-1, bundleManagerHelper.GetDefaultUidByBundleName(bundle, userId)); +} + +/** + * @tc.number : BundleManagerHelper_01400 + * @tc.name : BundleManagerHelper_01400 + * @tc.desc : test GetDefaultUidByBundleName function and bundleMgr_ != nullptr + */ +HWTEST_F(BundleManagerHelperBranchTest, BundleManagerHelper_01400, Function | SmallTest | Level1) +{ + ReminderBundleManagerHelper bundleManagerHelper; + MockGetSystemAbilityManager(false); + std::string bundle = "aa"; + int32_t userId = 1; + ASSERT_EQ(-1, bundleManagerHelper.GetDefaultUidByBundleName(bundle, userId)); +} + +} // namespace Notification +} // namespace OHOS diff --git a/services/reminder/test/unittest/bundle_manager_helper_branch_test/mock_service_registry.cpp b/services/reminder/test/unittest/bundle_manager_helper_branch_test/mock_service_registry.cpp new file mode 100755 index 0000000000000000000000000000000000000000..e6d1d346abc19bd3ee2b7d9aed8bc165b87d6800 --- /dev/null +++ b/services/reminder/test/unittest/bundle_manager_helper_branch_test/mock_service_registry.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2022 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 "iservice_registry.h" + +#include "ipc_skeleton.h" +#include "iremote_object.h" + +namespace { + bool g_mockGetSystemAbilityManagerRet = true; +} + +void MockGetSystemAbilityManager(bool mockRet) +{ + g_mockGetSystemAbilityManagerRet = mockRet; +} + +namespace OHOS { +sptr SystemAbilityManagerClient::GetSystemAbilityManager() +{ + if (false == g_mockGetSystemAbilityManagerRet) { + if (systemAbilityManager_ != nullptr) { + return systemAbilityManager_; + } + sptr registryObject = IPCSkeleton::GetContextObject(); + systemAbilityManager_ = iface_cast(registryObject); + return systemAbilityManager_; + } + return nullptr; +} +} // namespace OHOS diff --git a/services/reminder/test/unittest/bundle_manager_helper_test.cpp b/services/reminder/test/unittest/bundle_manager_helper_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7c608ec8ecaa52f6e95d2439801a059e391189f5 --- /dev/null +++ b/services/reminder/test/unittest/bundle_manager_helper_test.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021-2023 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 +#include + +#define private public +#define protected public +#include "reminder_bundle_manager_helper.h" +#undef private +#undef protected + +#include "if_system_ability_manager.h" +#include "ipc_skeleton.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class BundleManagerHelperTest : public testing::Test { +public: + static void SetUpTestCase() {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; +}; + +/** + * @tc.number : BundleManagerHelperTest_00100 + * @tc.name : ANS_GetBundleNameByUid_0100 + * @tc.desc : Test GetBundleNameByUid function + */ +HWTEST_F(BundleManagerHelperTest, BundleManagerHelperTest_00100, Function | SmallTest | Level1) +{ + pid_t callingUid = IPCSkeleton::GetCallingUid(); + std::shared_ptr bundleManager = ReminderBundleManagerHelper::GetInstance(); + ASSERT_EQ(bundleManager->GetBundleNameByUid(callingUid), "bundleName"); +} + +} // namespace Notification +} // namespace OHOS diff --git a/services/reminder/test/unittest/mock/include/mock_bundle_mgr.h b/services/reminder/test/unittest/mock/include/mock_bundle_mgr.h new file mode 100644 index 0000000000000000000000000000000000000000..c29406682e78ffe5551d779df1adcf6382ab16c4 --- /dev/null +++ b/services/reminder/test/unittest/mock/include/mock_bundle_mgr.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023-2023 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_MOCK_BUNDLE_MANAGER_H +#define BASE_NOTIFICATION_MOCK_BUNDLE_MANAGER_H + +#include "bundle_info.h" +#include "iremote_proxy.h" +#include "bundle_mgr_interface.h" + +namespace OHOS { +namespace AppExecFwk { +class BundleMgrProxy : public IRemoteProxy { +public: + explicit BundleMgrProxy(const sptr &impl) : IRemoteProxy(impl) {} + virtual ~BundleMgrProxy() {} + + ErrCode GetNameForUid(const int uid, std::string &name) override; + bool GetBundleInfo(const std::string &bundleName, const BundleFlag flag, + BundleInfo &bundleInfo, int32_t userId) override; + int GetUidByBundleName(const std::string &bundleName, const int userId) override; + bool GetApplicationInfo( + const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo) override; +}; +} // namespace AppExecFwk +} // namespace OHOS + +#endif // MOCK_OHOS_EDM_MOCK_BUNDLE_MANAGER_H diff --git a/services/reminder/test/unittest/mock/include/mock_ipc_skeleton.h b/services/reminder/test/unittest/mock/include/mock_ipc_skeleton.h new file mode 100644 index 0000000000000000000000000000000000000000..56591d38ecd7f3cfda4ede0bea42982ca6a8027a --- /dev/null +++ b/services/reminder/test/unittest/mock/include/mock_ipc_skeleton.h @@ -0,0 +1,139 @@ +/* + * 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 OHOS_IPC_IPC_SKELETON_H +#define OHOS_IPC_IPC_SKELETON_H + +#include "accesstoken_kit.h" +#include "iremote_object.h" + +namespace OHOS { +class IPCSkeleton { +public: + IPCSkeleton() = default; + ~IPCSkeleton() = default; + + /** + * @brief Set the max number of work thread. + * Default max is 4, only if you need a customize value. + * + * @param maxThreadNum Indicates the max number of work thread + * @return Indicates the result. + */ + static bool SetMaxWorkThreadNum(int maxThreadNum); + + /** + * @brief Join current thread into work loop. + */ + static void JoinWorkThread(); + + /** + * @brief Remove current thread from work loop. + */ + static void StopWorkThread(); + + /** + * @brief Get calling pid. + * + * @return Indicates the calling pid. + */ + static pid_t GetCallingPid(); + + /** + * @brief Get calling uid. + * + * @return Indicates the calling uid. + */ + static pid_t GetCallingUid(); + + /** + * @brief Get the ID of local device. + * + * @return Indicates the ID of local device. + */ + static std::string GetLocalDeviceID(); + + static Security::AccessToken::AccessTokenID GetCallingTokenID(); + + /** + * @brief Get the ID of calling device. + * + * @return Indicates the ID of calling device. + */ + static std::string GetCallingDeviceID(); + + /** + * @brief Whether it is locally calling. + * + * @return Return ture for calling from local, otherwise false. + */ + static bool IsLocalCalling(); + + /** + * @brief Get the instance. + * + * @return Indicates the instance. + */ + static IPCSkeleton &GetInstance(); + + /** + * @brief Get the object of context. + * + * @return Indicates the context cobject. + */ + static sptr GetContextObject(); + + /** + * @brief Set the object of context. + * + * @param object Indicates the context cobject. + * @return Indicates the result. + */ + static bool SetContextObject(sptr &object); + + /** + * @brief Flush the commands. + * + * @param object Indicates the object. + * @return Indicates the result. + */ + static int FlushCommands(IRemoteObject *object); + + /** + * @brief Reset calling identity. + * + * @return Indicates the result. + */ + static std::string ResetCallingIdentity(); + + /** + * @brief Set calling identity. + * + * @param identity Indicates the identity. + * @return Indicates the result. + */ + static bool SetCallingIdentity(std::string &identity); + + /** + * @brief Set calling uid. + * + * @param uid Indicates the uid. + */ + static void SetCallingUid(pid_t uid); + + static void SetCallingTokenID(Security::AccessToken::AccessTokenID callerToken); +}; +} // namespace OHOS +#endif // OHOS_IPC_IPC_SKELETON_H diff --git a/services/reminder/test/unittest/mock/mock_access_token_helper.cpp b/services/reminder/test/unittest/mock/mock_access_token_helper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5bc5dfd6099b8cd1db065db06523b9892652046f --- /dev/null +++ b/services/reminder/test/unittest/mock/mock_access_token_helper.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022 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 "reminder_access_token_helper.h" +#include "reminder_ut_constant.h" +#include "ipc_skeleton.h" + +namespace OHOS { +namespace Notification { + +bool ReminderAccessTokenHelper::VerifyNativeToken(const Security::AccessToken::AccessTokenID &callerToken) +{ + return callerToken == NATIVE_TOKEN; +} + +bool ReminderAccessTokenHelper::IsSystemApp() +{ + Security::AccessToken::AccessTokenID tokenId = IPCSkeleton::GetCallingTokenID(); + if (tokenId == NATIVE_TOKEN) { + return true; + } + return false; +} + +} // namespace Notification +} // namespace OHOS \ No newline at end of file diff --git a/services/reminder/test/unittest/mock/mock_accesstoken_kit.cpp b/services/reminder/test/unittest/mock/mock_accesstoken_kit.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ea0095d085348d6a110b5db1e0845fa5d4db5f7a --- /dev/null +++ b/services/reminder/test/unittest/mock/mock_accesstoken_kit.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 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 "accesstoken_kit.h" +#include "ans_log_wrapper.h" +#include "reminder_ut_constant.h" +#include "ipc_skeleton.h" + +using namespace OHOS::Security::AccessToken; +namespace OHOS { +namespace Notification { +namespace { +ATokenTypeEnum g_mockGetTokenTypeFlagRet = ATokenTypeEnum::TOKEN_INVALID; +DlpType g_mockDlpType = DlpType::DLP_COMMON; +ATokenAplEnum g_mockApl = ATokenAplEnum::APL_NORMAL; +bool g_mockVerfyPermisson = true; +} + +void MockGetTokenTypeFlag(ATokenTypeEnum mockRet) +{ + g_mockGetTokenTypeFlagRet = mockRet; +} +void MockDlpType(DlpType mockRet) +{ + g_mockDlpType = mockRet; +} +void MockApl(ATokenAplEnum mockRet) +{ + g_mockApl = mockRet; +} + +void MockIsVerfyPermisson(bool isVerify) +{ + g_mockVerfyPermisson = isVerify; +} +} +} +namespace OHOS { +namespace Security { +namespace AccessToken { +int AccessTokenKit::VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName) +{ + if (!Notification::g_mockVerfyPermisson) { + return PERMISSION_DENIED; + } + + if (tokenID == Notification::NON_NATIVE_TOKEN) { + return PERMISSION_DENIED; + } + return PERMISSION_GRANTED; +} + +ATokenTypeEnum AccessTokenKit::GetTokenTypeFlag(AccessTokenID tokenID) +{ + return Notification::g_mockGetTokenTypeFlagRet; +} + +int AccessTokenKit::GetHapTokenInfo(AccessTokenID tokenID, HapTokenInfo& info) +{ + info.dlpType = Notification::g_mockDlpType; + info.apl = Notification::g_mockApl; + return 0; +} +} // namespace AccessToken +} // namespace Security +} // namespace OHOS diff --git a/services/reminder/test/unittest/mock/mock_bundle_manager_helper.cpp b/services/reminder/test/unittest/mock/mock_bundle_manager_helper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..96f711816bb104d8025287260359e10db15c850b --- /dev/null +++ b/services/reminder/test/unittest/mock/mock_bundle_manager_helper.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2021-2022 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 "reminder_bundle_manager_helper.h" + +#include "reminder_ut_constant.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" + +namespace OHOS { +namespace Notification { +ReminderBundleManagerHelper::ReminderBundleManagerHelper() +{} + +ReminderBundleManagerHelper::~ReminderBundleManagerHelper() +{} + +void ReminderBundleManagerHelper::OnRemoteDied(const wptr &object) +{} + +std::string ReminderBundleManagerHelper::GetBundleNameByUid(int uid) +{ + return (uid == NON_BUNDLE_NAME_UID) ? "" : "bundleName"; +} + +int ReminderBundleManagerHelper::GetDefaultUidByBundleName(const std::string &bundle, const int32_t userId) +{ + if (userId == 0) { + return -1; + } else { + return NON_SYSTEM_APP_UID; + } +} + +void ReminderBundleManagerHelper::Connect() +{} + +void ReminderBundleManagerHelper::Disconnect() +{} + +} // namespace Notification +} // namespace OHOS diff --git a/services/reminder/test/unittest/mock/mock_bundle_mgr.cpp b/services/reminder/test/unittest/mock/mock_bundle_mgr.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6ee523bdfc062bebec2f495dd9630db3e7d688c9 --- /dev/null +++ b/services/reminder/test/unittest/mock/mock_bundle_mgr.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023-2023 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 "mock_bundle_mgr.h" + +#include +#include +#include "reminder_ut_constant.h" + +namespace OHOS { +namespace Notification { +namespace { +bool g_isNonBundleName = false; +bool g_isEnable = true; +} + +void MockIsNonBundleName(bool isNonBundleName) +{ + g_isNonBundleName = isNonBundleName; +} + +void MockDistributedNotificationEnabled(bool isEnable) +{ + g_isEnable = isEnable; +} +} +} + +namespace OHOS { +namespace AppExecFwk { +ErrCode BundleMgrProxy::GetNameForUid(const int uid, std::string &name) +{ + name = Notification::g_isNonBundleName ? "": "bundleName"; + return ERR_OK; +} + +bool BundleMgrProxy::GetBundleInfo(const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo, + int32_t userId) +{ + return true; +} + +int BundleMgrProxy::GetUidByBundleName(const std::string &bundleName, const int userId) +{ + if (userId == 0) { + return -1; + } else { + return Notification::NON_SYSTEM_APP_UID; + } +} + +bool BundleMgrProxy::GetApplicationInfo( + const std::string &appName, const ApplicationFlag flag, const int userId, ApplicationInfo &appInfo) +{ + appInfo.distributedNotificationEnabled = Notification::g_isEnable; + return true; +} + +} // namespace AppExecFwk +} // namespace OHOS diff --git a/services/reminder/test/unittest/mock/mock_ipc.cpp b/services/reminder/test/unittest/mock/mock_ipc.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dc9c4065d7b82c824e9d8d2cf28417ac9dccb8f1 --- /dev/null +++ b/services/reminder/test/unittest/mock/mock_ipc.cpp @@ -0,0 +1,50 @@ +/* + * 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 "mock_ipc_skeleton.h" + +namespace OHOS { +#ifdef CONFIG_IPC_SINGLE +using namespace IPC_SINGLE; +#endif + +pid_t uid_ = 1; +Security::AccessToken::AccessTokenID callerToken_ = 0; + +pid_t IPCSkeleton::GetCallingUid() +{ + return uid_; +} + +pid_t IPCSkeleton::GetCallingPid() +{ + return 1; +} + +Security::AccessToken::AccessTokenID IPCSkeleton::GetCallingTokenID() +{ + return callerToken_; +} + +void IPCSkeleton::SetCallingUid(pid_t uid) +{ + uid_ = uid; +} + +void IPCSkeleton::SetCallingTokenID(Security::AccessToken::AccessTokenID callerToken) +{ + callerToken_ = callerToken; +} +} // namespace OHOS diff --git a/services/reminder/test/unittest/mock/mock_os_account_manager_annex.cpp b/services/reminder/test/unittest/mock/mock_os_account_manager_annex.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8be5780b35d8bdd2c36a8f184568184b77c273e4 --- /dev/null +++ b/services/reminder/test/unittest/mock/mock_os_account_manager_annex.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2023 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 "os_account_manager.h" + +namespace { +int32_t g_mockId = 100; // default id when there is no os_account part +bool g_mockQueryForgroundOsAccountRet = true; +bool g_mockGetOsAccountLocalIdFromUidRet = true; +int32_t g_mockIdForGetOsAccountLocalIdFromUid = 100; +bool g_mockOsAccountExists = true; +} + +void MockQueryForgroundOsAccountId(bool mockRet, uint8_t mockCase) +{ + g_mockQueryForgroundOsAccountRet = mockRet; + switch (mockCase) { + case 1: { + g_mockId = 101; // 101 mockcase1 + break; + } + default: { + g_mockId = 100; // 100 mockdefault + break; + } + } +} + +void MockIsOsAccountExists(bool mockRet) +{ + g_mockOsAccountExists = mockRet; +} + +void ResetAccountMock() +{ + g_mockId = 100; // 100 mockId + g_mockQueryForgroundOsAccountRet = true; + g_mockGetOsAccountLocalIdFromUidRet = true; + g_mockIdForGetOsAccountLocalIdFromUid = 100; + g_mockOsAccountExists = true; +} + +void MockGetOsAccountLocalIdFromUid(bool mockRet, uint8_t mockCase = 0) +{ + g_mockGetOsAccountLocalIdFromUidRet = mockRet; + switch (mockCase) { + case 1: { // mock for invalid id + g_mockIdForGetOsAccountLocalIdFromUid = -2; // -2 mock for invalid id + break; + } + case 2: { // mock for system id + g_mockIdForGetOsAccountLocalIdFromUid = 88; // 88 mock for system id + break; + } + default: { + g_mockIdForGetOsAccountLocalIdFromUid = 100; // 100 mock for system id + break; + } + } +} + +namespace OHOS { +namespace AccountSA { +ErrCode OsAccountManager::GetForegroundOsAccountLocalId(int32_t &id) +{ + if (!g_mockQueryForgroundOsAccountRet) { + return ERR_INVALID_OPERATION; + } + id = g_mockId; + return ERR_OK; +} + +ErrCode OsAccountManager::GetOsAccountLocalIdFromUid(const int32_t uid, int32_t &id) +{ + id = g_mockIdForGetOsAccountLocalIdFromUid; + return g_mockGetOsAccountLocalIdFromUidRet ? ERR_OK : ERR_INVALID_OPERATION; +} + +ErrCode OsAccountManager::IsOsAccountExists(const int id, bool &isOsAccountExists) +{ + isOsAccountExists = g_mockOsAccountExists; + return ERR_OK; +} +} // namespace EventFwk +} // namespace OHOS \ No newline at end of file diff --git a/services/reminder/test/unittest/os_account_manager_helper_test.cpp b/services/reminder/test/unittest/os_account_manager_helper_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..38c892916826ba562a4412b74d99d842f2f1da82 --- /dev/null +++ b/services/reminder/test/unittest/os_account_manager_helper_test.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2022 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 +#include + +#include "reminder_os_account_manager_helper.h" +#include "accesstoken_kit.h" + + +using namespace testing::ext; +namespace OHOS { +namespace Notification { +class ReminderOsAccountManagerHelperTest : public testing::Test { +public: + static void SetUpTestSuite() {}; + static void TearDownTestSuite() {}; + void SetUp() override {}; + void TearDown() override {}; +}; + +/** + * @tc.number : GetOsAccountLocalIdFromUid_00100 + * @tc.name : GetOsAccountLocalIdFromUid_00100 + * @tc.desc : test GetOsAccountLocalIdFromUid function + */ +HWTEST_F(ReminderOsAccountManagerHelperTest, GetOsAccountLocalIdFromUid_00100, Function | SmallTest | Level1) +{ + int32_t userId = -1; + const int uid = 0; + ASSERT_EQ(ERR_OK, ReminderOsAccountManagerHelper::GetInstance().GetOsAccountLocalIdFromUid(uid, userId)); +} + +/** + * @tc.number : GetCurrentActiveUserId_00100 + * @tc.name : GetCurrentActiveUserId_00100 + * @tc.desc : test GetCurrentActiveUserId function + */ +HWTEST_F(ReminderOsAccountManagerHelperTest, GetCurrentActiveUserId_00100, Function | SmallTest | Level1) +{ + int32_t userId = -1; + ASSERT_EQ(ERR_OK, ReminderOsAccountManagerHelper::GetInstance().GetCurrentActiveUserId(userId)); +} +} +} \ No newline at end of file diff --git a/services/ans/test/unittest/reminder_data_manager_test.cpp b/services/reminder/test/unittest/reminder_data_manager_test.cpp similarity index 79% rename from services/ans/test/unittest/reminder_data_manager_test.cpp rename to services/reminder/test/unittest/reminder_data_manager_test.cpp index 5ca3295b1d29b46b6e5bf5dae035782147a1c290..ddfca76e67cc62a956e04cf38d1eb3b53324ae28 100644 --- a/services/ans/test/unittest/reminder_data_manager_test.cpp +++ b/services/reminder/test/unittest/reminder_data_manager_test.cpp @@ -42,7 +42,7 @@ class ReminderDataManagerTest : public testing::Test { public: static void SetUpTestCase() { - ReminderDataManager::InitInstance(nullptr); + ReminderDataManager::InitInstance(); manager = ReminderDataManager::GetInstance(); manager->Init(false); } @@ -68,12 +68,12 @@ std::shared_ptr ReminderDataManagerTest::manager = nullptr; HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_001, Level1) { sptr reminder = new ReminderRequestTimer(10); - sptr option = new NotificationBundleOption(); - manager->PublishReminder(reminder, option); - manager->CancelReminder(-1, option); + int32_t reminderId = -1; + manager->PublishReminder(reminder, reminderId); + manager->CancelReminder(reminderId, -1); manager->CancelAllReminders("", -1, -1); manager->CancelAllReminders(-1); - manager->IsMatched(reminder, "", -1, -1); + manager->IsMatched(reminder, -1, -1, true); system("rm -rf /data/service/el1/public/notification/"); EXPECT_TRUE(manager != nullptr); } @@ -86,11 +86,12 @@ HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_001, Level1) */ HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_002, Level1) { - sptr option = new NotificationBundleOption(); - std::vector> vec; - manager->GetValidReminders(option, vec); + int32_t callingUid = -1; + std::vector vec; + manager->GetValidReminders(callingUid, vec); sptr reminder = new ReminderRequestTimer(10); - manager->CheckReminderLimitExceededLocked(option, reminder); + + manager->CheckReminderLimitExceededLocked(callingUid, reminder); manager->CancelNotification(reminder); reminder->SetReminderId(10); manager->AddToShowedReminders(reminder); @@ -132,18 +133,17 @@ HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_003, Level1) */ HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_004, Level1) { - sptr option = new NotificationBundleOption(); - manager->OnProcessDiedLocked(option); + int32_t callingUid = -1; + manager->OnProcessDiedLocked(callingUid); sptr reminder = new ReminderRequestTimer(10); manager->CreateTimerInfo(ReminderDataManager::TimerType::TRIGGER_TIMER, reminder); manager->CreateTimerInfo(ReminderDataManager::TimerType::ALERTING_TIMER, reminder); - manager->FindReminderRequestLocked(0, ""); + manager->FindReminderRequestLocked(0); reminder->SetReminderId(10); manager->reminderVector_.push_back(reminder); - manager->FindReminderRequestLocked(10, ""); - option->SetBundleName("test"); - manager->FindReminderRequestLocked(10, ""); - manager->FindReminderRequestLocked(10, "test"); + manager->FindReminderRequestLocked(10); + manager->FindReminderRequestLocked(10); + manager->FindReminderRequestLocked(10); system("rm -rf /data/service/el1/public/notification/"); EXPECT_TRUE(manager != nullptr); } @@ -244,14 +244,12 @@ HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_008, Level1) */ HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_009, Level1) { + int32_t callingUid = -1; sptr reminder = new ReminderRequestTimer(10); - sptr option = new NotificationBundleOption(); - manager->UpdateAndSaveReminderLocked(reminder, option); - sptr service(new AdvancedNotificationService); - manager->SetService(service); + manager->UpdateAndSaveReminderLocked(reminder); + sptr service(new ReminderService); manager->ShouldAlert(nullptr); manager->currentUserId_ = 0; - option->SetUid(1); manager->ShouldAlert(reminder); system("rm -rf /data/service/el1/public/notification/"); EXPECT_TRUE(manager != nullptr); @@ -285,9 +283,7 @@ HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_011, Level1) { sptr reminder(new ReminderRequestTimer(10)); reminder->SetReminderId(0); - sptr option(new NotificationBundleOption()); manager->ShowReminder(reminder, true, true, true, true); - reminder->SetNotificationBundleOption(option); reminder->SetReminderId(10); manager->ShowReminder(reminder, true, true, true, true); manager->ShowReminder(reminder, true, true, true, true); @@ -447,22 +443,17 @@ HWTEST_F(ReminderDataManagerTest, ReminderDataManagerTest_017, Level1) sptr reminder1 = new ReminderRequestTimer(10); sptr reminder2 = new ReminderRequestTimer(10); sptr reminder3 = new ReminderRequestTimer(10); - int32_t oldReminderId = 1; + int32_t callingUid = 1; reminder1->SetReminderId(1); reminder2->SetReminderId(2); reminder3->SetReminderId(3); reminder1->SetGroupId("123"); reminder2->SetGroupId("123"); reminder3->SetGroupId("124"); - sptr option1 = new NotificationBundleOption(); - sptr option2 = new NotificationBundleOption(); - sptr option3 = new NotificationBundleOption(); - option1->SetBundleName("test"); - option2->SetBundleName("test"); - manager->PublishReminder(reminder1, option1); - manager->PublishReminder(reminder2, option2); - manager->PublishReminder(reminder3, option3); - manager->CloseRemindersByGroupId(oldReminderId, "test", "123"); + manager->PublishReminder(reminder1, callingUid); + manager->PublishReminder(reminder2, callingUid); + manager->PublishReminder(reminder3, callingUid); + manager->CloseRemindersByGroupId(1, "test", "123"); system("rm -rf /data/service/el1/public/notification/"); EXPECT_TRUE(reminder2->isExpired_); } @@ -632,16 +623,12 @@ HWTEST_F(ReminderDataManagerTest, StartExtensionAbilityTest_001, Level1) */ HWTEST_F(ReminderDataManagerTest, IsBelongToSameAppTest_001, Level1) { - sptr option1 = new NotificationBundleOption("test", 100); - sptr option2 = new NotificationBundleOption("test", 100); - EXPECT_TRUE(manager->IsBelongToSameApp(option1, option2)); - - option2->SetUid(101); - EXPECT_FALSE(manager->IsBelongToSameApp(option1, option2)); + int32_t uidSrc = 100; + int32_t uidTar = 100; + EXPECT_TRUE(manager->IsBelongToSameApp(uidSrc, uidTar)); - option2->SetUid(100); - option2->SetBundleName("test1"); - EXPECT_FALSE(manager->IsBelongToSameApp(option1, option2)); + uidTar = 101; + EXPECT_FALSE(manager->IsBelongToSameApp(uidSrc, uidTar)); } /** @@ -654,12 +641,12 @@ HWTEST_F(ReminderDataManagerTest, CheckIsSameAppTest_001, Level1) { sptr reminder = new ReminderRequestTimer(10); reminder->InitCreatorBundleName("test"); - reminder->InitUserId(-1); - sptr option = new NotificationBundleOption("test", -1); - EXPECT_TRUE(manager->CheckIsSameApp(reminder, option)); + int32_t callingUid = 100; + reminder->InitCreatorUid(callingUid); + EXPECT_TRUE(manager->CheckIsSameApp(reminder, callingUid)); - reminder->InitCreatorBundleName("test1"); - EXPECT_FALSE(manager->CheckIsSameApp(reminder, option)); + reminder->InitCreatorUid(-1); + EXPECT_FALSE(manager->CheckIsSameApp(reminder, callingUid)); } /** @@ -671,13 +658,13 @@ HWTEST_F(ReminderDataManagerTest, CheckIsSameAppTest_001, Level1) HWTEST_F(ReminderDataManagerTest, CheckPulishReminder_0001, Level1) { sptr reminder = new ReminderRequestTimer(10); - sptr option = new NotificationBundleOption(); + int32_t callingUid = -1; IPCSkeleton::SetCallingTokenID(0); - ErrCode ret = manager->PublishReminder(reminder, option); + ErrCode ret = manager->PublishReminder(reminder, callingUid); ASSERT_EQ(ret, ERR_REMINDER_CALLER_TOKEN_INVALID); IPCSkeleton::SetCallingTokenID(1); - ret = manager->PublishReminder(reminder, option); + ret = manager->PublishReminder(reminder, callingUid); EXPECT_NE(ret, ERR_REMINDER_DATA_SHARE_PERMISSION_DENIED); } @@ -711,17 +698,18 @@ HWTEST_F(ReminderDataManagerTest, OnLanguageChanged_0001, Level1) */ HWTEST_F(ReminderDataManagerTest, ExcludeDate_0001, Level1) { - std::vector dates; - auto result = manager->CheckExcludeDateParam(9999, nullptr); + std::vector dates; + int32_t callingUid = -1; + auto result = manager->CheckExcludeDateParam(9999, callingUid); EXPECT_TRUE(result == nullptr); - auto ret = manager->AddExcludeDate(9999, 100, nullptr); + auto ret = manager->AddExcludeDate(9999, 100, callingUid); EXPECT_TRUE(ret == ERR_REMINDER_NOT_EXIST); - ret = manager->DelExcludeDates(9999, nullptr); + ret = manager->DelExcludeDates(9999, callingUid); EXPECT_TRUE(ret == ERR_REMINDER_NOT_EXIST); - ret = manager->GetExcludeDates(9999, nullptr, dates); + ret = manager->GetExcludeDates(9999, callingUid, dates); EXPECT_TRUE(ret == ERR_REMINDER_NOT_EXIST); sptr reminder = new ReminderRequestCalendar(10); @@ -729,30 +717,29 @@ HWTEST_F(ReminderDataManagerTest, ExcludeDate_0001, Level1) reminder->InitUserId(-1); reminder->reminderId_ = 100; manager->reminderVector_.push_back(reminder); - sptr option = new NotificationBundleOption("test", -1); - result = manager->CheckExcludeDateParam(100, option); + result = manager->CheckExcludeDateParam(100, callingUid); EXPECT_TRUE(result == nullptr); reminder->InitCreatorBundleName("test"); reminder->reminderType_ = ReminderRequest::ReminderType::TIMER; - result = manager->CheckExcludeDateParam(100, option); + result = manager->CheckExcludeDateParam(100, callingUid); EXPECT_TRUE(result == nullptr); reminder->reminderType_ = ReminderRequest::ReminderType::CALENDAR; - result = manager->CheckExcludeDateParam(100, option); + result = manager->CheckExcludeDateParam(100, callingUid); EXPECT_TRUE(result == nullptr); reminder->repeatDaysOfWeek_ = 1; - result = manager->CheckExcludeDateParam(100, option); + result = manager->CheckExcludeDateParam(100, callingUid); EXPECT_TRUE(result != nullptr); - ret = manager->AddExcludeDate(100, 100, option); + ret = manager->AddExcludeDate(100, 100, callingUid); EXPECT_TRUE(ret == ERR_OK); - ret = manager->DelExcludeDates(100, option); + ret = manager->DelExcludeDates(100, callingUid); EXPECT_TRUE(ret == ERR_OK); - ret = manager->GetExcludeDates(100, option, dates); + ret = manager->GetExcludeDates(100, callingUid, dates); EXPECT_TRUE(ret == ERR_OK); } @@ -775,48 +762,6 @@ HWTEST_F(ReminderDataManagerTest, InitStartExtensionAbility_0001, Level1) EXPECT_TRUE(!manager->reminderVector_.empty()); } -/** - * @tc.name: ReminderNotificationSubscriber_00001 - * @tc.desc: Reminder data manager test - * @tc.type: FUNC - * @tc.require: issue#I9IIDE - */ -HWTEST_F(ReminderDataManagerTest, ReminderNotificationSubscriber_00001, Level1) -{ - ReminderEventManager::ReminderNotificationSubscriber test(manager); - sptr notificationReq = new NotificationRequest(); - std::shared_ptr notification = std::make_shared(notificationReq); - test.OnCanceled(notification, nullptr, NotificationConstant::CANCEL_REASON_DELETE); - SUCCEED(); - - test.OnCanceled(nullptr, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); - SUCCEED(); - - notificationReq->SetLabel(""); - test.OnCanceled(notification, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); - SUCCEED(); - - notificationReq->SetLabel("TEST_1"); - test.OnCanceled(notification, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); - SUCCEED(); - - notificationReq->SetLabel("TEST_NOTIFICATION_1"); - test.OnCanceled(notification, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); - SUCCEED(); - - notificationReq->SetLabel("REMINDER_NOTIFICATION_1"); - test.OnCanceled(notification, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); - SUCCEED(); - - notificationReq->SetLabel("REMINDER_AGENT_INFO"); - test.OnCanceled(notification, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); - SUCCEED(); - - notificationReq->SetLabel("REMINDER_AGENT_0"); - test.OnCanceled(notification, nullptr, NotificationConstant::APP_CANCEL_REASON_DELETE); - SUCCEED(); -} - /** * @tc.name: CancelAllReminders_00001 * @tc.desc: Reminder data manager test @@ -828,7 +773,7 @@ HWTEST_F(ReminderDataManagerTest, CancelAllReminders_00001, Level1) int32_t ret = manager->CancelAllReminders("", -1, -1); EXPECT_TRUE(ret == ERR_OK); - ret = manager->CancelAllReminders("com.example.simple", 100, 20020152); + ret = manager->CancelAllReminders("", 100, 20020152); EXPECT_TRUE(ret == ERR_OK); } @@ -845,8 +790,8 @@ HWTEST_F(ReminderDataManagerTest, GetVaildReminders_00001, Level1) reminder1->InitCreatorUid(98765); reminder1->InitBundleName("test_getvalid"); reminder1->InitUid(98765); - sptr option1 = new NotificationBundleOption("test_getvalid", 98765); - manager->PublishReminder(reminder1, option1); + int32_t callingUid = -1; + manager->PublishReminder(reminder1, callingUid); reminder1->SetExpired(false); sptr reminder2 = new ReminderRequestTimer(51); @@ -855,11 +800,10 @@ HWTEST_F(ReminderDataManagerTest, GetVaildReminders_00001, Level1) reminder2->InitBundleName("test_getvalid"); reminder2->InitUid(98765); reminder2->SetExpired(true); - sptr option2 = new NotificationBundleOption("test_getvalid", 98765); - manager->PublishReminder(reminder2, option2); + manager->PublishReminder(reminder2, callingUid); - std::vector> reminders; - manager->GetValidReminders(option2, reminders); + std::vector reminders; + manager->GetValidReminders(callingUid, reminders); EXPECT_TRUE(reminders.size() == 1); } @@ -877,17 +821,17 @@ HWTEST_F(ReminderDataManagerTest, IsMatched_00001, Level1) reminder->InitBundleName("test_IsMatched"); reminder->InitUid(98765); reminder->InitUserId(100); - bool ret = manager->IsMatched(reminder, "test_IsMatched", 101, 98765); + bool ret = manager->IsMatched(reminder, 101, 98765, true); EXPECT_EQ(ret, false); - ret = manager->IsMatched(reminder, "allPackages", 100, 98765); + ret = manager->IsMatched(reminder, 100, 98765, true); EXPECT_EQ(ret, true); - ret = manager->IsMatched(reminder, "test_IsMatched2", 100, 98765); + ret = manager->IsMatched(reminder, 100, 98765, true); EXPECT_EQ(ret, false); - ret = manager->IsMatched(reminder, "test_IsMatched", 100, -1); + ret = manager->IsMatched(reminder, 100, -1, true); EXPECT_EQ(ret, false); - ret = manager->IsMatched(reminder, "test_IsMatched", 100, 98766); + ret = manager->IsMatched(reminder, 100, 98766, true); EXPECT_EQ(ret, false); - ret = manager->IsMatched(reminder, "test_IsMatched", 100, 98765); + ret = manager->IsMatched(reminder, 100, 98765, true); EXPECT_EQ(ret, true); } } // namespace Notification diff --git a/services/reminder/test/unittest/reminder_service_test.cpp b/services/reminder/test/unittest/reminder_service_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..88a68eb9e938ab47067085e3fd67f246427d97f1 --- /dev/null +++ b/services/reminder/test/unittest/reminder_service_test.cpp @@ -0,0 +1,196 @@ +/* + * Copyright (c) 2021-2024 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 "errors.h" +#include +#include +#include +#include + +#include "gtest/gtest.h" +#include + +#define private public + +#include "reminder_service.h" +#include "ans_const_define.h" +#include "ans_inner_errors.h" +#include "ans_log_wrapper.h" +#include "reminder_ut_constant.h" +#include "iremote_object.h" +#include "accesstoken_kit.h" +#include "mock_ipc_skeleton.h" + +extern void MockIsOsAccountExists(bool mockRet); + +using namespace testing::ext; +using namespace OHOS::Media; + +namespace OHOS { +namespace Notification { +extern void MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum mockRet); +extern void MockIsSystemApp(bool isSystemApp); +extern void MockIsNonBundleName(bool isNonBundleName); +extern void MockIsVerfyPermisson(bool isVerify); + +class ReminderServiceTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + +private: + void TestAddLiveViewSlot(bool isForceControl); + void MockSystemApp(); + +private: + static sptr ReminderService_; +}; + +sptr ReminderServiceTest::ReminderService_ = nullptr; + +void ReminderServiceTest::SetUpTestCase() +{ + MockIsOsAccountExists(true); +} + +void ReminderServiceTest::TearDownTestCase() {} + +void ReminderServiceTest::SetUp() +{ + GTEST_LOG_(INFO) << "SetUp start"; + + ReminderService_ = new (std::nothrow) ReminderService(); + IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN); + IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); + ReminderService_->CancelAllReminders(); + MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE); + GTEST_LOG_(INFO) << "SetUp end"; +} + +void ReminderServiceTest::TearDown() +{ + IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); + ReminderService_ = nullptr; + GTEST_LOG_(INFO) << "TearDown"; +} + +void ReminderServiceTest::MockSystemApp() +{ + MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP); + MockIsSystemApp(true); + MockIsVerfyPermisson(true); +} + +inline void SleepForFC() +{ + // For Reminder Flow Control + std::this_thread::sleep_for(std::chrono::seconds(1)); +} + +/** + * @tc.number : ReminderServiceTest_13500 + * @tc.name : Reminder_GetValidReminders_0100 + * @tc.desc : Test GetValidReminders function when the result is ERR_NO_INIT + * @tc.require : issueI5S4VP + */ +HWTEST_F(ReminderServiceTest, ReminderServiceTest_13500, Function | SmallTest | Level1) +{ + std::vector reminders; + ASSERT_EQ(ReminderService_->GetValidReminders(reminders), (int)ERR_NO_INIT); +} + +/** + * @tc.number : ReminderServiceTest_16900 + * @tc.name : Reminder_GetActiveNotifications_0100 + * @tc.desc : Test function with bundle option is null + * @tc.require : #I60KYN + */ +HWTEST_F(ReminderServiceTest, ReminderServiceTest_16900, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "Reminder_GetActiveNotifications_0100 test start"; + + MockIsNonBundleName(true); + MockSystemApp(); + int32_t reminderId = 1; + ASSERT_EQ(ReminderService_->CancelReminder(reminderId), ERR_ANS_INVALID_BUNDLE); + + ASSERT_EQ(ReminderService_->CancelAllReminders(), ERR_ANS_INVALID_BUNDLE); + + std::vector reminders; + ASSERT_EQ(ReminderService_->GetValidReminders(reminders), ERR_ANS_INVALID_BUNDLE); + + MockIsNonBundleName(false); + GTEST_LOG_(INFO) << "Reminder_GetActiveNotifications_0100 test end"; +} + +/** + * @tc.number : AddExcludeDate_00001 + * @tc.name : Test AddExcludeDate + * @tc.desc : Test AddExcludeDate function when the result is ERR_NO_INIT + * @tc.require : issueI5S4VP + */ +HWTEST_F(ReminderServiceTest, AddExcludeDate_00001, Function | SmallTest | Level1) +{ + int32_t reminderId = 10; + uint64_t time = 124325; + MockIsVerfyPermisson(false); + ASSERT_EQ(ReminderService_->AddExcludeDate(reminderId, time), (int)ERR_REMINDER_PERMISSION_DENIED); + MockIsNonBundleName(true); + ASSERT_EQ(ReminderService_->AddExcludeDate(reminderId, time), (int)ERR_ANS_INVALID_BUNDLE); + MockIsNonBundleName(false); + ASSERT_EQ(ReminderService_->AddExcludeDate(reminderId, time), (int)ERR_NO_INIT); + MockIsVerfyPermisson(false); +} + +/** + * @tc.number : DelExcludeDates_00002 + * @tc.name : Test DelExcludeDates + * @tc.desc : Test DelExcludeDates function when the result is ERR_NO_INIT + * @tc.require : issueI5S4VP + */ +HWTEST_F(ReminderServiceTest, DelExcludeDates_00002, Function | SmallTest | Level1) +{ + int32_t reminderId = 10; + MockIsVerfyPermisson(false); + ASSERT_EQ(ReminderService_->DelExcludeDates(reminderId), (int)ERR_REMINDER_PERMISSION_DENIED); + MockIsNonBundleName(true); + ASSERT_EQ(ReminderService_->DelExcludeDates(reminderId), (int)ERR_ANS_INVALID_BUNDLE); + MockIsNonBundleName(false); + ASSERT_EQ(ReminderService_->DelExcludeDates(reminderId), (int)ERR_NO_INIT); + MockIsVerfyPermisson(false); +} + +/** + * @tc.number : GetExcludeDates_00001 + * @tc.name : Test GetExcludeDates + * @tc.desc : Test GetExcludeDates function when the result is ERR_NO_INIT + * @tc.require : issueI5S4VP + */ +HWTEST_F(ReminderServiceTest, GetExcludeDates_00001, Function | SmallTest | Level1) +{ + int32_t reminderId = 10; + std::vector times; + MockIsVerfyPermisson(false); + ASSERT_EQ(ReminderService_->GetExcludeDates(reminderId, times), (int)ERR_REMINDER_PERMISSION_DENIED); + MockIsNonBundleName(true); + ASSERT_EQ(ReminderService_->GetExcludeDates(reminderId, times), (int)ERR_ANS_INVALID_BUNDLE); + MockIsNonBundleName(false); + ASSERT_EQ(ReminderService_->GetExcludeDates(reminderId, times), (int)ERR_NO_INIT); + MockIsVerfyPermisson(false); +} +} // namespace Notification +} // namespace OHOS diff --git a/services/reminder/test/unittest/reminder_service_test/reminder_service_publish_test.cpp b/services/reminder/test/unittest/reminder_service_test/reminder_service_publish_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9ba484a3fea77863037c6bd137f39d5fee0edece --- /dev/null +++ b/services/reminder/test/unittest/reminder_service_test/reminder_service_publish_test.cpp @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2021-2024 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 "errors.h" +#include "notification_content.h" +#include "notification_request.h" +#include +#include +#include +#include + +#include "gtest/gtest.h" +#include + +#define private public +#define protected public + +#include "reminder_service.h" +#include "ans_const_define.h" +#include "ans_inner_errors.h" +#include "ans_log_wrapper.h" +#include "reminder_ut_constant.h" +#include "iremote_object.h" +#include "mock_ipc_skeleton.h" + +#include "reminder_bundle_manager_helper.h" + +extern void MockIsOsAccountExists(bool mockRet); + +using namespace testing::ext; +using namespace OHOS::Media; + +namespace OHOS { +namespace Notification { +extern void MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum mockRet); +extern void MockIsSystemApp(bool isSystemApp); +extern void MockIsNonBundleName(bool isNonBundleName); +extern void MockIsVerfyPermisson(bool isVerify); + +class ReminderServicePublishTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + +private: + void TestAddSlot(NotificationConstant::SlotType type); + void TestAddLiveViewSlot(bool isForceControl); + void MockSystemApp(); + +private: + static sptr reminderService_; +}; + +sptr ReminderServicePublishTest::reminderService_ = nullptr; + +void ReminderServicePublishTest::SetUpTestCase() +{ + MockIsOsAccountExists(true); +} + +void ReminderServicePublishTest::TearDownTestCase() {} + +void ReminderServicePublishTest::SetUp() +{ + GTEST_LOG_(INFO) << "SetUp start"; + + reminderService_ = new (std::nothrow) ReminderService(); + IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN); + IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); + + MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE); + GTEST_LOG_(INFO) << "SetUp end"; +} + +void ReminderServicePublishTest::TearDown() +{ + IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); + reminderService_ = nullptr; + GTEST_LOG_(INFO) << "TearDown"; +} + +inline void SleepForFC() +{ + // For ANS Flow Control + std::this_thread::sleep_for(std::chrono::seconds(1)); +} + +void ReminderServicePublishTest::MockSystemApp() +{ + MockGetTokenTypeFlag(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP); + MockIsSystemApp(true); + MockIsVerfyPermisson(true); +} + +/** + * @tc.number : ReminderServicePublishTest_13200 + * @tc.name : ANS_PublishReminder_0100 + * @tc.desc : Test PublishReminder function + * @tc.require : issueI5S4VP + */ +HWTEST_F(ReminderServicePublishTest, ReminderServicePublishTest_13200, Function | SmallTest | Level1) +{ + int32_t reminderId = 0; + ReminderRequest reminder; + ASSERT_EQ(reminderService_->PublishReminder(reminder, reminderId), ERR_ANS_INVALID_PARAM); +} + +/** + * @tc.number : ReminderServicePublishTest_13300 + * @tc.name : ANS_CancelReminder_0100 + * @tc.desc : Test CancelReminder function when the result is ERR_NO_INIT + * @tc.require : issueI5S4VP + */ +HWTEST_F(ReminderServicePublishTest, ReminderServicePublishTest_13300, Function | SmallTest | Level1) +{ + int32_t reminderId = 1; + ASSERT_EQ(reminderService_->CancelReminder(reminderId), (int)ERR_NO_INIT); +} + +/** + * @tc.number : ReminderServicePublishTest_13400 + * @tc.name : ANS_CancelAllReminders_0100 + * @tc.desc : Test CancelAllReminders function when the result is ERR_NO_INIT + * @tc.require : issueI5S4VP + */ +HWTEST_F(ReminderServicePublishTest, ReminderServicePublishTest_13400, Function | SmallTest | Level1) +{ + ASSERT_EQ(reminderService_->CancelAllReminders(), (int)ERR_NO_INIT); +} + +/** + * @tc.number : ReminderServicePublishTest_17900 + * @tc.name : PublishReminder_1000 + * @tc.desc : Test PublishReminder function. + * @tc.require : #I61RF2 + */ +HWTEST_F(ReminderServicePublishTest, ReminderServicePublishTest_17900, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetAppTargetBundle_1000 test start"; + + int32_t reminderId = 1; + ReminderRequest reminder; + ASSERT_EQ(reminderService_->PublishReminder(reminder, reminderId), ERR_REMINDER_NOTIFICATION_NOT_ENABLE); + + GTEST_LOG_(INFO) << "GetAppTargetBundle_1000 test end"; +} + +/** + * @tc.number : ReminderServicePublishTest_18000 + * @tc.name : PublishReminder_2000 + * @tc.desc : Test PublishReminder function. + * @tc.require : #I61RF2 + */ +HWTEST_F(ReminderServicePublishTest, ReminderServicePublishTest_18000, Function | SmallTest | Level1) +{ + GTEST_LOG_(INFO) << "GetAppTargetBundle_2000 test start"; + + MockIsNonBundleName(true); + int32_t reminderId = 1; + ReminderRequest reminder; + ASSERT_EQ(reminderService_->PublishReminder(reminder, reminderId), ERR_ANS_INVALID_BUNDLE); + MockIsNonBundleName(false); + GTEST_LOG_(INFO) << "GetAppTargetBundle_2000 test end"; +} +} // namespace Notification +} // namespace OHOS diff --git a/frameworks/ans/test/unittest/reminder_store_test.cpp b/services/reminder/test/unittest/reminder_store_test.cpp similarity index 93% rename from frameworks/ans/test/unittest/reminder_store_test.cpp rename to services/reminder/test/unittest/reminder_store_test.cpp index d50879009dae9a46edeacae841cad9264e62bf4c..d629397c33f97691a63bba5fa2af72b6db33d9ed 100644 --- a/frameworks/ans/test/unittest/reminder_store_test.cpp +++ b/services/reminder/test/unittest/reminder_store_test.cpp @@ -26,7 +26,6 @@ #undef private #undef protected #include "reminder_helper.h" -#include "notification_preferences.h" using namespace testing::ext; namespace OHOS { @@ -68,11 +67,8 @@ public: NativeRdb::RdbHelper::ClearCache(); NativeRdb::RdbHelper::DeleteRdbStore(ReminderStore::REMINDER_DB_DIR + "notification_test.db"); } - static sptr bundleOption_; }; -sptr ReminderStoreTest::bundleOption_ = - new NotificationBundleOption(TEST_DEFUALT_BUNDLE, NON_SYSTEM_APP_UID); /** * @tc.name: Init_00001 @@ -122,10 +118,9 @@ HWTEST_F(ReminderStoreTest, Delete_00001, Function | SmallTest | Level1) */ HWTEST_F(ReminderStoreTest, Delete_00002, Function | SmallTest | Level1) { - std::string pkg = "pkg"; int32_t userId = 1; ReminderStore reminderStore; - int32_t ret = reminderStore.Delete(pkg, userId, -1); + int32_t ret = reminderStore.Delete("", userId, -1); EXPECT_EQ(ret, -1); } @@ -153,7 +148,7 @@ HWTEST_F(ReminderStoreTest, Insert_00001, Function | SmallTest | Level1) { sptr reminder = nullptr; ReminderStore reminderStore; - int64_t ret = reminderStore.Insert(reminder, bundleOption_); + int64_t ret = reminderStore.Insert(reminder); EXPECT_EQ(ret, -1); } @@ -167,7 +162,7 @@ HWTEST_F(ReminderStoreTest, Update_00001, Function | SmallTest | Level1) { sptr reminder = nullptr; ReminderStore reminderStore; - int64_t ret = reminderStore.Update(reminder, bundleOption_); + int64_t ret = reminderStore.Update(reminder); EXPECT_EQ(ret, -1); } @@ -282,7 +277,7 @@ HWTEST_F(ReminderStoreTest, UpdateOrInsert_00001, Function | SmallTest | Level1) { sptr reminder = nullptr; ReminderStore reminderStore; - int64_t ret = reminderStore.UpdateOrInsert(reminder, bundleOption_); + int64_t ret = reminderStore.UpdateOrInsert(reminder); EXPECT_EQ(ret, -1); } @@ -351,8 +346,7 @@ HWTEST_F(ReminderStoreTest, ReminderTimerStrategyTest_00001, Function | SmallTes ReminderRequestTimer* timer = static_cast(reminder.GetRefPtr()); timer->countDownTimeInSeconds_ = 10001; - sptr bundleOption = new NotificationBundleOption("test", 101); - reminderStore.UpdateOrInsert(reminder, bundleOption); + reminderStore.UpdateOrInsert(reminder); auto reminders = reminderStore.GetAllValidReminders(); bool succeed = false; for (auto each : reminders) { @@ -412,8 +406,7 @@ HWTEST_F(ReminderStoreTest, ReminderTimerStrategyTest_00002, Function | SmallTes ReminderRequestTimer* timer = static_cast(reminder.GetRefPtr()); timer->countDownTimeInSeconds_ = 10001; - sptr bundleOption = new NotificationBundleOption("test", 101); - reminderStore.UpdateOrInsert(reminder, bundleOption); + reminderStore.UpdateOrInsert(reminder); auto reminders = reminderStore.GetAllValidReminders(); bool succeed = false; for (auto each : reminders) { @@ -467,8 +460,7 @@ HWTEST_F(ReminderStoreTest, ReminderTimerStrategyTest_00003, Function | SmallTes ReminderRequestTimer* timer = static_cast(reminder.GetRefPtr()); timer->countDownTimeInSeconds_ = 10001; - sptr bundleOption = new NotificationBundleOption("test", 101); - reminderStore.UpdateOrInsert(reminder, bundleOption); + reminderStore.UpdateOrInsert(reminder); auto reminders = reminderStore.GetAllValidReminders(); bool succeed = false; for (auto each : reminders) { @@ -508,8 +500,7 @@ HWTEST_F(ReminderStoreTest, ReminderAlarmStrategyTest_00001, Function | SmallTes alarm->hour_ = 12; alarm->minute_ = 30; - sptr bundleOption = new NotificationBundleOption("test", 101); - reminderStore.UpdateOrInsert(reminder, bundleOption); + reminderStore.UpdateOrInsert(reminder); auto reminders = reminderStore.GetAllValidReminders(); bool succeed = false; for (auto each : reminders) { @@ -557,8 +548,7 @@ HWTEST_F(ReminderStoreTest, ReminderCalendarStrategyTest_00001, Function | Small calendar->repeatMonth_ = 13; calendar->AddExcludeDate(ts); - sptr bundleOption = new NotificationBundleOption("test", 101); - reminderStore.UpdateOrInsert(reminder, bundleOption); + reminderStore.UpdateOrInsert(reminder); auto reminders = reminderStore.GetAllValidReminders(); bool succeed = false; for (auto each : reminders) { @@ -610,8 +600,7 @@ HWTEST_F(ReminderStoreTest, ReminderCalendarStrategyTest_00002, Function | Small calendar->rruleWantAgentInfo_->abilityName = "abilityName"; calendar->rruleWantAgentInfo_->uri = "uri"; - sptr bundleOption = new NotificationBundleOption("test", 101); - reminderStore.UpdateOrInsert(reminder, bundleOption); + reminderStore.UpdateOrInsert(reminder); auto reminders = reminderStore.GetAllValidReminders(); bool succeed = false; for (auto each : reminders) { diff --git a/services/reminder/test/unittest/reminder_ut_constant.h b/services/reminder/test/unittest/reminder_ut_constant.h new file mode 100644 index 0000000000000000000000000000000000000000..676455b87b191e096f8cfd0496a80cda7ce27e71 --- /dev/null +++ b/services/reminder/test/unittest/reminder_ut_constant.h @@ -0,0 +1,34 @@ +/* + * 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_SERVICES_ANS_TEST_UNITEST_REMINDER_UT_CONSTANT_H +#define BASE_NOTIFICATION_ANS_STANDARD_SERVICES_ANS_TEST_UNITEST_REMINDER_UT_CONSTANT_H + +#include + +namespace OHOS { +namespace Notification { +constexpr uint32_t NATIVE_TOKEN = 0; +constexpr uint32_t NON_NATIVE_TOKEN = 1; +constexpr uint32_t DLP_NATIVE_TOKEN = 2; +constexpr int32_t SYSTEM_APP_UID = 100; +constexpr int32_t NON_SYSTEM_APP_UID = 1000; +constexpr int32_t NON_BUNDLE_NAME_UID = 2000; +const std::string TEST_DEFUALT_BUNDLE = "bundleName"; +constexpr int32_t TEST_SUBSCRIBE_USER_INIT = -1; +} // namespace Notification +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/services/test/moduletest/BUILD.gn b/services/test/moduletest/BUILD.gn index 1c3e9f6ca5988ee843dd8f87052b0bb081ad0210..83a2800e383863b0491b12182e70f6a9e7f6c39e 100644 --- a/services/test/moduletest/BUILD.gn +++ b/services/test/moduletest/BUILD.gn @@ -26,7 +26,6 @@ ohos_moduletest("ans_module_test") { "${services_path}/ans/test/unittest", "${services_path}/ans/test/unittest/mock/include", "${services_path}/test/moduletest/mock/include", - "${ffrt_path}/interfaces/kits", ] sources = [ diff --git a/test/bechmarktest/notification_services_test/BUILD.gn b/test/bechmarktest/notification_services_test/BUILD.gn index 3d7d3916357153e70f4ab225151040b027d527ca..d19d933cad09411af7ec363bd2588129ec5f8dbc 100644 --- a/test/bechmarktest/notification_services_test/BUILD.gn +++ b/test/bechmarktest/notification_services_test/BUILD.gn @@ -25,7 +25,6 @@ ohos_benchmarktest("Benchmark_Notification_Servece_Test") { "${access_token_path}/interfaces/innerkits/nativetoken/include", "${access_token_path}/interfaces/innerkits/accesstoken/include", "${services_path}/ans/include", - "${ffrt_path}/interfaces/kits", ] sources = [ diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 9c4a7e4619d52806279a53d7b7b2c9f19137990d..41863d197b01fe9ccddbfeeed4589e729a30ffd3 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -82,6 +82,7 @@ group("fuzztest") { "reminderrequestcalendar_fuzzer:ReminderRequestCalendarFuzzTest", "reminderrequestcontinuate_fuzzer:ReminderRequestContinuateFuzzTest", "reminderrequesttimer_fuzzer:ReminderRequestTimerFuzzTest", + "reminderservice_fuzzer:ReminderServiceFuzzTest", "reminderstore_fuzzer:ReminderStoreFuzzTest", "reminderstoreannex_fuzzer:ReminderStoreAnnexFuzzTest", "removenotification_fuzzer:RemoveNotificationFuzzTest", diff --git a/test/fuzztest/advancednotificationservice_fuzzer/BUILD.gn b/test/fuzztest/advancednotificationservice_fuzzer/BUILD.gn index c93255c1afb36cba9803e794815baa4702bec4b5..cf431ff4a0c2c80c3fdff18cc31edfa1dbd0d1a7 100644 --- a/test/fuzztest/advancednotificationservice_fuzzer/BUILD.gn +++ b/test/fuzztest/advancednotificationservice_fuzzer/BUILD.gn @@ -24,7 +24,6 @@ ohos_fuzztest("AdvancedNotificationServiceFuzzTest") { include_dirs = [ "${services_path}/ans/include", "${core_path}/include", - "${ffrt_path}/interfaces/kits", ] cflags = [ diff --git a/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp b/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp index 871a89ba996b32e0e03295e12752051bf627cce9..1c8b5bee8596bbaeb84fd1d26d4ce960e14c0a0e 100644 --- a/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp @@ -126,18 +126,6 @@ namespace OHOS { sptr request = new Notification::NotificationRequest(); service->PublishContinuousTaskNotification(request); service->CancelContinuousTaskNotification(stringData, notificationId); - sptr reminder = new Notification::ReminderRequest(); - service->PublishReminder(reminder); - int32_t reminderId = fuzzData->ConsumeIntegral(); - service->CancelReminder(reminderId); - std::vector> reminders; - service->GetValidReminders(reminders); - service->CancelAllReminders(); - uint64_t excludeDate = fuzzData->ConsumeIntegral(); - service->AddExcludeDate(reminderId, excludeDate); - service->DelExcludeDates(reminderId); - std::vector excludeDates; - service->GetExcludeDates(reminderId, excludeDates); bool support = fuzzData->ConsumeBool(); service->IsSupportTemplate(stringData, support); service->IsSpecialUserAllowedNotify(userId, allowed); diff --git a/test/fuzztest/ansmanagerstub_fuzzer/BUILD.gn b/test/fuzztest/ansmanagerstub_fuzzer/BUILD.gn index dcfbae6c64ee35338c3798505ac123b0fa8e96aa..3f90b7d7904ceca06b3b5692845fe4bdd1b6d89e 100644 --- a/test/fuzztest/ansmanagerstub_fuzzer/BUILD.gn +++ b/test/fuzztest/ansmanagerstub_fuzzer/BUILD.gn @@ -24,7 +24,6 @@ ohos_fuzztest("AnsManagerStubFuzzTest") { include_dirs = [ "${services_path}/ans/include", "${core_path}/include", - "${ffrt_path}/interfaces/kits", ] defines = [] cflags = [ diff --git a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp index fb488dc33812e659aab0cc2d18187f14f177cfde..ac5fae3281594287d7d20b97589f40143448242a 100644 --- a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp @@ -251,18 +251,6 @@ namespace OHOS { datas.WriteInt32(intData); datas.WriteInt32(intData); ansManagerStub.HandleShellDump(datas, reply); - ansManagerStub.HandlePublishReminder(datas, reply); - datas.WriteInt32(intData); - ansManagerStub.HandleCancelReminder(datas, reply); - ansManagerStub.HandleCancelAllReminders(datas, reply); - ansManagerStub.HandleGetValidReminders(datas, reply); - datas.WriteInt32(intData); - datas.WriteUint64(intData); - ansManagerStub.HandleAddExcludeDate(datas, reply); - datas.WriteInt32(intData); - ansManagerStub.HandleDelExcludeDates(datas, reply); - datas.WriteInt32(intData); - ansManagerStub.HandleGetExcludeDates(datas, reply); datas.WriteString(stringData); ansManagerStub.HandleIsSupportTemplate(datas, reply); datas.WriteInt32(intData); @@ -399,18 +387,6 @@ namespace OHOS { sptr request = new Notification::NotificationRequest(); ansManagerStub.PublishContinuousTaskNotification(request); ansManagerStub.CancelContinuousTaskNotification(stringData, notificationId); - sptr reminder = new Notification::ReminderRequest(); - ansManagerStub.PublishReminder(reminder); - int32_t reminderId = fuzzData->ConsumeIntegral(); - ansManagerStub.CancelReminder(reminderId); - std::vector> reminders; - ansManagerStub.GetValidReminders(reminders); - ansManagerStub.CancelAllReminders(); - uint64_t excludeDate = fuzzData->ConsumeIntegral(); - ansManagerStub.AddExcludeDate(reminderId, excludeDate); - ansManagerStub.DelExcludeDates(reminderId); - std::vector excludeDates; - ansManagerStub.GetExcludeDates(reminderId, excludeDates); bool support = fuzzData->ConsumeBool(); ansManagerStub.IsSupportTemplate(stringData, support); ansManagerStub.IsSpecialUserAllowedNotify(userId, allowed); diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/BUILD.gn b/test/fuzztest/ansmanagerstubannex_fuzzer/BUILD.gn index cfbac6226ef45baa322436f33157f4e6435ce8c4..c755413d7e2e212fc039885e679e52d08599f0d1 100644 --- a/test/fuzztest/ansmanagerstubannex_fuzzer/BUILD.gn +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/BUILD.gn @@ -25,7 +25,6 @@ ohos_fuzztest("AnsManagerStubAnnexFuzzTest") { include_dirs = [ "${services_path}/ans/include", "${core_path}/include", - "${ffrt_path}/interfaces/kits", ] cflags = [ diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp index eac3447760289114d459b23788a95ce2a8dc4a1d..60d5c977c9dd19311f3dcaca8a9568bec11e62f0 100644 --- a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp @@ -250,18 +250,6 @@ namespace OHOS { datas.WriteInt32(intData); datas.WriteInt32(intData); ansManagerStub.HandleShellDump(datas, reply); - ansManagerStub.HandlePublishReminder(datas, reply); - datas.WriteInt32(intData); - ansManagerStub.HandleCancelReminder(datas, reply); - ansManagerStub.HandleCancelAllReminders(datas, reply); - ansManagerStub.HandleGetValidReminders(datas, reply); - datas.WriteInt32(intData); - datas.WriteUint64(intData); - ansManagerStub.HandleAddExcludeDate(datas, reply); - datas.WriteInt32(intData); - ansManagerStub.HandleDelExcludeDates(datas, reply); - datas.WriteInt32(intData); - ansManagerStub.HandleGetExcludeDates(datas, reply); datas.WriteString(stringData); ansManagerStub.HandleIsSupportTemplate(datas, reply); datas.WriteInt32(intData); @@ -395,18 +383,6 @@ namespace OHOS { sptr request = new Notification::NotificationRequest(); ansManagerStub.PublishContinuousTaskNotification(request); ansManagerStub.CancelContinuousTaskNotification(stringData, notificationId); - sptr reminder = new Notification::ReminderRequest(); - ansManagerStub.PublishReminder(reminder); - int32_t reminderId = fuzzData->ConsumeIntegral(); - ansManagerStub.CancelReminder(reminderId); - std::vector> reminders; - ansManagerStub.GetValidReminders(reminders); - ansManagerStub.CancelAllReminders(); - uint64_t excludeDate = fuzzData->ConsumeIntegral(); - ansManagerStub.AddExcludeDate(reminderId, excludeDate); - ansManagerStub.DelExcludeDates(reminderId); - std::vector excludeDates; - ansManagerStub.GetExcludeDates(reminderId, excludeDates); bool support = fuzzData->ConsumeBool(); ansManagerStub.IsSupportTemplate(stringData, support); ansManagerStub.IsSpecialUserAllowedNotify(userId, allowed); diff --git a/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp index ebac94b90822aba4656c4842ea28904427db6739..3b5c561523da52dd3caadd3c6e3a54e3fc7563fc 100644 --- a/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp +++ b/test/fuzztest/ansmanagerstubannexthree_fuzzer/ansmanagerstubannexthree_fuzzer.cpp @@ -242,18 +242,6 @@ namespace OHOS { datas.WriteInt32(intData); datas.WriteInt32(intData); ansManagerStub.HandleShellDump(datas, reply); - ansManagerStub.HandlePublishReminder(datas, reply); - datas.WriteInt32(intData); - ansManagerStub.HandleCancelReminder(datas, reply); - ansManagerStub.HandleCancelAllReminders(datas, reply); - ansManagerStub.HandleGetValidReminders(datas, reply); - datas.WriteInt32(intData); - datas.WriteUint64(intData); - ansManagerStub.HandleAddExcludeDate(datas, reply); - datas.WriteInt32(intData); - ansManagerStub.HandleDelExcludeDates(datas, reply); - datas.WriteInt32(intData); - ansManagerStub.HandleGetExcludeDates(datas, reply); datas.WriteString(stringData); ansManagerStub.HandleIsSupportTemplate(datas, reply); datas.WriteInt32(intData); @@ -387,18 +375,6 @@ namespace OHOS { sptr request = new Notification::NotificationRequest(); ansManagerStub.PublishContinuousTaskNotification(request); ansManagerStub.CancelContinuousTaskNotification(stringData, notificationId); - sptr reminder = new Notification::ReminderRequest(); - ansManagerStub.PublishReminder(reminder); - int32_t reminderId = fuzzData->ConsumeIntegral(); - ansManagerStub.CancelReminder(reminderId); - std::vector> reminders; - ansManagerStub.GetValidReminders(reminders); - ansManagerStub.CancelAllReminders(); - uint64_t excludeDate = fuzzData->ConsumeIntegral(); - ansManagerStub.AddExcludeDate(reminderId, excludeDate); - ansManagerStub.DelExcludeDates(reminderId); - std::vector excludeDates; - ansManagerStub.GetExcludeDates(reminderId, excludeDates); bool support = fuzzData->ConsumeBool(); ansManagerStub.IsSupportTemplate(stringData, support); ansManagerStub.IsSpecialUserAllowedNotify(userId, allowed); diff --git a/test/fuzztest/notificationrequest_fuzzer/notificationrequest_fuzzer.cpp b/test/fuzztest/notificationrequest_fuzzer/notificationrequest_fuzzer.cpp index 0d8709c870d94af4cde4646cec6d09c421e0a4c6..e761abe5e88150478f7901341ffd25db9be7181a 100644 --- a/test/fuzztest/notificationrequest_fuzzer/notificationrequest_fuzzer.cpp +++ b/test/fuzztest/notificationrequest_fuzzer/notificationrequest_fuzzer.cpp @@ -43,7 +43,6 @@ namespace OHOS { request.GetWantAgent(); request.SetRemovalWantAgent(wantAgent); request.GetRemovalWantAgent(); - request.SetMaxScreenWantAgent(wantAgent); request.GetMaxScreenWantAgent(); std::shared_ptr extras = nullptr; request.SetAdditionalData(extras); diff --git a/test/fuzztest/reminderdatamanager_fuzzer/BUILD.gn b/test/fuzztest/reminderdatamanager_fuzzer/BUILD.gn index 29f362f31c60504de1cb8de3bfd6bf79bdaca222..44df209c64006380ef1f42093a8982fdce6de3ed 100644 --- a/test/fuzztest/reminderdatamanager_fuzzer/BUILD.gn +++ b/test/fuzztest/reminderdatamanager_fuzzer/BUILD.gn @@ -24,7 +24,7 @@ ohos_fuzztest("ReminderDataManagerFuzzTest") { include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base", - "${component_path}/services/ans/include", + "${component_path}/services/reminder/include", ] cflags = [ "-g", @@ -38,8 +38,8 @@ ohos_fuzztest("ReminderDataManagerFuzzTest") { deps = [ "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", - "${frameworks_module_ans_path}:ans_innerkits", - "${services_path}/ans:libans", + "${frameworks_module_reminder_path}:reminder_innerkits", + "${services_path}/reminder:libreminder", ] external_deps = [ diff --git a/test/fuzztest/reminderdatamanager_fuzzer/reminderdatamanager_fuzzer.cpp b/test/fuzztest/reminderdatamanager_fuzzer/reminderdatamanager_fuzzer.cpp index e157d2a8828d275e5b5ab6a2bbca8a76e7f50276..d7d6087cef4f43b25b1d52b1d3b7668b1e00ea72 100644 --- a/test/fuzztest/reminderdatamanager_fuzzer/reminderdatamanager_fuzzer.cpp +++ b/test/fuzztest/reminderdatamanager_fuzzer/reminderdatamanager_fuzzer.cpp @@ -28,27 +28,26 @@ namespace OHOS { uint64_t date = fdp->ConsumeIntegral(); bool value = fdp->ConsumeBool(); uint8_t type = fdp->ConsumeIntegral(); + int32_t callingUid = fdp->ConsumeIntegral(); EventFwk::Want want; constexpr uint64_t seconds = 1200; sptr reminder = new Notification::ReminderRequestTimer(seconds); - Notification::ReminderDataManager::InitInstance(nullptr); + Notification::ReminderDataManager::InitInstance(); auto manager = Notification::ReminderDataManager::GetInstance(); manager->Init(false); manager->Dump(); manager->CancelAllReminders(bundleName, userId, uid); - sptr option = new Notification::NotificationBundleOption( - bundleName, uid); - manager->CancelReminder(reminderId, option); - manager->CheckExcludeDateParam(reminderId, option); - manager->AddExcludeDate(reminderId, date, option); - manager->DelExcludeDates(reminderId, option); + manager->CancelReminder(reminderId, callingUid); + manager->CheckExcludeDateParam(reminderId, callingUid); + manager->AddExcludeDate(reminderId, date, callingUid); + manager->DelExcludeDates(reminderId, callingUid); - std::vector dates; - manager->GetExcludeDates(reminderId, option, dates); + std::vector dates; + manager->GetExcludeDates(reminderId, callingUid, dates); manager->CloseReminder(want, value); - std::vector> reminders; - manager->GetValidReminders(option, reminders); + std::vector reminders; + manager->GetValidReminders(callingUid, reminders); manager->Init(value); manager->InitUserId(); std::vector> immediatelyReminders; @@ -60,7 +59,7 @@ namespace OHOS { manager->OnBundleMgrServiceStart(); manager->OnAbilityMgrServiceStart(); manager->OnUserSwitch(userId); - manager->OnProcessDiedLocked(option); + manager->OnProcessDiedLocked(callingUid); manager->RefreshRemindersDueToSysTimeChange(type); manager->ShouldAlert(reminder); manager->ShowActiveReminder(want); @@ -79,25 +78,23 @@ namespace OHOS { int32_t uid = fdp->ConsumeIntegral(); int32_t reminderId = fdp->ConsumeIntegral(); bool value = fdp->ConsumeBool(); + int32_t callingUid = fdp->ConsumeIntegral(); constexpr uint64_t seconds = 1200; sptr reminder = new Notification::ReminderRequestTimer(seconds); auto manager = Notification::ReminderDataManager::GetInstance(); - sptr option = new Notification::NotificationBundleOption( - bundleName, uid); manager->OnLanguageChanged(); manager->OnRemoveAppMgr(); manager->CancelAllReminders(userId); manager->CheckUpdateConditions(reminder, Notification::ReminderRequest::ActionButtonType::INVALID, reminder->GetActionButtons()); manager->GetCustomRingUri(reminder); - manager->CancelRemindersImplLocked(bundleName, userId, uid); + manager->CancelRemindersImplLocked(bundleName, userId, uid, value); manager->CloseRemindersByGroupId(reminderId, bundleName, bundleName); manager->CancelNotification(reminder); - manager->CheckReminderLimitExceededLocked(option, reminder); + manager->CheckReminderLimitExceededLocked(callingUid, reminder); std::vector> reminders; manager->GetImmediatelyShowRemindersLocked(reminders); - manager->GetSoundUri(reminder); manager->AddToShowedReminders(reminder); manager->IsAllowedNotify(reminder); @@ -113,15 +110,14 @@ namespace OHOS { std::vector> extensionReminders; std::vector> immediatelyReminders; - manager->PublishReminder(reminder, option); + manager->PublishReminder(reminder, callingUid); manager->FindReminderRequestLocked(reminderId); - manager->FindReminderRequestLocked(reminderId, bundleName); manager->GetRecentReminderLocked(); manager->HandleImmediatelyShow(immediatelyReminders, value); manager->HandleExtensionReminder(extensionReminders); manager->HandleSameNotificationIdShowing(reminder); - manager->IsBelongToSameApp(option, option); - manager->CheckIsSameApp(reminder, option); + manager->IsBelongToSameApp(uid, uid); + manager->CheckIsSameApp(reminder, uid); manager->ShowReminder(reminder, value, value, value, value); return true; } diff --git a/test/fuzztest/reminderhelper_fuzzer/BUILD.gn b/test/fuzztest/reminderhelper_fuzzer/BUILD.gn index 106b694e830560c3d42926c0edd239a6ba660ef9..88159ad7529df0bffb38164f05e464b7d000daea 100644 --- a/test/fuzztest/reminderhelper_fuzzer/BUILD.gn +++ b/test/fuzztest/reminderhelper_fuzzer/BUILD.gn @@ -32,7 +32,7 @@ ohos_fuzztest("ReminderHelperFuzzTest") { deps = [ "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", - "${frameworks_module_ans_path}:ans_innerkits", + "${frameworks_module_reminder_path}:reminder_innerkits", ] external_deps = [ diff --git a/test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.cpp b/test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.cpp index c4597246799f5bfe5c4b5874377eb3ce1b1453ba..557bc304d513ac374fe477476fa1caa90a1f89f3 100644 --- a/test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.cpp +++ b/test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.cpp @@ -22,34 +22,24 @@ #include namespace OHOS { - namespace { - constexpr uint8_t SLOT_TYPE_NUM = 5; - } bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider* fdp) { std::string stringData = fdp->ConsumeRandomLengthString(); Notification::ReminderRequest reminder; reminder.SetContent(stringData); reminder.SetExpiredContent(stringData); - Notification::ReminderHelper::PublishReminder(reminder); + int32_t reminderId2 = 0; + Notification::ReminderHelper::PublishReminder(reminder, reminderId2); int32_t reminderId = fdp->ConsumeIntegral(); Notification::ReminderHelper::CancelReminder(reminderId); - sptr valid = new Notification::ReminderRequest(); - std::vector> validReminders; + Notification::ReminderRequest valid; + std::vector validReminders; validReminders.emplace_back(valid); Notification::ReminderHelper::GetValidReminders(validReminders); - Notification::NotificationSlot notificationSlot; - bool enabled = fdp->ConsumeBool(); - notificationSlot.SetEnableLight(enabled); - notificationSlot.SetEnableVibration(enabled); - Notification::ReminderHelper::AddNotificationSlot(notificationSlot); - uint8_t type = fdp->ConsumeIntegral() % SLOT_TYPE_NUM; - Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type); - Notification::ReminderHelper::RemoveNotificationSlot(slotType); - uint64_t excludeDate = static_cast(reminderId); + uint64_t excludeDate = static_cast(reminderId); Notification::ReminderHelper::AddExcludeDate(reminderId, excludeDate); Notification::ReminderHelper::DelExcludeDates(reminderId); - std::vector dates; + std::vector dates; Notification::ReminderHelper::GetExcludeDates(reminderId, dates); return Notification::ReminderHelper::CancelAllReminders(); } diff --git a/test/fuzztest/reminderrequest_fuzzer/BUILD.gn b/test/fuzztest/reminderrequest_fuzzer/BUILD.gn index 3bc258ff08d2d9dc961bac792e0eecb88a324786..e467478ea597de125368c4155cda452b3ffdfefc 100644 --- a/test/fuzztest/reminderrequest_fuzzer/BUILD.gn +++ b/test/fuzztest/reminderrequest_fuzzer/BUILD.gn @@ -32,7 +32,7 @@ ohos_fuzztest("ReminderRequestFuzzTest") { deps = [ "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", - "${frameworks_module_ans_path}:ans_innerkits", + "${frameworks_module_reminder_path}:reminder_innerkits", ] external_deps = [ diff --git a/test/fuzztest/reminderrequestalarm_fuzzer/BUILD.gn b/test/fuzztest/reminderrequestalarm_fuzzer/BUILD.gn index bb166c3a80e24e787fa95f0e8fc3831ca621b084..1a1d90e9a183bf36c683c7d327956d1d0eca598d 100644 --- a/test/fuzztest/reminderrequestalarm_fuzzer/BUILD.gn +++ b/test/fuzztest/reminderrequestalarm_fuzzer/BUILD.gn @@ -33,7 +33,7 @@ ohos_fuzztest("ReminderRequestAlarmFuzzTest") { deps = [ "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", - "${frameworks_module_ans_path}:ans_innerkits", + "${frameworks_module_reminder_path}:reminder_innerkits", ] external_deps = [ diff --git a/test/fuzztest/reminderrequestannex_fuzzer/BUILD.gn b/test/fuzztest/reminderrequestannex_fuzzer/BUILD.gn index bb4b6750f8b98ba3f031f3e1bb780645f993e862..ef0d6d50e7e6376050045cd5c0de176c50d2a18c 100644 --- a/test/fuzztest/reminderrequestannex_fuzzer/BUILD.gn +++ b/test/fuzztest/reminderrequestannex_fuzzer/BUILD.gn @@ -33,7 +33,7 @@ ohos_fuzztest("ReminderRequestAnnexFuzzTest") { deps = [ "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", - "${frameworks_module_ans_path}:ans_innerkits", + "${frameworks_module_reminder_path}:reminder_innerkits", ] external_deps = [ diff --git a/test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.cpp b/test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.cpp index e891852b0f112afe2d6bf0974666ab9ffaf3cb79..4d98dd87c5aef54cf0f7e4fca52be60365078068 100644 --- a/test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.cpp +++ b/test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.cpp @@ -44,7 +44,6 @@ namespace OHOS { reminderRequest.GetExpiredContent(); reminderRequest.GetMaxScreenWantAgentInfo(); reminderRequest.GetNotificationId(); - reminderRequest.GetNotificationRequest(); reminderRequest.GetReminderId(); reminderRequest.GetReminderTimeInMilli(); reminderRequest.SetReminderId(reminderId); @@ -66,7 +65,6 @@ namespace OHOS { reminderRequest.UpdateNextReminder(); reminderRequest.SetNextTriggerTime(); Parcel parcel; - reminderRequest.InitNotificationRequest(); reminderRequest.InitServerObj(); return reminderRequest.IsAlerting(); } diff --git a/test/fuzztest/reminderrequestannexthree_fuzzer/BUILD.gn b/test/fuzztest/reminderrequestannexthree_fuzzer/BUILD.gn index 5c19e4084c6339e8105699a3fdfb55bc4c1a08c6..41b58748ce80a110fb3775bfb4ef8ec9269cbc1e 100644 --- a/test/fuzztest/reminderrequestannexthree_fuzzer/BUILD.gn +++ b/test/fuzztest/reminderrequestannexthree_fuzzer/BUILD.gn @@ -33,7 +33,7 @@ ohos_fuzztest("ReminderRequestAnnexThreeFuzzTest") { deps = [ "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", - "${frameworks_module_ans_path}:ans_innerkits", + "${frameworks_module_reminder_path}:reminder_innerkits", ] external_deps = [ diff --git a/test/fuzztest/reminderrequestcalendar_fuzzer/BUILD.gn b/test/fuzztest/reminderrequestcalendar_fuzzer/BUILD.gn index befcba816532602d3eb757581d066a16d11aed6d..fec148d0095ac638c458775e06115cddf8ab8240 100644 --- a/test/fuzztest/reminderrequestcalendar_fuzzer/BUILD.gn +++ b/test/fuzztest/reminderrequestcalendar_fuzzer/BUILD.gn @@ -33,7 +33,7 @@ ohos_fuzztest("ReminderRequestCalendarFuzzTest") { deps = [ "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", - "${frameworks_module_ans_path}:ans_innerkits", + "${frameworks_module_reminder_path}:reminder_innerkits", ] external_deps = [ diff --git a/test/fuzztest/reminderrequestcontinuate_fuzzer/BUILD.gn b/test/fuzztest/reminderrequestcontinuate_fuzzer/BUILD.gn index cc3ee404355a7dffc8f47ff7f826814d5f90dc74..b9d0ef779208baf6d44b49a993d0b779b9754425 100644 --- a/test/fuzztest/reminderrequestcontinuate_fuzzer/BUILD.gn +++ b/test/fuzztest/reminderrequestcontinuate_fuzzer/BUILD.gn @@ -33,7 +33,7 @@ ohos_fuzztest("ReminderRequestContinuateFuzzTest") { deps = [ "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", - "${frameworks_module_ans_path}:ans_innerkits", + "${frameworks_module_reminder_path}:reminder_innerkits", ] external_deps = [ diff --git a/test/fuzztest/reminderrequesttimer_fuzzer/BUILD.gn b/test/fuzztest/reminderrequesttimer_fuzzer/BUILD.gn index df1be7306a07bffc135e9488fee2970d938b2c67..6fb5013e678d9ede136576fd5e37e223540304b5 100644 --- a/test/fuzztest/reminderrequesttimer_fuzzer/BUILD.gn +++ b/test/fuzztest/reminderrequesttimer_fuzzer/BUILD.gn @@ -33,7 +33,7 @@ ohos_fuzztest("ReminderRequestTimerFuzzTest") { deps = [ "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", - "${frameworks_module_ans_path}:ans_innerkits", + "${frameworks_module_reminder_path}:reminder_innerkits", ] external_deps = [ diff --git a/test/fuzztest/reminderservice_fuzzer/BUILD.gn b/test/fuzztest/reminderservice_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..5b277ca2a0850ed23e2f75932dc62cf7f6750e29 --- /dev/null +++ b/test/fuzztest/reminderservice_fuzzer/BUILD.gn @@ -0,0 +1,145 @@ +# Copyright (c) 2023 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. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("ReminderServiceFuzzTest") { + module_out_path = service_fuzz_test_path + fuzz_config_file = + "${component_path}/test/fuzztest/reminderservice_fuzzer" + include_dirs = [ + "${services_path}/reminder/include", + "${core_path}/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderservice_fuzzer.cpp" ] + defines = [] + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_reminder_path}:reminder_innerkits", + "${services_path}/reminder:reminder_service_sources", + ] + + if (is_double_framework) { + cflags += [ "-DCONFIG_DUAL_FRAMEWORK" ] + } + + if (distributed_notification_supported) { + defines += [ "DISTRIBUTED_NOTIFICATION_SUPPORTED" ] + deps += [ "${services_path}/distributed:libans_distributed" ] + include_dirs += [ "${services_path}/distributed/include" ] + } + + if (notification_smart_reminder_supported) { + defines += [ "NOTIFICATION_SMART_REMINDER_SUPPORTED" ] + } + + external_deps = [ + "ability_base:configuration", + "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "ability_runtime:appkit_native", + "ability_runtime:dataobs_manager", + "ability_runtime:extension_manager", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "config_policy:configpolicy_util", + "data_share:datashare_common", + "data_share:datashare_consumer", + "data_share:datashare_permission", + "device_manager:devicemanagersdk", + "ffrt:libffrt", + "hilog:libhilog", + "i18n:intl_util", + "image_framework:image_native", + "init:libbegetutil", + "icu:shared_icuuc", + "libxml2:libxml2", + "kv_store:distributeddata_inner", + "openssl:libcrypto_shared", + "os_account:os_account_innerkits", + "relational_store:native_rdb", + "resource_management:global_resmgr", + "time_service:time_client", + ] + external_deps += component_external_deps + + if (device_usage) { + external_deps += [ "device_usage_statistics:usagestatsinner" ] + defines += [ "DEVICE_USAGE_STATISTICS_ENABLE" ] + } + + if (hisysevent_usage) { + cflags += [ "-DHAS_HISYSEVENT_PART" ] + external_deps += [ "hisysevent:libhisysevent" ] + } + + if (standby_enable) { + external_deps += [ "device_standby:standby_innerkits" ] + defines += [ "DEVICE_STANDBY_ENABLE" ] + } + + if (player_framework) { + external_deps += [ "player_framework:media_client" ] + defines += [ "PLAYER_FRAMEWORK_ENABLE" ] + } + + if (ans_hitrace_usage) { + external_deps += [ "hitrace:hitrace_meter" ] + defines += [ "HITRACE_METER_ENABLE" ] + } + + if (ans_config_policy_enable) { + external_deps += [ "config_policy:configpolicy_util" ] + defines += [ "CONFIG_POLICY_ENABLE" ] + } + + if (screenlock_mgr_enable) { + external_deps += [ "screenlock_mgr:screenlock_client" ] + defines += [ "SCREENLOCK_MGR_ENABLE" ] + } + + if (distributed_notification_service_feature_summary) { + defines += [ "ENABLE_ANS_EXT_WRAPPER" ] + } + + if (telephony_cust) { + defines += [ "ENABLE_ANS_TELEPHONY_CUST_WRAPPER" ] + } + + if (distributed_notification_service_feature_disable_fa_model) { + defines += [ "ANS_DISABLE_FA_MODEL" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderServiceFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderservice_fuzzer/corpus/init b/test/fuzztest/reminderservice_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..d6a927d5409f58fd33b8e793135561bca72e8409 --- /dev/null +++ b/test/fuzztest/reminderservice_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2023 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. +100 \ No newline at end of file diff --git a/test/fuzztest/reminderservice_fuzzer/project.xml b/test/fuzztest/reminderservice_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/test/fuzztest/reminderservice_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderservice_fuzzer/reminderservice_fuzzer.cpp b/test/fuzztest/reminderservice_fuzzer/reminderservice_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..39c92f1361fd67e39b7bf2d8fa20aa9a63b6a12c --- /dev/null +++ b/test/fuzztest/reminderservice_fuzzer/reminderservice_fuzzer.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2023 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 +#include +#include +#include +#define private public +#define protected public +#include "reminder_service.h" +#undef private +#undef protected +#include "reminderservice_fuzzer.h" +#include "ans_permission_def.h" + +constexpr uint8_t SLOT_TYPE_NUM = 5; + +namespace OHOS { + + bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) + { + auto service = std::make_shared(); + std::string stringData = fuzzData->ConsumeRandomLengthString(); + int32_t userId = fuzzData->ConsumeIntegral(); + Notification::ReminderRequest reminder; + int32_t reminderId2 = 0; + service->PublishReminder(reminder, reminderId2); + int32_t reminderId = fuzzData->ConsumeIntegral(); + service->CancelReminder(reminderId); + std::vector reminders; + service->GetValidReminders(reminders); + service->CancelAllReminders(); + int64_t excludeDate = fuzzData->ConsumeIntegral(); + service->AddExcludeDate(reminderId, excludeDate); + service->DelExcludeDates(reminderId); + std::vector excludeDates; + service->GetExcludeDates(reminderId, excludeDates); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + SystemHapTokenGet(requestPermission); + OHOS::DoSomethingInterestingWithMyAPI(&fdp); + return 0; +} diff --git a/test/fuzztest/reminderservice_fuzzer/reminderservice_fuzzer.h b/test/fuzztest/reminderservice_fuzzer/reminderservice_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..350a6904cc741d29cf29e243745a972c601ba211 --- /dev/null +++ b/test/fuzztest/reminderservice_fuzzer/reminderservice_fuzzer.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023 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 TEST_FUZZTEST_ADVANCEDNOTIFICATIONSERVICE_FUZZER_REMINDERSERVICE_FUZZER_H +#define TEST_FUZZTEST_ADVANCEDNOTIFICATIONSERVICE_FUZZER_REMINDERSERVICE_FUZZER_H + +#include "fuzz_common_base.h" +#include + +#define FUZZ_PROJECT_NAME "reminderservice_fuzzer" + +namespace OHOS { +} + +#endif // TEST_FUZZTEST_ADVANCEDNOTIFICATIONSERVICE_FUZZER_REMINDERSERVICE_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderstore_fuzzer/BUILD.gn b/test/fuzztest/reminderstore_fuzzer/BUILD.gn index 28132be530dec0f9da99e03c3eb4f25053d6115a..4e256fc3c815f1272da85a97237ac2ba429b3936 100644 --- a/test/fuzztest/reminderstore_fuzzer/BUILD.gn +++ b/test/fuzztest/reminderstore_fuzzer/BUILD.gn @@ -23,7 +23,7 @@ ohos_fuzztest("ReminderStoreFuzzTest") { include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base", - "${component_path}/services/ans/include", + "${component_path}/services/reminder/include", ] cflags = [ "-g", @@ -35,8 +35,8 @@ ohos_fuzztest("ReminderStoreFuzzTest") { deps = [ "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", - "${frameworks_module_ans_path}:ans_innerkits", - "${services_path}/ans:libans", + "${frameworks_module_reminder_path}:reminder_innerkits", + "${services_path}/reminder:libreminder", ] external_deps = [ diff --git a/test/fuzztest/reminderstoreannex_fuzzer/BUILD.gn b/test/fuzztest/reminderstoreannex_fuzzer/BUILD.gn index 74b52ec226b7f24639c5389452185c295ca7c418..45dce50410f08bc1edfb4cec11723fd7ac76e09c 100644 --- a/test/fuzztest/reminderstoreannex_fuzzer/BUILD.gn +++ b/test/fuzztest/reminderstoreannex_fuzzer/BUILD.gn @@ -23,7 +23,7 @@ ohos_fuzztest("ReminderStoreAnnexFuzzTest") { include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base", - "${component_path}/services/ans/include", + "${component_path}/services/reminder/include", ] cflags = [ "-g", @@ -35,8 +35,8 @@ ohos_fuzztest("ReminderStoreAnnexFuzzTest") { deps = [ "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", - "${frameworks_module_ans_path}:ans_innerkits", - "${services_path}/ans:libans", + "${frameworks_module_reminder_path}:reminder_innerkits", + "${services_path}/reminder:libreminder", ] external_deps = [