1/* 2 * Copyright (c) 2021-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 { NotificationRequest } from './notificationRequest'; 17import { NotificationSortingMap } from './notificationSortingMap'; 18import notification from '../@ohos.notification'; 19 20/** 21 * Provides methods that will be called back when the subscriber receives a new notification or 22 * a notification is canceled. 23 * 24 * @interface NotificationSubscriber 25 * @syscap SystemCapability.Notification.Notification 26 * @systemapi 27 * @since 7 28 */ 29export interface NotificationSubscriber { 30 /** 31 * The callback function that receives a new notification. 32 * 33 * @syscap SystemCapability.Notification.Notification 34 * @systemapi 35 * @since 7 36 */ 37 onConsume?: (data: SubscribeCallbackData) => void; 38 39 /** 40 * The callback function that cancels the notification. 41 * 42 * @syscap SystemCapability.Notification.Notification 43 * @systemapi 44 * @since 7 45 */ 46 onCancel?: (data: SubscribeCallbackData) => void; 47 48 /** 49 * The callback function that updates the sort of notifications. 50 * 51 * @syscap SystemCapability.Notification.Notification 52 * @systemapi 53 * @since 7 54 */ 55 onUpdate?: (data: NotificationSortingMap) => void; 56 57 /** 58 * The callback function of the completed subscription. 59 * 60 * @syscap SystemCapability.Notification.Notification 61 * @systemapi 62 * @since 7 63 */ 64 onConnect?: () => void; 65 66 /** 67 * The callback function to unsubscribe. 68 * 69 * @syscap SystemCapability.Notification.Notification 70 * @systemapi 71 * @since 7 72 */ 73 onDisconnect?: () => void; 74 75 /** 76 * The callback function that service disconnected. 77 * 78 * @syscap SystemCapability.Notification.Notification 79 * @systemapi 80 * @since 7 81 */ 82 onDestroy?: () => void; 83 84 /** 85 * Callback when the Do Not Disturb setting changed. 86 * 87 * @syscap SystemCapability.Notification.Notification 88 * @systemapi 89 * @since 8 90 */ 91 onDoNotDisturbDateChange?: (mode: notification.DoNotDisturbDate) => void; 92 93 /** 94 * Callback when the notification permission is changed. 95 * 96 * @syscap SystemCapability.Notification.Notification 97 * @systemapi 98 * @since 8 99 */ 100 onEnabledNotificationChanged?: (callbackData: EnabledNotificationCallbackData) => void; 101 102 /** 103 * Callback when badge number changed. 104 * 105 * @syscap SystemCapability.Notification.Notification 106 * @systemapi 107 * @since 10 108 */ 109 onBadgeChanged?: (data: BadgeNumberCallbackData) => void; 110} 111 112/** 113 * Provides methods that will be called back when the subscriber receives a new notification or 114 * a notification is canceled. 115 * 116 * @typedef SubscribeCallbackData 117 * @syscap SystemCapability.Notification.Notification 118 * @systemapi 119 * @since 7 120 */ 121export interface SubscribeCallbackData { 122 /** 123 * Content of the notice. 124 * 125 * @type { NotificationRequest } 126 * @readonly 127 * @syscap SystemCapability.Notification.Notification 128 * @systemapi 129 * @since 7 130 */ 131 readonly request: NotificationRequest; 132 133 /** 134 * Notify sorting information. 135 * 136 * @type { ?NotificationSortingMap } 137 * @readonly 138 * @syscap SystemCapability.Notification.Notification 139 * @systemapi 140 * @since 7 141 */ 142 readonly sortingMap?: NotificationSortingMap; 143 144 /** 145 * Delete the reason. 146 * 147 * @type { ?number } 148 * @readonly 149 * @syscap SystemCapability.Notification.Notification 150 * @systemapi 151 * @since 7 152 */ 153 readonly reason?: number; 154 155 /** 156 * Notification sound. 157 * 158 * @type { ?string } 159 * @readonly 160 * @syscap SystemCapability.Notification.Notification 161 * @systemapi 162 * @since 7 163 */ 164 readonly sound?: string; 165 166 /** 167 * Notice the vibration. 168 * 169 * @type { ?Array<number> } 170 * @readonly 171 * @syscap SystemCapability.Notification.Notification 172 * @systemapi 173 * @since 7 174 */ 175 readonly vibrationValues?: Array<number>; 176} 177 178/** 179 * Describes the properties of the application that the permission to send notifications has changed. 180 * 181 * @typedef EnabledNotificationCallbackData 182 * @syscap SystemCapability.Notification.Notification 183 * @systemapi 184 * @since 8 185 */ 186export interface EnabledNotificationCallbackData { 187 /** 188 * The bundle name of the application. 189 * 190 * @type { string } 191 * @readonly 192 * @syscap SystemCapability.Notification.Notification 193 * @systemapi 194 * @since 8 195 */ 196 readonly bundle: string; 197 198 /** 199 * The uid of the application. 200 * 201 * @type { number } 202 * @readonly 203 * @syscap SystemCapability.Notification.Notification 204 * @systemapi 205 * @since 8 206 */ 207 readonly uid: number; 208 209 /** 210 * Apply notification enable status. 211 * 212 * @type { boolean } 213 * @readonly 214 * @syscap SystemCapability.Notification.Notification 215 * @systemapi 216 * @since 8 217 */ 218 readonly enable: boolean; 219} 220 221/** 222 * Describes the badge number of the application has changed. 223 * 224 * @typedef BadgeNumberCallbackData 225 * @syscap SystemCapability.Notification.Notification 226 * @systemapi 227 * @since 10 228 */ 229export interface BadgeNumberCallbackData { 230 /** 231 * bundle name 232 * 233 * @type { string } 234 * @readonly 235 * @syscap SystemCapability.Notification.Notification 236 * @systemapi 237 * @since 10 238 */ 239 readonly bundle: string; 240 241 /** 242 * The uid of the application. 243 * 244 * @type { number } 245 * @readonly 246 * @syscap SystemCapability.Notification.Notification 247 * @systemapi 248 * @since 10 249 */ 250 readonly uid: number; 251 252 /** 253 * badge number 254 * 255 * @type { number } 256 * @readonly 257 * @syscap SystemCapability.Notification.Notification 258 * @systemapi 259 * @since 10 260 */ 261 readonly badgeNumber: number; 262} 263