1/* 2 * Copyright (c) 2021-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 16/** 17 * @file Provides methods that will be called back when the subscriber receives a new notification or a notification is canceled 18 * @kit NotificationKit 19 */ 20 21import { NotificationRequest } from './notificationRequest'; 22import { NotificationSortingMap } from './notificationSortingMap'; 23/*** if arkts 1.1 */ 24import notification from '../@ohos.notification'; 25import type notificationManager from '../@ohos.notificationManager'; 26/*** endif */ 27 28/** 29 * Provides methods that will be called back when the subscriber receives a new notification or 30 * a notification is canceled. 31 * 32 * @interface NotificationSubscriber 33 * @syscap SystemCapability.Notification.Notification 34 * @systemapi 35 * @since arkts {'1.1':'7', '1.2':'20'} 36 * @arkts 1.1&1.2 37 */ 38export interface NotificationSubscriber { 39 /** 40 * The callback function that receives a new notification. 41 * 42 * @type { ?function } 43 * @syscap SystemCapability.Notification.Notification 44 * @systemapi 45 * @since 7 46 */ 47 onConsume?: (data: SubscribeCallbackData) => void; 48 49 /** 50 * The callback function that cancels the notification. 51 * 52 * @type { ?function } 53 * @syscap SystemCapability.Notification.Notification 54 * @systemapi 55 * @since 7 56 */ 57 onCancel?: (data: SubscribeCallbackData) => void; 58 59 /** 60 * The callback function that updates the sort of notifications. 61 * 62 * @type { ?function } 63 * @syscap SystemCapability.Notification.Notification 64 * @systemapi 65 * @since 7 66 */ 67 onUpdate?: (data: NotificationSortingMap) => void; 68 69 /** 70 * The callback function of the completed subscription. 71 * 72 * @type { ?function } 73 * @syscap SystemCapability.Notification.Notification 74 * @systemapi 75 * @since 7 76 */ 77 onConnect?: () => void; 78 79 /** 80 * The callback function to unsubscribe. 81 * 82 * @type { ?function } 83 * @syscap SystemCapability.Notification.Notification 84 * @systemapi 85 * @since 7 86 */ 87 onDisconnect?: () => void; 88 89 /** 90 * The callback function that service disconnected. 91 * 92 * @type { ?function } 93 * @syscap SystemCapability.Notification.Notification 94 * @systemapi 95 * @since 7 96 */ 97 onDestroy?: () => void; 98 99 /** 100 * Callback when the Do Not Disturb setting changed. 101 * 102 * @type { ?function } 103 * @syscap SystemCapability.Notification.Notification 104 * @systemapi 105 * @since 8 106 * @deprecated since 11 107 * @useinstead NotificationSubscriber#onDoNotDisturbChanged 108 */ 109 onDoNotDisturbDateChange?: (mode: notification.DoNotDisturbDate) => void; 110 111 /** 112 * Callback when the Do Not Disturb setting changed. 113 * 114 * @type { ?function } 115 * @syscap SystemCapability.Notification.Notification 116 * @systemapi 117 * @since 11 118 */ 119 onDoNotDisturbChanged?: (mode: notificationManager.DoNotDisturbDate) => void; 120 121 /** 122 * Callback when the notification permission is changed. 123 * 124 * @type { ?function } 125 * @syscap SystemCapability.Notification.Notification 126 * @systemapi 127 * @since 8 128 */ 129 onEnabledNotificationChanged?: (callbackData: EnabledNotificationCallbackData) => void; 130 131 /** 132 * Callback when badge number changed. 133 * 134 * @type { ?function } 135 * @syscap SystemCapability.Notification.Notification 136 * @systemapi 137 * @since 10 138 */ 139 onBadgeChanged?: (data: BadgeNumberCallbackData) => void; 140 141 /** 142 * Callback when badge enabled state changed. 143 * 144 * @type { ?BadgeEnabledChangedCallback } 145 * @syscap SystemCapability.Notification.Notification 146 * @systemapi 147 * @since 12 148 */ 149 onBadgeEnabledChanged?: BadgeEnabledChangedCallback; 150 151 /** 152 * Callback when badge cancel notifications. 153 * 154 * @type { ?function } 155 * @syscap SystemCapability.Notification.Notification 156 * @systemapi 157 * @since 11 158 */ 159 onBatchCancel?: (data: Array<SubscribeCallbackData>) => void; 160} 161 162/** 163 * Provides methods that will be called back when the subscriber receives a new notification or 164 * a notification is canceled. 165 * 166 * @typedef SubscribeCallbackData 167 * @syscap SystemCapability.Notification.Notification 168 * @systemapi 169 * @since arkts {'1.1':'7', '1.2':'20'} 170 * @arkts 1.1&1.2 171 */ 172export interface SubscribeCallbackData { 173 /** 174 * Content of the notice. 175 * 176 * @type { NotificationRequest } 177 * @readonly 178 * @syscap SystemCapability.Notification.Notification 179 * @systemapi 180 * @since arkts {'1.1':'7', '1.2':'20'} 181 * @arkts 1.1&1.2 182 */ 183 readonly request: NotificationRequest; 184 185 /** 186 * Notify sorting information. 187 * 188 * @type { ?NotificationSortingMap } 189 * @readonly 190 * @syscap SystemCapability.Notification.Notification 191 * @systemapi 192 * @since arkts {'1.1':'7', '1.2':'20'} 193 * @arkts 1.1&1.2 194 */ 195 readonly sortingMap?: NotificationSortingMap; 196 197 /** 198 * The reason for the deletion.(1:CLICK_REASON_REMOVE,2:CANCEL_REASON_REMOVE) 199 * 200 * @type { ?number } 201 * @readonly 202 * @syscap SystemCapability.Notification.Notification 203 * @systemapi 204 * @since arkts {'1.1':'7', '1.2':'20'} 205 * @arkts 1.1&1.2 206 */ 207 readonly reason?: number; 208 209 /** 210 * Notification sound. 211 * 212 * @type { ?string } 213 * @readonly 214 * @syscap SystemCapability.Notification.Notification 215 * @systemapi 216 * @since arkts {'1.1':'7', '1.2':'20'} 217 * @arkts 1.1&1.2 218 */ 219 readonly sound?: string; 220 221 /** 222 * Notice the vibration. 223 * 224 * @type { ?Array<number> } 225 * @readonly 226 * @syscap SystemCapability.Notification.Notification 227 * @systemapi 228 * @since arkts {'1.1':'7', '1.2':'20'} 229 * @arkts 1.1&1.2 230 */ 231 readonly vibrationValues?: Array<number>; 232} 233 234/** 235 * Describes the properties of the application that the permission to send notifications 236 * or the badge enabled state has changed. 237 * 238 * @typedef EnabledNotificationCallbackData 239 * @syscap SystemCapability.Notification.Notification 240 * @systemapi 241 * @since arkts {'1.1':'8', '1.2':'20'} 242 * @arkts 1.1&1.2 243 */ 244export interface EnabledNotificationCallbackData { 245 /** 246 * The bundle name of the application. 247 * 248 * @type { string } 249 * @readonly 250 * @syscap SystemCapability.Notification.Notification 251 * @systemapi 252 * @since arkts {'1.1':'8', '1.2':'20'} 253 * @arkts 1.1&1.2 254 */ 255 readonly bundle: string; 256 257 /** 258 * The uid of the application. 259 * 260 * @type { number } 261 * @readonly 262 * @syscap SystemCapability.Notification.Notification 263 * @systemapi 264 * @since arkts {'1.1':'8', '1.2':'20'} 265 * @arkts 1.1&1.2 266 */ 267 readonly uid: number; 268 269 /** 270 * Apply notification enable status. 271 * 272 * @type { boolean } 273 * @readonly 274 * @syscap SystemCapability.Notification.Notification 275 * @systemapi 276 * @since arkts {'1.1':'8', '1.2':'20'} 277 * @arkts 1.1&1.2 278 */ 279 readonly enable: boolean; 280} 281 282/** 283 * Describes the badge number of the application has changed. 284 * 285 * @typedef BadgeNumberCallbackData 286 * @syscap SystemCapability.Notification.Notification 287 * @systemapi 288 * @since arkts {'1.1':'10', '1.2':'20'} 289 * @arkts 1.1&1.2 290 */ 291export interface BadgeNumberCallbackData { 292 /** 293 * bundle name 294 * 295 * @type { string } 296 * @readonly 297 * @syscap SystemCapability.Notification.Notification 298 * @systemapi 299 * @since arkts {'1.1':'10', '1.2':'20'} 300 * @arkts 1.1&1.2 301 */ 302 readonly bundle: string; 303 304 /** 305 * The uid of the application. 306 * 307 * @type { number } 308 * @readonly 309 * @syscap SystemCapability.Notification.Notification 310 * @systemapi 311 * @since arkts {'1.1':'10', '1.2':'20'} 312 * @arkts 1.1&1.2 313 */ 314 readonly uid: number; 315 316 /** 317 * badge number 318 * 319 * @type { number } 320 * @readonly 321 * @syscap SystemCapability.Notification.Notification 322 * @systemapi 323 * @since arkts {'1.1':'10', '1.2':'20'} 324 * @arkts 1.1&1.2 325 */ 326 readonly badgeNumber: number; 327 328 /** 329 * Application instance key. 330 * 331 * @type { ?number } 332 * @readonly 333 * @syscap SystemCapability.Notification.Notification 334 * @systemapi 335 * @since 12 336 * @deprecated since 15 337 * @useinstead BadgeNumberCallbackData#appInstanceKey 338 */ 339 readonly instanceKey?: number; 340 341 /** 342 * Application instance key. 343 * 344 * @type { ?string } 345 * @readonly 346 * @syscap SystemCapability.Notification.Notification 347 * @systemapi 348 * @since arkts {'1.1':'15', '1.2':'20'} 349 * @arkts 1.1&1.2 350 */ 351 readonly appInstanceKey?: string; 352} 353 354/** 355 * Defines the callback of BadgeEnabledChanged. 356 * @typedef BadgeEnabledChangedCallback 357 * @syscap SystemCapability.Notification.Notification 358 * @since 12 359 */ 360export interface BadgeEnabledChangedCallback { 361 /** 362 * Defines the BadgeEnabledChanged callback. 363 * @param { EnabledNotificationCallbackData } data 364 * @syscap SystemCapability.Notification.Notification 365 * @systemapi 366 * @since 12 367 */ 368 (data: EnabledNotificationCallbackData): void; 369} 370 371/** 372 * Defines the BadgeEnabledChanged callback. 373 * @param { EnabledNotificationCallbackData } data 374 * @syscap SystemCapability.Notification.Notification 375 * @systemapi 376 * @since 20 377 * @arkts 1.2 378 */ 379export type BadgeEnabledChangedCallback = (data: EnabledNotificationCallbackData) => void; 380