• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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
16import { AsyncCallback } from './basic';
17import notification from './@ohos.notification';
18import { NotificationSlot } from './notification/notificationSlot';
19
20/**
21 * Providers static methods for managing reminders, including publishing or canceling a reminder.
22 * Add or remove a notification slot, and obtain or cancel all reminders of the current application.
23 *
24 * @since 9
25 * @syscap SystemCapability.Notification.ReminderAgent
26 */
27declare namespace reminderAgentManager {
28  /**
29   * Publishes a scheduled reminder.
30   *
31   * @since 9
32   * @syscap SystemCapability.Notification.ReminderAgent
33   * @permission ohos.permission.PUBLISH_AGENT_REMINDER
34   * @param { ReminderRequest } reminderReq - Indicates the reminder instance to publish.
35   * @param { AsyncCallback<number> } callback - Indicates the callback function.
36   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
37   */
38  function publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback<number>): void;
39
40  /**
41   * Publishes a scheduled reminder.
42   *
43   * @since 9
44   * @syscap SystemCapability.Notification.ReminderAgent
45   * @permission ohos.permission.PUBLISH_AGENT_REMINDER
46   * @param { ReminderRequest } reminderReq - Indicates the reminder instance to publish.
47   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
48   * @returns { Promise<number> } The reminder id.
49   */
50  function publishReminder(reminderReq: ReminderRequest): Promise<number>;
51
52  /**
53   * Cancel a reminder.
54   *
55   * @since 9
56   * @syscap SystemCapability.Notification.ReminderAgent
57   * @param { number } reminderId - Indicates the reminder id.
58   * @param { AsyncCallback<void> } callback - Indicates the callback function.
59   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
60   */
61  function cancelReminder(reminderId: number, callback: AsyncCallback<void>): void;
62
63  /**
64   * Cancel a reminder.
65   *
66   * @since 9
67   * @syscap SystemCapability.Notification.ReminderAgent
68   * @param { number } reminderId - Indicates the reminder id.
69   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
70   * @returns { Promise<void> } The promise returned by the function.
71   */
72  function cancelReminder(reminderId: number): Promise<void>;
73
74  /**
75   * Obtains all the valid reminders of current application.
76   *
77   * @since 9
78   * @syscap SystemCapability.Notification.ReminderAgent
79   * @param { AsyncCallback<Array<ReminderRequest>> } callback - Indicates the callback function.
80   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
81   */
82  function getValidReminders(callback: AsyncCallback<Array<ReminderRequest>>): void;
83
84  /**
85   * Obtains all the valid reminders of current application.
86   *
87   * @since 9
88   * @syscap SystemCapability.Notification.ReminderAgent
89   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
90   * @returns { Promise<Array<ReminderRequest>> } The promise returned by the function.
91   */
92  function getValidReminders(): Promise<Array<ReminderRequest>>;
93
94  /**
95   * Cancel all the reminders of current application.
96   *
97   * @since 9
98   * @syscap SystemCapability.Notification.ReminderAgent
99   * @param { AsyncCallback<void> } callback - Indicates the callback function.
100   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
101   */
102  function cancelAllReminders(callback: AsyncCallback<void>): void;
103
104  /**
105   * Cancel all the reminders of current application.
106   *
107   * @since 9
108   * @syscap SystemCapability.Notification.ReminderAgent
109   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
110   * @returns { Promise<void> } The promise returned by the function.
111   */
112  function cancelAllReminders(): Promise<void>;
113
114  /**
115   * Add notification slot.
116   *
117   * @since 9
118   * @syscap SystemCapability.Notification.ReminderAgent
119   * @param { NotificationSlot } slot - Indicates the slot.
120   * @param { AsyncCallback<void> } callback - Indicates the callback function.
121   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
122   */
123  function addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback<void>): void;
124
125  /**
126   * Add notification slot.
127   *
128   * @since 9
129   * @syscap SystemCapability.Notification.ReminderAgent
130   * @param { NotificationSlot } slot - Indicates the slot.
131   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
132   * @returns { Promise<void> } The promise returned by the function.
133   */
134  function addNotificationSlot(slot: NotificationSlot): Promise<void>;
135
136  /**
137   * Deletes a created notification slot based on the slot type.
138   *
139   * @since 9
140   * @syscap SystemCapability.Notification.ReminderAgent
141   * @param { notification.SlotType } slotType Indicates the type of the slot.
142   * @param { AsyncCallback<void> } callback - Indicates the callback function.
143   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
144   */
145  function removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback<void>): void;
146
147  /**
148   * Deletes a created notification slot based on the slot type.
149   *
150   * @since 9
151   * @syscap SystemCapability.Notification.ReminderAgent
152   * @param { notification.SlotType } slotType Indicates the type of the slot.
153   * @throws { BusinessError } 401 - If the input parameter is not valid parameter.
154   * @returns { Promise<void> } The promise returned by the function.
155   */
156  function removeNotificationSlot(slotType: notification.SlotType): Promise<void>;
157
158  /**
159   * Declares action button type.
160   *
161   * @since 9
162   * @syscap SystemCapability.Notification.ReminderAgent
163   */
164  export enum ActionButtonType {
165    /**
166     * Button for closing the reminder.
167     * @since 9
168     * @syscap SystemCapability.Notification.ReminderAgent
169     */
170    ACTION_BUTTON_TYPE_CLOSE = 0,
171
172    /**
173     * Button for snoozing the reminder.
174     * @since 9
175     * @syscap SystemCapability.Notification.ReminderAgent
176     */
177    ACTION_BUTTON_TYPE_SNOOZE = 1
178  }
179
180  /**
181   * Declares reminder type.
182   *
183   * @since 9
184   * @syscap SystemCapability.Notification.ReminderAgent
185   */
186  export enum ReminderType {
187    /**
188     * Countdown reminder.
189     * @since 9
190     * @syscap SystemCapability.Notification.ReminderAgent
191     */
192    REMINDER_TYPE_TIMER = 0,
193
194    /**
195     * Calendar reminder.
196     * @since 9
197     * @syscap SystemCapability.Notification.ReminderAgent
198     */
199    REMINDER_TYPE_CALENDAR = 1,
200
201    /**
202     * Alarm reminder.
203     * @since 9
204     * @syscap SystemCapability.Notification.ReminderAgent
205     */
206    REMINDER_TYPE_ALARM = 2
207  }
208
209  /**
210   * Action button information. The button will show on displayed reminder.
211   *
212   * @since 9
213   * @syscap SystemCapability.Notification.ReminderAgent
214   */
215  interface ActionButton {
216    /**
217     * Text on the button.
218     * @since 9
219     * @syscap SystemCapability.Notification.ReminderAgent
220     */
221    title: string;
222
223    /**
224     * Button type.
225     * @since 9
226     * @syscap SystemCapability.Notification.ReminderAgent
227     */
228    type: ActionButtonType;
229  }
230
231  /**
232   * Want agent information.
233   * It will switch to target ability when you click the displayed reminder.
234   *
235   * @since 9
236   * @syscap SystemCapability.Notification.ReminderAgent
237   */
238  interface WantAgent {
239    /**
240     * Name of the package redirected to when the reminder notification is clicked.
241     * @since 9
242     * @syscap SystemCapability.Notification.ReminderAgent
243     */
244    pkgName: string;
245
246    /**
247     * Name of the ability that is redirected to when the reminder notification is clicked.
248     * @since 9
249     * @syscap SystemCapability.Notification.ReminderAgent
250     */
251    abilityName: string;
252  }
253
254  /**
255   * Max screen want agent information.
256   *
257   * @since 9
258   * @syscap SystemCapability.Notification.ReminderAgent
259   */
260  interface MaxScreenWantAgent {
261    /**
262     * Name of the package that is automatically started when the reminder arrives and the device is not in use.
263     * @since 9
264     * @syscap SystemCapability.Notification.ReminderAgent
265     */
266    pkgName: string;
267
268    /**
269     * Name of the ability that is automatically started when the reminder arrives and the device is not in use.
270     * @since 9
271     * @syscap SystemCapability.Notification.ReminderAgent
272     */
273    abilityName: string;
274  }
275
276  /**
277   * Reminder Common information.
278   *
279   * @since 9
280   * @syscap SystemCapability.Notification.ReminderAgent
281   */
282  interface ReminderRequest {
283    /**
284     * Type of the reminder.
285     * @since 9
286     * @syscap SystemCapability.Notification.ReminderAgent
287     */
288    reminderType: ReminderType;
289
290    /**
291     * Action button displayed on the reminder notification.
292     * (The parameter is optional. Up to two buttons are supported).
293     * @since 9
294     * @syscap SystemCapability.Notification.ReminderAgent
295     */
296    actionButton?: [ActionButton?, ActionButton?];
297
298    /**
299     * Information about the ability that is redirected to when the notification is clicked.
300     * @since 9
301     * @syscap SystemCapability.Notification.ReminderAgent
302     */
303    wantAgent?: WantAgent;
304
305    /**
306     * Information about the ability that is automatically started when the reminder arrives.
307     * If the device is in use, a notification will be displayed.
308     * @since 9
309     * @syscap SystemCapability.Notification.ReminderAgent
310     */
311    maxScreenWantAgent?: MaxScreenWantAgent;
312
313    /**
314     * Ringing duration.
315     * @since 9
316     * @syscap SystemCapability.Notification.ReminderAgent
317     */
318    ringDuration?: number;
319
320    /**
321     * Number of reminder snooze times.
322     * @since 9
323     * @syscap SystemCapability.Notification.ReminderAgent
324     */
325    snoozeTimes?: number;
326
327    /**
328     * Reminder snooze interval.
329     * @since 9
330     * @syscap SystemCapability.Notification.ReminderAgent
331     */
332    timeInterval?: number;
333
334    /**
335     * Reminder title.
336     * @since 9
337     * @syscap SystemCapability.Notification.ReminderAgent
338     */
339    title?: string;
340
341    /**
342     * Reminder content.
343     * @since 9
344     * @syscap SystemCapability.Notification.ReminderAgent
345     */
346    content?: string;
347
348    /**
349     * Content to be displayed when the reminder is expired.
350     * @since 9
351     * @syscap SystemCapability.Notification.ReminderAgent
352     */
353    expiredContent?: string;
354
355    /**
356     * Content to be displayed when the reminder is snoozing.
357     * @since 9
358     * @syscap SystemCapability.Notification.ReminderAgent
359     */
360    snoozeContent?: string;
361
362    /**
363     * Notification id. If there are reminders with the same ID, the later one will overwrite the earlier one.
364     * @since 9
365     * @syscap SystemCapability.Notification.ReminderAgent
366     */
367    notificationId?: number;
368
369    /**
370     * Type of the slot used by the reminder.
371     * @since 9
372     * @syscap SystemCapability.Notification.ReminderAgent
373     */
374    slotType?: notification.SlotType;
375  }
376
377  interface ReminderRequestCalendar extends ReminderRequest {
378    /**
379     * Reminder time.
380     * @since 9
381     * @syscap SystemCapability.Notification.ReminderAgent
382     */
383    dateTime: LocalDateTime;
384
385    /**
386     * Month in which the reminder repeats.
387     * @since 9
388     * @syscap SystemCapability.Notification.ReminderAgent
389     */
390    repeatMonths?: Array<number>;
391
392    /**
393     * Date on which the reminder repeats.
394     * @since 9
395     * @syscap SystemCapability.Notification.ReminderAgent
396     */
397    repeatDays?: Array<number>;
398  }
399
400  /**
401   * Alarm reminder information.
402   *
403   * @since 9
404   * @syscap SystemCapability.Notification.ReminderAgent
405   */
406  interface ReminderRequestAlarm extends ReminderRequest {
407    /**
408     * Hour portion of the reminder time.
409     * @since 9
410     * @syscap SystemCapability.Notification.ReminderAgent
411     */
412    hour: number;
413
414    /**
415     * Minute portion of the reminder time.
416     * @since 9
417     * @syscap SystemCapability.Notification.ReminderAgent
418     */
419    minute: number;
420
421    /**
422     * Days of a week when the reminder repeats.
423     * @since 9
424     * @syscap SystemCapability.Notification.ReminderAgent
425     */
426    daysOfWeek?: Array<number>;
427  }
428
429  /**
430   * CountDown reminder information.
431   *
432   * @since 9
433   * @syscap SystemCapability.Notification.ReminderAgent
434   */
435  interface ReminderRequestTimer extends ReminderRequest {
436    triggerTimeInSeconds: number;
437  }
438
439  interface LocalDateTime {
440    /**
441     * Value of year.
442     * @since 9
443     * @syscap SystemCapability.Notification.ReminderAgent
444     */
445    year: number;
446
447    /**
448     * Value of month.
449     * @since 9
450     * @syscap SystemCapability.Notification.ReminderAgent
451     */
452    month: number;
453
454    /**
455     * Value of day.
456     * @since 9
457     * @syscap SystemCapability.Notification.ReminderAgent
458     */
459    day: number;
460
461    /**
462     * Value of hour.
463     * @since 9
464     * @syscap SystemCapability.Notification.ReminderAgent
465     */
466    hour: number;
467
468    /**
469     * Value of minute.
470     * @since 9
471     * @syscap SystemCapability.Notification.ReminderAgent
472     */
473    minute: number;
474
475    /**
476     * Value of second.
477     * @since 9
478     * @syscap SystemCapability.Notification.ReminderAgent
479     */
480    second?: number;
481  }
482}
483export default reminderAgentManager;
484