1 /* 2 * Copyright (c) 2021-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 16 #ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_NOTIFICATION_H 17 #define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_NOTIFICATION_H 18 19 #include <list> 20 21 #include "ans_manager_death_recipient.h" 22 #include "ans_manager_interface.h" 23 #include "notification_subscriber.h" 24 25 namespace OHOS { 26 namespace Notification { 27 class AnsNotification { 28 public: 29 /** 30 * @brief Creates a notification slot. 31 * @note You can call the NotificationRequest::SetSlotType(NotificationConstant::SlotType) method to bind the slot 32 * for publishing. A NotificationSlot instance cannot be used directly after being initialized. Instead, you have to 33 * call this method to create a notification slot and bind the slot ID to a NotificationRequest object so that the 34 * notification published can have all the characteristics set in the NotificationSlot. After a notification slot is 35 * created by using this method, only the name and description of the notification slot can be changed. Changes to 36 * the other attributes, such as the vibration status and notification tone, will no longer take effect. 37 * 38 * @param slot Indicates the notification slot to be created, which is set by NotificationSlot. 39 * This parameter must be specified. 40 * @return Returns add notification slot result. 41 */ 42 ErrCode AddNotificationSlot(const NotificationSlot &slot); 43 44 /** 45 * @brief Adds a notification slot by type. 46 * 47 * @param slotType Indicates the notification slot type to be added. 48 * @return Returns add notification slot result. 49 */ 50 ErrCode AddSlotByType(const NotificationConstant::SlotType &slotType); 51 52 /** 53 * @brief Creates multiple notification slots. 54 * 55 * @param slots Indicates the notification slots to create. 56 * @return Returns add notification slots result. 57 */ 58 ErrCode AddNotificationSlots(const std::vector<NotificationSlot> &slots); 59 60 /** 61 * @brief Deletes a created notification slot based on the slot ID. 62 * 63 * @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot 64 * This parameter must be specified. 65 * @return Returns remove notification slot result. 66 */ 67 ErrCode RemoveNotificationSlot(const NotificationConstant::SlotType &slotType); 68 69 /** 70 * @brief Deletes all notification slots. 71 * 72 * @return Returns remove all slots result. 73 */ 74 ErrCode RemoveAllSlots(); 75 76 /** 77 * @brief Queries a created notification slot. 78 * 79 * @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot(NotificationSlot). This 80 * parameter must be specified. 81 * @param slot Indicates the created NotificationSlot. 82 * @return Returns the get notification slot result. 83 */ 84 ErrCode GetNotificationSlot(const NotificationConstant::SlotType &slotType, sptr<NotificationSlot> &slot); 85 86 /** 87 * @brief Obtains all notification slots of this application. 88 * 89 * @param slots Indicates the created NotificationSlot. 90 * @return Returns all notification slots of this application. 91 */ 92 ErrCode GetNotificationSlots(std::vector<sptr<NotificationSlot>> &slots); 93 94 /** 95 * @brief Obtains number of slot. 96 * 97 * @param bundleOption Indicates the bundle name and uid of the application. 98 * @param num Indicates number of slot. 99 * @return Returns get slot number by bundle result. 100 */ 101 ErrCode GetNotificationSlotNumAsBundle(const NotificationBundleOption &bundleOption, uint64_t &num); 102 103 /** 104 * @brief Publishes a notification. 105 * @note If a notification with the same ID has been published by the current application and has not been deleted, 106 * this method will update the notification. 107 * 108 * @param request Indicates the NotificationRequest object for setting the notification content. 109 * This parameter must be specified. 110 * @return Returns publish notification result. 111 */ 112 ErrCode PublishNotification(const NotificationRequest &request); 113 114 /** 115 * @brief Publishes a notification with a specified label. 116 * @note If a notification with the same ID has been published by the current application and has not been deleted, 117 * this method will update the notification. 118 * 119 * @param label Indicates the label of the notification to publish. 120 * @param request Indicates the NotificationRequest object for setting the notification content. 121 * This parameter must be specified. 122 * @return Returns publish notification result. 123 */ 124 ErrCode PublishNotification(const std::string &label, const NotificationRequest &request); 125 126 /** 127 * @brief Publishes a notification on a specified remote device. 128 * @note If a notification with the same ID has been published by the current application and has not been deleted, 129 * this method will update the notification. 130 * 131 * @param request Indicates the NotificationRequest object for setting the notification content. 132 * This parameter must be specified. 133 * @param deviceId Indicates the ID of the remote device. If this parameter is null or an empty string, 134 * the notification will be published on the local device. 135 * @return Returns publish notification result. 136 */ 137 ErrCode PublishNotification(const NotificationRequest &request, const std::string &deviceId); 138 139 /** 140 * @brief Cancels a published notification. 141 * 142 * @param notificationId Indicates the unique notification ID in the application. 143 * The value must be the ID of a published notification. 144 * Otherwise, this method does not take effect. 145 * @return Returns cancel notification result. 146 */ 147 ErrCode CancelNotification(int32_t notificationId); 148 149 /** 150 * @brief Cancels a published notification matching the specified label and notificationId. 151 * 152 * @param label Indicates the label of the notification to cancel. 153 * @param notificationId Indicates the ID of the notification to cancel. 154 * @return Returns cancel notification result. 155 */ 156 ErrCode CancelNotification(const std::string &label, int32_t notificationId); 157 158 /** 159 * @brief Cancels all the published notifications. 160 * @note To cancel a specified notification, see CancelNotification(int_32). 161 * 162 * @return Returns cancel all notifications result. 163 */ 164 ErrCode CancelAllNotifications(); 165 166 /** 167 * @brief Cancels a published agent notification. 168 * 169 * @param notificationId Indicates the unique notification ID in the application. 170 * The value must be the ID of a published notification. 171 * Otherwise, this method does not take effect. 172 * @param representativeBundle Indicates the name of application bundle your application is representing. 173 * @param userId Indicates the specific user. 174 * @return Returns cancel notification result. 175 */ 176 ErrCode CancelAsBundle(int32_t notificationId, const std::string &representativeBundle, int32_t userId); 177 178 /** 179 * @brief Obtains the number of active notifications of the current application in the system. 180 * 181 * @param num Indicates the number of active notifications of the current application. 182 * @return Returns get active notification nums result. 183 */ 184 ErrCode GetActiveNotificationNums(uint64_t &num); 185 186 /** 187 * @brief Obtains active notifications of the current application in the system. 188 * 189 * @param request Indicates active NotificationRequest objects of the current application. 190 * @return Returns get active notifications result. 191 */ 192 ErrCode GetActiveNotifications(std::vector<sptr<NotificationRequest>> &request); 193 194 /** 195 * @brief Obtains the map for sorting notifications of the current application. 196 * 197 * @param sortingMap Indicates the NotificationSortingMap object for the current application. 198 * @return Returns get current app sorting result. 199 */ 200 ErrCode GetCurrentAppSorting(sptr<NotificationSortingMap> &sortingMap); 201 202 /** 203 * @brief Allows another application to act as an agent to publish notifications in the name of your application 204 * bundle. You can revoke this authorization by passing null to this method. 205 * 206 * @param agent Indicates the name of the application bundle that can publish notifications for your application. 207 * @return Returns set notification agent result. 208 */ 209 ErrCode SetNotificationAgent(const std::string &agent); 210 211 /** 212 * @brief Obtains the name of the application bundle that can publish notifications in the name of your application. 213 * 214 * @param agent Indicates the name of the application bundle that can publish notifications for your application if 215 * any; returns null otherwise. 216 * @return Returns get notification agent result. 217 */ 218 ErrCode GetNotificationAgent(std::string &agent); 219 220 /** 221 * @brief Checks whether your application has permission to publish notifications by calling 222 * PublishNotificationAsBundle(string, NotificationRequest) in the name of another application indicated by the 223 * given representativeBundle. 224 * 225 * @param representativeBundle Indicates the name of application bundle your application is representing. 226 * @param canPublish Indicates whether your application has permission to publish notifications. 227 * @return Returns can publish notification as bundle result. 228 */ 229 ErrCode CanPublishNotificationAsBundle(const std::string &representativeBundle, bool &canPublish); 230 231 /** 232 * @brief Publishes a notification in the name of a specified application bundle. 233 * @note If the notification to be published has the same ID as a published notification that has not been canceled, 234 * the existing notification will be replaced by the new one. 235 * 236 * @param request Indicates the NotificationRequest object for setting the notification content. 237 * This parameter must be specified. 238 * @param representativeBundle Indicates the name of the application bundle that allows your application to publish 239 * notifications for it by calling setNotificationAgent. 240 * @return Returns publish notification as bundle result. 241 */ 242 ErrCode PublishNotificationAsBundle(const std::string &representativeBundle, const NotificationRequest &request); 243 244 /** 245 * @brief Sets the number of active notifications of the current application as the number to be displayed on the 246 * notification badge. 247 * 248 * @return Returns set notification badge num result. 249 */ 250 ErrCode SetNotificationBadgeNum(); 251 252 /** 253 * @brief Sets the number to be displayed on the notification badge of the application. 254 * 255 * @param num Indicates the number to display. A negative number indicates that the badge setting remains unchanged. 256 * The value 0 indicates that no badge is displayed on the application icon. 257 * If the value is greater than 99, 99+ will be displayed. 258 * @return Returns set notification badge num result. 259 */ 260 ErrCode SetNotificationBadgeNum(int32_t num); 261 262 /** 263 * @brief Checks whether this application has permission to publish notifications. The caller must have 264 * system permissions to call this method. 265 * 266 * @param allowed True if this application has the permission; returns false otherwise 267 * @return Returns is allowed notify result. 268 */ 269 ErrCode IsAllowedNotify(bool &allowed); 270 271 /** 272 * @brief Checks whether this application has permission to publish notifications. 273 * 274 * @param allowed True if this application has the permission; returns false otherwise 275 * @return Returns is allowed notify result. 276 */ 277 ErrCode IsAllowedNotifySelf(bool &allowed); 278 279 /** 280 * @brief Allows the current application to publish notifications on a specified device. 281 * 282 * @param deviceId Indicates the ID of the device running the application. At present, this parameter can 283 * only be null or an empty string, indicating the current device. 284 * @return Returns set notifications enabled for default bundle result. 285 */ 286 ErrCode RequestEnableNotification(std::string &deviceId); 287 288 /** 289 * @brief Checks whether this application is in the suspended state.Applications in this state cannot publish 290 * notifications. 291 * 292 * @param suspended True if this application is suspended; returns false otherwise. 293 * @return Returns are notifications suspended. 294 */ 295 ErrCode AreNotificationsSuspended(bool &suspended); 296 297 /** 298 * @brief Checks whether this application has permission to modify the Do Not Disturb (DND) notification policy. 299 * 300 * @param hasPermission True if this application is suspended; returns false otherwise. 301 * @return Returns has notification policy access permission. 302 */ 303 ErrCode HasNotificationPolicyAccessPermission(bool &hasPermission); 304 305 /** 306 * @brief Obtains the importance level of this application. 307 * 308 * @param importance the importance level of this application, which can be LEVEL_NONE, 309 LEVEL_MIN, LEVEL_LOW, LEVEL_DEFAULT, LEVEL_HIGH, or LEVEL_UNDEFINED. 310 * @return Returns get bundle importance result 311 */ 312 ErrCode GetBundleImportance(NotificationSlot::NotificationLevel &importance); 313 314 /** 315 * @brief Subscribes to notifications from all applications. This method can be called only by applications 316 * with required system permissions. 317 * @note To subscribe to a notification, inherit the {NotificationSubscriber} class, override its 318 * callback methods and create a subscriber. The subscriber will be used as a parameter of this method. 319 * After the notification is published, subscribers that meet the filter criteria can receive the 320 * notification. To subscribe to notifications published only by specified sources, for example, notifications from 321 * certain applications, call the {SubscribeNotification(NotificationSubscriber, NotificationSubscribeInfo)} 322 * method. 323 * 324 * @param subscriber Indicates the {NotificationSubscriber} to receive notifications. 325 * This parameter must be specified. 326 * @return Returns subscribe notification result. 327 */ 328 ErrCode SubscribeNotification(const NotificationSubscriber &subscriber); 329 330 /** 331 * @brief Subscribes to all notifications based on the filtering criteria. This method can be called only 332 * by applications with required system permissions. 333 * @note After {subscribeInfo} is specified, a subscriber receives only the notifications that 334 * meet the filter criteria specified by {subscribeInfo}. 335 * To subscribe to a notification, inherit the {NotificationSubscriber} class, override its 336 * callback methods and create a subscriber. The subscriber will be used as a parameter of this method. 337 * After the notification is published, subscribers that meet the filter criteria can receive the 338 * notification. To subscribe to and receive all notifications, call the 339 * {SubscribeNotification(NotificationSubscriber)} method. 340 * 341 * @param subscriber Indicates the subscribers to receive notifications. This parameter must be specified. 342 * For details, see {NotificationSubscriber}. 343 * @param subscribeInfo Indicates the filters for specified notification sources, including application name, 344 * user ID, or device name. This parameter is optional. 345 * @return Returns subscribe notification result. 346 */ 347 ErrCode SubscribeNotification( 348 const NotificationSubscriber &subscriber, const NotificationSubscribeInfo &subscribeInfo); 349 350 /** 351 * @brief Unsubscribes from all notifications. This method can be called only by applications with required 352 * system permissions. 353 * @note Generally, you subscribe to a notification by calling the 354 * {SubscribeNotification(NotificationSubscriber)} method. If you do not want your application 355 * to receive a notification any longer, unsubscribe from that notification using this method. 356 * You can unsubscribe from only those notifications that your application has subscribed to. 357 * To unsubscribe from notifications published only by specified sources, for example, 358 * notifications from certain applications, call the 359 * {UnSubscribeNotification(NotificationSubscriber, NotificationSubscribeInfo)} method. 360 * 361 * @param subscriber Indicates the {NotificationSubscriber} to receive notifications. 362 * This parameter must be specified. 363 * @return Returns unsubscribe notification result. 364 */ 365 ErrCode UnSubscribeNotification(NotificationSubscriber &subscriber); 366 367 /** 368 * @brief Unsubscribes from all notifications based on the filtering criteria. This method can be called 369 * only by applications with required system permissions. 370 * @note A subscriber will no longer receive the notifications from specified notification sources. 371 * 372 * @param subscriber Indicates the {NotificationSubscriber} to receive notifications. 373 * This parameter must be specified. 374 * @param subscribeInfo Indicates the filters for , including application name, 375 * user ID, or device name. This parameter is optional. 376 * @return Returns unsubscribe notification result. 377 */ 378 ErrCode UnSubscribeNotification(NotificationSubscriber &subscriber, NotificationSubscribeInfo subscribeInfo); 379 380 /** 381 * @brief Removes a specified removable notification of other applications. 382 * @note Your application must have platform signature to use this method. 383 * 384 * @param key Indicates the key of the notification to remove. 385 * @param removeReason Indicates the reason of remove notification. 386 * @return Returns remove notification result. 387 */ 388 ErrCode RemoveNotification(const std::string &key, int32_t removeReason); 389 390 /** 391 * @brief Removes a specified removable notification of other applications. 392 * @note Your application must have platform signature to use this method. 393 * 394 * @param bundleOption Indicates the bundle name and uid of the application whose notifications are to be removed. 395 * @param notificationId Indicates the id of the notification to remove. 396 * @param label Indicates the label of the notification to remove. 397 * @param removeReason Indicates the reason of remove notification. 398 * @return Returns remove notification result. 399 */ 400 ErrCode RemoveNotification(const NotificationBundleOption &bundleOption, const int32_t notificationId, 401 const std::string &label, int32_t removeReason); 402 403 /** 404 * @brief Removes a specified removable notification of other applications. 405 * @note Your application must have platform signature to use this method. 406 * 407 * @param bundleOption Indicates the bundle name and uid of the application whose notifications are to be removed. 408 * @return Returns remove notification result. 409 */ 410 ErrCode RemoveAllNotifications(const NotificationBundleOption &bundleOption); 411 412 /** 413 * @brief Removes all removable notifications of a specified bundle. 414 * @note Your application must have platform signature to use this method. 415 * 416 * @param bundleOption Indicates the bundle name and uid of the application whose notifications are to be removed. 417 * @return Returns remove notifications result. 418 */ 419 ErrCode RemoveNotificationsByBundle(const NotificationBundleOption &bundleOption); 420 421 /** 422 * @brief Removes all removable notifications in the system. 423 * @note Your application must have platform signature to use this method. 424 * 425 * @return Returns remove notifications result. 426 */ 427 ErrCode RemoveNotifications(); 428 429 /** 430 * @brief Obtains all notification slots belonging to the specified bundle. 431 * 432 * @param bundleOption Indicates the bundle name and uid of the application. 433 * @param slots Indicates a list of notification slots. 434 * @return Returns get notification slots for bundle result. 435 */ 436 ErrCode GetNotificationSlotsForBundle( 437 const NotificationBundleOption &bundleOption, std::vector<sptr<NotificationSlot>> &slots); 438 439 /** 440 * @brief Updates all notification slots for the specified bundle. 441 * 442 * @param bundleOption Indicates the bundle name and uid of the application. 443 * @param slots Indicates a list of new notification slots. 444 * @return Returns update notification slots for bundle result. 445 */ 446 ErrCode UpdateNotificationSlots( 447 const NotificationBundleOption &bundleOption, const std::vector<sptr<NotificationSlot>> &slots); 448 449 /** 450 * @brief Obtains all active notifications in the current system. The caller must have system permissions to 451 * call this method. 452 * 453 * @param notification Indicates all active notifications of this application. 454 * @return Returns get all active notifications 455 */ 456 ErrCode GetAllActiveNotifications(std::vector<sptr<Notification>> ¬ification); 457 458 /** 459 * @brief Obtains the active notifications corresponding to the specified key in the system. To call this method 460 * to obtain particular active notifications, you must have received the notifications and obtained the key 461 * via {Notification::GetKey()}. 462 * 463 * @param key Indicates the key array for querying corresponding active notifications. 464 * If this parameter is null, this method returns all active notifications in the system. 465 * @param notification Indicates the set of active notifications corresponding to the specified key. 466 * @return Returns get all active notifications result. 467 */ 468 ErrCode GetAllActiveNotifications( 469 const std::vector<std::string> key, std::vector<sptr<Notification>> ¬ification); 470 471 /** 472 * @brief Checks whether a specified application has the permission to publish notifications. If bundle specifies 473 * the current application, no permission is required for calling this method. If bundle specifies another 474 * application, the caller must have system permissions. 475 * 476 * @param bundleOption Indicates the bundle name and uid of the application. 477 * @param allowed True if the application has permissions; returns false otherwise. 478 * @return Returns is allowed notify result. 479 */ 480 ErrCode IsAllowedNotify(const NotificationBundleOption &bundleOption, bool &allowed); 481 482 /** 483 * @brief Sets whether to allow all applications to publish notifications on a specified device. The caller must 484 * have system permissions to call this method. 485 * 486 * @param deviceId Indicates the ID of the device running the application. At present, this parameter can only 487 * be null or an empty string, indicating the current device. 488 * @param enabled Specifies whether to allow all applications to publish notifications. The value true 489 * indicates that notifications are allowed, and the value false indicates that notifications are not 490 * allowed. 491 * @return Returns set notifications enabled for all bundles result. 492 */ 493 ErrCode SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled); 494 495 /** 496 * @brief Sets whether to allow the current application to publish notifications on a specified device. The caller 497 * must have system permissions to call this method. 498 * 499 * @param deviceId Indicates the ID of the device running the application. At present, this parameter can 500 * only be null or an empty string, indicating the current device. 501 * @param enabled Specifies whether to allow the current application to publish notifications. The value 502 * true indicates that notifications are allowed, and the value false indicates that 503 * notifications are not allowed. 504 * @return Returns set notifications enabled for default bundle result. 505 */ 506 ErrCode SetNotificationsEnabledForDefaultBundle(const std::string &deviceId, bool enabled); 507 508 /** 509 * @brief Sets whether to allow a specified application to publish notifications on a specified device. The caller 510 * must have system permissions to call this method. 511 * 512 * @param bundleOption Indicates the bundle name and uid of the application. 513 * @param deviceId Indicates the ID of the device running the application. At present, this parameter can only 514 * be null or an empty string, indicating the current device. 515 * @param enabled Specifies whether to allow the given application to publish notifications. The value 516 * true indicates that notifications are allowed, and the value false indicates that notifications 517 * are not allowed. 518 * @return Returns set notifications enabled for specified bundle result. 519 */ 520 ErrCode SetNotificationsEnabledForSpecifiedBundle( 521 const NotificationBundleOption &bundleOption, const std::string &deviceId, bool enabled); 522 523 /** 524 * @brief Sets whether to allow a specified application to to show badge. 525 * 526 * @param bundleOption Indicates the bundle name and uid of the application. 527 * @param enabled Specifies whether to allow the given application to show badge. 528 * @return Returns set result. 529 */ 530 ErrCode SetShowBadgeEnabledForBundle(const NotificationBundleOption &bundleOption, bool enabled); 531 532 /** 533 * @brief Obtains the flag that whether to allow a specified application to to show badge. 534 * 535 * @param bundleOption Indicates the bundle name and uid of the application. 536 * @param enabled Specifies whether to allow the given application to show badge. 537 * @return Returns get result. 538 */ 539 ErrCode GetShowBadgeEnabledForBundle(const NotificationBundleOption &bundleOption, bool &enabled); 540 541 /** 542 * @brief Obtains the flag that whether to allow the current application to to show badge. 543 * 544 * @param enabled Specifies whether to allow the given application to show badge. 545 * @return Returns get result. 546 */ 547 ErrCode GetShowBadgeEnabled(bool &enabled); 548 549 /** 550 * @brief Cancels the notification of the specified group of this application. 551 * 552 * @param groupName the specified group name. 553 * @return Returns cancel group result. 554 */ 555 ErrCode CancelGroup(const std::string &groupName); 556 557 /** 558 * @brief Removes the notification of the specified group of the specified application. 559 * 560 * @param bundleOption Indicates the bundle name and uid of the specified application. 561 * @param groupName Indicates the specified group name. 562 * @return Returns remove group by bundle result. 563 */ 564 ErrCode RemoveGroupByBundle(const NotificationBundleOption &bundleOption, const std::string &groupName); 565 566 /** 567 * @brief Sets the do not disturb time. 568 * @note Your application must have system signature to call this method. 569 * 570 * @param doNotDisturbDate Indicates the do not disturb time to set. 571 * @return Returns set do not disturb time result. 572 */ 573 ErrCode SetDoNotDisturbDate(const NotificationDoNotDisturbDate &doNotDisturbDate); 574 575 /** 576 * @brief Obtains the do not disturb time. 577 * @note Your application must have system signature to call this method. 578 * 579 * @param doNotDisturbDate Indicates the do not disturb time to get. 580 * @return Returns set do not disturb time result. 581 */ 582 ErrCode GetDoNotDisturbDate(NotificationDoNotDisturbDate &doNotDisturbDate); 583 584 /** 585 * @brief Obtains the flag that whether to support do not disturb mode. 586 * 587 * @param doesSupport Specifies whether to support do not disturb mode. 588 * @return Returns check result. 589 */ 590 ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport); 591 592 /** 593 * @brief Checks if the device supports distributed notification. 594 * 595 * @param enabled True if the device supports distributed notification; false otherwise. 596 * @return Returns is distributed enabled result. 597 */ 598 ErrCode IsDistributedEnabled(bool &enabled); 599 600 /** 601 * @brief Sets whether the device supports distributed notifications. 602 * 603 * @param enable Specifies whether to enable the device to support distributed notification. 604 * The value true indicates that the device is enabled to support distributed notifications, and 605 * the value false indicates that the device is forbidden to support distributed notifications. 606 * @return Returns enable distributed result. 607 */ 608 ErrCode EnableDistributed(const bool enabled); 609 610 /** 611 * @brief Sets whether an application supports distributed notifications. 612 * 613 * @param bundleOption Indicates the bundle name and uid of an application. 614 * @param enabled Specifies whether to enable an application to support distributed notification. 615 * The value true indicates that the application is enabled to support distributed notifications, 616 * and the value false indicates that the application is forbidden to support distributed 617 * notifications. 618 * @return Returns enable distributed by bundle result. 619 */ 620 ErrCode EnableDistributedByBundle(const NotificationBundleOption &bundleOption, const bool enabled); 621 622 /** 623 * @brief Sets whether this application supports distributed notifications. 624 * 625 * @param enabled Specifies whether to enable this application to support distributed notification. 626 * The value true indicates that this application is enabled to support distributed notifications, 627 * and the value false indicates that this application is forbidden to support distributed 628 * notifications. 629 * @return Returns enable distributed self result. 630 */ 631 ErrCode EnableDistributedSelf(const bool enabled); 632 633 /** 634 * @brief Checks whether an application supports distributed notifications. 635 * 636 * @param bundleOption Indicates the bundle name and uid of an application. 637 * @param enabled True if the application supports distributed notification; false otherwise. 638 * @return Returns is distributed enabled by bundle result. 639 */ 640 ErrCode IsDistributedEnableByBundle(const NotificationBundleOption &bundleOption, bool &enabled); 641 642 /** 643 * @brief Obtains the device remind type. 644 * @note Your application must have system signature to call this method. 645 * 646 * @param remindType Indicates the device remind type to get. 647 * @return Returns get device reminder type result. 648 */ 649 ErrCode GetDeviceRemindType(NotificationConstant::RemindType &remindType); 650 651 /** 652 * @brief Publishes a continuous task notification. 653 * 654 * @param request Indicates the NotificationRequest object for setting the notification content. 655 * This parameter must be specified. 656 * @return Returns publish continuous task notification result. 657 */ 658 ErrCode PublishContinuousTaskNotification(const NotificationRequest &request); 659 660 /** 661 * @brief Cancels a published continuous task notification matching the specified label and notificationId. 662 * 663 * @param label Indicates the label of the continuous task notification to cancel. 664 * @param notificationId Indicates the ID of the continuous task notification to cancel. 665 * @return Returns cancel continuous task notification result. 666 */ 667 ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId); 668 669 /** 670 * @brief Obtains whether the template is supported by the system. 671 * 672 * @param support whether is it a system supported template. 673 * @return Returns check result. 674 */ 675 ErrCode IsSupportTemplate(const std::string &templateName, bool &support); 676 677 /** 678 * @brief Resets ans manager proxy when OnRemoteDied called. 679 */ 680 void ResetAnsManagerProxy(); 681 682 /** 683 * @brief Publishes a scheduled reminder. 684 * 685 * @param reminder Indicates a reminder. 686 * @return Returns publish result. 687 */ 688 ErrCode PublishReminder(ReminderRequest &reminder); 689 690 /** 691 * @brief Cancels a specified reminder. 692 * 693 * @param reminderId Indicates reminder Id. 694 * @return Returns cancel result. 695 */ 696 ErrCode CancelReminder(const int32_t reminderId); 697 698 /** 699 * @brief Cancels all reminders of current third part application. 700 * 701 * @return Returns cancel result. 702 */ 703 ErrCode CancelAllReminders(); 704 705 /** 706 * @brief Obtains all valid reminder notifications set by the current application. 707 * 708 * @param[out] validReminders Indicates the vector to store the result. 709 * @return Returns get valid reminders result. 710 */ 711 ErrCode GetValidReminders(std::vector<sptr<ReminderRequest>> &validReminders); 712 713 /** 714 * @brief Checks whether this application has permission to publish notifications under the user. 715 * 716 * @param userId Indicates the userId of the application. 717 * @param allowed True if the application has permissions; returns false otherwise. 718 * @return Returns get allowed result. 719 */ 720 ErrCode IsAllowedNotify(const int32_t &userId, bool &allowed); 721 722 /** 723 * @brief Sets whether to allow all applications to publish notifications on a specified user. 724 * The caller must have system permissions to call this method. 725 * 726 * @param userId Indicates the ID of the user running the application. 727 * @param enabled Specifies whether to allow all applications to publish notifications. The value true 728 * indicates that notifications are allowed, and the value false indicates that notifications 729 * are not allowed. 730 * @return Returns set notifications enabled for all bundles result. 731 */ 732 ErrCode SetNotificationsEnabledForAllBundles(const int32_t &userId, bool enabled); 733 734 /** 735 * @brief Removes notifications under specified user. 736 * @note Your application must have platform signature to use this method. 737 * 738 * @param userId Indicates the ID of user whose notifications are to be removed. 739 * @return Returns remove notification result. 740 */ 741 ErrCode RemoveNotifications(const int32_t &userId); 742 743 /** 744 * @brief Sets the do not disturb time on a specified user. 745 * @note Your application must have system signature to call this method. 746 * 747 * @param userId Indicates the specific user. 748 * @param doNotDisturbDate Indicates the do not disturb time to set. 749 * @return Returns set do not disturb time result. 750 */ 751 ErrCode SetDoNotDisturbDate(const int32_t &userId, const NotificationDoNotDisturbDate &doNotDisturbDate); 752 753 /** 754 * @brief Obtains the do not disturb time on a specified user. 755 * @note Your application must have system signature to call this method. 756 * 757 * @param userId Indicates the specific user. 758 * @param doNotDisturbDate Indicates the do not disturb time to get. 759 * @return Returns set do not disturb time result. 760 */ 761 ErrCode GetDoNotDisturbDate(const int32_t &userId, NotificationDoNotDisturbDate &doNotDisturbDate); 762 763 /** 764 * Set whether the application slot is enabled. 765 * 766 * @param bundleOption Indicates the bundle name and uid of the application. 767 * @param slotType Indicates type of slot. 768 * @param enable the type of slot enabled. 769 * @return Returns get slot number by bundle result. 770 */ 771 ErrCode SetEnabledForBundleSlot( 772 const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, bool enabled); 773 774 /** 775 * Obtains whether the application slot is enabled. 776 * 777 * @param bundleOption Indicates the bundle name and uid of the application. 778 * @param slotType Indicates type of slot. 779 * @param enable the type of slot enabled to get. 780 * @return Returns get slot number by bundle result. 781 */ 782 ErrCode GetEnabledForBundleSlot( 783 const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled); 784 785 /** 786 * @brief Obtains specific datas via specified dump option. 787 * 788 * @param cmd Indicates the specified dump command. 789 * @param bundle Indicates the specified bundle name. 790 * @param userId Indicates the specified userId. 791 * @param dumpInfo Indicates the container containing datas. 792 * @return Returns check result. 793 */ 794 ErrCode ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, 795 std::vector<std::string> &dumpInfo); 796 797 /** 798 * @brief Set whether to sync notifications to devices that do not have the app installed. 799 * 800 * @param userId Indicates the specific user. 801 * @param enabled Allow or disallow sync notifications. 802 * @return Returns set enabled result. 803 */ 804 ErrCode SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled); 805 806 /** 807 * @brief Obtains whether to sync notifications to devices that do not have the app installed. 808 * 809 * @param userId Indicates the specific user. 810 * @param enabled Allow or disallow sync notifications. 811 * @return Returns get enabled result. 812 */ 813 ErrCode GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled); 814 815 private: 816 /** 817 * @brief Gets Ans Manager proxy. 818 * 819 * @return Returns true if succeed; returns false otherwise. 820 */ 821 bool GetAnsManagerProxy(); 822 823 /** 824 * @brief Checks if the MediaContent can be published. 825 * 826 * @param request Indicates the specified request. 827 * @return Returns true if the MediaContent can be published; returns false otherwise. 828 */ 829 bool CanPublishMediaContent(const NotificationRequest &request) const; 830 831 /** 832 * @brief Checks whether the picture size exceeds the limit in PixelMap. 833 * 834 * @param pixelMap Indicates the specified image. 835 * @param maxSize Indicates the limit size. 836 * @return Returns true if the limit size is exceeded; returns false otherwise. 837 */ 838 bool CheckImageOverSizeForPixelMap( 839 const std::shared_ptr<Media::PixelMap> &pixelMap, uint32_t maxSize); 840 841 /** 842 * @brief Checks whether the picture size exceeds the limit in NotificationRequest's content. 843 * 844 * @param request Indicates the specified request. 845 * @return Returns the ErrCode. 846 */ 847 ErrCode CheckImageSizeForContent(const NotificationRequest &request); 848 849 /** 850 * @brief Checks whether the picture size exceeds the limit. 851 * 852 * @param request Indicates the specified request. 853 * @return Returns the ErrCode. 854 */ 855 ErrCode CheckImageSize(const NotificationRequest &request); 856 857 /** 858 * @brief Checks whether the notification doesn't support distribution. 859 * 860 * @param type Indicates the specified NotificationContent::Type. 861 * @return Returns true if the notification doesn't support distribution; returns false otherwise. 862 */ 863 bool IsNonDistributedNotificationType(const NotificationContent::Type &type); 864 865 private: 866 std::mutex mutex_; 867 sptr<AnsManagerInterface> ansManagerProxy_; 868 sptr<AnsManagerDeathRecipient> recipient_; 869 }; 870 } // namespace Notification 871 } // namespace OHOS 872 873 #endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_NOTIFICATION_H