1/* 2 * Copyright (c) 2022-2023 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 './@ohos.base'; 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 * @namespace notificationSubscribe 25 * @syscap SystemCapability.Notification.Notification 26 * @systemapi 27 * @since 9 28 */ 29declare namespace notificationSubscribe { 30 /** 31 * Describes a NotificationKey, which can be used to identify a notification. 32 * 33 * @typedef NotificationKey 34 * @syscap SystemCapability.Notification.Notification 35 * @systemapi 36 * @since 9 37 */ 38 export interface NotificationKey { 39 /** 40 * Notify ID. 41 * 42 * @type { number } 43 * @syscap SystemCapability.Notification.Notification 44 * @systemapi 45 * @since 9 46 */ 47 id: number; 48 49 /** 50 * Notification label. 51 * 52 * @type { ?string } 53 * @syscap SystemCapability.Notification.Notification 54 * @systemapi 55 * @since 9 56 */ 57 label?: string; 58 } 59 60 /** 61 * Reason for remove a notification 62 * 63 * @enum { number } 64 * @syscap SystemCapability.Notification.Notification 65 * @systemapi 66 * @since 9 67 */ 68 export enum RemoveReason { 69 /** 70 * Notification clicked notification on the status bar 71 * 72 * @syscap SystemCapability.Notification.Notification 73 * @systemapi 74 * @since 9 75 */ 76 CLICK_REASON_REMOVE = 1, 77 78 /** 79 * User dismissal notification on the status bar 80 * 81 * @syscap SystemCapability.Notification.Notification 82 * @systemapi 83 * @since 9 84 */ 85 CANCEL_REASON_REMOVE = 2 86 } 87 88 /** 89 * Subscribe to notifications. 90 * 91 * @permission ohos.permission.NOTIFICATION_CONTROLLER 92 * @param { NotificationSubscriber } subscriber - The notification subscriber. 93 * @param { AsyncCallback<void> } callback - The callback of subscribe. 94 * @throws { BusinessError } 201 - Permission denied. 95 * @throws { BusinessError } 202 - Not system application to call the interface. 96 * @throws { BusinessError } 401 - The parameter check failed. 97 * @throws { BusinessError } 1600001 - Internal error. 98 * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error. 99 * @throws { BusinessError } 1600003 - Failed to connect service. 100 * @throws { BusinessError } 1600012 - No memory space. 101 * @syscap SystemCapability.Notification.Notification 102 * @systemapi 103 * @since 9 104 */ 105 function subscribe(subscriber: NotificationSubscriber, callback: AsyncCallback<void>): void; 106 107 /** 108 * Subscribe to notifications. 109 * 110 * @permission ohos.permission.NOTIFICATION_CONTROLLER 111 * @param { NotificationSubscriber } subscriber - The notification subscriber. 112 * @param { NotificationSubscribeInfo } info - The notification subscribe info. 113 * @param { AsyncCallback<void> } callback - The callback of subscribe. 114 * @throws { BusinessError } 201 - Permission denied. 115 * @throws { BusinessError } 202 - Not system application to call the interface. 116 * @throws { BusinessError } 401 - The parameter check failed. 117 * @throws { BusinessError } 1600001 - Internal error. 118 * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error. 119 * @throws { BusinessError } 1600003 - Failed to connect service. 120 * @throws { BusinessError } 1600012 - No memory space. 121 * @syscap SystemCapability.Notification.Notification 122 * @systemapi 123 * @since 9 124 */ 125 function subscribe( 126 subscriber: NotificationSubscriber, 127 info: NotificationSubscribeInfo, 128 callback: AsyncCallback<void> 129 ): void; 130 131 /** 132 * Subscribe to notifications 133 * 134 * @permission ohos.permission.NOTIFICATION_CONTROLLER 135 * @param { NotificationSubscriber } subscriber - The notification subscriber. 136 * @param { NotificationSubscribeInfo } [info] - The notification subscribe info. 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 * @throws { BusinessError } 1600012 - No memory space. 145 * @syscap SystemCapability.Notification.Notification 146 * @systemapi 147 * @since 9 148 */ 149 function subscribe(subscriber: NotificationSubscriber, info?: NotificationSubscribeInfo): Promise<void>; 150 151 /** 152 * Unsubscribe notifications. 153 * 154 * @permission ohos.permission.NOTIFICATION_CONTROLLER 155 * @param { NotificationSubscriber } subscriber - The notification subscriber. 156 * @param { AsyncCallback<void> } callback - The callback of unsubscribe. 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 * @syscap SystemCapability.Notification.Notification 164 * @systemapi 165 * @since 9 166 */ 167 function unsubscribe(subscriber: NotificationSubscriber, callback: AsyncCallback<void>): void; 168 169 /** 170 * Unsubscribe notifications. 171 * 172 * @permission ohos.permission.NOTIFICATION_CONTROLLER 173 * @param { NotificationSubscriber } subscriber - The notification subscriber. 174 * @returns { Promise<void> } The promise returned by the function. 175 * @throws { BusinessError } 201 - Permission denied. 176 * @throws { BusinessError } 202 - Not system application to call the interface. 177 * @throws { BusinessError } 401 - The parameter check failed. 178 * @throws { BusinessError } 1600001 - Internal error. 179 * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error. 180 * @throws { BusinessError } 1600003 - Failed to connect service. 181 * @syscap SystemCapability.Notification.Notification 182 * @systemapi 183 * @since 9 184 */ 185 function unsubscribe(subscriber: NotificationSubscriber): Promise<void>; 186 187 /** 188 * Remove notification. 189 * 190 * @permission ohos.permission.NOTIFICATION_CONTROLLER 191 * @param { BundleOption } bundle - The bundle option. 192 * @param { NotificationKey } notificationKey - The notification key. 193 * @param { RemoveReason } reason - The remove reason. 194 * @param { AsyncCallback<void> } callback - The callback of remove. 195 * @throws { BusinessError } 201 - Permission denied. 196 * @throws { BusinessError } 202 - Not system application to call the interface. 197 * @throws { BusinessError } 401 - The parameter check failed. 198 * @throws { BusinessError } 1600001 - Internal error. 199 * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error. 200 * @throws { BusinessError } 1600003 - Failed to connect service. 201 * @throws { BusinessError } 1600007 - The notification is not exist. 202 * @throws { BusinessError } 17700001 - The specified bundle name was not found. 203 * @syscap SystemCapability.Notification.Notification 204 * @systemapi 205 * @since 9 206 */ 207 function remove( 208 bundle: BundleOption, 209 notificationKey: NotificationKey, 210 reason: RemoveReason, 211 callback: AsyncCallback<void> 212 ): void; 213 214 /** 215 * Remove notification. 216 * 217 * @permission ohos.permission.NOTIFICATION_CONTROLLER 218 * @param { BundleOption } bundle - The bundle option. 219 * @param { NotificationKey } notificationKey - The notification key. 220 * @param { RemoveReason } reason - The remove reason. 221 * @returns { Promise<void> } The promise returned by the function. 222 * @throws { BusinessError } 201 - Permission denied. 223 * @throws { BusinessError } 202 - Not system application to call the interface. 224 * @throws { BusinessError } 401 - The parameter check failed. 225 * @throws { BusinessError } 1600001 - Internal error. 226 * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error. 227 * @throws { BusinessError } 1600003 - Failed to connect service. 228 * @throws { BusinessError } 1600007 - The notification is not exist. 229 * @throws { BusinessError } 17700001 - The specified bundle name was not found. 230 * @syscap SystemCapability.Notification.Notification 231 * @systemapi 232 * @since 9 233 */ 234 function remove(bundle: BundleOption, notificationKey: NotificationKey, reason: RemoveReason): Promise<void>; 235 236 /** 237 * Remove notification. 238 * 239 * @permission ohos.permission.NOTIFICATION_CONTROLLER 240 * @param { string } hashCode - The hashCode. 241 * @param { RemoveReason } reason - The remove reason. 242 * @param { AsyncCallback<void> } callback - The callback of remove. 243 * @throws { BusinessError } 201 - Permission denied. 244 * @throws { BusinessError } 202 - Not system application to call the interface. 245 * @throws { BusinessError } 401 - The parameter check failed. 246 * @throws { BusinessError } 1600001 - Internal error. 247 * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error. 248 * @throws { BusinessError } 1600003 - Failed to connect service. 249 * @throws { BusinessError } 1600007 - The notification is not exist. 250 * @syscap SystemCapability.Notification.Notification 251 * @systemapi 252 * @since 9 253 */ 254 function remove(hashCode: string, reason: RemoveReason, callback: AsyncCallback<void>): void; 255 256 257 /** 258 * Remove notifications. 259 * 260 * @permission ohos.permission.NOTIFICATION_CONTROLLER 261 * @param { Array<String> } hashCodes - The hashCode array. 262 * @param { RemoveReason } reason - The remove reason. 263 * @param { AsyncCallback<void> } callback - The callback of remove. 264 * @throws { BusinessError } 201 - Permission denied. 265 * @throws { BusinessError } 202 - Not system application to call the interface. 266 * @throws { BusinessError } 401 - The parameter check failed. 267 * @throws { BusinessError } 1600001 - Internal error. 268 * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error. 269 * @throws { BusinessError } 1600003 - Failed to connect service. 270 * @syscap SystemCapability.Notification.Notification 271 * @systemapi 272 * @since 10 273 */ 274 function remove(hashCodes: Array<String>, reason: RemoveReason, callback: AsyncCallback<void>): void; 275 276 /** 277 * Remove notification. 278 * 279 * @permission ohos.permission.NOTIFICATION_CONTROLLER 280 * @param { string } hashCode - The hashCode. 281 * @param { RemoveReason } reason - The remove reason. 282 * @returns { Promise<void> } The promise returned by the function. 283 * @throws { BusinessError } 201 - Permission denied. 284 * @throws { BusinessError } 202 - Not system application to call the interface. 285 * @throws { BusinessError } 401 - The parameter check failed. 286 * @throws { BusinessError } 1600001 - Internal error. 287 * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error. 288 * @throws { BusinessError } 1600003 - Failed to connect service. 289 * @throws { BusinessError } 1600007 - The notification is not exist. 290 * @syscap SystemCapability.Notification.Notification 291 * @systemapi 292 * @since 9 293 */ 294 function remove(hashCode: string, reason: RemoveReason): Promise<void>; 295 296 /** 297 * Remove notifications. 298 * 299 * @permission ohos.permission.NOTIFICATION_CONTROLLER 300 * @param { Array<String> } hashCodes - The hashCode array. 301 * @param { RemoveReason } reason - The remove reason. 302 * @returns { Promise<void> } The promise returned by the function. 303 * @throws { BusinessError } 201 - Permission denied. 304 * @throws { BusinessError } 202 - Not system application to call the interface. 305 * @throws { BusinessError } 401 - The parameter check failed. 306 * @throws { BusinessError } 1600001 - Internal error. 307 * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error. 308 * @throws { BusinessError } 1600003 - Failed to connect service. 309 * @syscap SystemCapability.Notification.Notification 310 * @systemapi 311 * @since 10 312 */ 313 function remove(hashCodes: Array<String>, reason: RemoveReason): Promise<void>; 314 315 /** 316 * RemoveAll all notifications. 317 * 318 * @permission ohos.permission.NOTIFICATION_CONTROLLER 319 * @param { BundleOption } bundle - The bundle option. 320 * @param { AsyncCallback<void> } callback - The callback of removeAll. 321 * @throws { BusinessError } 201 - Permission denied. 322 * @throws { BusinessError } 202 - Not system application to call the interface. 323 * @throws { BusinessError } 401 - The parameter check failed. 324 * @throws { BusinessError } 1600001 - Internal error. 325 * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error. 326 * @throws { BusinessError } 1600003 - Failed to connect service. 327 * @throws { BusinessError } 17700001 - The specified bundle name was not found. 328 * @syscap SystemCapability.Notification.Notification 329 * @systemapi 330 * @since 9 331 */ 332 function removeAll(bundle: BundleOption, callback: AsyncCallback<void>): void; 333 334 /** 335 * RemoveAll all notifications. 336 * 337 * @permission ohos.permission.NOTIFICATION_CONTROLLER 338 * @param { AsyncCallback<void> } callback - The callback of removeAll. 339 * @throws { BusinessError } 201 - Permission denied. 340 * @throws { BusinessError } 202 - Not system application to call the interface. 341 * @throws { BusinessError } 401 - The parameter check failed. 342 * @throws { BusinessError } 1600001 - Internal error. 343 * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error. 344 * @throws { BusinessError } 1600003 - Failed to connect service. 345 * @syscap SystemCapability.Notification.Notification 346 * @systemapi 347 * @since 9 348 */ 349 function removeAll(callback: AsyncCallback<void>): void; 350 351 /** 352 * Remove all notifications under the specified user. 353 * 354 * @permission ohos.permission.NOTIFICATION_CONTROLLER 355 * @param { number } userId - The userId. 356 * @param { AsyncCallback<void> } callback - The callback of removeAll. 357 * @throws { BusinessError } 201 - Permission denied. 358 * @throws { BusinessError } 202 - Not system application to call the interface. 359 * @throws { BusinessError } 401 - The parameter check failed. 360 * @throws { BusinessError } 1600001 - Internal error. 361 * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error. 362 * @throws { BusinessError } 1600003 - Failed to connect service. 363 * @throws { BusinessError } 1600008 - The user is not exist. 364 * @syscap SystemCapability.Notification.Notification 365 * @systemapi 366 * @since 9 367 */ 368 function removeAll(userId: number, callback: AsyncCallback<void>): void; 369 370 /** 371 * Remove all notifications under the specified user. 372 * 373 * @permission ohos.permission.NOTIFICATION_CONTROLLER 374 * @param { number } userId - The userId. 375 * @returns { Promise<void> } The promise returned by the function. 376 * @throws { BusinessError } 201 - Permission denied. 377 * @throws { BusinessError } 202 - Not system application to call the interface. 378 * @throws { BusinessError } 401 - The parameter check failed. 379 * @throws { BusinessError } 1600001 - Internal error. 380 * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error. 381 * @throws { BusinessError } 1600003 - Failed to connect service. 382 * @throws { BusinessError } 1600008 - The user is not exist. 383 * @syscap SystemCapability.Notification.Notification 384 * @systemapi 385 * @since 9 386 */ 387 function removeAll(userId: number): Promise<void>; 388 389 /** 390 * RemoveAll all notifications. 391 * 392 * @permission ohos.permission.NOTIFICATION_CONTROLLER 393 * @param { BundleOption } [bundle] - The bundle option. 394 * @returns { Promise<void> } The promise returned by the function. 395 * @throws { BusinessError } 201 - Permission denied. 396 * @throws { BusinessError } 202 - Not system application to call the interface. 397 * @throws { BusinessError } 401 - The parameter check failed. 398 * @throws { BusinessError } 1600001 - Internal error. 399 * @throws { BusinessError } 1600002 - Marshalling or unmarshalling error. 400 * @throws { BusinessError } 1600003 - Failed to connect service. 401 * @throws { BusinessError } 17700001 - The specified bundle name was not found. 402 * @syscap SystemCapability.Notification.Notification 403 * @systemapi 404 * @since 9 405 */ 406 function removeAll(bundle?: BundleOption): Promise<void>; 407 408 /** 409 * Describes a bundleOption in a notification. 410 * 411 * @syscap SystemCapability.Notification.Notification 412 * @systemapi 413 * @since 9 414 */ 415 export type BundleOption = _BundleOption; 416 417 /** 418 * Sets filter criteria of publishers for subscribing to desired notifications. 419 * 420 * @syscap SystemCapability.Notification.Notification 421 * @systemapi 422 * @since 9 423 */ 424 export type NotificationSubscribeInfo = _NotificationSubscribeInfo; 425 426 /** 427 * Provides methods that will be called back when the subscriber receives a new notification or 428 * a notification is canceled. 429 * 430 * @syscap SystemCapability.Notification.Notification 431 * @systemapi 432 * @since 9 433 */ 434 export type NotificationSubscriber = _NotificationSubscriber; 435 436 /** 437 * Provides methods that will be called back when the subscriber receives a new notification or 438 * a notification is canceled. 439 * 440 * @syscap SystemCapability.Notification.Notification 441 * @systemapi 442 * @since 9 443 */ 444 export type SubscribeCallbackData = _SubscribeCallbackData; 445 446 /** 447 * Describes the properties of the application that the permission to send notifications has changed. 448 * 449 * @syscap SystemCapability.Notification.Notification 450 * @systemapi 451 * @since 9 452 */ 453 export type EnabledNotificationCallbackData = _EnabledNotificationCallbackData; 454} 455 456export default notificationSubscribe; 457