1 /* 2 * Copyright (c) 2024 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 #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_CLIENT_H 16 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_CLIENT_H 17 #include <list> 18 #include <memory> 19 20 #include "reminder_request.h" 21 #include "reminder_request_adaptation.h" 22 #include "notification_slot.h" 23 #include "notification_constant.h" 24 #include "ans_manager_interface.h" 25 #include "ireminder_agent_service.h" 26 #include "ffrt.h" 27 28 namespace OHOS { 29 namespace Notification { 30 class ReminderRequestClient { 31 public: 32 /** 33 * @brief Publishes a scheduled reminder. 34 * 35 * @param reminder Indicates a reminder. 36 * @return Returns publish result. 37 */ 38 ErrCode PublishReminder(const ReminderRequest& reminder, int32_t& reminderId); 39 40 /** 41 * @brief Cancels a specified reminder. 42 * 43 * @param reminderId Indicates reminder Id. 44 * @return Returns cancel result. 45 */ 46 ErrCode CancelReminder(const int32_t reminderId); 47 48 /** 49 * @brief Cancels all reminders of current third part application. 50 * 51 * @return Returns cancel result. 52 */ 53 ErrCode CancelAllReminders(); 54 55 /** 56 * @brief Obtains all valid reminder notifications set by the current application. 57 * 58 * @param[out] validReminders Indicates the vector to store the result. 59 * @return Returns get valid reminders result. 60 */ 61 ErrCode GetValidReminders(std::vector<ReminderRequestAdaptation> &validReminders); 62 63 /** 64 * @brief Add exclude date for reminder 65 * 66 * @param reminderId Identifies the reminders id. 67 * @param date exclude date 68 * @return Returns ERR_OK on success, others on failure. 69 */ 70 ErrCode AddExcludeDate(const int32_t reminderId, const int64_t date); 71 72 /** 73 * @brief Clear exclude date for reminder 74 * 75 * @param reminderId Identifies the reminders id. 76 * @return Returns ERR_OK on success, others on failure. 77 */ 78 ErrCode DelExcludeDates(const int32_t reminderId); 79 80 /** 81 * @brief Get exclude date for reminder 82 * 83 * @param reminderId Identifies the reminders id. 84 * @param dates exclude dates 85 * @return Returns ERR_OK on success, others on failure. 86 */ 87 ErrCode GetExcludeDates(const int32_t reminderId, std::vector<int64_t>& dates); 88 89 /** 90 * @brief Creates a notification slot. 91 * @note You can call the NotificationRequest::SetSlotType(NotificationConstant::SlotType) method to bind the slot 92 * for publishing. A NotificationSlot instance cannot be used directly after being initialized. Instead, you have to 93 * call this method to create a notification slot and bind the slot ID to a NotificationRequest object so that the 94 * notification published can have all the characteristics set in the NotificationSlot. After a notification slot is 95 * created by using this method, only the name and description of the notification slot can be changed. Changes to 96 * the other attributes, such as the vibration status and notification tone, will no longer take effect. 97 * 98 * @param slot Indicates the notification slot to be created, which is set by NotificationSlot. 99 * This parameter must be specified. 100 * @return Returns add notification slot result. 101 */ 102 ErrCode AddNotificationSlot(const NotificationSlot &slot); 103 104 /** 105 * @brief Deletes a created notification slot based on the slot ID. 106 * 107 * @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot 108 * This parameter must be specified. 109 * @return Returns remove notification slot result. 110 */ 111 ErrCode RemoveNotificationSlot(const NotificationConstant::SlotType &slotType); 112 113 void LoadSystemAbilitySuccess(const sptr<IRemoteObject> &remoteObject); 114 115 void LoadSystemAbilityFail(); 116 117 void StartReminderAgentService(); 118 119 private: 120 121 /** 122 * @brief Adds a notification slot by type. 123 * 124 * @param slotType Indicates the notification slot type to be added. 125 * @return Returns add notification slot result. 126 */ 127 ErrCode AddSlotByType(const NotificationConstant::SlotType &slotType); 128 129 sptr<AnsManagerInterface> GetAnsManagerProxy(); 130 131 sptr<IReminderAgentService> GetReminderServiceProxy(); 132 133 bool LoadReminderService(); 134 135 ffrt::mutex serviceLock_; 136 137 ffrt::condition_variable proxyConVar_; 138 139 sptr<IReminderAgentService> proxy_; 140 }; 141 } // namespace Notification 142 } // namespace OHOS 143 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_CLIENT_H 144 145