• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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      * Cancels a specified reminder.
56      *
57      * @param reminderId Indicates the ID of the reminder instance to cancel.
58      * @return Returns cancel reminder result.
59      */
60     static ErrCode CancelReminder(const int32_t reminderId);
61 
62     /**
63      * Cancels all reminders of current third part application.
64      *
65      * @return Returns cancel all reminders result.
66      */
67     static ErrCode CancelAllReminders();
68 
69     /**
70      * Obtains all valid reminder notifications set by the current application, namely, the reminders that will
71      * still be triggered later. If a reminder will never be triggered again, it is not considered a valid reminder.
72      *
73      * @param[out] validReminders Indicates an initial vector to receive the result.
74      * @return Returns an array list containing all valid reminder notifications set by the current application.
75      */
76     static ErrCode GetValidReminders(std::vector<ReminderRequestAdaptation> &validReminders);
77 
78     /**
79      * Creates a NotificationSlot.
80      *
81      * After a notification slot is created by using this method, only the name and description of the notification
82      * slot can be changed. Changes to the other attributes, such as the vibration status and notification tone,
83      * will no longer take effect.
84      *
85      * You can call the ReminderRequest#setSlotId(String) method to bind the slot for publishing a reminder.
86      * When the application is uninstalled, all notification slots related to the application will be deleted.
87      *
88      * @param slot Indicates the NotificationSlot instance to add.
89      * @return Returns add notification slot result.
90      */
91     static ErrCode AddNotificationSlot(const NotificationSlot &slot);
92 
93     /**
94      * Removes a NotificationSlot instance used by the reminder.
95      *
96      * @param slotType Indicates the type of the slot, which is set when calling AddNotificationSlot to add a slot.
97      * @return Returns remove notification slot result.
98      */
99     static ErrCode RemoveNotificationSlot(const NotificationConstant::SlotType &slotType);
100 
101     /**
102      * @brief Add exclude date for reminder
103      *
104      * @param reminderId Identifies the reminders id.
105      * @param date exclude date
106      * @return Returns ERR_OK on success, others on failure.
107      */
108     static ErrCode AddExcludeDate(const int32_t reminderId, const int64_t date);
109 
110     /**
111      * @brief Clear exclude date for reminder
112      *
113      * @param reminderId Identifies the reminders id.
114      * @return Returns ERR_OK on success, others on failure.
115      */
116     static ErrCode DelExcludeDates(const int32_t reminderId);
117 
118     /**
119      * @brief Get exclude date for reminder
120      *
121      * @param reminderId Identifies the reminders id.
122      * @param dates exclude dates
123      * @return Returns ERR_OK on success, others on failure.
124      */
125     static ErrCode GetExcludeDates(const int32_t reminderId, std::vector<int64_t>& dates);
126 
127     static void StartReminderAgentService();
128 
129 private:
130     static bool CheckPermission();
131 };
132 }  // namespace Reminder
133 }  // namespace OHOS
134 
135 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_HELPER_H