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_REQUEST_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_REQUEST_H 18 19 #include "ans_const_define.h" 20 #include "message_user.h" 21 #include "notification_action_button.h" 22 #include "notification_content.h" 23 #include "notification_distributed_options.h" 24 #include "notification_flags.h" 25 #include "notification_json_convert.h" 26 #include "notification_template.h" 27 #include "parcel.h" 28 #include "pixel_map.h" 29 #include "want_agent.h" 30 #include "want_params.h" 31 32 namespace OHOS { 33 namespace Notification { 34 class NotificationRequest : public Parcelable, public NotificationJsonConvertionBase { 35 public: 36 enum class BadgeStyle { 37 /** 38 * displays only numbers. 39 */ 40 NONE, 41 /** 42 * displayed as a large icon. 43 */ 44 BIG, 45 /** 46 * displayed as a small icon. 47 */ 48 LITTLE 49 }; 50 51 enum class GroupAlertType { 52 /** 53 * all notifications in a group have sound or vibration if sound or vibration is enabled 54 * for the associated NotificationSlot objects. 55 */ 56 ALL, 57 /** 58 * child notifications have sound or vibration but the overview notification is muted (no sound or vibration) 59 * in a group if sound or vibration is enabled for the associated NotificationSlot objects. 60 */ 61 CHILD, 62 /** 63 * the overview notification has sound or vibration but child notifications are muted (no sound or vibration) 64 * in a group if sound or vibration is enabled for the associated NotificationSlot objects. 65 */ 66 OVERVIEW 67 }; 68 69 /** 70 * Indicates the classification of notifications for alarms or timers. 71 */ 72 static const std::string CLASSIFICATION_ALARM; 73 /** 74 * Indicates the classification of notifications for incoming calls or similar synchronous communication requests. 75 */ 76 static const std::string CLASSIFICATION_CALL; 77 /** 78 * Indicates the classification of notifications for emails. 79 */ 80 static const std::string CLASSIFICATION_EMAIL; 81 /** 82 * Indicates the classification of notifications for errors occurred during background operations or identity 83 * authentication. 84 */ 85 static const std::string CLASSIFICATION_ERROR; 86 /** 87 * Indicates the classification of notifications for calendar events. 88 */ 89 static const std::string CLASSIFICATION_EVENT; 90 /** 91 * Indicates the classification of notifications for short messages or instant messages. 92 */ 93 static const std::string CLASSIFICATION_MESSAGE; 94 /** 95 * Indicates the classification of notifications for map navigation. 96 */ 97 static const std::string CLASSIFICATION_NAVIGATION; 98 /** 99 * Indicates the classification of notifications for processes that are operated in the background for a long time. 100 */ 101 static const std::string CLASSIFICATION_PROGRESS; 102 /** 103 * Indicates the classification of notifications for advertisement or promotion information. 104 */ 105 static const std::string CLASSIFICATION_PROMO; 106 /** 107 * Indicates the classification of notifications for specific and timely recommendations of a particular 108 * transaction. 109 */ 110 static const std::string CLASSIFICATION_RECOMMENDATION; 111 /** 112 * Indicates the classification of notifications for reminders previously set by the user. 113 */ 114 static const std::string CLASSIFICATION_REMINDER; 115 /** 116 * Indicates the classification of notifications for ongoing background services. 117 */ 118 static const std::string CLASSIFICATION_SERVICE; 119 /** 120 * Indicates the classification of notifications for social network or sharing updates. 121 */ 122 static const std::string CLASSIFICATION_SOCIAL; 123 /** 124 * Indicates the classification of notifications for ongoing information about the device and contextual status. 125 */ 126 static const std::string CLASSIFICATION_STATUS; 127 /** 128 * Indicates the classification of notifications for system or device status updates. 129 */ 130 static const std::string CLASSIFICATION_SYSTEM; 131 /** 132 * Indicates the classification of notifications for media transport control during playback. 133 */ 134 static const std::string CLASSIFICATION_TRANSPORT; 135 136 /** 137 * Indicates the default notification background color, which means that no color is displayed. 138 */ 139 static const uint32_t COLOR_DEFAULT; 140 141 public: 142 NotificationRequest() = default; 143 144 /** 145 * @brief A constructor used to create a NotificationRequest instance with the input parameter notificationId 146 * passed. 147 * 148 * @param notificationId Indicates notification ID. 149 */ 150 explicit NotificationRequest(int32_t notificationId); 151 152 /** 153 * @brief A constructor used to create a NotificationRequest instance by copying parameters from an existing one. 154 * 155 * @param other Indicates the existing object. 156 */ 157 NotificationRequest(const NotificationRequest &other); 158 159 /** 160 * @brief A constructor used to create a NotificationRequest instance by copying parameters from an existing one. 161 * 162 * @param other Indicates the existing object. 163 */ 164 NotificationRequest &operator=(const NotificationRequest &other); 165 166 virtual ~NotificationRequest(); 167 168 /** 169 * @brief Checks whether this notification is in progress. 170 * 171 * @return Returns true if this notification is in progress; returns false otherwise. 172 */ 173 bool IsInProgress() const; 174 175 /** 176 * @brief Sets whether this notification is in progress. 177 * Users cannot directly dismiss notifications in progress because 178 * they usually contain some ongoing background services such as music playback. 179 * 180 * @param isOngoing Specifies whether this notification is in progress. 181 */ 182 void SetInProgress(bool isOngoing); 183 184 /** 185 * @brief Checks whether this notification is unremovable. 186 * 187 * @return Returns true if this notification is unremovable; returns false otherwise. 188 */ 189 bool IsUnremovable() const; 190 191 /** 192 * @brief Sets whether this notification is unremovable. 193 * If it is set to be unremovable, it cannot be removed by users. 194 * 195 * @param isUnremovable Specifies whether this notification is unremovable. 196 */ 197 void SetUnremovable(bool isUnremovable); 198 199 /** 200 * @brief Sets the number to be displayed for this notification. 201 * 202 * @param number Indicates the number to set. 203 */ 204 void SetBadgeNumber(uint32_t number); 205 206 /** 207 * @brief Obtains the number to be displayed for this notification. 208 * 209 * @return Returns the number to be displayed for this notification. 210 */ 211 uint32_t GetBadgeNumber() const; 212 213 /** 214 * @brief Sets the current notification ID to uniquely identify the notification in the application. 215 * After a notification is received, its ID is obtained by using the getNotificationId() method. 216 * 217 * @param notificationId Indicates the ID of the notification to be set. 218 */ 219 void SetNotificationId(int32_t notificationId); 220 221 /** 222 * @brief Obtains the notification ID, which is unique in the current application. 223 * 224 * @return the notification ID. 225 */ 226 int32_t GetNotificationId() const; 227 228 /** 229 * @brief Adds an WantAgent to this notification. 230 * After a notification is tapped, subsequent operations such as ability and common events will be triggered as 231 * set by WantAgent. 232 * 233 * @param wantAgent Indicates the operation triggered by tapping the notification, which can be set by 234 * WantAgent. 235 */ 236 void SetWantAgent(const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> &wantAgent); 237 238 /** 239 * @brief Obtains the WantAgent contained in this notification. 240 * 241 * @return Returns the WantAgent contained in this notification. 242 */ 243 const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> GetWantAgent() const; 244 245 /** 246 * @brief Sets an WantAgent object that is triggered when the user explicitly removes this notification. 247 * 248 * @param wantAgent Indicates the WantAgent object to be triggered. 249 */ 250 void SetRemovalWantAgent(const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> &wantAgent); 251 252 /** 253 * @brief Obtains the WantAgent object that is triggered when the user explicitly removes this notification. 254 * 255 * @return Returns the WantAgent object to be triggered. 256 */ 257 const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> GetRemovalWantAgent() const; 258 259 /** 260 * @brief Sets the WantAgent to start when the device is not in use, 261 * instead of showing this notification in the status bar. 262 * When the device is in use, the system UI displays a pop-up notification 263 * instead of starting the WantAgent specified by maxScreenWantAgent. 264 * Your application must have the ohos.permission.USE_WHOLE_SCREEN permission to use this method. 265 * 266 * @param wantAgent Indicates the WantAgent object containing information about the to-be-started ability that 267 * uses the Page template. 268 */ 269 void SetMaxScreenWantAgent(const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> &wantAgent); 270 271 /** 272 * @brief Obtains the full-screen WantAgent set by calling setMaxScreenWantAgent(WantAgent). 273 * 274 * @return Returns the full-screen WantAgent. 275 */ 276 const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> GetMaxScreenWantAgent() const; 277 278 /** 279 * @brief Sets extra parameters that are stored as key-value pairs for the notification. 280 * 281 * @param extras Indicates the WantParams object containing the extra parameters in key-value pair format. 282 */ 283 void SetAdditionalData(const std::shared_ptr<AAFwk::WantParams> &extras); 284 285 /** 286 * @brief Obtains the WantParams object set in the notification. 287 * 288 * @return Returns the WantParams object. 289 */ 290 const std::shared_ptr<AAFwk::WantParams> GetAdditionalData() const; 291 292 /** 293 * @brief Sets the time to deliver a notification. 294 * 295 * @param deliveryTime Indicates the time in milliseconds. 296 */ 297 void SetDeliveryTime(int64_t deliveryTime); 298 299 /** 300 * @brief Obtains the time when a notification is delivered. 301 * 302 * @return Returns the time in milliseconds. 303 */ 304 int64_t GetDeliveryTime() const; 305 306 /** 307 * @brief Checks whether the notification delivery time is displayed for this notification. 308 * 309 * @return Returns true if the time is displayed; returns false otherwise. 310 */ 311 bool IsShowDeliveryTime() const; 312 313 /** 314 * @brief Sets whether to show the notification delivery time for this notification. 315 * This method is valid only when the notification delivery time has been set by calling setDeliveryTime(int64_t). 316 * 317 * @param showDeliveryTime Specifies whether to show the notification delivery time. 318 */ 319 void SetShowDeliveryTime(bool showDeliveryTime); 320 321 /** 322 * @brief Adds a NotificationActionButton to this notification. 323 * An operation button is usually placed next to the notification content by the system. 324 * Each action button must contain an icon, a title, and an WantAgent. When a notification is expanded, 325 * a maximum of three action buttons can be displayed from left to right in the order they were added. 326 * When the notification is collapsed, no action buttons will be displayed. 327 * 328 * @param actionButton Indicates the NotificationActionButton object to add. 329 */ 330 void AddActionButton(const std::shared_ptr<NotificationActionButton> &actionButton); 331 332 /** 333 * @brief Obtains the list of all NotificationActionButton objects included in this notification. 334 * 335 * @return Returns the list of NotificationActionButton objects. 336 */ 337 const std::vector<std::shared_ptr<NotificationActionButton>> GetActionButtons() const; 338 339 /** 340 * @brief Clear the list of all NotificationActionButton objects included in this notification. 341 */ 342 void ClearActionButtons(); 343 344 /** 345 * @brief Checks whether the platform is allowed to generate contextual NotificationActionButton objects for this 346 * notification. 347 * 348 * @return Returns true if the platform is allowed to generate contextual NotificationActionButton objects; 349 * returns false otherwise. 350 */ 351 bool IsPermitSystemGeneratedContextualActionButtons() const; 352 353 /** 354 * @brief Sets whether to allow the platform to generate contextual NotificationActionButton objects for this 355 * notification. 356 * 357 * @param permitted Specifies whether to allow the platform to generate contextual NotificationActionButton objects. 358 * The default value true indicates that the platform is allowed to generate contextual action buttons, 359 * and the value false indicates not. 360 */ 361 void SetPermitSystemGeneratedContextualActionButtons(bool permitted); 362 363 bool IsAgentNotification() const; 364 365 void SetIsAgentNotification(bool isAgent); 366 367 /** 368 * @brief Adds a MessageUser object and associates it with this notification. 369 * 370 * @param messageUser Indicates the MessageUser object to add. 371 */ 372 void AddMessageUser(const std::shared_ptr<MessageUser> &messageUser); 373 374 /** 375 * @brief Obtains all MessageUser objects associated with this notification. 376 * 377 * @return Returns the list of MessageUser objects associated with this notification. 378 */ 379 const std::vector<std::shared_ptr<MessageUser>> GetMessageUsers() const; 380 381 /** 382 * @brief Checks whether this notification is set to alert only once, 383 * which means that sound or vibration will no longer be played 384 * for notifications with the same ID upon their updates. 385 * 386 * @return Returns true if this notification is set to alert only once; returns false otherwise. 387 */ 388 bool IsAlertOneTime() const; 389 390 /** 391 * @brief Sets whether to have this notification alert only once. 392 * If a notification alerts only once, sound or vibration will no longer be played 393 * for notifications with the same ID upon their updates after they are published. 394 * 395 * @param isAlertOnce Specifies whether to have this notification alert only once. 396 */ 397 void SetAlertOneTime(bool isAlertOnce); 398 399 /** 400 * @brief Sets the time to delete a notification. 401 * 402 * @param deletedTime Indicates the time in milliseconds. 403 * The default value is 0, indicating that the notification will not be automatically deleted. 404 * To enable the notification to be automatically deleted, set this parameter to an integer greater than 0. 405 */ 406 void SetAutoDeletedTime(int64_t deletedTime); 407 408 /** 409 * @brief Obtains the period during which a notification is deleted. 410 * 411 * @return Returns the period in milliseconds. 412 */ 413 int64_t GetAutoDeletedTime() const; 414 415 /** 416 * @brief Sets the little icon of the notification. 417 * 418 * @param littleIcon Indicates the icon of the notification. 419 */ 420 void SetLittleIcon(const std::shared_ptr<Media::PixelMap> &littleIcon); 421 422 /** 423 * @brief Obtains the icon of the notification. 424 * 425 * @return Returns the notification icon. 426 */ 427 const std::shared_ptr<Media::PixelMap> GetLittleIcon() const; 428 429 /** 430 * @brief Sets the large icon of this notification, which is usually displayed on the right of the notification. 431 * 432 * @param bigIcon Indicates the large icon to set. It must be a PixelMap object. 433 */ 434 void SetBigIcon(const std::shared_ptr<Media::PixelMap> &bigIcon); 435 436 /** 437 * @brief Obtains the large icon of this notification. 438 * 439 * @return Returns the large icon of this notification. 440 */ 441 const std::shared_ptr<Media::PixelMap> GetBigIcon() const; 442 443 /** 444 * @brief Sets the classification of this notification, which describes the purpose of this notification. 445 * Notification classifications are used to filter and sort notifications. 446 * 447 * @param classification Indicates the notification classification predefined in the system, 448 * such as CLASSIFICATION_CALL or CLASSIFICATION_NAVIGATION etc. 449 */ 450 void SetClassification(const std::string &classification); 451 452 /** 453 * @brief Obtains the classification of this notification. 454 * 455 * @return Returns the classification of this notification. 456 */ 457 std::string GetClassification() const; 458 459 /** 460 * @brief Sets the background color of this notification. 461 * This method is valid only when background color has been enabled by calling setColorEnabled(bool). 462 * 463 * @param color Indicates the background color to set. For details about the value range, see Color. 464 */ 465 void SetColor(uint32_t color); 466 467 /** 468 * @brief Obtains the background color of this notification. 469 * The return value, except for the default color COLOR_DEFAULT, 470 * is the bitwise OR operation result of 0xFF000000 and the ARGB value set by setColor(uint32_t). 471 * 472 * @return Returns the background color of this notification. 473 */ 474 uint32_t GetColor() const; 475 476 /** 477 * @brief Checks whether background color is enabled for this notification. 478 * 479 * @return Returns true if background color is enabled; returns false otherwise. 480 */ 481 bool IsColorEnabled() const; 482 483 /** 484 * @brief Sets whether to enable background color for this notification. 485 * If colorEnabled is set to true, this method takes effect only 486 * when the notification content type has been set to NotificationRequest. 487 * NotificationMediaContent in the NotificationRequest object through 488 * NotificationRequest::setContent(NotificationContent) and an AVToken has been attached to 489 * that NotificationMediaContent object through NotificationMediaContent::setAVToken(AVToken). 490 * 491 * @param colorEnabled Specifies whether to enable background color. 492 */ 493 void SetColorEnabled(bool colorEnabled); 494 495 /** 496 * @brief Sets the notification content type to NotificationNormalContent, NotificationLongTextContent, 497 * or NotificationPictureContent etc. 498 * Each content type indicates a particular notification content. 499 * 500 * @param content Indicates the notification content type. 501 */ 502 void SetContent(const std::shared_ptr<NotificationContent> &content); 503 504 /** 505 * @brief Obtains the notification content set by calling the setContent(NotificationContent) method. 506 * 507 * @return Returns the notification content. 508 */ 509 const std::shared_ptr<NotificationContent> GetContent() const; 510 511 /** 512 * @brief Obtains the notification type. 513 * 514 * @return Returns the type of the current notification, which can be 515 * NotificationContent::Type::BASIC_TEXT, 516 * NotificationContent::Type::LONG_TEXT, 517 * NotificationContent::Type::PICTURE, 518 * NotificationContent::Type::CONVERSATION, 519 * NotificationContent::Type::MULTILINE, 520 * or NotificationContent::Type::MEDIA. 521 */ 522 NotificationContent::Type GetNotificationType() const; 523 524 /** 525 * @brief Checks whether the notification creation time is displayed as a countdown timer. 526 * 527 * @return Returns true if the time is displayed as a countdown timer; returns false otherwise. 528 */ 529 bool IsCountdownTimer() const; 530 531 /** 532 * @brief Sets whether to show the notification creation time as a countdown timer. 533 * This method is valid only when setShowStopwatch(boolean) is set to true. 534 * 535 * @param isCountDown Specifies whether to show the notification creation time as a countdown timer. 536 */ 537 void SetCountdownTimer(bool isCountDown); 538 539 /** 540 * @brief Sets the group alert type for this notification, 541 * which determines how the group overview and other notifications in a group are published. 542 * The group information must have been set by calling setGroupValue(string). 543 * Otherwise, this method does not take effect. 544 * 545 * @param type Indicates the group alert type to set. which can be GroupAlertType::ALL (default value), 546 * GroupAlertType::OVERVIEW, or GroupAlertType::CHILD etc. 547 */ 548 void SetGroupAlertType(NotificationRequest::GroupAlertType type); 549 550 /** 551 * @brief Obtains the group alert type of this notification. 552 * 553 * @return Returns the group alert type of this notification. 554 */ 555 NotificationRequest::GroupAlertType GetGroupAlertType() const; 556 557 /** 558 * @brief Checks whether this notification is the group overview. 559 * 560 * @return Returns true if this notification is the group overview; returns false otherwise. 561 */ 562 bool IsGroupOverview() const; 563 564 /** 565 * @brief Sets whether to use this notification as the overview of its group. 566 * This method helps display the notifications that are assigned the same group name by calling 567 * setGroupName(string) as one stack in the notification bar. 568 * Each group requires only one group overview. After a notification is set as the group overview, 569 * it becomes invisible if another notification in the same group is published. 570 * 571 * @param overView Specifies whether to set this notification as the group overview. 572 */ 573 void SetGroupOverview(bool overView); 574 575 /** 576 * @brief Sets the group information for this notification. 577 * If no groups are set for notifications, all notifications from the same application will appear 578 * in the notification bar as one stack with the number of stacked notifications displayed. 579 * If notifications are grouped and there are multiple groups identified by different groupName, 580 * notifications with different groupName will appear in separate stacks. 581 * Note that one of the notifications in a group must be set as the overview of its group by calling 582 * setGroupOverview(bool), and other notifications are considered as child notifications. 583 * Otherwise, notifications will not be displayed as one group even if they are assigned the same groupName by 584 * calling setGroupName(string). 585 * 586 * @param groupName Specifies whether to set this notification as the group overview. 587 */ 588 void SetGroupName(const std::string &groupName); 589 590 /** 591 * @brief Obtains the group information about this notification. 592 * 593 * @return Returns the group information about this notification. 594 */ 595 std::string GetGroupName() const; 596 597 /** 598 * @brief Checks whether this notification is relevant only to the local device and cannot be displayed on remote 599 * devices. 600 * 601 * @return Returns true if this notification is relevant only to the local device; returns false otherwise. 602 */ 603 bool IsOnlyLocal() const; 604 605 /** 606 * @brief Sets whether this notification is relevant only to the local device and cannot be displayed on remote 607 * devices.This method takes effect only for notifications published by calling 608 * NotificationHelper::publishNotification(NotificationRequest) or 609 * NotificationHelper#publishNotification(string, NotificationRequest). 610 * Notifications published using NotificationHelper::publishNotification(NotificationRequest, string) 611 * in a distributed system will not be affected. 612 * 613 * @param flag Specifies whether this notification can be displayed only on the local device. 614 */ 615 void SetOnlyLocal(bool flag); 616 617 /** 618 * @brief Sets the text that will be displayed as a link to the settings of the application. 619 * Calling this method is invalid if the notification content type has been set to NotificationLongTextContent 620 * or NotificationPictureContent in the NotificationRequest object through setContent(NotificationContent). 621 * 622 * @param text Indicates the text to be included. You can set it to any valid link. 623 */ 624 void SetSettingsText(const std::string &text); 625 626 /** 627 * @brief Obtains the text that will be displayed as a link to the settings of the application. 628 * 629 * @return Returns the text displayed as the link to the application settings. 630 */ 631 std::string GetSettingsText() const; 632 633 /** 634 * @brief Deprecated. Obtains the time when a notification is created. 635 * 636 * @return Returns the time in milliseconds. 637 */ 638 int64_t GetCreateTime() const; 639 640 /** 641 * @brief Checks whether the notification creation time is displayed as a stopwatch. 642 * 643 * @return Returns true if the time is displayed as a stopwatch; returns false otherwise. 644 */ 645 bool IsShowStopwatch() const; 646 647 /** 648 * @brief Sets whether to show the notification creation time as a stopwatch. 649 * This method is valid only when the notification creation time has been set by calling setDeliveryTime(int64_t). 650 * When the notification creation time is set to be shown as a stopwatch, the interval between the current time 651 * and the creation time set by setDeliveryTime(int64_t) is dynamically displayed for this notification 652 * in Minutes: Seconds format. If the interval is longer than 60 minutes, it will be displayed 653 * in Hours: Minutes: Seconds format. If this method and setShowDeliveryTime(boolean) are both set to true, only 654 * this method takes effect, that is, the notification creation time will be shown as a stopwatch. 655 * 656 * @param isShow Specifies whether to show the notification creation time as a stopwatch. 657 */ 658 void SetShowStopwatch(bool isShow); 659 660 /** 661 * @brief Sets the slot type of a notification to bind the created NotificationSlot object. 662 * You can use NotificationSlot to create a slot object, 663 * then set the notification vibration and lock screen display, and use the current method to bind the slot. 664 * The value must be the type of an existing NotificationSlot object. 665 * 666 * @param slotType Indicates the unique type of the NotificationSlot object. 667 */ 668 void SetSlotType(NotificationConstant::SlotType slotType); 669 670 /** 671 * @brief Obtains the slot type of a notification set by calling the setSlotType(string) method. 672 * 673 * @return Returns the notification slot type. 674 */ 675 NotificationConstant::SlotType GetSlotType() const; 676 677 /** 678 * @brief Sets a key used for sorting notifications from the same application bundle. 679 * 680 * @param key Indicates the key to set. 681 */ 682 void SetSortingKey(const std::string &key); 683 684 /** 685 * @brief Obtains the key used for sorting notifications from the same application bundle. 686 * 687 * @return Returns the key for sorting notifications. 688 */ 689 std::string GetSortingKey() const; 690 691 /** 692 * @brief Sets the scrolling text to be displayed in the status bar when this notification is received. 693 * 694 * @param text Indicates the scrolling text to be displayed. 695 */ 696 void SetStatusBarText(const std::string &text); 697 698 /** 699 * @brief Obtains the scrolling text that will be displayed in the status bar when this notification is received. 700 * 701 * @return Returns the scrolling notification text. 702 */ 703 std::string GetStatusBarText() const; 704 705 /** 706 * @brief Checks whether the current notification will be automatically dismissed after being tapped. 707 * 708 * @return Returns true if the notification will be automatically dismissed; returns false otherwise. 709 */ 710 bool IsTapDismissed() const; 711 712 /** 713 * @brief Sets whether to automatically dismiss a notification after being tapped. 714 * If you set tapDismissed to true, 715 * you must call the setWantAgent(WantAgent) method to make the settings take effect. 716 * 717 * @param isDismissed Specifies whether a notification will be automatically dismissed after being tapped. 718 */ 719 void SetTapDismissed(bool isDismissed); 720 721 /** 722 * @brief Sets the notification display effect, including whether to display this notification on the lock screen, 723 * and how it will be presented if displayed. 724 * For details, see NotificationSlot::setLockscreenVisibleness(int). 725 * If the lock screen display effect is set for a NotificationRequest object 726 * and its associated NotificationSlot object, the display effect set in the NotificationRequest object prevails. 727 * 728 * @param type Indicates the notification display effect on the lock screen. 729 */ 730 void SetVisibleness(NotificationConstant::VisiblenessType type); 731 732 /** 733 * @brief Obtains the display effect of this notification on the lock screen. 734 * 735 * @return Returns the display effect of this notification on the lock screen. 736 */ 737 NotificationConstant::VisiblenessType GetVisibleness() const; 738 739 /** 740 * @brief Sets the badge icon style for this notification. 741 * This method does not take effect if the home screen does not support badge icons. 742 * 743 * @param style Indicates the type of the badge icon to be displayed for this notification. 744 * The value must be BadgeStyle::NONE, BadgeStyle::LITTLE, or BadgeStyle::BIG. 745 */ 746 void SetBadgeIconStyle(NotificationRequest::BadgeStyle style); 747 748 /** 749 * @brief Obtains the badge icon style of this notification. 750 * 751 * @return Returns the badge icon style of this notification. 752 */ 753 NotificationRequest::BadgeStyle GetBadgeIconStyle() const; 754 755 /** 756 * @brief Sets the shortcut ID for this notification. 757 * After a shortcut ID is set for a notification, the notification will be associated with the corresponding 758 * home-screen shortcut, and the shortcut will be hidden when the Home application displays the badge or content 759 * of the notification. 760 * 761 * @param shortcutId Indicates the shortcut ID to set. 762 */ 763 void SetShortcutId(const std::string &shortcutId); 764 765 /** 766 * @brief Obtains the shortcut ID associated with this notification. 767 * 768 * @return Returns the shortcut ID of this notification. 769 */ 770 std::string GetShortcutId() const; 771 772 /** 773 * @brief Sets whether this notification is displayed as a floating icon on top of the screen. 774 * 775 * @param floatingIcon Specifies whether a notification is displayed as a floating icon on top of the screen. 776 */ 777 void SetFloatingIcon(bool floatingIcon); 778 779 /** 780 * @brief Checks whether this notification is displayed as a floating icon on top of the screen. 781 * 782 * @return Returns true if this notification is displayed as a floating icon; returns false otherwise. 783 */ 784 bool IsFloatingIcon() const; 785 786 /** 787 * @brief Sets how the progress bar will be displayed for this notification. 788 * A progress bar is usually used in notification scenarios such as download. 789 * 790 * @param progress Indicates the current value displayed for the notification progress bar. 791 * @param progressMax Indicates the maximum value displayed for the notification progress bar. 792 * @param indeterminate Specifies whether the progress bar is indeterminate. The value true indicates that 793 * the progress bar is indeterminate, and users cannot see its current and maximum values. 794 */ 795 void SetProgressBar(int32_t progress, int32_t progressMax, bool indeterminate); 796 797 /** 798 * @brief Obtains the maximum value displayed for the progress bar of this notification. 799 * 800 * @return Returns the maximum value of the notification progress bar. 801 */ 802 int32_t GetProgressMax() const; 803 804 /** 805 * @brief Obtains the current value displayed for the progress bar of this notification. 806 * 807 * @return Returns the current value of the notification progress bar. 808 */ 809 int32_t GetProgressValue() const; 810 811 /** 812 * @brief Checks whether the progress bar of this notification is indeterminate. 813 * 814 * @return Returns true if the notification progress bar is indeterminate; returns false otherwise. 815 */ 816 bool IsProgressIndeterminate() const; 817 818 /** 819 * @brief Sets the most recent NotificationUserInput records that have been sent through this notification. 820 * The most recent input must be stored in index 0, 821 * the second most recent input must be stored in index 1, and so on. 822 * The system displays a maximum of five inputs. 823 * 824 * @param text Indicates the list of inputs to set. 825 */ 826 void SetNotificationUserInputHistory(const std::vector<std::string> &text); 827 828 /** 829 * @brief Obtains the most recent NotificationUserInput records. 830 * 831 * @return Returns the most recent NotificationUserInput records. 832 */ 833 std::vector<std::string> GetNotificationUserInputHistory() const; 834 835 /** 836 * @brief Obtains the unique hash code of a notification in the current application. 837 * To obtain a valid hash code, you must have subscribed to and received the notification. 838 * A valid notification hash code is a string composed of multiple attributes separated by an underscore (_), 839 * including the notification ID, creator bundle name, creator UID, and owner bundle name. 840 * 841 * @return Returns the hash code of the notification. 842 */ 843 std::string GetNotificationHashCode() const; 844 845 /** 846 * @brief Sets the bundle name of the notification owner. 847 * The notification owner refers to the application that subscribes to the notification. 848 * 849 * @param ownerName Indicates the bundle name of the notification owner. 850 */ 851 void SetOwnerBundleName(const std::string &ownerName); 852 853 /** 854 * @brief Obtains the bundle name of the notification owner. 855 * The notification owner refers to the application that subscribes to the notification. 856 * 857 * @return Returns the bundle name of the notification owner. 858 */ 859 std::string GetOwnerBundleName() const; 860 861 /** 862 * @brief Sets the bundle name of the notification creator. 863 * The notification creator refers to the application that publishes the notification. 864 * 865 * @param creatorName Indicates the bundle name of the notification creator. 866 */ 867 void SetCreatorBundleName(const std::string &creatorName); 868 869 /** 870 * @brief Obtains the bundle name of the notification creator. 871 * The notification creator refers to the application that publishes the notification. 872 * 873 * @return Returns the bundle name of the notification creator. 874 */ 875 std::string GetCreatorBundleName() const; 876 877 /** 878 * @brief Sets the PID of the notification creator. 879 * 880 * @param pid Indicates the PID of the notification creator. 881 */ 882 void SetCreatorPid(pid_t pid); 883 884 /** 885 * @brief Obtains the PID of the notification creator. 886 * 887 * @return Returns the PID of the notification creator. 888 */ 889 pid_t GetCreatorPid() const; 890 891 /** 892 * @brief Sets the UID of the notification creator. 893 * 894 * @param uid Indicates the UID of the notification creator. 895 */ 896 void SetCreatorUid(int32_t uid); 897 898 /** 899 * @brief Obtains the UID of the notification creator. 900 * 901 * @return Returns the UID of the notification creator. 902 */ 903 int32_t GetCreatorUid() const; 904 905 /** 906 * @brief Sets the UID of the notification owner. 907 * 908 * @param uid the UID of the notification owner. 909 */ 910 void SetOwnerUid(int32_t uid); 911 912 /** 913 * @brief Obtains the UID of the notification owner. 914 * 915 * @return the UID of the notification owner. 916 */ 917 int32_t GetOwnerUid() const; 918 919 /** 920 * @brief Sets the label of this notification. 921 * 922 * @param label Indicates the label of this notification. 923 */ 924 void SetLabel(const std::string &label); 925 926 /** 927 * @brief Obtains the label of this notification. 928 * The label is set via NotificationHelper::publishNotification(string, NotificationRequest). 929 * This method returns null if no specific label is set for this notification. 930 * 931 * @return Returns the label of this notification. 932 */ 933 std::string GetLabel() const; 934 935 /** 936 * @brief Sets whether this notification is distributed. 937 * 938 * @param distribute Specifies whether a notification is displayed as a floating icon on top of the screen. 939 */ 940 void SetDistributed(bool distribute); 941 942 /** 943 * @brief Sets devices that support display. 944 * 945 * @param devices Indicates the devices that support display. 946 */ 947 void SetDevicesSupportDisplay(const std::vector<std::string> &devices); 948 949 /** 950 * @brief Sets devices that support operate. 951 * 952 * @param devices Indicates the devices that support operate. 953 */ 954 void SetDevicesSupportOperate(const std::vector<std::string> &devices); 955 956 /** 957 * @brief Obtains the distributed Options. 958 * 959 * @return Returns the distributed Options. 960 */ 961 NotificationDistributedOptions GetNotificationDistributedOptions() const; 962 963 /** 964 * @brief Sets the UserId of the notification creator. 965 * 966 * @param userId Indicates the UserId of the notification creator. 967 */ 968 void SetCreatorUserId(int32_t userId); 969 970 /** 971 * @brief Obtains the UserId of the notification creator. 972 * 973 * @return Returns the UserId of the notification creator. 974 */ 975 int32_t GetCreatorUserId() const; 976 977 /** 978 * @brief Sets the UserId of the notification owner. 979 * 980 * @param userId the UserId of the notification owner. 981 */ 982 void SetOwnerUserId(int32_t userId); 983 984 /** 985 * @brief Obtains the UserId of the notification owner. 986 * 987 * @return the UserId of the notification owner. 988 */ 989 int32_t GetOwnerUserId() const; 990 991 /** 992 * @brief Returns a string representation of the object. 993 * 994 * @return Returns a string representation of the object. 995 */ 996 std::string Dump(); 997 998 /** 999 * @brief Converts a NotificationRequest object into a Json. 1000 * 1001 * @param jsonObject Indicates the Json object. 1002 * @return Returns true if succeed; returns false otherwise. 1003 */ 1004 bool ToJson(nlohmann::json &jsonObject) const override; 1005 1006 /** 1007 * @brief Creates a NotificationRequest object from a Json. 1008 * 1009 * @param jsonObject Indicates the Json object. 1010 * @return Returns the NotificationRequest. 1011 */ 1012 static NotificationRequest *FromJson(const nlohmann::json &jsonObject); 1013 1014 /** 1015 * @brief Marshal a NotificationRequest object into a Parcel. 1016 * 1017 * @param parcel Indicates the object into the parcel. 1018 * @return Returns true if succeed; returns false otherwise. 1019 */ 1020 virtual bool Marshalling(Parcel &parcel) const override; 1021 1022 /** 1023 * @brief Unmarshal object from a Parcel. 1024 * 1025 * @param parcel Indicates the parcel object. 1026 * @return Returns the NotificationRequest. 1027 */ 1028 static NotificationRequest *Unmarshalling(Parcel &parcel); 1029 1030 /** 1031 * @brief Sets the template of this notification. 1032 * 1033 * @param template Indicates the template of this notification. 1034 */ 1035 void SetTemplate(const std::shared_ptr<NotificationTemplate> &templ); 1036 1037 /** 1038 * @brief Obtains the Template of the notification. 1039 * 1040 * @return Returns the Template of the notification. 1041 */ 1042 std::shared_ptr<NotificationTemplate> GetTemplate() const; 1043 1044 /** 1045 * @brief Sets the flags of this notification. 1046 * 1047 * @param flags Indicates the flags of this notification. 1048 */ 1049 void SetFlags(const std::shared_ptr<NotificationFlags> &flags); 1050 1051 /** 1052 * @brief Obtains the flags of the notification. 1053 * 1054 * @return Returns the flags of the notification. 1055 */ 1056 std::shared_ptr<NotificationFlags> GetFlags() const; 1057 1058 /** 1059 * @brief Sets the userId of the notification receiver. 1060 * 1061 * @param userId Indicates the userId of the notification receiver. 1062 */ 1063 void SetReceiverUserId(int32_t userId); 1064 1065 /** 1066 * @brief Obtains the userId of the notification receiver. 1067 * 1068 * @return Returns the userId of the notification receiver. 1069 */ 1070 int32_t GetReceiverUserId() const; 1071 1072 bool IsRemoveAllowed() const; 1073 1074 void SetRemoveAllowed(bool isRemoveAllowed); 1075 1076 private: 1077 /** 1078 * Indicates the color mask, used for calculation with the ARGB value set by setColor(int32_t). 1079 */ 1080 static const uint32_t COLOR_MASK; 1081 1082 /** 1083 * the maximum number of user input history is 5. 1084 */ 1085 static const std::size_t MAX_USER_INPUT_HISTORY; 1086 1087 /** 1088 * the maximum number of action buttons is 3. 1089 */ 1090 static const std::size_t MAX_ACTION_BUTTONS; 1091 1092 /** 1093 * the maximum number of message users is 1000. 1094 */ 1095 static const std::size_t MAX_MESSAGE_USERS; 1096 1097 private: 1098 /** 1099 * @brief Read a NotificationRequest object from a Parcel. 1100 * 1101 * @param parcel Indicates the parcel object. 1102 * @return Returns true if succeed; returns false otherwise. 1103 */ 1104 bool ReadFromParcel(Parcel &parcel); 1105 1106 /** 1107 * @brief Obtains the current system time in milliseconds. 1108 * 1109 * @return Returns the current system time in milliseconds. 1110 */ 1111 int64_t GetNowSysTime(); 1112 1113 void CopyBase(const NotificationRequest &other); 1114 void CopyOther(const NotificationRequest &other); 1115 1116 bool ConvertObjectsToJson(nlohmann::json &jsonObject) const; 1117 1118 static void ConvertJsonToNum(NotificationRequest *target, const nlohmann::json &jsonObject); 1119 static void ConvertJsonToString(NotificationRequest *target, const nlohmann::json &jsonObject); 1120 static void ConvertJsonToEnum(NotificationRequest *target, const nlohmann::json &jsonObject); 1121 static void ConvertJsonToBool(NotificationRequest *target, const nlohmann::json &jsonObject); 1122 static void ConvertJsonToPixelMap(NotificationRequest *target, const nlohmann::json &jsonObject); 1123 static bool ConvertJsonToNotificationContent(NotificationRequest *target, const nlohmann::json &jsonObject); 1124 static bool ConvertJsonToNotificationActionButton(NotificationRequest *target, const nlohmann::json &jsonObject); 1125 static bool ConvertJsonToNotificationDistributedOptions( 1126 NotificationRequest *target, const nlohmann::json &jsonObject); 1127 static bool ConvertJsonToNotificationFlags(NotificationRequest *target, const nlohmann::json &jsonObject); 1128 1129 private: 1130 int32_t notificationId_ {0}; 1131 uint32_t color_ {NotificationRequest::COLOR_DEFAULT}; 1132 uint32_t badgeNumber_ {0}; 1133 int32_t progressValue_ {0}; 1134 int32_t progressMax_ {0}; 1135 int64_t createTime_ {0}; 1136 int64_t deliveryTime_ {0}; 1137 int64_t autoDeletedTime_ {0}; 1138 1139 pid_t creatorPid_ {0}; 1140 int32_t creatorUid_ {0}; 1141 int32_t ownerUid_ {0}; 1142 int32_t creatorUserId_ {SUBSCRIBE_USER_INIT}; 1143 int32_t ownerUserId_ {SUBSCRIBE_USER_INIT}; 1144 int32_t receiverUserId_ {SUBSCRIBE_USER_INIT}; 1145 1146 std::string settingsText_ {}; 1147 std::string creatorBundleName_ {}; 1148 std::string ownerBundleName_ {}; 1149 std::string groupName_ {}; 1150 std::string statusBarText_ {}; 1151 std::string label_ {}; 1152 std::string shortcutId_ {}; 1153 std::string sortingKey_ {}; 1154 std::string classification_ {}; 1155 1156 NotificationConstant::SlotType slotType_ {NotificationConstant::SlotType::OTHER}; 1157 NotificationRequest::GroupAlertType groupAlertType_ {NotificationRequest::GroupAlertType::ALL}; 1158 NotificationConstant::VisiblenessType visiblenessType_ {NotificationConstant::VisiblenessType::NO_OVERRIDE}; 1159 NotificationRequest::BadgeStyle badgeStyle_ {NotificationRequest::BadgeStyle::NONE}; 1160 NotificationContent::Type notificationContentType_ {NotificationContent::Type::NONE}; 1161 1162 bool showDeliveryTime_ {false}; 1163 bool tapDismissed_ {true}; 1164 bool colorEnabled_ {false}; 1165 bool alertOneTime_ {false}; 1166 bool showStopwatch_ {false}; 1167 bool isCountdown_ {false}; 1168 bool inProgress_ {false}; 1169 bool groupOverview_ {false}; 1170 bool progressIndeterminate_ {false}; 1171 bool unremovable_ {false}; 1172 bool floatingIcon_ {false}; 1173 bool onlyLocal_ {false}; 1174 bool permitted_ {true}; 1175 bool isAgent_ {false}; 1176 bool isRemoveAllowed_ {true}; 1177 1178 std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent_ {}; 1179 std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> removalWantAgent_ {}; 1180 std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> maxScreenWantAgent_ {}; 1181 std::shared_ptr<AAFwk::WantParams> additionalParams_ {}; 1182 std::shared_ptr<Media::PixelMap> littleIcon_ {}; 1183 std::shared_ptr<Media::PixelMap> bigIcon_ {}; 1184 std::shared_ptr<NotificationContent> notificationContent_ {}; 1185 1186 std::vector<std::shared_ptr<NotificationActionButton>> actionButtons_ {}; 1187 std::vector<std::shared_ptr<MessageUser>> messageUsers_ {}; 1188 std::vector<std::string> userInputHistory_ {}; 1189 1190 NotificationDistributedOptions distributedOptions_; 1191 1192 std::shared_ptr<NotificationTemplate> notificationTemplate_ {}; 1193 std::shared_ptr<NotificationFlags> notificationFlags_ {}; 1194 }; 1195 } // namespace Notification 1196 } // namespace OHOS 1197 1198 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_REQUEST_H 1199