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