• 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 { BundleOption as _BundleOption } from './notification/NotificationCommonDef';
18import { NotificationSubscribeInfo as _NotificationSubscribeInfo } from './notification/notificationSubscribeInfo';
19import { NotificationSubscriber as _NotificationSubscriber } from './notification/notificationSubscriber';
20import { SubscribeCallbackData as _SubscribeCallbackData } from './notification/notificationSubscriber';
21import { EnabledNotificationCallbackData as _EnabledNotificationCallbackData } from './notification/notificationSubscriber';
22
23/**
24 * @name notificationSubscribe
25 * @since 9
26 * @systemapi
27 * @syscap SystemCapability.Notification.Notification
28 * @permission N/A
29 */
30declare namespace notificationSubscribe {
31  /**
32   * Describes a NotificationKey, which can be used to identify a notification.
33   * @typedef NotificationKey
34   * @syscap SystemCapability.Notification.Notification
35   * @systemapi
36   * @since 9
37   */
38  export interface NotificationKey {
39    id: number;
40    label?: string;
41  }
42
43  /**
44   * Reason for remove a notification
45   * @enum { number }
46   * @syscap SystemCapability.Notification.Notification
47   * @systemapi
48   * @since 9
49   */
50  export enum RemoveReason {
51    /**
52     * Notification clicked notification on the status bar
53     */
54    CLICK_REASON_REMOVE = 1,
55
56    /**
57     * User dismissal notification  on the status bar
58     */
59    CANCEL_REASON_REMOVE = 2,
60  }
61
62  /**
63   * Subscribe to notifications.
64   * @permission ohos.permission.NOTIFICATION_CONTROLLER
65   * @param { NotificationSubscriber } subscriber - The notification subscriber.
66   * @param { AsyncCallback<void> } callback - The callback of subscribe.
67   * @throws { BusinessError } 201 - Permission denied.
68   * @throws { BusinessError } 202 - Not system application to call the interface.
69   * @throws { BusinessError } 401 - The parameter check failed.
70   * @throws { BusinessError } 1600001 - Internal error.
71   * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error.
72   * @throws { BusinessError } 1600003 - Failed to connect service.
73   * @syscap SystemCapability.Notification.Notification
74   * @systemapi
75   * @since 9
76   */
77  function subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback<void>): void;
78
79  /**
80   * Subscribe to notifications.
81   * @permission ohos.permission.NOTIFICATION_CONTROLLER
82   * @param { NotificationSubscriber } subscriber - The notification subscriber.
83   * @param { NotificationSubscribeInfo } info - The notification subscribe info.
84   * @param { AsyncCallback<void> } callback - The callback of subscribe.
85   * @returns { Promise<void> } The promise returned by the function.
86   * @throws { BusinessError } 201 - Permission denied.
87   * @throws { BusinessError } 202 - Not system application to call the interface.
88   * @throws { BusinessError } 401 - The parameter check failed.
89   * @throws { BusinessError } 1600001 - Internal error.
90   * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error.
91   * @throws { BusinessError } 1600003 - Failed to connect service.
92   * @syscap SystemCapability.Notification.Notification
93   * @systemapi
94   * @since 9
95   */
96  function subscribe(subscriber: NotificationSubscriber, info: NotificationSubscribeInfo, callback: AsyncCallback<void>): void;
97
98  /**
99   * Subscribe to notifications
100   * @permission ohos.permission.NOTIFICATION_CONTROLLER
101   * @param { NotificationSubscriber } subscriber - The notification subscriber.
102   * @param { NotificationSubscribeInfo } info - The notification subscribe info.
103   * @returns { Promise<void> } The promise returned by the function.
104   * @throws { BusinessError } 201 - Permission denied.
105   * @throws { BusinessError } 202 - Not system application to call the interface.
106   * @throws { BusinessError } 401 - The parameter check failed.
107   * @throws { BusinessError } 1600001 - Internal error.
108   * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error.
109   * @throws { BusinessError } 1600003 - Failed to connect service.
110   * @syscap SystemCapability.Notification.Notification
111   * @systemapi
112   * @since 9
113   */
114  function subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo): Promise<void>;
115
116  /**
117   * Unsubscribe notifications.
118   * @permission ohos.permission.NOTIFICATION_CONTROLLER
119   * @param { NotificationSubscriber } subscriber - The notification subscriber.
120   * @param { AsyncCallback<void> } callback - The callback of unsubscribe.
121   * @throws { BusinessError } 201 - Permission denied.
122   * @throws { BusinessError } 202 - Not system application to call the interface.
123   * @throws { BusinessError } 401 - The parameter check failed.
124   * @throws { BusinessError } 1600001 - Internal error.
125   * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error.
126   * @throws { BusinessError } 1600003 - Failed to connect service.
127   * @syscap SystemCapability.Notification.Notification
128   * @systemapi
129   * @since 9
130   */
131  function unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback<void>): void;
132
133  /**
134   * Unsubscribe notifications.
135   * @permission ohos.permission.NOTIFICATION_CONTROLLER
136   * @param { NotificationSubscriber } subscriber - The notification subscriber.
137   * @returns { Promise<void> } The promise returned by the function.
138   * @throws { BusinessError } 201 - Permission denied.
139   * @throws { BusinessError } 202 - Not system application to call the interface.
140   * @throws { BusinessError } 401 - The parameter check failed.
141   * @throws { BusinessError } 1600001 - Internal error.
142   * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error.
143   * @throws { BusinessError } 1600003 - Failed to connect service.
144   * @syscap SystemCapability.Notification.Notification
145   * @systemapi
146   * @since 9
147   */
148  function unsubscribe(subscriber: NotificationSubscriber): Promise<void>;
149
150  /**
151   * Remove notification.
152   * @permission ohos.permission.NOTIFICATION_CONTROLLER
153   * @param { BundleOption } bundle - The bundle option.
154   * @param { NotificationKey } notificationKey - The notification key.
155   * @param { RemoveReason } reason - The remove reason.
156   * @param { AsyncCallback<void> } callback - The callback of remove.
157   * @throws { BusinessError } 201 - Permission denied.
158   * @throws { BusinessError } 202 - Not system application to call the interface.
159   * @throws { BusinessError } 401 - The parameter check failed.
160   * @throws { BusinessError } 1600001 - Internal error.
161   * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error.
162   * @throws { BusinessError } 1600003 - Failed to connect service.
163   * @throws { BusinessError } 1600007 - The notification is not exist.
164   * @throws { BusinessError } 17700001 - The specified bundle name was not found.
165   * @syscap SystemCapability.Notification.Notification
166   * @systemapi
167   * @since 9
168   */
169   function remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason, callback: AsyncCallback<void>): void;
170
171   /**
172    * Remove notification.
173    * @permission ohos.permission.NOTIFICATION_CONTROLLER
174    * @param { BundleOption } bundle - The bundle option.
175    * @param { NotificationKey } notificationKey - The notification key.
176    * @param { RemoveReason } reason - The remove reason.
177    * @returns { Promise<void> } The promise returned by the function.
178    * @throws { BusinessError } 201 - Permission denied.
179    * @throws { BusinessError } 202 - Not system application to call the interface.
180    * @throws { BusinessError } 401 - The parameter check failed.
181    * @throws { BusinessError } 1600001 - Internal error.
182    * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error.
183    * @throws { BusinessError } 1600003 - Failed to connect service.
184    * @throws { BusinessError } 1600007 - The notification is not exist.
185    * @throws { BusinessError } 17700001 - The specified bundle name was not found.
186    * @syscap SystemCapability.Notification.Notification
187    * @systemapi
188    * @since 9
189    */
190   function remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason): Promise<void>;
191
192   /**
193    * Remove notification.
194    * @permission ohos.permission.NOTIFICATION_CONTROLLER
195    * @param { string } hashCode - The hashCode.
196    * @param { RemoveReason } reason - The remove reason.
197    * @param { AsyncCallback<void> } callback - The callback of remove.
198    * @throws { BusinessError } 201 - Permission denied.
199    * @throws { BusinessError } 202 - Not system application to call the interface.
200    * @throws { BusinessError } 401 - The parameter check failed.
201    * @throws { BusinessError } 1600001 - Internal error.
202    * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error.
203    * @throws { BusinessError } 1600003 - Failed to connect service.
204    * @throws { BusinessError } 1600007 - The notification is not exist.
205    * @syscap SystemCapability.Notification.Notification
206    * @systemapi
207    * @since 9
208    */
209   function remove(hashCode: string, reason: RemoveReason, callback: AsyncCallback<void>): void;
210
211   /**
212    * Remove notification.
213    * @permission ohos.permission.NOTIFICATION_CONTROLLER
214    * @param { string } hashCode - The hashCode.
215    * @param { RemoveReason } reason - The remove reason.
216    * @returns { Promise<void> } The promise returned by the function.
217    * @throws { BusinessError } 201 - Permission denied.
218    * @throws { BusinessError } 202 - Not system application to call the interface.
219    * @throws { BusinessError } 401 - The parameter check failed.
220    * @throws { BusinessError } 1600001 - Internal error.
221    * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error.
222    * @throws { BusinessError } 1600003 - Failed to connect service.
223    * @throws { BusinessError } 1600007 - The notification is not exist.
224    * @syscap SystemCapability.Notification.Notification
225    * @systemapi
226    * @since 9
227    */
228   function remove(hashCode: string, reason: RemoveReason): Promise<void>;
229
230   /**
231    * RemoveAll all notifications.
232    * @permission ohos.permission.NOTIFICATION_CONTROLLER
233    * @param { BundleOption } bundle - The bundle option.
234    * @param { AsyncCallback<void> } callback - The callback of removeAll.
235    * @throws { BusinessError } 201 - Permission denied.
236    * @throws { BusinessError } 202 - Not system application to call the interface.
237    * @throws { BusinessError } 401 - The parameter check failed.
238    * @throws { BusinessError } 1600001 - Internal error.
239    * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error.
240    * @throws { BusinessError } 1600003 - Failed to connect service.
241    * @throws { BusinessError } 17700001 - The specified bundle name was not found.
242    * @syscap SystemCapability.Notification.Notification
243    * @systemapi
244    * @since 9
245    */
246   function removeAll(bundle: BundleOption, callback: AsyncCallback<void>): void;
247
248   /**
249    * RemoveAll all notifications.
250    * @permission ohos.permission.NOTIFICATION_CONTROLLER
251    * @param { AsyncCallback<void> } callback - The callback of removeAll.
252    * @throws { BusinessError } 201 - Permission denied.
253    * @throws { BusinessError } 202 - Not system application to call the interface.
254    * @throws { BusinessError } 401 - The parameter check failed.
255    * @throws { BusinessError } 1600001 - Internal error.
256    * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error.
257    * @throws { BusinessError } 1600003 - Failed to connect service.
258    * @syscap SystemCapability.Notification.Notification
259    * @systemapi
260    * @since 9
261    */
262   function removeAll(callback: AsyncCallback<void>): void;
263
264   /**
265    * Remove all notifications under the specified user.
266    * @permission ohos.permission.NOTIFICATION_CONTROLLER
267    * @param { number } userId - The userId.
268    * @param { AsyncCallback<void> } callback - The callback of removeAll.
269    * @throws { BusinessError } 201 - Permission denied.
270    * @throws { BusinessError } 202 - Not system application to call the interface.
271    * @throws { BusinessError } 401 - The parameter check failed.
272    * @throws { BusinessError } 1600001 - Internal error.
273    * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error.
274    * @throws { BusinessError } 1600003 - Failed to connect service.
275    * @throws { BusinessError } 1600008 - The user is not exist.
276    * @syscap SystemCapability.Notification.Notification
277    * @systemapi
278    * @since 9
279    */
280   function removeAll(userId: number, callback: AsyncCallback<void>): void;
281
282   /**
283    * Remove all notifications under the specified user.
284    * @permission ohos.permission.NOTIFICATION_CONTROLLER
285    * @param { number } userId - The userId.
286    * @returns { Promise<void> } The promise returned by the function.
287    * @throws { BusinessError } 201 - Permission denied.
288    * @throws { BusinessError } 202 - Not system application to call the interface.
289    * @throws { BusinessError } 401 - The parameter check failed.
290    * @throws { BusinessError } 1600001 - Internal error.
291    * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error.
292    * @throws { BusinessError } 1600003 - Failed to connect service.
293    * @throws { BusinessError } 1600008 - The user is not exist.
294    * @syscap SystemCapability.Notification.Notification
295    * @systemapi
296    * @since 9
297    */
298   function removeAll(userId: number): Promise<void>;
299
300   /**
301    * RemoveAll all notifications.
302    * @permission ohos.permission.NOTIFICATION_CONTROLLER
303    * @param { BundleOption } bundle - The bundle option.
304    * @returns { Promise<void> } The promise returned by the function.
305    * @throws { BusinessError } 201 - Permission denied.
306    * @throws { BusinessError } 202 - Not system application to call the interface.
307    * @throws { BusinessError } 401 - The parameter check failed.
308    * @throws { BusinessError } 1600001 - Internal error.
309    * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error.
310    * @throws { BusinessError } 1600003 - Failed to connect service.
311    * @throws { BusinessError } 17700001 - The specified bundle name was not found.
312    * @syscap SystemCapability.Notification.Notification
313    * @systemapi
314    * @since 9
315    */
316   function removeAll(bundle?: BundleOption): Promise<void>;
317
318  /**
319   * Describes a bundleOption in a notification.
320   * @syscap SystemCapability.Notification.Notification
321   * @since 9
322   */
323  export type BundleOption = _BundleOption
324
325  /**
326   * Sets filter criteria of publishers for subscribing to desired notifications.
327   * @syscap SystemCapability.Notification.Notification
328   * @systemapi
329   * @since 9
330   */
331  export type NotificationSubscribeInfo = _NotificationSubscribeInfo
332
333  /**
334   * Provides methods that will be called back when the subscriber receives a new notification or
335   * a notification is canceled.
336   * @syscap SystemCapability.Notification.Notification
337   * @systemapi
338   * @since 9
339   */
340  export type NotificationSubscriber = _NotificationSubscriber
341
342  /**
343   * Provides methods that will be called back when the subscriber receives a new notification or
344   * a notification is canceled.
345   * @syscap SystemCapability.Notification.Notification
346   * @systemapi
347   * @since 9
348   */
349  export type SubscribeCallbackData = _SubscribeCallbackData
350
351  /**
352   * Describes the properties of the application that the permission to send notifications has changed.
353   * @syscap SystemCapability.Notification.Notification
354   * @systemapi
355   * @since 9
356   */
357  export type EnabledNotificationCallbackData = _EnabledNotificationCallbackData
358}
359
360export default notificationSubscribe;
361