• 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_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_HELPER_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_HELPER_H
18 
19 #include "ans_dialog_host_client.h"
20 #include "notification_bundle_option.h"
21 #include "notification_button_option.h"
22 #include "notification_do_not_disturb_date.h"
23 #include "notification_do_not_disturb_profile.h"
24 #include "enabled_notification_callback_data.h"
25 #include "notification_request.h"
26 #include "notification_slot.h"
27 #include "notification_sorting_map.h"
28 #include "notification_subscriber.h"
29 #include "notification_local_live_view_subscriber.h"
30 #include "want_params.h"
31 
32 namespace OHOS {
33 namespace Notification {
34 class NotificationHelper {
35 public:
36     /**
37      * @brief Creates a notification slot.
38      * @note You can call the NotificationRequest::SetSlotType(NotificationConstant::SlotType) method to bind the slot
39      * for publishing. A NotificationSlot instance cannot be used directly after being initialized. Instead, you have to
40      * call this method to create a notification slot and bind the slot ID to a NotificationRequest object so that the
41      * notification published can have all the characteristics set in the NotificationSlot. After a notification slot is
42      * created by using this method, only the name and description of the notification slot can be changed. Changes to
43      * the other attributes, such as the vibration status and notification tone, will no longer take effect.
44      *
45      * @param slot Indicates the notification slot to be created, which is set by NotificationSlot.
46      *             This parameter must be specified.
47      * @return Returns add notification slot result.
48      */
49     static ErrCode AddNotificationSlot(const NotificationSlot &slot);
50 
51     /**
52      * @brief Adds a notification slot by type.
53      *
54      * @param slotType Indicates the notification slot type to be added.
55      * @return Returns add notification slot result.
56      */
57     static ErrCode AddSlotByType(const NotificationConstant::SlotType &slotType);
58 
59     /**
60      * @brief Creates multiple notification slots.
61      *
62      * @param slots Indicates the notification slots to create.
63      * @return Returns add notification slots result.
64      */
65     static ErrCode AddNotificationSlots(const std::vector<NotificationSlot> &slots);
66 
67     /**
68      * @brief Deletes a created notification slot based on the slot ID.
69      *
70      * @param slotType Indicates the type of the slot, which is created by AddNotificationSlot
71      *                 This parameter must be specified.
72      * @return Returns remove notification slot result.
73      */
74     static ErrCode RemoveNotificationSlot(const NotificationConstant::SlotType &slotType);
75 
76     /**
77      * @brief Deletes all notification slots.
78      *
79      * @return Returns remove all slots result.
80      */
81     static ErrCode RemoveAllSlots();
82 
83     /**
84      * @brief Queries a created notification slot.
85      *
86      * @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot(NotificationSlot). This
87      *        parameter must be specified.
88      * @param slot Indicates the created NotificationSlot.
89      * @return Returns the get notification slot result.
90      */
91     static ErrCode GetNotificationSlot(const NotificationConstant::SlotType &slotType, sptr<NotificationSlot> &slot);
92 
93     /**
94      * @brief Obtains all notification slots of this application.
95      * @param slots Indicates the created NotificationSlot.
96      * @return Returns all notification slots of this application.
97      */
98     static 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     static 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     static 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 get slotFlags by bundle result.
124      */
125     static 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     static ErrCode PublishNotification(const NotificationRequest &request);
137 
138     /**
139      * @brief Publishes a notification.
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 request Indicates the NotificationRequest object for setting the notification content.
144      *                This parameter must be specified.
145      * @return Returns publish notification result.
146      */
147     static ErrCode PublishNotificationForIndirectProxy(const NotificationRequest &request);
148 
149     /**
150      * @brief Publishes a notification with a specified label.
151      * @note If a notification with the same ID has been published by the current application and has not been deleted,
152      *       this method will update the notification.
153      *
154      * @param label Indicates the label of the notification to publish.
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     static ErrCode PublishNotification(const std::string &label, 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     static 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     static ErrCode CancelNotification(const std::string &label, int32_t notificationId);
179 
180     /**
181      * @brief Cancels all the published notifications.
182      *
183      * @note To cancel a specified notification, see CancelNotification(int32_t).
184      * @return Returns cancel all notifications result.
185      */
186     static 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     static 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 bundle 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     static 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 nums Indicates the number of active notifications of the current application.
215      * @return Returns get active notification nums result.
216      */
217     static 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     static 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.
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     static 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     static 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     static 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     static ErrCode PublishNotificationAsBundle(
268         const std::string &representativeBundle, const NotificationRequest &request);
269 
270     /**
271      * @brief Sets the number of active notifications of the current application as the number to be displayed on the
272      * notification badge.
273      *
274      * @return Returns set notification badge num result.
275      */
276     static ErrCode SetNotificationBadgeNum();
277 
278     /**
279      * @brief Sets the number to be displayed on the notification badge of the application.
280      *
281      * @param num Indicates the number to display. A negative number indicates that the badge setting remains unchanged.
282      *            The value 0 indicates that no badge is displayed on the application icon.
283      *            If the value is greater than 99, 99+ will be displayed.
284      * @return Returns set notification badge num result.
285      */
286     static ErrCode SetNotificationBadgeNum(int32_t num);
287 
288     /**
289      * @brief Checks whether this application has permission to publish notifications. The caller must have
290      * system permissions to call this method.
291      *
292      * @param  allowed True if this application has the permission; returns false otherwise
293      * @return Returns is allowed notify result.
294      */
295     static ErrCode IsAllowedNotify(bool &allowed);
296 
297     /**
298      * @brief Checks whether this application has permission to publish notifications.
299      *
300      * @param  allowed True if this application has the permission; returns false otherwise
301      * @return Returns is allowed notify result.
302      */
303     static ErrCode IsAllowedNotifySelf(bool &allowed);
304 
305     /**
306      * @brief Checks whether this application can pop enable notification dialog.
307      *
308      * @param  canPop True if can pop enable notification dialog
309      * @return Returns is canPop result.
310      */
311     static ErrCode CanPopEnableNotificationDialog(sptr<AnsDialogHostClient> &hostClient,
312         bool &canPop, std::string &bundleName);
313 
314     /**
315      * @brief remove enable notification dialog.
316      *
317      * @return Returns remove dialog result.
318      */
319     static ErrCode RemoveEnableNotificationDialog();
320 
321     /**
322      * @brief Allow the current application to publish notifications on a specified device.
323      *
324      * @param deviceId Indicates the ID of the device running the application. At present, this parameter can
325      *                 only be null or an empty string, indicating the current device.
326      * @return Returns set notifications enabled for default bundle result.
327      */
328     static ErrCode RequestEnableNotification(std::string &deviceId,
329         sptr<AnsDialogHostClient> &hostClient,
330         sptr<IRemoteObject> &callerToken);
331 
332     /**
333      * @brief Checks whether this application has permission to modify the Do Not Disturb (DND) notification policy.
334      *
335      * @param hasPermission True if this application is suspended; false otherwise.
336      * @return Returns has notification policy access permission.
337      */
338     static ErrCode HasNotificationPolicyAccessPermission(bool &hasPermission);
339 
340     /**
341      * @brief Obtains the importance level of this application.
342      *
343      * @param  importance Indicates the importance level of this application, which can be LEVEL_NONE,
344                LEVEL_MIN, LEVEL_LOW, LEVEL_DEFAULT, LEVEL_HIGH, or LEVEL_UNDEFINED.
345      * @return Returns get bundle importance result
346      */
347     static ErrCode GetBundleImportance(NotificationSlot::NotificationLevel &importance);
348 
349     /**
350      * @brief Subscribes to notifications from all applications. This method can be called only by applications
351      * with required system permissions.
352      * @note  To subscribe to a notification, inherit the {NotificationSubscriber} class, override its
353      *        callback methods and create a subscriber. The subscriber will be used as a parameter of this method.
354      *        After the notification is published, subscribers that meet the filter criteria can receive the
355      *        notification. To subscribe to notifications published only by specified sources, for example,
356      *        notifications from certain applications,
357      *        call the {SubscribeNotification(NotificationSubscriber, NotificationSubscribeInfo)} method.
358      *
359      * @param subscriber Indicates the {NotificationSubscriber} to receive notifications.
360      *                   This parameter must be specified.
361      * @return Returns unsubscribe notification result.
362      */
363     static ErrCode SubscribeNotification(const NotificationSubscriber &subscriber);
364 
365     /**
366      * @brief Subscribes to notifications from the appliaction self.
367      * @note  To subscribe to a notification, inherit the {NotificationSubscriber} class, override its
368      *        callback methods and create a subscriber. The subscriber will be used as a parameter of this method.
369      *        After the notification is published, subscribers that meet the filter criteria can receive the
370      *        notification.
371      *
372      * @param subscriber Indicates the {NotificationSubscriber} to receive notifications.
373      *                   This parameter must be specified.
374      * @return Returns unsubscribe notification result.
375      */
376     static ErrCode SubscribeNotificationSelf(const NotificationSubscriber &subscriber);
377 
378     /**
379      * @brief Subscribes to all notifications based on the filtering criteria. This method can be called only
380      * by applications with required system permissions.
381      * @note  After {subscribeInfo} is specified, a subscriber receives only the notifications that
382      *        meet the filter criteria specified by {subscribeInfo}.
383      *        To subscribe to a notification, inherit the {NotificationSubscriber} class, override its
384      *        callback methods and create a subscriber. The subscriber will be used as a parameter of this method.
385      *        After the notification is published, subscribers that meet the filter criteria can receive the
386      *        notification. To subscribe to and receive all notifications, call the
387      *        {SubscribeNotification(NotificationSubscriber)} method.
388      *
389      * @param subscriber Indicates the subscribers to receive notifications. This parameter must be specified.
390      *                   For details, see {NotificationSubscriber}.
391      * @param subscribeInfo Indicates the filters for specified notification sources, including application name,
392      *                      user ID, or device name. This parameter is optional.
393      * @return Returns subscribe notification result.
394      */
395     static ErrCode SubscribeNotification(
396         const NotificationSubscriber &subscriber, const NotificationSubscribeInfo &subscribeInfo);
397 
398     /**
399      * @brief Subscribes the localLiveView button click. This method can be called only
400      * by applications with required system permissions.
401      * @note  To subscribe to a button click, inherit the {NotificationLocalLiveViewSubscriber} class, override its
402      *        callback methods and create a subscriber. The subscriber will be used as a parameter of this method.
403      *        After the button is clicked, subscribers that meet the filter criteria can receive the response
404      *
405      * @param subscriber Indicates the subscribers to receive notifications. This parameter must be specified.
406      *                   For details, see {NotificationSubscriber}.
407      * @return Returns subscribe notification result.
408      */
409     static ErrCode SubscribeLocalLiveViewNotification(const NotificationLocalLiveViewSubscriber &subscriber,
410         const bool isNative = true);
411 
412     /**
413      * @brief Unsubscribes from all notifications. This method can be called only by applications with required
414      * system permissions.
415      * @note Generally, you subscribe to a notification by calling the
416      *       {SubscribeNotification(NotificationSubscriber)} method. If you do not want your application
417      *       to receive a notification any longer, unsubscribe from that notification using this method.
418      *       You can unsubscribe from only those notifications that your application has subscribed to.
419      *        To unsubscribe from notifications published only by specified sources, for example,
420      *       notifications from certain applications, call the
421      *       {UnSubscribeNotification(NotificationSubscriber, NotificationSubscribeInfo)} method.
422      *
423      * @param subscriber Indicates the {NotificationSubscriber} to receive notifications.
424      *                   This parameter must be specified.
425      * @return Returns unsubscribe notification result.
426      */
427     static ErrCode UnSubscribeNotification(NotificationSubscriber &subscriber);
428 
429     /**
430      * @brief Unsubscribes from all notifications based on the filtering criteria. This method can be called
431      * only by applications with required system permissions.
432      * @note A subscriber will no longer receive the notifications from specified notification sources.
433      *
434      * @param subscriber Indicates the {NotificationSubscriber} to receive notifications.
435      *                   This parameter must be specified.
436      * @param subscribeInfo Indicates the filters for , including application name,
437      *                      user ID, or device name. This parameter is optional.
438      * @return Returns unsubscribe notification result.
439      */
440     static ErrCode UnSubscribeNotification(NotificationSubscriber &subscriber, NotificationSubscribeInfo subscribeInfo);
441 
442     /**
443      * @brief Trigger the local live view after the button has been clicked.
444      * @note Your application must have platform signature to use this method.
445      *
446      * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked.
447      * @param notificationId Indicates the id of the notification.
448      * @param buttonOption Indicates which button has been clicked.
449      * @return Returns trigger localLiveView result.
450      */
451     static ErrCode TriggerLocalLiveView(const NotificationBundleOption &bundleOption,
452         const int32_t notificationId, const NotificationButtonOption &buttonOption);
453 
454     /**
455      * @brief Removes a specified removable notification of other applications.
456      * @note Your application must have platform signature to use this method.
457      *
458      * @param key Indicates the key of the notification to remove.
459      * @param removeReason Indicates the reason of remove notification.
460      * @return Returns remove notification result.
461      */
462     static ErrCode RemoveNotification(const std::string &key, int32_t removeReason);
463 
464     /**
465      * @brief Removes a specified removable notification of other applications.
466      * @note Your application must have platform signature to use this method.
467      *
468      * @param bundleOption Indicates the bundle name and uid of the application whose notifications are to be removed.
469      * @param notificationId Indicates the id of the notification to remove.
470      * @param label Indicates the label of the notification to remove.
471      * @param removeReason Indicates the reason of remove notification.
472      * @return Returns remove notification result.
473      */
474     static ErrCode RemoveNotification(const NotificationBundleOption &bundleOption,
475         const int32_t notificationId, const std::string &label, int32_t removeReason);
476 
477     /**
478      * @brief Removes a specified removable notification of other applications.
479      * @note Your application must have platform signature to use this method.
480      *
481      * @param bundleOption Indicates the bundle name and uid of the application whose notifications are to be removed.
482      * @return Returns remove notification result.
483      */
484     static ErrCode RemoveAllNotifications(const NotificationBundleOption &bundleOption);
485 
486     static ErrCode RemoveNotifications(const std::vector<std::string> hashcodes, int32_t removeReason);
487 
488     /**
489      * @brief Removes all removable notifications of a specified bundle.
490      * @note Your application must have platform signature to use this method.
491      *
492      * @param bundleOption Indicates the bundle name and uid of the application whose notifications are to be removed.
493      * @return Returns remove notifications result.
494      */
495     static ErrCode RemoveNotificationsByBundle(const NotificationBundleOption &bundleOption);
496 
497     /**
498      * @brief Removes all removable notifications in the system.
499      * @note Your application must have platform signature to use this method.
500      * @return Returns remove notifications result.
501      */
502     static ErrCode RemoveNotifications();
503 
504     /**
505      * @brief Obtains all notification slots belonging to the specified bundle.
506      *
507      * @param bundleOption Indicates the bundle name and uid of the application.
508      * @param slots Indicates a list of notification slots.
509      * @return Returns get notification slots for bundle result.
510      */
511     static ErrCode GetNotificationSlotsForBundle(
512         const NotificationBundleOption &bundleOption, std::vector<sptr<NotificationSlot>> &slots);
513 
514     /**
515      * @brief Obtains all notification slots belonging to the specified bundle.
516      *
517      * @param bundleOption Indicates the bundle name and uid of the application.
518      * @param slotType Indicates the type of the slot, which is created by AddNotificationSlot.
519      * @param slot Indicates a notification slot.
520      * @return Returns get notification slots for bundle result.
521      */
522     static ErrCode GetNotificationSlotForBundle(
523         const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType,
524         sptr<NotificationSlot> &slot);
525 
526     /**
527      * @brief Update all notification slots for the specified bundle.
528      *
529      * @param bundleOption Indicates the bundle name and uid of the application.
530      * @param slots Indicates a list of new notification slots.
531      * @return Returns update notification slots for bundle result.
532      */
533     static ErrCode UpdateNotificationSlots(
534         const NotificationBundleOption &bundleOption, const std::vector<sptr<NotificationSlot>> &slots);
535 
536     /**
537      * @brief Obtains all active notifications in the current system. The caller must have system permissions to
538      * call this method.
539      *
540      * @param notification Indicates all active notifications of this application.
541      * @return Returns get all active notifications
542      */
543     static ErrCode GetAllActiveNotifications(std::vector<sptr<Notification>> &notification);
544 
545     /**
546      * @brief Obtains the active notifications corresponding to the specified key in the system. To call this method
547      * to obtain particular active notifications, you must have received the notifications and obtained the key
548      * via {Notification::GetKey()}.
549      *
550      * @param key Indicates the key array for querying corresponding active notifications.
551      *            If this parameter is null, this method returns all active notifications in the system.
552      * @param notification Indicates the set of active notifications corresponding to the specified key.
553      * @return Returns get all active notifications.
554      */
555     static ErrCode GetAllActiveNotifications(
556         const std::vector<std::string> key, std::vector<sptr<Notification>> &notification);
557 
558     /**
559      * @brief Obtains the active notifications by filter.
560      * @param filter
561      * @param extraInfo
562      * @return
563      */
564     static 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; false otherwise.
574      * @return Returns is allowed notify result.
575      */
576     static 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
586      *                are not allowed.
587      * @return Returns set notifications enabled for all bundles result.
588      */
589     static 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     static 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     static ErrCode SetNotificationsEnabledForSpecifiedBundle(
617         const NotificationBundleOption &bundleOption, std::string &deviceId, bool enabled);
618 
619     /**
620      * @brief Sets whether to allow a specified application 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     static ErrCode SetShowBadgeEnabledForBundle(const NotificationBundleOption &bundleOption, bool enabled);
627 
628     /**
629      * @brief Obtains the flag that whether to allow a specified application 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     static ErrCode GetShowBadgeEnabledForBundle(const NotificationBundleOption &bundleOption, bool &enabled);
636 
637     /**
638      * @brief Obtains the flag that whether to allow the current application to show badge.
639      *
640      * @param enabled Specifies whether to allow the given application to show badge.
641      * @return Returns get result.
642      */
643     static ErrCode GetShowBadgeEnabled(bool &enabled);
644 
645     /**
646      * @brief Cancel the notification of the specified group of this application.
647      *
648      * @param groupName Indicates the specified group name.
649      * @return Returns cancel group result.
650      */
651     static ErrCode CancelGroup(const std::string &groupName);
652 
653     /**
654      * @brief Remove 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     static 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     static 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     static ErrCode GetDoNotDisturbDate(NotificationDoNotDisturbDate &doNotDisturbDate);
679 
680     /**
681      * @brief Obtains the flag that whether to support do not disturb mode.
682      *
683      * @param doesSupport Specifies whether to support do not disturb mode.
684      * @return Returns check result.
685      */
686     static ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport);
687 
688     /**
689      * @brief Is coming call need silent in do not disturb mode.
690      *
691      * @param phoneNumber the calling format number.
692      * @return Returns silent in do not disturb mode.
693      */
694     static ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType);
695 
696     /**
697      * @brief Check if the device supports distributed notification.
698      *
699      * @param enabled True if the device supports distributed notification; false otherwise.
700      * @return Returns is distributed enabled result.
701      */
702     static ErrCode IsDistributedEnabled(bool &enabled);
703 
704     /**
705      * @brief Set whether the device supports distributed notifications.
706      *
707      * @param enable Specifies whether to enable the device to support distributed notification.
708      *               The value true indicates that the device is enabled to support distributed notifications, and
709      *               the value false indicates that the device is forbidden to support distributed notifications.
710      * @return Returns enable distributed result.
711      */
712     static ErrCode EnableDistributed(const bool enabled);
713 
714     /**
715      * @brief Set whether an application supports distributed notifications.
716      *
717      * @param bundleOption Indicates the bundle name and uid of an application.
718      * @param enabled Specifies whether to enable an application to support distributed notification.
719      *                The value true indicates that the application is enabled to support distributed notifications,
720      *                and the value false indicates that the application is forbidden to support distributed
721      *                notifications.
722      * @return Returns enable distributed by bundle result.
723      */
724     static ErrCode EnableDistributedByBundle(const NotificationBundleOption &bundleOption, const bool enabled);
725 
726     /**
727      * @brief Set whether this application supports distributed notifications.
728      *
729      * @param enabled Specifies whether to enable this application to support distributed notification.
730      *                The value true indicates that this application is enabled to support distributed notifications,
731      *                and the value false indicates that this application is forbidden to support distributed
732      *                notifications.
733      * @return Returns enable distributed self result.
734      */
735     static ErrCode EnableDistributedSelf(const bool enabled);
736 
737     /**
738      * @brief Check whether an application supports distributed notifications.
739      *
740      * @param bundleOption Indicates the bundle name and uid of an application.
741      * @param enabled True if the application supports distributed notification; false otherwise.
742      * @return Returns is distributed enabled by bundle result.
743      */
744     static ErrCode IsDistributedEnableByBundle(const NotificationBundleOption &bundleOption, bool &enabled);
745 
746     /**
747      * @brief Obtains the device remind type.
748      * @note Your application must have system signature to call this method.
749      *
750      * @param remindType Indicates the device remind type to get.
751      * @return Returns get device reminder type result.
752      */
753     static ErrCode GetDeviceRemindType(NotificationConstant::RemindType &remindType);
754 
755     /**
756      * @brief Publishes a continuous task notification.
757      * @param request Indicates the NotificationRequest object for setting the notification content.
758      *                This parameter must be specified.
759      * @return Returns publish continuous task notification result.
760      */
761     static ErrCode PublishContinuousTaskNotification(const NotificationRequest &request);
762 
763     /**
764      * @brief Cancels a published continuous task notification matching the specified label and notificationId.
765      *
766      * @param label Indicates the label of the continuous task notification to cancel.
767      * @param notificationId Indicates the ID of the continuous task notification to cancel.
768      * @return Returns cancel continuous task notification result.
769      */
770     static ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId);
771 
772     /**
773      * @brief Obtains whether the template is supported by the system.
774      *
775      * @param support Indicates whether is it a system supported template.
776      * @return Returns check result.
777      */
778     static ErrCode IsSupportTemplate(const std::string &templateName, bool &support);
779 
780     /**
781      * @brief Checks whether this application has permission to publish notifications under the user.
782      *
783      * @param userId Indicates the userId of the application.
784      * @param allowed True if the application has permissions; false otherwise.
785      * @return Returns get allowed result.
786      */
787     static ErrCode IsAllowedNotify(const int32_t &userId, bool &allowed);
788 
789     /**
790      * @brief Sets whether to allow all applications to publish notifications on a specified user.
791      * The caller must have system permissions to call this method.
792      *
793      * @param userId Indicates the ID of the user running the application.
794      * @param enabled Specifies whether to allow all applications to publish notifications. The value true
795      *                indicates that notifications are allowed, and the value false indicates that notifications
796      *                are not allowed.
797      * @return Returns set notifications enabled for all bundles result.
798      */
799     static ErrCode SetNotificationsEnabledForAllBundles(const int32_t &userId, bool enabled);
800 
801     /**
802      * @brief Removes notifications under specified user.
803      * @note Your application must have platform signature to use this method.
804      *
805      * @param userId Indicates the ID of user whose notifications are to be removed.
806      * @return Returns remove notification result.
807      */
808     static ErrCode RemoveNotifications(const int32_t &userId);
809 
810     /**
811      * @brief Sets the do not disturb time on a specified user.
812      * @note Your application must have system signature to call this method.
813      *
814      * @param userId Indicates the specific user.
815      * @param doNotDisturbDate Indicates the do not disturb time to set.
816      * @return Returns set do not disturb time result.
817      */
818     static ErrCode SetDoNotDisturbDate(const int32_t &userId, const NotificationDoNotDisturbDate &doNotDisturbDate);
819 
820     /**
821      * @brief Obtains the do not disturb time on a specified user.
822      * @note Your application must have system signature to call this method.
823      *
824      * @param userId Indicates the specific user.
825      * @param doNotDisturbDate Indicates the do not disturb time to get.
826      * @return Returns set do not disturb time result.
827      */
828     static ErrCode GetDoNotDisturbDate(const int32_t &userId, NotificationDoNotDisturbDate &doNotDisturbDate);
829 
830     /**
831      * @brief Obtains the do not disturb  on a specified user.
832      * @note Your application must have system signature to call this method.
833      *
834      * @param profiles Indicates the do not disturb time to add.
835      * @return Returns set do not disturb time result.
836      */
837     static ErrCode AddDoNotDisturbProfiles(const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles);
838 
839     /**
840      * @brief Obtains the do not disturb on a specified user.
841      * @note Your application must have system signature to call this method.
842      *
843      * @param profiles Indicates the do not disturb time to remove.
844      * @return Returns set do not disturb time result.
845      */
846     static ErrCode RemoveDoNotDisturbProfiles(const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles);
847 
848     /**
849      * Set whether the application slot is enabled.
850      *
851      * @param bundleOption Indicates the bundle name and uid of the application.
852      * @param slotType Indicates type of slot.
853      * @param enabled the type of slot enabled.
854      * @param isForceControl Indicates whether the slot is affected by the notification switch.
855      * @return Returns get slot number by bundle result.
856      */
857     static ErrCode SetEnabledForBundleSlot(const NotificationBundleOption &bundleOption,
858         const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl);
859 
860     /**
861      * Obtains whether the application slot is enabled.
862      *
863      * @param bundleOption Indicates the bundle name and uid of the application.
864      * @param slotType Indicates type of slot.
865      * @param enabled the type of slot enabled to get.
866      * @return Returns get slot number by bundle result.
867      */
868     static ErrCode GetEnabledForBundleSlot(
869         const NotificationBundleOption &bundleOption, const NotificationConstant::SlotType &slotType, bool &enabled);
870 
871     /**
872      * Obtains whether the current application slot is enabled.
873      *
874      * @param slotType Indicates type of slot.
875      * @param enabled the type of slot enabled to get.
876      * @return Returns get enabled result.
877      */
878     static ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled);
879 
880     /**
881      * @brief Set whether to sync notifications to devices that do not have the app installed.
882      *
883      * @param userId Indicates the specific user.
884      * @param enabled Allow or disallow sync notifications.
885      * @return Returns set enabled result.
886      */
887     static ErrCode SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled);
888 
889     /**
890      * @brief Obtains whether to sync notifications to devices that do not have the app installed.
891      *
892      * @param userId Indicates the specific user.
893      * @param enabled Allow or disallow sync notifications.
894      * @return Returns get enabled result.
895      */
896     static ErrCode GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled);
897 
898     /**
899      * @brief Set badge number.
900      *
901      * @param badgeNumber The badge number.
902      * @return Returns set badge number result.
903      */
904     static ErrCode SetBadgeNumber(int32_t badgeNumber);
905 
906     /**
907      * @brief Set badge number by bundle.
908      *
909      * @param bundleOption Indicates the bundle name and uid of the application.
910      * @param badgeNumber The badge number.
911      * @return Returns set badge number by bundle result.
912      */
913     static ErrCode SetBadgeNumberByBundle(const NotificationBundleOption &bundleOption, int32_t badgeNumber);
914 
915     /**
916      * @brief Obtains allow notification application list.
917      *
918      * @param bundleOption Indicates the bundle bundleOption.
919      * @return Returns ERR_OK on success, others on failure.
920      */
921     static ErrCode GetAllNotificationEnabledBundles(std::vector<NotificationBundleOption> &bundleOption);
922 
923     /**
924      * @brief Register Push Callback.
925      *
926      * @param pushCallback push appliction's Callback.
927      * @param notificationCheckRequest Filter conditions for push check.
928      * @return Returns register push callback result.
929      */
930     static ErrCode RegisterPushCallback(
931         const sptr<IRemoteObject>& pushCallback, const sptr<NotificationCheckRequest> &notificationCheckRequest);
932 
933     /**
934      * @brief Unregister Push Callback.
935      *
936      * @return Returns unregister push Callback result.
937      */
938     static ErrCode UnregisterPushCallback();
939 
940     /**
941      * @brief Sets whether to allow a specified application to publish notifications cross
942      * device collaboration. The caller must have system permissions to call this method.
943      *
944      * @param bundleOption Indicates the bundle name and uid of the application.
945      * @param deviceType Indicates the type of the device running the application.
946      * @param enabled Specifies whether to allow the given application to publish notifications. The value
947      *                true indicates that notifications are allowed, and the value false indicates that
948      *                notifications are not allowed.
949      * @return Returns set notifications enabled for specified bundle result.
950      */
951     static ErrCode SetDistributedEnabledByBundle(
952         const NotificationBundleOption &bundleOption, const std::string &deviceType, const bool enabled);
953 
954     /**
955      * @brief Get whether to allow a specified application to publish notifications cross
956      * device collaboration. The caller must have system permissions to call this method.
957      *
958      * @param bundleOption Indicates the bundle name and uid of the application.
959      * @param deviceType Indicates the type of the device running the application.
960      * @param enabled Specifies whether to allow the given application to publish notifications. The value
961      *                true indicates that notifications are allowed, and the value false indicates that
962      *                notifications are not allowed.
963      * @return Returns set notifications enabled for specified bundle result.
964      */
965     static ErrCode IsDistributedEnabledByBundle(
966         const NotificationBundleOption &bundleOption, const std::string &deviceType, bool &enabled);
967 
968     /**
969      * @brief Get Enable smartphone to collaborate with other devices for intelligent reminders
970      *
971      * @param deviceType Indicates the type of the device running the application.
972      * @param enabled Specifies whether to allow the given application to publish notifications.
973      *                The value true indicates that notifications are allowed, and the value
974      *                false indicates that notifications are not allowed.
975      * @return Returns set notifications enabled for specified bundle result.
976      */
977     static ErrCode IsSmartReminderEnabled(const std::string &deviceType, bool &enabled);
978 
979     /**
980      * @brief Set Enable smartphone to collaborate with other devices for intelligent reminders
981      *
982      * @param deviceType Indicates the type of the device running the application.
983      * @param enabled Specifies whether to allow the given application to publish notifications.
984      *                The value true indicates that notifications are allowed, and the value
985      *                false indicates that notifications are not allowed.
986      * @return Returns set notifications enabled for specified bundle result.
987      */
988     static ErrCode SetSmartReminderEnabled(const std::string &deviceType, const bool enabled);
989 
990     /**
991      * @brief Set agent relationship.
992      *
993      * @param key Indicates storing agent relationship if the value is "PROXY_PKG".
994      * @param value Indicates key-value pair of agent relationship.
995      * @return Returns set result.
996      */
997     static ErrCode SetAdditionConfig(const std::string &key, const std::string &value);
998 
999     /**
1000      * @brief Cancels a published agent notification.
1001      *
1002      * @param bundleOption Indicates the bundle name and uid of the application.
1003      * @param id Indicates the unique notification ID in the application.
1004      * @return Returns cancel result.
1005      */
1006     static ErrCode CancelAsBundleWithAgent(const NotificationBundleOption &bundleOption, const int32_t id);
1007 
1008     /**
1009      * @brief Set the status of the target device.
1010      *
1011      * @param deviceType Type of the device whose status you want to set.
1012      * @param status The status.
1013      * @return Returns set result.
1014      */
1015     static ErrCode SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status);
1016 
1017     /**
1018      * @brief Register Swing Callback Function.
1019      *
1020      * @param swingCallback swing Callback Function.
1021      * @return Returns register swing callback result.
1022      */
1023     static ErrCode RegisterSwingCallback(const std::function<void(bool, int)> swingCbFunc);
1024 
1025     /**
1026      * @brief Get do not disturb profile by id.
1027      *
1028      * @param id Profile id.
1029      * @param status Indicates the NotificationDoNotDisturbProfile objects.
1030      * @return Returns ERR_OK on success, others on failure.
1031      */
1032     static ErrCode GetDoNotDisturbProfile(int32_t id, sptr<NotificationDoNotDisturbProfile> &profile);
1033 };
1034 }  // namespace Notification
1035 }  // namespace OHOS
1036 
1037 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_HELPER_H
1038