• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_NOTIFICATION_H
17 #define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_NOTIFICATION_H
18 
19 #include <list>
20 
21 #include "ans_dialog_host_client.h"
22 #include "ans_manager_death_recipient.h"
23 #include "ans_manager_interface.h"
24 #include "notification_subscriber.h"
25 #include "notification_local_live_view_subscriber.h"
26 #include "want_params.h"
27 #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED
28 #include "swing_callback_stub.h"
29 #endif
30 
31 namespace OHOS {
32 namespace Notification {
33 class AnsNotification {
34 public:
35     /**
36      * @brief Creates a notification slot.
37      * @note You can call the NotificationRequest::SetSlotType(NotificationConstant::SlotType) method to bind the slot
38      * for publishing. A NotificationSlot instance cannot be used directly after being initialized. Instead, you have to
39      * call this method to create a notification slot and bind the slot ID to a NotificationRequest object so that the
40      * notification published can have all the characteristics set in the NotificationSlot. After a notification slot is
41      * created by using this method, only the name and description of the notification slot can be changed. Changes to
42      * the other attributes, such as the vibration status and notification tone, will no longer take effect.
43      *
44      * @param slot Indicates the notification slot to be created, which is set by NotificationSlot.
45      *             This parameter must be specified.
46      * @return Returns add notification slot result.
47      */
48     ErrCode AddNotificationSlot(const NotificationSlot &slot);
49 
50     /**
51      * @brief Adds a notification slot by type.
52      *
53      * @param slotType Indicates the notification slot type to be added.
54      * @return Returns add notification slot result.
55      */
56     ErrCode AddSlotByType(const NotificationConstant::SlotType &slotType);
57 
58     /**
59      * @brief Creates multiple notification slots.
60      *
61      * @param slots Indicates the notification slots to create.
62      * @return Returns add notification slots result.
63      */
64     ErrCode AddNotificationSlots(const std::vector<NotificationSlot> &slots);
65 
66     /**
67      * @brief Deletes a created notification slot based on the slot ID.
68      *
69      * @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot
70      *                This parameter must be specified.
71      * @return Returns remove notification slot result.
72      */
73     ErrCode RemoveNotificationSlot(const NotificationConstant::SlotType &slotType);
74 
75     /**
76      * @brief Deletes all notification slots.
77      *
78      * @return Returns remove all slots result.
79      */
80     ErrCode RemoveAllSlots();
81 
82     /**
83      * @brief Queries a created notification slot.
84      *
85      * @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot(NotificationSlot). This
86      *        parameter must be specified.
87      * @param slot Indicates the created NotificationSlot.
88      * @return Returns the get notification slot result.
89      */
90     ErrCode GetNotificationSlot(const NotificationConstant::SlotType &slotType, sptr<NotificationSlot> &slot);
91 
92     /**
93      * @brief Obtains all notification slots of this application.
94      *
95      * @param slots Indicates the created NotificationSlot.
96      * @return Returns all notification slots of this application.
97      */
98     ErrCode GetNotificationSlots(std::vector<sptr<NotificationSlot>> &slots);
99 
100     /**
101      * @brief Obtains number of slot.
102      *
103      * @param bundleOption Indicates the bundle name and uid of the application.
104      * @param num Indicates number of slot.
105      * @return Returns get slot number by bundle result.
106      */
107     ErrCode GetNotificationSlotNumAsBundle(const NotificationBundleOption &bundleOption, uint64_t &num);
108 
109     /**
110      * @brief Obtains slotFlags of bundle.
111      *
112      * @param bundleOption Indicates the bundle name and uid of the application.
113      * @param slotFlags Indicates slotFlags of bundle.
114      * @return Returns get slotflags by bundle result.
115      */
116     ErrCode GetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t &slotFlags);
117 
118     /**
119      * @brief Set slotFlags of bundle.
120      *
121      * @param bundleOption Indicates the bundle name and uid of the application.
122      * @param slotFlags Indicates slotFlags of bundle.
123      * @return Returns set slotflags by bundle result.
124      */
125     ErrCode SetNotificationSlotFlagsAsBundle(const NotificationBundleOption &bundleOption, uint32_t slotFlags);
126 
127     /**
128      * @brief Publishes a notification.
129      * @note If a notification with the same ID has been published by the current application and has not been deleted,
130      * this method will update the notification.
131      *
132      * @param request Indicates the NotificationRequest object for setting the notification content.
133      *                This parameter must be specified.
134      * @return Returns publish notification result.
135      */
136     ErrCode PublishNotification(const NotificationRequest &request);
137 
138     /**
139      * @brief Publishes a notification with a specified label.
140      * @note If a notification with the same ID has been published by the current application and has not been deleted,
141      *       this method will update the notification.
142      *
143      * @param label Indicates the label of the notification to publish.
144      * @param request Indicates the NotificationRequest object for setting the notification content.
145      *                This parameter must be specified.
146      * @return Returns publish notification result.
147      */
148     ErrCode PublishNotification(const std::string &label, const NotificationRequest &request);
149 
150     /**
151      * @brief Publishes a notification.
152      * @note If a notification with the same ID has been published by the current application and has not been deleted,
153      * this method will update the notification.
154      *
155      * @param request Indicates the NotificationRequest object for setting the notification content.
156      *                This parameter must be specified.
157      * @return Returns publish notification result.
158      */
159     ErrCode PublishNotificationForIndirectProxy(const NotificationRequest &request);
160 
161     /**
162      * @brief Cancels a published notification.
163      *
164      * @param notificationId Indicates the unique notification ID in the application.
165      *                       The value must be the ID of a published notification.
166      *                       Otherwise, this method does not take effect.
167      * @return Returns cancel notification result.
168      */
169     ErrCode CancelNotification(int32_t notificationId);
170 
171     /**
172      * @brief Cancels a published notification matching the specified label and notificationId.
173      *
174      * @param label Indicates the label of the notification to cancel.
175      * @param notificationId Indicates the ID of the notification to cancel.
176      * @return Returns cancel notification result.
177      */
178     ErrCode CancelNotification(const std::string &label, int32_t notificationId);
179 
180     /**
181      * @brief Cancels all the published notifications.
182      * @note To cancel a specified notification, see CancelNotification(int32_t).
183      *
184      * @return Returns cancel all notifications result.
185      */
186     ErrCode CancelAllNotifications();
187 
188     /**
189      * @brief Cancels a published agent notification.
190      *
191      * @param notificationId Indicates the unique notification ID in the application.
192      *                       The value must be the ID of a published notification.
193      *                       Otherwise, this method does not take effect.
194      * @param representativeBundle Indicates the name of application bundle your application is representing.
195      * @param userId Indicates the specific user.
196      * @return Returns cancel notification result.
197      */
198     ErrCode CancelAsBundle(int32_t notificationId, const std::string &representativeBundle, int32_t userId);
199 
200     /**
201      * @brief Cancels a published agent notification.
202      *
203      * @param bundleOption Indicates the bundle of application your application is representing.
204      * @param notificationId Indicates the unique notification ID in the application.
205      *                       The value must be the ID of a published notification.
206      *                       Otherwise, this method does not take effect.
207      * @return Returns cancel notification result.
208      */
209     ErrCode CancelAsBundle(const NotificationBundleOption &bundleOption, int32_t notificationId);
210 
211     /**
212      * @brief Obtains the number of active notifications of the current application in the system.
213      *
214      * @param num Indicates the number of active notifications of the current application.
215      * @return Returns get active notification nums result.
216      */
217     ErrCode GetActiveNotificationNums(uint64_t &num);
218 
219     /**
220      * @brief Obtains active notifications of the current application in the system.
221      *
222      * @param  request Indicates active NotificationRequest objects of the current application.
223      * @return Returns get active notifications result.
224      */
225     ErrCode GetActiveNotifications(std::vector<sptr<NotificationRequest>> &request);
226 
227     /**
228      * @brief Allows another application to act as an agent to publish notifications in the name of your application
229      * bundle. You can revoke this authorization by passing null to this method.
230      *
231      * @param agent Indicates the name of the application bundle that can publish notifications for your application.
232      * @return Returns set notification agent result.
233      */
234     ErrCode SetNotificationAgent(const std::string &agent);
235 
236     /**
237      * @brief Obtains the name of the application bundle that can publish notifications in the name of your application.
238      *
239      * @param agent Indicates the name of the application bundle that can publish notifications for your application if
240      * any; returns null otherwise.
241      * @return Returns get notification agent result.
242      */
243     ErrCode GetNotificationAgent(std::string &agent);
244 
245     /**
246      * @brief Checks whether your application has permission to publish notifications by calling
247      * PublishNotificationAsBundle(string, NotificationRequest) in the name of another application indicated by the
248      * given representativeBundle.
249      *
250      * @param representativeBundle Indicates the name of application bundle your application is representing.
251      * @param canPublish Indicates whether your application has permission to publish notifications.
252      * @return Returns can publish notification as bundle result.
253      */
254     ErrCode CanPublishNotificationAsBundle(const std::string &representativeBundle, bool &canPublish);
255 
256     /**
257      * @brief Publishes a notification in the name of a specified application bundle.
258      * @note If the notification to be published has the same ID as a published notification that has not been canceled,
259      * the existing notification will be replaced by the new one.
260      *
261      * @param request Indicates the NotificationRequest object for setting the notification content.
262      *                This parameter must be specified.
263      * @param representativeBundle Indicates the name of the application bundle that allows your application to publish
264      *                             notifications for it by calling setNotificationAgent.
265      * @return Returns publish notification as bundle result.
266      */
267     ErrCode PublishNotificationAsBundle(const std::string &representativeBundle, const NotificationRequest &request);
268 
269     /**
270      * @brief Sets the number of active notifications of the current application as the number to be displayed on the
271      * notification badge.
272      *
273      * @return Returns set notification badge num result.
274      */
275     ErrCode SetNotificationBadgeNum();
276 
277     /**
278      * @brief Sets the number to be displayed on the notification badge of the application.
279      *
280      * @param num Indicates the number to display. A negative number indicates that the badge setting remains unchanged.
281      *            The value 0 indicates that no badge is displayed on the application icon.
282      *            If the value is greater than 99, 99+ will be displayed.
283      * @return Returns set notification badge num result.
284      */
285     ErrCode SetNotificationBadgeNum(int32_t num);
286 
287     /**
288      * @brief Checks whether this application has permission to publish notifications. The caller must have
289      * system permissions to call this method.
290      *
291      * @param  allowed True if this application has the permission; returns false otherwise
292      * @return Returns is allowed notify result.
293      */
294     ErrCode IsAllowedNotify(bool &allowed);
295 
296     /**
297      * @brief Checks whether this application has permission to publish notifications.
298      *
299      * @param  allowed True if this application has the permission; returns false otherwise
300      * @return Returns is allowed notify result.
301      */
302     ErrCode IsAllowedNotifySelf(bool &allowed);
303 
304     /**
305      * @brief Checks whether this application can pop enable notification dialog.
306      *
307      * @param  canPop True if can pop enable notification dialog
308      * @return Returns is canPop result.
309      */
310     ErrCode CanPopEnableNotificationDialog(sptr<AnsDialogHostClient> &hostClient,
311         bool &canPop, std::string &bundleName);
312 
313     /**
314      * @brief remove enable notification dialog.
315      *
316      * @return Returns remove dialog result.
317      */
318     ErrCode RemoveEnableNotificationDialog();
319 
320     /**
321      * @brief Allows the current application to publish notifications on a specified device.
322      *
323      * @param deviceId Indicates the ID of the device running the application. At present, this parameter can
324      *                 only be null or an empty string, indicating the current device.
325      * @return Returns set notifications enabled for default bundle result.
326      */
327     ErrCode RequestEnableNotification(std::string &deviceId,
328         sptr<AnsDialogHostClient> &hostClient,
329         sptr<IRemoteObject> &callerToken);
330 
331     /**
332      * @brief Checks whether this application has permission to modify the Do Not Disturb (DND) notification policy.
333      *
334      * @param hasPermission True if this application is suspended; returns false otherwise.
335      * @return Returns has notification policy access permission.
336      */
337     ErrCode HasNotificationPolicyAccessPermission(bool &hasPermission);
338 
339     /**
340      * @brief Obtains the importance level of this application.
341      *
342      * @param  importance the importance level of this application, which can be LEVEL_NONE,
343                LEVEL_MIN, LEVEL_LOW, LEVEL_DEFAULT, LEVEL_HIGH, or LEVEL_UNDEFINED.
344      * @return Returns get bundle importance result
345      */
346     ErrCode GetBundleImportance(NotificationSlot::NotificationLevel &importance);
347 
348     /**
349      * @brief Subscribes to notifications from all applications. This method can be called only by applications
350      * with required system permissions.
351      * @note  To subscribe to a notification, inherit the {NotificationSubscriber} class, override its
352      *        callback methods and create a subscriber. The subscriber will be used as a parameter of this method.
353      *        After the notification is published, subscribers that meet the filter criteria can receive the
354      * notification. To subscribe to notifications published only by specified sources, for example, notifications from
355      *        certain applications, call the {SubscribeNotification(NotificationSubscriber, NotificationSubscribeInfo)}
356      * method.
357      *
358      * @param subscriber Indicates the {NotificationSubscriber} to receive notifications.
359      *                   This parameter must be specified.
360      * @return Returns subscribe notification result.
361      */
362     ErrCode SubscribeNotification(const NotificationSubscriber &subscriber);
363 
364     /**
365      * @brief Subscribes to notifications from the appliaction self.
366      * @note  To subscribe to a notification, inherit the {NotificationSubscriber} class, override its
367      *        callback methods and create a subscriber. The subscriber will be used as a parameter of this method.
368      *        After the notification is published, subscribers that meet the filter criteria can receive the
369      * notification.
370      *
371      * @param subscriber Indicates the {NotificationSubscriber} to receive notifications.
372      *                   This parameter must be specified.
373      * @return Returns subscribe notification result.
374      */
375     ErrCode SubscribeNotificationSelf(const NotificationSubscriber &subscriber);
376 
377     /**
378      * @brief Subscribes liveView notification. This method can be called only by applications
379      * with required system permissions.
380      * @note  To subscribe to a notification, inherit the {NotificationLocalLiveViewSubscriber} class, override its
381      *        callback methods and create a subscriber. The subscriber will be used as a parameter of this method.
382      *
383      * @param subscriber Indicates the {NotificationLocalLiveViewSubscriber} to receive notifications.
384      *                   This parameter must be specified.
385      * @return Returns subscribe notification result.
386      */
387     ErrCode SubscribeLocalLiveViewNotification(const NotificationLocalLiveViewSubscriber &subscriber,
388         const bool isNative = true);
389 
390     /**
391      * @brief Subscribes to all notifications based on the filtering criteria. This method can be called only
392      * by applications with required system permissions.
393      * @note  After {subscribeInfo} is specified, a subscriber receives only the notifications that
394      *        meet the filter criteria specified by {subscribeInfo}.
395      *        To subscribe to a notification, inherit the {NotificationSubscriber} class, override its
396      *        callback methods and create a subscriber. The subscriber will be used as a parameter of this method.
397      *        After the notification is published, subscribers that meet the filter criteria can receive the
398      * notification. To subscribe to and receive all notifications, call the
399      * {SubscribeNotification(NotificationSubscriber)} method.
400      *
401      * @param subscriber Indicates the subscribers to receive notifications. This parameter must be specified.
402      *                   For details, see {NotificationSubscriber}.
403      * @param subscribeInfo Indicates the filters for specified notification sources, including application name,
404      *                      user ID, or device name. This parameter is optional.
405      * @return Returns subscribe notification result.
406      */
407     ErrCode SubscribeNotification(
408         const NotificationSubscriber &subscriber, const NotificationSubscribeInfo &subscribeInfo);
409 
410     /**
411      * @brief Unsubscribes from all notifications. This method can be called only by applications with required
412      * system permissions.
413      * @note Generally, you subscribe to a notification by calling the
414      *       {SubscribeNotification(NotificationSubscriber)} method. If you do not want your application
415      *       to receive a notification any longer, unsubscribe from that notification using this method.
416      *       You can unsubscribe from only those notifications that your application has subscribed to.
417      *        To unsubscribe from notifications published only by specified sources, for example,
418      *       notifications from certain applications, call the
419      *       {UnSubscribeNotification(NotificationSubscriber, NotificationSubscribeInfo)} method.
420      *
421      * @param subscriber Indicates the {NotificationSubscriber} to receive notifications.
422      *                   This parameter must be specified.
423      * @return Returns unsubscribe notification result.
424      */
425     ErrCode UnSubscribeNotification(NotificationSubscriber &subscriber);
426 
427     /**
428      * @brief Unsubscribes from all notifications based on the filtering criteria. This method can be called
429      * only by applications with required system permissions.
430      * @note A subscriber will no longer receive the notifications from specified notification sources.
431      *
432      * @param subscriber Indicates the {NotificationSubscriber} to receive notifications.
433      *                   This parameter must be specified.
434      * @param subscribeInfo Indicates the filters for , including application name,
435      *                      user ID, or device name. This parameter is optional.
436      * @return Returns unsubscribe notification result.
437      */
438     ErrCode UnSubscribeNotification(NotificationSubscriber &subscriber, NotificationSubscribeInfo subscribeInfo);
439 
440     /**
441      * @brief Trigger the local live view after the button has been clicked.
442      * @note Your application must have platform signature to use this method.
443      *
444      * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked.
445      * @param notificationId Indicates the id of the notification.
446      * @param buttonOption Indicates which button has been clicked.
447      * @return Returns trigger localLiveView result.
448      */
449     ErrCode TriggerLocalLiveView(const NotificationBundleOption &bundleOption,
450         const int32_t notificationId, const NotificationButtonOption &buttonOption);
451 
452     /**
453      * @brief Removes a specified removable notification of other applications.
454      * @note Your application must have platform signature to use this method.
455      *
456      * @param key Indicates the key of the notification to remove.
457      * @param removeReason Indicates the reason of remove notification.
458      * @return Returns remove notification result.
459      */
460     ErrCode RemoveNotification(const std::string &key, int32_t removeReason);
461 
462     /**
463      * @brief Removes a specified removable notification of other applications.
464      * @note Your application must have platform signature to use this method.
465      *
466      * @param bundleOption Indicates the bundle name and uid of the application whose notifications are to be removed.
467      * @param notificationId Indicates the id of the notification to remove.
468      * @param label Indicates the label of the notification to remove.
469      * @param removeReason Indicates the reason of remove notification.
470      * @return Returns remove notification result.
471      */
472     ErrCode RemoveNotification(const NotificationBundleOption &bundleOption, const int32_t notificationId,
473         const std::string &label, int32_t removeReason);
474 
475     /**
476      * @brief Removes a specified removable notification of other applications.
477      * @note Your application must have platform signature to use this method.
478      *
479      * @param bundleOption Indicates the bundle name and uid of the application whose notifications are to be removed.
480      * @return Returns remove notification result.
481      */
482     ErrCode RemoveAllNotifications(const NotificationBundleOption &bundleOption);
483 
484     ErrCode RemoveNotifications(const std::vector<std::string> hashcodes, int32_t removeReason);
485 
486     /**
487      * @brief Removes all removable notifications of a specified bundle.
488      * @note Your application must have platform signature to use this method.
489      *
490      * @param bundleOption Indicates the bundle name and uid of the application whose notifications are to be removed.
491      * @return Returns remove notifications result.
492      */
493     ErrCode RemoveNotificationsByBundle(const NotificationBundleOption &bundleOption);
494 
495     /**
496      * @brief Removes all removable notifications in the system.
497      * @note Your application must have platform signature to use this method.
498      *
499      * @return Returns remove notifications result.
500      */
501     ErrCode RemoveNotifications();
502 
503     /**
504      * @brief Obtains all notification slots belonging to the specified bundle.
505      *
506      * @param bundleOption Indicates the bundle name and uid of the application.
507      * @param slots Indicates a list of notification slots.
508      * @return Returns get notification slots for bundle result.
509      */
510     ErrCode GetNotificationSlotsForBundle(
511         const NotificationBundleOption &bundleOption, std::vector<sptr<NotificationSlot>> &slots);
512 
513     /**
514      * @brief Obtains notification slot belonging to the specified bundle.
515      *
516      * @param bundleOption Indicates the bundle name and uid of the application.
517      * @param slotType Indicates the type of the slot, which is created by AddNotificationSlot.
518      * @param slot Indicates a notification slot.
519      * @return Returns get notification slots for bundle result.
520      */
521     ErrCode GetNotificationSlotForBundle(
522         const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType,
523         sptr<NotificationSlot> &slot);
524 
525     /**
526      * @brief Updates all notification slots for the specified bundle.
527      *
528      * @param bundleOption Indicates the bundle name and uid of the application.
529      * @param slots Indicates a list of new notification slots.
530      * @return Returns update notification slots for bundle result.
531      */
532     ErrCode UpdateNotificationSlots(
533         const NotificationBundleOption &bundleOption, const std::vector<sptr<NotificationSlot>> &slots);
534 
535     /**
536      * @brief Obtains all active notifications in the current system. The caller must have system permissions to
537      * call this method.
538      *
539      * @param notification Indicates all active notifications of this application.
540      * @return Returns get all active notifications
541      */
542     ErrCode GetAllActiveNotifications(std::vector<sptr<Notification>> &notification);
543 
544     /**
545      * @brief Obtains the active notifications corresponding to the specified key in the system. To call this method
546      * to obtain particular active notifications, you must have received the notifications and obtained the key
547      * via {Notification::GetKey()}.
548      *
549      * @param key Indicates the key array for querying corresponding active notifications.
550      *            If this parameter is null, this method returns all active notifications in the system.
551      * @param notification Indicates the set of active notifications corresponding to the specified key.
552      * @return Returns get all active notifications result.
553      */
554     ErrCode GetAllActiveNotifications(
555         const std::vector<std::string> key, std::vector<sptr<Notification>> &notification);
556 
557     /**
558      * @brief Obtains the live view notification extra info by the extraInfoKeys. To call this method
559      * to obtain particular live view notification extra info, you must have received the
560      * @param filter
561      * @param extraInfo
562      * @return
563      */
564     ErrCode GetActiveNotificationByFilter(
565         const LiveViewFilter &filter, sptr<NotificationRequest> &request);
566 
567     /**
568      * @brief Checks whether a specified application has the permission to publish notifications. If bundle specifies
569      * the current application, no permission is required for calling this method. If bundle specifies another
570      * application, the caller must have system permissions.
571      *
572      * @param bundleOption Indicates the bundle name and uid of the application.
573      * @param allowed True if the application has permissions; returns false otherwise.
574      * @return Returns is allowed notify result.
575      */
576     ErrCode IsAllowedNotify(const NotificationBundleOption &bundleOption, bool &allowed);
577 
578     /**
579      * @brief Sets whether to allow all applications to publish notifications on a specified device. The caller must
580      * have system permissions to call this method.
581      *
582      * @param deviceId Indicates the ID of the device running the application. At present, this parameter can only
583      *                 be null or an empty string, indicating the current device.
584      * @param enabled Specifies whether to allow all applications to publish notifications. The value true
585      *                indicates that notifications are allowed, and the value false indicates that notifications are not
586      *                allowed.
587      * @return Returns set notifications enabled for all bundles result.
588      */
589     ErrCode SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled);
590 
591     /**
592      * @brief Sets whether to allow the current application to publish notifications on a specified device. The caller
593      * must have system permissions to call this method.
594      *
595      * @param deviceId Indicates the ID of the device running the application. At present, this parameter can
596      *                 only be null or an empty string, indicating the current device.
597      * @param enabled Specifies whether to allow the current application to publish notifications. The value
598      *                true indicates that notifications are allowed, and the value false indicates that
599      *                notifications are not allowed.
600      * @return Returns set notifications enabled for default bundle result.
601      */
602     ErrCode SetNotificationsEnabledForDefaultBundle(const std::string &deviceId, bool enabled);
603 
604     /**
605      * @brief Sets whether to allow a specified application to publish notifications on a specified device. The caller
606      * must have system permissions to call this method.
607      *
608      * @param bundleOption Indicates the bundle name and uid of the application.
609      * @param deviceId Indicates the ID of the device running the application. At present, this parameter can only
610      *                 be null or an empty string, indicating the current device.
611      * @param enabled Specifies whether to allow the given application to publish notifications. The value
612      *                true indicates that notifications are allowed, and the value false indicates that notifications
613      *                are not allowed.
614      * @return Returns set notifications enabled for specified bundle result.
615      */
616     ErrCode SetNotificationsEnabledForSpecifiedBundle(
617         const NotificationBundleOption &bundleOption, const std::string &deviceId, bool enabled);
618 
619     /**
620      * @brief Sets whether to allow a specified application to to show badge.
621      *
622      * @param bundleOption Indicates the bundle name and uid of the application.
623      * @param enabled Specifies whether to allow the given application to show badge.
624      * @return Returns set result.
625      */
626     ErrCode SetShowBadgeEnabledForBundle(const NotificationBundleOption &bundleOption, bool enabled);
627 
628     /**
629      * @brief Obtains the flag that whether to allow a specified application to to show badge.
630      *
631      * @param bundleOption Indicates the bundle name and uid of the application.
632      * @param enabled Specifies whether to allow the given application to show badge.
633      * @return Returns get result.
634      */
635     ErrCode GetShowBadgeEnabledForBundle(const NotificationBundleOption &bundleOption, bool &enabled);
636 
637     /**
638      * @brief Obtains the flag that whether to allow the current application to to show badge.
639      *
640      * @param enabled Specifies whether to allow the given application to show badge.
641      * @return Returns get result.
642      */
643     ErrCode GetShowBadgeEnabled(bool &enabled);
644 
645     /**
646      * @brief Cancels the notification of the specified group of this application.
647      *
648      * @param groupName the specified group name.
649      * @return Returns cancel group result.
650      */
651     ErrCode CancelGroup(const std::string &groupName);
652 
653     /**
654      * @brief Removes the notification of the specified group of the specified application.
655      *
656      * @param bundleOption Indicates the bundle name and uid of the specified application.
657      * @param groupName Indicates the specified group name.
658      * @return Returns remove group by bundle result.
659      */
660     ErrCode RemoveGroupByBundle(const NotificationBundleOption &bundleOption, const std::string &groupName);
661 
662     /**
663      * @brief Sets the do not disturb time.
664      * @note Your application must have system signature to call this method.
665      *
666      * @param doNotDisturbDate Indicates the do not disturb time to set.
667      * @return Returns set do not disturb time result.
668      */
669     ErrCode SetDoNotDisturbDate(const NotificationDoNotDisturbDate &doNotDisturbDate);
670 
671     /**
672      * @brief Obtains the do not disturb time.
673      * @note Your application must have system signature to call this method.
674      *
675      * @param doNotDisturbDate Indicates the do not disturb time to get.
676      * @return Returns set do not disturb time result.
677      */
678     ErrCode GetDoNotDisturbDate(NotificationDoNotDisturbDate &doNotDisturbDate);
679 
680     /**
681      * @brief Add the do not disturb profiles.
682      * @note Your application must have system signature to call this method.
683      *
684      * @param doNotDisturbProfiles Indicates the do not disturb profiles to add.
685      * @return Returns add do not disturb profiles result.
686      */
687     ErrCode AddDoNotDisturbProfiles(const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles);
688 
689     /**
690      * @brief Remove the do not disturb profiles.
691      * @note Your application must have system signature to call this method.
692      *
693      * @param doNotDisturbProfiles Indicates the do not disturb profiles to remove.
694      * @return Returns remove do not disturb profiles result.
695      */
696     ErrCode RemoveDoNotDisturbProfiles(const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles);
697 
698     /**
699      * @brief Obtains the flag that whether to support do not disturb mode.
700      *
701      * @param doesSupport Specifies whether to support do not disturb mode.
702      * @return Returns check result.
703      */
704     ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport);
705 
706     /**
707      * @brief Is coming call need silent in do not disturb mode.
708      *
709      * @param phoneNumber the calling format number.
710      * @return Returns silent in do not disturb mode.
711      */
712     ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType);
713 
714     /**
715      * @brief Checks if the device supports distributed notification.
716      *
717      * @param enabled True if the device supports distributed notification; false otherwise.
718      * @return Returns is distributed enabled result.
719      */
720     ErrCode IsDistributedEnabled(bool &enabled);
721 
722     /**
723      * @brief Sets whether the device supports distributed notifications.
724      *
725      * @param enable Specifies whether to enable the device to support distributed notification.
726      *               The value true indicates that the device is enabled to support distributed notifications, and
727      *               the value false indicates that the device is forbidden to support distributed notifications.
728      * @return Returns enable distributed result.
729      */
730     ErrCode EnableDistributed(const bool enabled);
731 
732     /**
733      * @brief Sets whether an application supports distributed notifications.
734      *
735      * @param bundleOption Indicates the bundle name and uid of an application.
736      * @param enabled Specifies whether to enable an application to support distributed notification.
737      *                The value true indicates that the application is enabled to support distributed notifications,
738      *                and the value false indicates that the application is forbidden to support distributed
739      *                notifications.
740      * @return Returns enable distributed by bundle result.
741      */
742     ErrCode EnableDistributedByBundle(const NotificationBundleOption &bundleOption, const bool enabled);
743 
744     /**
745      * @brief Sets whether this application supports distributed notifications.
746      *
747      * @param enabled Specifies whether to enable this application to support distributed notification.
748      *                The value true indicates that this application is enabled to support distributed notifications,
749      *                and the value false indicates that this application is forbidden to support distributed
750      *                notifications.
751      * @return Returns enable distributed self result.
752      */
753     ErrCode EnableDistributedSelf(const bool enabled);
754 
755     /**
756      * @brief Checks whether an application supports distributed notifications.
757      *
758      * @param bundleOption Indicates the bundle name and uid of an application.
759      * @param enabled True if the application supports distributed notification; false otherwise.
760      * @return Returns is distributed enabled by bundle result.
761      */
762     ErrCode IsDistributedEnableByBundle(const NotificationBundleOption &bundleOption, bool &enabled);
763 
764     /**
765      * @brief Obtains the device remind type.
766      * @note Your application must have system signature to call this method.
767      *
768      * @param remindType Indicates the device remind type to get.
769      * @return Returns get device reminder type result.
770      */
771     ErrCode GetDeviceRemindType(NotificationConstant::RemindType &remindType);
772 
773     /**
774      * @brief Publishes a continuous task notification.
775      *
776      * @param request Indicates the NotificationRequest object for setting the notification content.
777      *                This parameter must be specified.
778      * @return Returns publish continuous task notification result.
779      */
780     ErrCode PublishContinuousTaskNotification(const NotificationRequest &request);
781 
782     /**
783      * @brief Cancels a published continuous task notification matching the specified label and notificationId.
784      *
785      * @param label Indicates the label of the continuous task notification to cancel.
786      * @param notificationId Indicates the ID of the continuous task notification to cancel.
787      * @return Returns cancel continuous task notification result.
788      */
789     ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId);
790 
791     /**
792      * @brief Obtains whether the template is supported by the system.
793      *
794      * @param support whether is it a system supported template.
795      * @return Returns check result.
796      */
797     ErrCode IsSupportTemplate(const std::string &templateName, bool &support);
798 
799     /**
800      * @brief Resets ans manager proxy when OnRemoteDied called.
801      */
802     void ResetAnsManagerProxy();
803 
804     /**
805      * @brief try to reconnect ans SA when SA manager OnAddSystemAbility called.
806      */
807     void Reconnect();
808 
809     /**
810      * @brief Publishes a scheduled reminder.
811      *
812      * @param reminder Indicates a reminder.
813      * @return Returns publish result.
814      */
815     ErrCode PublishReminder(ReminderRequest &reminder);
816 
817     /**
818      * @brief Cancels a specified reminder.
819      *
820      * @param reminderId Indicates reminder Id.
821      * @return Returns cancel result.
822      */
823     ErrCode CancelReminder(const int32_t reminderId);
824 
825     /**
826      * @brief Cancels all reminders of current third part application.
827      *
828      * @return Returns cancel result.
829      */
830     ErrCode CancelAllReminders();
831 
832     /**
833      * @brief Obtains all valid reminder notifications set by the current application.
834      *
835      * @param[out] validReminders Indicates the vector to store the result.
836      * @return Returns get valid reminders result.
837      */
838     ErrCode GetValidReminders(std::vector<sptr<ReminderRequest>> &validReminders);
839 
840     /**
841      * @brief Add exclude date for reminder
842      *
843      * @param reminderId Identifies the reminders id.
844      * @param date exclude date
845      * @return Returns ERR_OK on success, others on failure.
846      */
847     ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date);
848 
849     /**
850      * @brief Clear exclude date for reminder
851      *
852      * @param reminderId Identifies the reminders id.
853      * @return Returns ERR_OK on success, others on failure.
854      */
855     ErrCode DelExcludeDates(const int32_t reminderId);
856 
857     /**
858      * @brief Get exclude date for reminder
859      *
860      * @param reminderId Identifies the reminders id.
861      * @param dates exclude dates
862      * @return Returns ERR_OK on success, others on failure.
863      */
864     ErrCode GetExcludeDates(const int32_t reminderId, std::vector<uint64_t>& dates);
865 
866     /**
867      * @brief Checks whether this application has permission to publish notifications under the user.
868      *
869      * @param userId Indicates the userId of the application.
870      * @param allowed True if the application has permissions; returns false otherwise.
871      * @return Returns get allowed result.
872      */
873     ErrCode IsAllowedNotify(const int32_t &userId, bool &allowed);
874 
875     /**
876      * @brief Sets whether to allow all applications to publish notifications on a specified user.
877      * The caller must have system permissions to call this method.
878      *
879      * @param userId Indicates the ID of the user running the application.
880      * @param enabled Specifies whether to allow all applications to publish notifications. The value true
881      *                indicates that notifications are allowed, and the value false indicates that notifications
882      *                are not allowed.
883      * @return Returns set notifications enabled for all bundles result.
884      */
885     ErrCode SetNotificationsEnabledForAllBundles(const int32_t &userId, bool enabled);
886 
887     /**
888      * @brief Removes notifications under specified user.
889      * @note Your application must have platform signature to use this method.
890      *
891      * @param userId Indicates the ID of user whose notifications are to be removed.
892      * @return Returns remove notification result.
893      */
894     ErrCode RemoveNotifications(const int32_t &userId);
895 
896     /**
897      * @brief Sets the do not disturb time on a specified user.
898      * @note Your application must have system signature to call this method.
899      *
900      * @param userId Indicates the specific user.
901      * @param doNotDisturbDate Indicates the do not disturb time to set.
902      * @return Returns set do not disturb time result.
903      */
904     ErrCode SetDoNotDisturbDate(const int32_t &userId, const NotificationDoNotDisturbDate &doNotDisturbDate);
905 
906     /**
907      * @brief Obtains the do not disturb time on a specified user.
908      * @note Your application must have system signature to call this method.
909      *
910      * @param userId Indicates the specific user.
911      * @param doNotDisturbDate Indicates the do not disturb time to get.
912      * @return Returns set do not disturb time result.
913      */
914     ErrCode GetDoNotDisturbDate(const int32_t &userId, NotificationDoNotDisturbDate &doNotDisturbDate);
915 
916     /**
917      * Set whether the application slot is enabled.
918      *
919      * @param bundleOption Indicates the bundle name and uid of the application.
920      * @param slotType Indicates type of slot.
921      * @param enable the type of slot enabled.
922      * @param isForceControl Indicates whether the slot is affected by the notification switch.
923      * @return Returns get slot number by bundle result.
924      */
925     ErrCode SetEnabledForBundleSlot(const NotificationBundleOption &bundleOption,
926         const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl);
927 
928     /**
929      * Obtains whether the application slot is enabled.
930      *
931      * @param bundleOption Indicates the bundle name and uid of the application.
932      * @param slotType Indicates type of slot.
933      * @param enable the type of slot enabled to get.
934      * @return Returns get slot number by bundle result.
935      */
936     ErrCode GetEnabledForBundleSlot(
937         const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled);
938 
939     /**
940      * Obtains whether the current application slot is enabled.
941      *
942      * @param slotType Indicates type of slot.
943      * @param enable the type of slot enabled to get.
944      * @return Returns get enabled result.
945      */
946     ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled);
947 
948     /**
949      * @brief Obtains specific datas via specified dump option.
950      *
951      * @param cmd Indicates the specified dump command.
952      * @param bundle Indicates the specified bundle name.
953      * @param userId Indicates the specified userId.
954      * @param recvUserId Indicates the specified receiver userId.
955      * @param dumpInfo Indicates the container containing datas.
956      * @return Returns check result.
957      */
958     ErrCode ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, int32_t recvUserId,
959         std::vector<std::string> &dumpInfo);
960 
961     /**
962      * @brief Set whether to sync notifications to devices that do not have the app installed.
963      *
964      * @param userId Indicates the specific user.
965      * @param enabled Allow or disallow sync notifications.
966      * @return Returns set enabled result.
967      */
968     ErrCode SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled);
969 
970     /**
971      * @brief Obtains whether to sync notifications to devices that do not have the app installed.
972      *
973      * @param userId Indicates the specific user.
974      * @param enabled Allow or disallow sync notifications.
975      * @return Returns get enabled result.
976      */
977     ErrCode GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled);
978 
979     /**
980      * @brief Set badge number.
981      *
982      * @param badgeNumber The badge number.
983      * @return Returns set badge number result.
984      */
985     ErrCode SetBadgeNumber(int32_t badgeNumber);
986 
987     /**
988      * @brief Set badge number by bundle.
989      *
990      * @param bundleOption Indicates the bundle name and uid of the application.
991      * @param badgeNumber The badge number.
992      * @return Returns set badge number by bundle result.
993      */
994     ErrCode SetBadgeNumberByBundle(const NotificationBundleOption &bundleOption, int32_t badgeNumber);
995 
996     /**
997      * @brief Obtains allow notification application list.
998      *
999      * @param bundleOption Indicates the bundle bundleOption.
1000      * @return Returns ERR_OK on success, others on failure.
1001      */
1002     ErrCode GetAllNotificationEnabledBundles(std::vector<NotificationBundleOption> &bundleOption);
1003 
1004     /**
1005      * @brief Register Push Callback.
1006      *
1007      * @param pushCallback PushCallBack.
1008      * @param notificationCheckRequest Filter conditions for push check
1009      * @return Returns register PushCallback result.
1010      */
1011     ErrCode RegisterPushCallback(
1012         const sptr<IRemoteObject> &pushCallback, const sptr<NotificationCheckRequest> &notificationCheckRequest);
1013 
1014     /**
1015      * @brief Unregister Push Callback.
1016      *
1017      * @return Returns unregister push Callback result.
1018      */
1019     ErrCode UnregisterPushCallback();
1020 
1021     /**
1022      * @brief Set agent relationship.
1023      *
1024      * @param key Indicates storing agent relationship if the value is "PROXY_PKG".
1025      * @param value Indicates key-value pair of agent relationship.
1026      * @return Returns set result.
1027      */
1028     ErrCode SetAdditionConfig(const std::string &key, const std::string &value);
1029 
1030     /**
1031      * @brief Sets whether to allow a specified application to publish notifications cross
1032      * device collaboration. The caller must have system permissions to call this method.
1033      *
1034      * @param bundleOption Indicates the bundle name and uid of the application.
1035      * @param deviceType Indicates the type of the device running the application.
1036      * @param enabled Specifies whether to allow the given application to publish notifications. The value
1037      *                true indicates that notifications are allowed, and the value false indicates that notifications
1038      *                are not allowed.
1039      * @return Returns set notifications enabled for specified bundle result.
1040      */
1041     ErrCode SetDistributedEnabledByBundle(
1042         const NotificationBundleOption &bundleOption, const std::string &deviceType, const bool enabled);
1043 
1044     /**
1045      * @brief get whether to allow a specified application to publish notifications cross
1046      * device collaboration. The caller must have system permissions to call this method.
1047      *
1048      * @param bundleOption Indicates the bundle name and uid of the application.
1049      * @param deviceType Indicates the type of the device running the application.
1050      * @param enabled Specifies whether to allow the given application to publish notifications. The value
1051      *                true indicates that notifications are allowed, and the value false indicates that notifications
1052      *                are not allowed.
1053      * @return Returns set notifications enabled for specified bundle result.
1054      */
1055     ErrCode IsDistributedEnabledByBundle(
1056         const NotificationBundleOption &bundleOption, const std::string &deviceType, bool &enabled);
1057 
1058     /**
1059      * @brief Get Enable smartphone to collaborate with other devices for intelligent reminders
1060      *
1061      * @param deviceType Indicates the type of the device running the application.
1062      * @param enabled Specifies whether to allow the given application to publish notifications.
1063      *                The value true indicates that notifications are allowed, and the value
1064      *                false indicates that notifications are not allowed.
1065      * @return Returns set notifications enabled for specified bundle result.
1066      */
1067     ErrCode IsSmartReminderEnabled(const std::string &deviceType, bool &enabled);
1068 
1069     /**
1070      * @brief Set Enable smartphone to collaborate with other devices for intelligent reminders
1071      *
1072      * @param deviceType Indicates the type of the device running the application.
1073      * @param enabled Specifies whether to allow the given application to publish notifications.
1074      *                The value true indicates that notifications are allowed, and the value
1075      *                false indicates that notifications are not allowed.
1076      * @return Returns set notifications enabled for specified bundle result.
1077      */
1078     ErrCode SetSmartReminderEnabled(const std::string &deviceType, const bool enabled);
1079 
1080     /**
1081      * @brief Cancels a published agent notification.
1082      *
1083      * @param bundleOption Indicates the bundle name and uid of the application.
1084      * @param id Indicates the unique notification ID in the application.
1085      * @return Returns cancel result.
1086      */
1087     ErrCode CancelAsBundleWithAgent(const NotificationBundleOption &bundleOption, const int32_t id);
1088 
1089     /**
1090      * @brief Set the status of the target device.
1091      *
1092      * @param deviceType Type of the device whose status you want to set.
1093      * @param status The status.
1094      * @return Returns set result.
1095      */
1096     ErrCode SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status);
1097 
1098 #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED
1099     /**
1100      * @brief Register Swing swingCbFunc.
1101      *
1102      * @param swingCallback swingCbFunc.
1103      * @return Returns register swingCbFunc result.
1104      */
1105     ErrCode RegisterSwingCallback(const std::function<void(bool, int)> swingCbFunc);
1106 #endif
1107 
1108     /**
1109      * @brief Get do not disturb profile by id.
1110      *
1111      * @param id Profile id.
1112      * @param status Indicates the NotificationDoNotDisturbProfile objects.
1113      * @return Returns ERR_OK on success, others on failure.
1114      */
1115     ErrCode GetDoNotDisturbProfile(int32_t id, sptr<NotificationDoNotDisturbProfile> &profile);
1116 private:
1117     /**
1118      * @brief Gets Ans Manager proxy.
1119      *
1120      * @return Returns true if succeed; returns false otherwise.
1121      */
1122     sptr<AnsManagerInterface> GetAnsManagerProxy();
1123 
1124     /**
1125      * @brief Checks if the MediaContent can be published.
1126      *
1127      * @param request Indicates the specified request.
1128      * @return Returns true if the MediaContent can be published; returns false otherwise.
1129      */
1130     bool CanPublishMediaContent(const NotificationRequest &request) const;
1131 
1132     /**
1133      * @brief Checks whether the picture size exceeds the limit.
1134      *
1135      * @param request Indicates the specified request.
1136      * @return Returns the ErrCode.
1137      */
1138     ErrCode CheckImageSize(const NotificationRequest &request);
1139 
1140     /**
1141      * @brief Checks whether the notification doesn't support distribution.
1142      *
1143      * @param type Indicates the specified NotificationContent::Type.
1144      * @return Returns true if the notification doesn't support distribution; returns false otherwise.
1145      */
1146     bool IsNonDistributedNotificationType(const NotificationContent::Type &type);
1147 
1148     /**
1149      * @brief Checks if the LiveViewContent can be published.
1150      *
1151      * @param request Indicates the specified request.
1152      * @return Returns true if the MediaContent can be published; returns false otherwise.
1153      */
1154     bool CanPublishLiveViewContent(const NotificationRequest &request) const;
1155 
1156     bool IsValidTemplate(const NotificationRequest &request) const;
1157     bool IsValidDelayTime(const NotificationRequest &request) const;
1158 
1159 private:
1160     std::mutex mutex_;
1161     sptr<AnsManagerInterface> ansManagerProxy_;
1162 #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED
1163     sptr<SwingCallBackStub> swingCallBackStub_;
1164 #endif
1165 };
1166 }  // namespace Notification
1167 }  // namespace OHOS
1168 
1169 #endif  // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_NOTIFICATION_H
1170