1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_HELPER_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_HELPER_H 18 19 #include <vector> 20 21 #include "notification_slot.h" 22 #include "reminder_request.h" 23 #include "reminder_request_adaptation.h" 24 25 namespace OHOS { 26 namespace Notification { 27 class ReminderHelper { 28 public: 29 /** 30 * Publishes a scheduled reminder. 31 * 32 * Third-party applications can call this method to publish a scheduled reminder. After this method is called, 33 * the timing and pop-up notification functions of the calling application will be performed by the system service 34 * agent in the background, even when the application is frozen or exits. You can call the 35 * ReminderRequest::SetWantAgentInfo(WantAgentInfo wantAgentInfo) method to specify whether to start the 36 * application after the pop-up notification is taped. 37 * 38 * The background agent maintains an ordered list of reminders for all third-party applications. The list is 39 * updated based on the scheduled trigger time of each reminder. The system starts only one most recent scheduled 40 * reminder at a time. If a reminder with a more recent trigger time is added, the new scheduled reminder will 41 * be put on top of the list. The next reminder is triggered only after the current reminder is complete. 42 * 43 * @note One application can create a maximum of 30 valid reminders, and the total number of valid reminders 44 * in the system cannot exceed 2000. The minimum snooze interval for a reminder is 5 minutes. 45 * 46 * @param reminder Indicates the reminder instance to publish. This parameter cannot be null. Otherwise, 47 * an exception will be thrown due to invalid parameters, causing the application to crash. 48 * @return Returns publish reminder result. 49 * Reminder id will be set with a number >= 0 if publishing the reminder successfully, Otherwise 50 * reminder id is -1. You can call reminder.GetReminderId() to get the reminder id. 51 */ 52 static ErrCode PublishReminder(const ReminderRequest &reminder, int32_t& reminderId); 53 54 /** 55 * @brief Updates a scheduled reminder. 56 * 57 * @param reminderId Indicates reminder Id. 58 * @param reminder Indicates a reminder. 59 * @return Returns publish result. 60 */ 61 static ErrCode UpdateReminder(const int32_t reminderId, const ReminderRequest& reminder); 62 63 /** 64 * Cancels a specified reminder. 65 * 66 * @param reminderId Indicates the ID of the reminder instance to cancel. 67 * @return Returns cancel reminder result. 68 */ 69 static ErrCode CancelReminder(const int32_t reminderId); 70 71 /** 72 * Cancels all reminders of current third part application. 73 * 74 * @return Returns cancel all reminders result. 75 */ 76 static ErrCode CancelAllReminders(); 77 78 /** 79 * Obtains all valid reminder notifications set by the current application, namely, the reminders that will 80 * still be triggered later. If a reminder will never be triggered again, it is not considered a valid reminder. 81 * 82 * @param[out] validReminders Indicates an initial vector to receive the result. 83 * @return Returns an array list containing all valid reminder notifications set by the current application. 84 */ 85 static ErrCode GetValidReminders(std::vector<ReminderRequestAdaptation> &validReminders); 86 87 /** 88 * Creates a NotificationSlot. 89 * 90 * After a notification slot is created by using this method, only the name and description of the notification 91 * slot can be changed. Changes to the other attributes, such as the vibration status and notification tone, 92 * will no longer take effect. 93 * 94 * You can call the ReminderRequest#setSlotId(String) method to bind the slot for publishing a reminder. 95 * When the application is uninstalled, all notification slots related to the application will be deleted. 96 * 97 * @param slot Indicates the NotificationSlot instance to add. 98 * @return Returns add notification slot result. 99 */ 100 static ErrCode AddNotificationSlot(const NotificationSlot &slot); 101 102 /** 103 * Removes a NotificationSlot instance used by the reminder. 104 * 105 * @param slotType Indicates the type of the slot, which is set when calling AddNotificationSlot to add a slot. 106 * @return Returns remove notification slot result. 107 */ 108 static ErrCode RemoveNotificationSlot(const NotificationConstant::SlotType &slotType); 109 110 /** 111 * @brief Add exclude date for reminder 112 * 113 * @param reminderId Identifies the reminders id. 114 * @param date exclude date 115 * @return Returns ERR_OK on success, others on failure. 116 */ 117 static ErrCode AddExcludeDate(const int32_t reminderId, const int64_t date); 118 119 /** 120 * @brief Clear exclude date for reminder 121 * 122 * @param reminderId Identifies the reminders id. 123 * @return Returns ERR_OK on success, others on failure. 124 */ 125 static ErrCode DelExcludeDates(const int32_t reminderId); 126 127 /** 128 * @brief Get exclude date for reminder 129 * 130 * @param reminderId Identifies the reminders id. 131 * @param dates exclude dates 132 * @return Returns ERR_OK on success, others on failure. 133 */ 134 static ErrCode GetExcludeDates(const int32_t reminderId, std::vector<int64_t>& dates); 135 136 static void StartReminderAgentService(); 137 138 private: 139 static bool CheckPermission(); 140 }; 141 } // namespace Reminder 142 } // namespace OHOS 143 144 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_HELPER_H