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