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