• 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_MANAGER_PROXY_H
17 #define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_MANAGER_PROXY_H
18 
19 #include "ans_manager_interface.h"
20 #include "distributed_notification_service_ipc_interface_code.h"
21 #include "iremote_proxy.h"
22 #include "want_params.h"
23 
24 namespace OHOS {
25 namespace Notification {
26 class AnsManagerProxy : public IRemoteProxy<AnsManagerInterface> {
27 public:
28     AnsManagerProxy() = delete;
29     explicit AnsManagerProxy(const sptr<IRemoteObject> &impl);
30     ~AnsManagerProxy() override;
31     DISALLOW_COPY_AND_MOVE(AnsManagerProxy);
32 
33     /**
34      * @brief Publishes a notification with a specified label.
35      * @note If a notification with the same ID has been published by the current application and has not been deleted,
36      *       this method will update the notification.
37      *
38      * @param label Indicates the label of the notification to publish.
39      * @param notification Indicates the NotificationRequest object for setting the notification content.
40      *                This parameter must be specified.
41      * @return Returns ERR_OK on success, others on failure.
42      */
43     ErrCode Publish(const std::string &label, const sptr<NotificationRequest> &notification) override;
44 
45     /**
46      * @brief Publishes a notification.
47      * @note If a notification with the same ID has been published by the current application and has not been deleted,
48      *       this method will update the notification.
49      *
50      * @param notification Indicates the NotificationRequest object for setting the notification content.
51      *                This parameter must be specified.
52      * @return Returns ERR_OK on success, others on failure.
53      */
54     ErrCode PublishNotificationForIndirectProxy(const sptr<NotificationRequest> &notification) override;
55 
56     /**
57      * @brief Cancels a published notification matching the specified label and notificationId.
58      *
59      * @param notificationId Indicates the ID of the notification to cancel.
60      * @param label Indicates the label of the notification to cancel.
61      * @param instanceKey Indicates the application instance key.
62      * @return Returns cancel notification result.
63      */
64     ErrCode Cancel(int32_t notificationId, const std::string &label, const std::string &instanceKey) override;
65 
66     /**
67      * @brief Cancels all the published notifications.
68      *
69      * @param instanceKey Indicates the application instance key.
70      * @return Returns ERR_OK on success, others on failure.
71      */
72     ErrCode CancelAll(const std::string &instanceKey) override;
73 
74     /**
75      * @brief Cancels a published agent notification.
76      *
77      * @param notificationId Indicates the unique notification ID in the application.
78      *                       The value must be the ID of a published notification.
79      *                       Otherwise, this method does not take effect.
80      * @param representativeBundle Indicates the name of application bundle your application is representing.
81      * @param userId Indicates the specific user.
82      * @return Returns cancel notification result.
83      */
84     ErrCode CancelAsBundle(int32_t notificationId, const std::string &representativeBundle, int32_t userId) override;
85 
86     /**
87      * @brief Cancels a published agent notification.
88      *
89      * @param bundleOption Indicates the bundle of application your application is representing.
90      * @param notificationId Indicates the unique notification ID in the application.
91      *                       The value must be the ID of a published notification.
92      *                       Otherwise, this method does not take effect.
93      * @return Returns cancel notification result.
94      */
95     ErrCode CancelAsBundle(const sptr<NotificationBundleOption> &bundleOption, int32_t notificationId) override;
96 
97     /**
98      * @brief Cancels a published agent notification.
99      *
100      * @param bundleOption Indicates the bundle of application bundle your application is representing.
101      * @param notificationId Indicates the unique notification ID in the application.
102      *                       The value must be the ID of a published notification.
103      *                       Otherwise, this method does not take effect.
104      * @param userId Indicates the specific user.
105      * @return Returns cancel notification result.
106      */
107     ErrCode CancelAsBundle(
108         const sptr<NotificationBundleOption> &bundleOption, int32_t notificationId, int32_t userId) override;
109 
110     /**
111      * @brief Adds a notification slot by type.
112      *
113      * @param slotType Indicates the notification slot type to be added.
114      * @return Returns ERR_OK on success, others on failure.
115      */
116     ErrCode AddSlotByType(NotificationConstant::SlotType slotType) override;
117 
118     /**
119      * @brief Creates multiple notification slots.
120      *
121      * @param slots Indicates the notification slots to create.
122      * @return Returns ERR_OK on success, others on failure.
123      */
124     ErrCode AddSlots(const std::vector<sptr<NotificationSlot>> &slots) override;
125 
126     /**
127      * @brief Deletes a created notification slot based on the slot ID.
128      *
129      * @param slotType Indicates the type of the slot, which is created by AddNotificationSlot
130      *                 This parameter must be specified.
131      * @return Returns ERR_OK on success, others on failure.
132      */
133     ErrCode RemoveSlotByType(const NotificationConstant::SlotType &slotType) override;
134 
135     /**
136      * @brief Deletes all notification slots.
137      *
138      * @return Returns ERR_OK on success, others on failure.
139      */
140     ErrCode RemoveAllSlots() override;
141 
142     /**
143      * @brief Queries a created notification slot.
144      *
145      * @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot(NotificationSlot). This
146      *        parameter must be specified.
147      * @param slot Indicates the created NotificationSlot.
148      * @return Returns ERR_OK on success, others on failure.
149      */
150     ErrCode GetSlotByType(const NotificationConstant::SlotType &slotType, sptr<NotificationSlot> &slot) override;
151 
152     /**
153      * @brief Obtains all notification slots of this application.
154      *
155      * @param slots Indicates the created NotificationSlot.
156      * @return Returns ERR_OK on success, others on failure.
157      */
158     ErrCode GetSlots(std::vector<sptr<NotificationSlot>> &slots) override;
159 
160     /**
161      * @brief Obtains the number of slot.
162      *
163      * @param bundleOption Indicates the bundle name and uid of the application.
164      * @param num Indicates the number of slot.
165      * @return Returns ERR_OK on success, others on failure.
166      */
167     ErrCode GetSlotNumAsBundle(const sptr<NotificationBundleOption> &bundleOption, uint64_t &num) override;
168 
169     /**
170      * @brief Obtains active notifications of the current application in the system.
171      *
172      * @param notifications Indicates active NotificationRequest objects of the current application.
173      * @param instanceKey Indicates the application instance key.
174      * @return Returns ERR_OK on success, others on failure.
175      */
176     ErrCode GetActiveNotifications(std::vector<sptr<NotificationRequest>> &notifications,
177         const std::string &instanceKey) override;
178 
179     /**
180      * @brief Obtains the number of active notifications of the current application in the system.
181      *
182      * @param num Indicates the number of active notifications of the current application.
183      * @return Returns ERR_OK on success, others on failure.
184      */
185     ErrCode GetActiveNotificationNums(uint64_t &num) override;
186 
187     /**
188      * @brief Obtains all active notifications in the current system. The caller must have system permissions to
189      * call this method.
190      *
191      * @param notifications Indicates all active notifications of this application.
192      * @return Returns ERR_OK on success, others on failure.
193      */
194     ErrCode GetAllActiveNotifications(std::vector<sptr<Notification>> &notifications) override;
195 
196     ErrCode GetAllNotificationsBySlotType(std::vector<sptr<Notification>> &notifications,
197         const NotificationConstant::SlotType slotType) override;
198 
199     /**
200      * @brief Obtains the active notifications corresponding to the specified key in the system. To call this method
201      * to obtain particular active notifications, you must have received the notifications and obtained the key
202      * via {Notification::GetKey()}.
203      *
204      * @param key Indicates the key array for querying corresponding active notifications.
205      *            If this parameter is null, this method returns all active notifications in the system.
206      * @param notification Indicates the set of active notifications corresponding to the specified key.
207      * @return Returns ERR_OK on success, others on failure.
208      */
209     ErrCode GetSpecialActiveNotifications(
210         const std::vector<std::string> &key, std::vector<sptr<Notification>> &notifications) override;
211 
212     /**
213      * @brief Obtains the live view notification extra info by the extraInfoKeys. To call this method
214      * to obtain particular live view notification extra info, you must have received the
215      *
216      * @param bundleOption Indicates the bundle name and uid of the application.
217      * @param notificationId Indicates the id of the notification to get the extra info by extra info keys.
218      * @param label
219      * @param extraInfoKeys
220      * @param extraInfo
221      * @return
222      */
223     ErrCode GetActiveNotificationByFilter(
224         const sptr<NotificationBundleOption> &bundleOption, const int32_t notificationId, const std::string &label,
225         const std::vector<std::string> extraInfoKeys, sptr<NotificationRequest> &request) override;
226 
227     /**
228      * @brief Checks whether your application has permission to publish notifications by calling
229      * PublishNotificationAsBundle(string, NotificationRequest) in the name of another application indicated by the
230      * given representativeBundle.
231      *
232      * @param representativeBundle Indicates the name of application bundle your application is representing.
233      * @param canPublish Indicates whether your application has permission to publish notifications.
234      * @return Returns ERR_OK on success, others on failure.
235      */
236     ErrCode CanPublishAsBundle(const std::string &representativeBundle, bool &canPublish) override;
237 
238     /**
239      * @brief Publishes a notification in the name of a specified application bundle.
240      * @note If the notification to be published has the same ID as a published notification that has not been canceled,
241      * the existing notification will be replaced by the new one.
242      *
243      * @param notification Indicates the NotificationRequest object for setting the notification content.
244      *                This parameter must be specified.
245      * @param representativeBundle Indicates the name of the application bundle that allows your application to publish
246      *                             notifications for it by calling setNotificationAgent.
247      * @return Returns ERR_OK on success, others on failure.
248      */
249     ErrCode PublishAsBundle(
250         const sptr<NotificationRequest> notification, const std::string &representativeBundle) override;
251 
252     /**
253      * @brief Sets the number of active notifications of the current application as the number to be displayed on the
254      * notification badge.
255      *
256      * @param num Indicates the badge number.
257      * @return Returns ERR_OK on success, others on failure.
258      */
259     ErrCode SetNotificationBadgeNum(int32_t num) override;
260 
261     /**
262      * @brief Obtains the importance level of this application.
263      *
264      * @param importance Indicates the importance level of this application, which can be LEVEL_NONE,
265                LEVEL_MIN, LEVEL_LOW, LEVEL_DEFAULT, LEVEL_HIGH, or LEVEL_UNDEFINED.
266      * @return Returns ERR_OK on success, others on failure.
267      */
268     ErrCode GetBundleImportance(int32_t &importance) override;
269 
270     /**
271      * @brief Checks whether this application has permission to modify the Do Not Disturb (DND) notification policy.
272      *
273      * @param granted True if the application has permission; false for otherwise.
274      * @return Returns ERR_OK on success, others on failure.
275      */
276     ErrCode HasNotificationPolicyAccessPermission(bool &granted) override;
277 
278     /**
279      * @brief Trigger the local live view after the button has been clicked.
280      * @note Your application must have platform signature to use this method.
281      *
282      * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked.
283      * @param notificationId Indicates the id of the notification.
284      * @param buttonOption Indicates which button has been clicked.
285      * @return Returns trigger localLiveView result.
286      */
287     ErrCode TriggerLocalLiveView(const sptr<NotificationBundleOption> &bundleOption,
288         const int32_t notificationId, const sptr<NotificationButtonOption> &buttonOption) override;
289 
290     /**
291      * @brief Delete notification.
292      *
293      * @param bundleOption Indicates the NotificationBundleOption of the notification.
294      * @param notificationId Indicates the id of the notification.
295      * @param label Indicates the label of the notification.
296      * @param removeReason Indicates the reason of remove notification.
297      * @return Returns ERR_OK on success, others on failure.
298      */
299     ErrCode RemoveNotification(const sptr<NotificationBundleOption> &bundleOption, int32_t notificationId,
300         const std::string &label, int32_t removeReason) override;
301 
302     /**
303      * @brief Delete all notifications.
304      *
305      * @param bundleOption Indicates the NotificationBundleOption of notifications.
306      * @return Returns ERR_OK on success, others on failure.
307      */
308     ErrCode RemoveAllNotifications(const sptr<NotificationBundleOption> &bundleOption) override;
309 
310     ErrCode RemoveNotifications(const std::vector<std::string> &hashcodes, int32_t removeReason) override;
311 
312     /**
313      * @brief Delete notification based on key.
314      *
315      * @param key Indicates the key to delete notification.
316      * @param removeReason Indicates the reason of remove notification.
317      * @return Returns ERR_OK on success, others on failure.
318      */
319     ErrCode Delete(const std::string &key, int32_t removeReason) override;
320 
321     /**
322      * @brief Remove notifications based on bundle.
323      *
324      * @param bundleOption Indicates the NotificationBundleOption of notifications.
325      * @return Returns ERR_OK on success, others on failure.
326      */
327     ErrCode DeleteByBundle(const sptr<NotificationBundleOption> &bundleOption) override;
328 
329     /**
330      * @brief Remove all notifications.
331      *
332      * @return Returns ERR_OK on success, others on failure.
333      */
334     ErrCode DeleteAll() override;
335 
336     /**
337      * @brief Get all the slots corresponding to the bundle.
338      *
339      * @param bundleOption Indicates the NotificationBundleOption object.
340      * @param slots Indicates the notification slots.
341      * @return Returns ERR_OK on success, others on failure.
342      */
343     ErrCode GetSlotsByBundle(
344         const sptr<NotificationBundleOption> &bundleOption, std::vector<sptr<NotificationSlot>> &slots) override;
345 
346     /**
347      * @brief Get the specified slot corresponding to the bundle.
348      *
349      * @param bundleOption Indicates the NotificationBundleOption object.
350      * @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot(NotificationSlot). This
351      *        parameter must be specified.
352      * @param slot Indicates the notification slot.
353      * @return Returns ERR_OK on success, others on failure.
354      */
355     ErrCode GetSlotByBundle(
356         const sptr<NotificationBundleOption> &bundleOption, const NotificationConstant::SlotType &slotType,
357         sptr<NotificationSlot> &slot) override;
358 
359     /**
360      * @brief Update slots according to bundle.
361      *
362      * @param bundleOption Indicates the NotificationBundleOption object.
363      * @param slots Indicates the notification slots to be updated.
364      * @return Returns ERR_OK on success, others on failure.
365      */
366     ErrCode UpdateSlots(
367         const sptr<NotificationBundleOption> &bundleOption, const std::vector<sptr<NotificationSlot>> &slots) override;
368 
369     /**
370      * @brief Allow notifications to be sent based on the deviceId.
371      *
372      * @param deviceId Indicates the device Id.
373      * @return Returns ERR_OK on success, others on failure.
374      */
375     ErrCode RequestEnableNotification(const std::string &deviceId,
376         const sptr<AnsDialogCallback> &callback,
377         const sptr<IRemoteObject> &callerToken) override;
378 
379     /**
380      * @brief Allow application to publish notifications.
381      *
382      * @param bundleName bundle name.
383      * @param uid uid.
384      * @return Returns set notifications enabled for the bundle result.
385      */
386     ErrCode RequestEnableNotification(const std::string bundleName, const int32_t uid) override;
387 
388     /**
389      * @brief Set whether to allow the specified deviceId to send notifications for current bundle.
390      *
391      * @param deviceId Indicates the device Id.
392      * @param enabled Indicates the flag that allows notification to be pulished.
393      * @return Returns ERR_OK on success, others on failure.
394      */
395     ErrCode SetNotificationsEnabledForBundle(const std::string &deviceId, bool enabled) override;
396 
397     /**
398      * @brief Set whether to allow the specified deviceId to send notifications for all bundles.
399      *
400      * @param deviceId Indicates the device Id.
401      * @param enabled Indicates the flag that allows notification to be pulished.
402      * @return Returns ERR_OK on success, others on failure.
403      */
404     ErrCode SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled) override;
405 
406     /**
407      * @brief Set whether to allow the specified bundle to send notifications.
408      *
409      * @param bundleOption Indicates the NotificationBundleOption object.
410      * @param enabled Indicates the flag that allows notification to be pulished.
411      * @return Returns ERR_OK on success, others on failure.
412      */
413     ErrCode SetNotificationsEnabledForSpecialBundle(
414         const std::string &deviceId, const sptr<NotificationBundleOption> &bundleOption, bool enabled) override;
415 
416     /**
417      * @brief Sets whether the bundle allows the banner to display notification.
418      *
419      * @param bundleOption Indicates the NotificationBundleOption object.
420      * @param enabled Indicates the flag that allows badge to be shown.
421      * @return Returns ERR_OK on success, others on failure.
422      */
423     ErrCode SetShowBadgeEnabledForBundle(const sptr<NotificationBundleOption> &bundleOption, bool enabled) override;
424 
425     /**
426      * @brief Gets whether the bundle allows the badge to display the status of notifications.
427      *
428      * @param bundleOption Indicates the NotificationBundleOption object.
429      * @param enabled Indicates the flag that allows badge to be shown.
430      * @return Returns ERR_OK on success, others on failure.
431      */
432     ErrCode GetShowBadgeEnabledForBundle(const sptr<NotificationBundleOption> &bundleOption, bool &enabled) override;
433 
434     /**
435      * @brief Gets whether allows the badge to display the status of notifications.
436      *
437      * @param enabled Indicates the flag that allows badge to be shown.
438      * @return Returns ERR_OK on success, others on failure.
439      */
440     ErrCode GetShowBadgeEnabled(bool &enabled) override;
441 
442     /**
443      * @brief Subscribes notifications.
444      *
445      * @param subscriber Indicates the subscriber.
446      * @param info Indicates the NotificationSubscribeInfo object.
447      * @return Returns ERR_OK on success, others on failure.
448      */
449     ErrCode Subscribe(const sptr<AnsSubscriberInterface> &subscriber,
450         const sptr<NotificationSubscribeInfo> &info) override;
451 
452     /**
453      * @brief Subscribes notifications self.
454      *
455      * @param subscriber Indicates the subscriber.
456      * @param info Indicates the NotificationSubscribeInfo object.
457      * @return Returns ERR_OK on success, others on failure.
458      */
459     ErrCode SubscribeSelf(const sptr<AnsSubscriberInterface> &subscriber) override;
460 
461     /**
462      * @brief Subscribes notifications.
463      *
464      * @param subscriber Indicates the subscriber.
465      * @param info Indicates the NotificationSubscribeInfo object.
466      * @return Returns ERR_OK on success, others on failure.
467      */
468     ErrCode SubscribeLocalLiveView(const sptr<AnsSubscriberLocalLiveViewInterface> &subscriber,
469         const sptr<NotificationSubscribeInfo> &info, const bool isNative) override;
470 
471     /**
472      * @brief Unsubscribes notifications.
473      *
474      * @param subscriber Indicates the subscriber.
475      * @param info Indicates the NotificationSubscribeInfo object.
476      * @return Returns ERR_OK on success, others on failure.
477      */
478     ErrCode Unsubscribe(const sptr<AnsSubscriberInterface> &subscriber,
479         const sptr<NotificationSubscribeInfo> &info) override;
480 
481     /**
482      * @brief Checks whether this device is allowed to publish notifications.
483      *
484      * @param allowed Indicates the flag that allows notification.
485      * @return Returns ERR_OK on success, others on failure.
486      */
487     ErrCode IsAllowedNotify(bool &allowed) override;
488 
489     /**
490      * @brief Checks whether this application is allowed to publish notifications.
491      *
492      * @param allowed Indicates the flag that allows notification.
493      * @return Returns ERR_OK on success, others on failure.
494      */
495     ErrCode IsAllowedNotifySelf(bool &allowed) override;
496 
497     /**
498      * @brief Checks whether this application can pop enable notification dialog.
499      *
500      * @param  canPop True if can pop enable notification dialog
501      * @return Returns is canPop result.
502      */
503     ErrCode CanPopEnableNotificationDialog(const sptr<AnsDialogCallback> &callback,
504         bool &canPop, std::string &bundleName) override;
505 
506     /**
507      * @brief remove enable notification dialog.
508      *
509      * @return Returns remove dialog result.
510      */
511     ErrCode RemoveEnableNotificationDialog() override;
512 
513     /**
514      * @brief Checks whether notifications are allowed for a specific bundle.
515      *
516      * @param bundleOption Indicates the NotificationBundleOption object.
517      * @param allowed Indicates the flag that allows notification.
518      * @return Returns ERR_OK on success, others on failure.
519      */
520     ErrCode IsSpecialBundleAllowedNotify(const sptr<NotificationBundleOption> &bundleOption, bool &allowed) override;
521 
522     /**
523      * @brief Set do not disturb date.
524      *
525      * @param date Indicates the NotificationDoNotDisturbDate object.
526      * @return Returns ERR_OK on success, others on failure.
527      */
528     ErrCode SetDoNotDisturbDate(const sptr<NotificationDoNotDisturbDate> &date) override;
529 
530     /**
531      * @brief Get do not disturb date.
532      *
533      * @param date Indicates the NotificationDoNotDisturbDate object.
534      * @return Returns ERR_OK on success, others on failure.
535      */
536     ErrCode GetDoNotDisturbDate(sptr<NotificationDoNotDisturbDate> &date) override;
537 
538     /**
539      * @brief Add do not disturb Profiles.
540      *
541      * @param profiles Indicates the NotificationDoNotDisturbProfile objects.
542      * @return Returns ERR_OK on success, others on failure.
543      */
544     ErrCode AddDoNotDisturbProfiles(const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles) override;
545 
546     /**
547      * @brief Remove do not disturb Profiles.
548      *
549      * @param profiles Indicates the NotificationDoNotDisturbProfile objects.
550      * @return Returns ERR_OK on success, others on failure.
551      */
552     ErrCode RemoveDoNotDisturbProfiles(const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles) override;
553 
554     /**
555      * @brief Get whether Do Not Disturb mode is supported.
556      *
557      * @param doesSupport Indicates the flag that supports DND mode.
558      * @return Returns ERR_OK on success, others on failure.
559      */
560     ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport) override;
561 
562     /**
563      * @brief Is coming call need silent in do not disturb mode.
564      *
565      * @param phoneNumber the calling format number.
566      * @return Returns silent in do not disturb mode.
567      */
568     ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType) override;
569 
570     /**
571      * @brief Cancel notifications according to group.
572      *
573      * @param groupName Indicates the group name.
574      * @param instanceKey Indicates the application instance key.
575      * @return Returns ERR_OK on success, others on failure.
576      */
577     ErrCode CancelGroup(const std::string &groupName, const std::string &instanceKey) override;
578 
579     /**
580      * @brief Delete notifications according to bundle and group.
581      *
582      * @param bundleOption Indicates the NotificationBundleOption object.
583      * @param groupName Indicates the group name.
584      * @return Returns ERR_OK on success, others on failure.
585      */
586     ErrCode RemoveGroupByBundle(
587         const sptr<NotificationBundleOption> &bundleOption, const std::string &groupName) override;
588 
589     /**
590      * @brief Gets whether distributed notification is enabled.
591      *
592      * @param enabled Indicates the enabled flag.
593      * @return Returns ERR_OK on success, others on failure.
594      */
595     ErrCode IsDistributedEnabled(bool &enabled) override;
596 
597     /**
598      * @brief Sets distributed notification enabled or disabled.
599      *
600      * @param enabled Indicates the enabled flag.
601      * @return Returns ERR_OK on success, others on failure.
602      */
603     ErrCode EnableDistributed(bool enabled) override;
604 
605     /**
606      * @brief Sets distributed notification enabled or disabled for specific bundle.
607      *
608      * @param bundleOption Indicates the NotificationBundleOption object.
609      * @param enabled Indicates the enabled flag.
610      * @return Returns ERR_OK on success, others on failure.
611      */
612     ErrCode EnableDistributedByBundle(const sptr<NotificationBundleOption> &bundleOption, bool enabled) override;
613 
614     /**
615      * @brief Sets distributed notification enabled or disabled for current bundle.
616      *
617      * @param enabled Indicates the enabled flag.
618      * @return Returns ERR_OK on success, others on failure.
619      */
620     ErrCode EnableDistributedSelf(bool enabled) override;
621 
622     /**
623      * @brief Gets whether distributed notification is enabled for specific bundle.
624      *
625      * @param bundleOption Indicates the NotificationBundleOption object.
626      * @param enabled Indicates the enabled flag.
627      * @return Returns ERR_OK on success, others on failure.
628      */
629     ErrCode IsDistributedEnableByBundle(const sptr<NotificationBundleOption> &bundleOption, bool &enabled) override;
630 
631     /**
632      * @brief Get the reminder type of the current device.
633      *
634      * @param remindType Reminder type for the device.
635      * @return Returns ERR_OK on success, others on failure.
636      */
637     ErrCode GetDeviceRemindType(NotificationConstant::RemindType &remindType) override;
638 
639     /**
640      * @brief Publishes a continuous notification.
641      *
642      * @param request Notification requests that need to be posted.
643      * @return Returns ERR_OK on success, others on failure.
644      */
645     ErrCode PublishContinuousTaskNotification(const sptr<NotificationRequest> &request) override;
646 
647     /**
648      * @brief Cancels a continuous notification.
649      *
650      * @param label Identifies the label of the specified notification.
651      * @param notificationId Identifies the id of the specified notification.
652      * @return Returns ERR_OK on success, others on failure.
653      */
654     ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) override;
655 
656     /**
657      * @brief Checks whether this device is support template.
658      *
659      * @param templateName Identifies the template name for searching as a condition.
660      * @param support Identifies the support flag.
661      * @return Returns ERR_OK on success, others on failure.
662      */
663     ErrCode IsSupportTemplate(const std::string &templateName, bool &support) override;
664 
665     /**
666      * @brief Checks Whether the specified users is allowed to publish notifications.
667      *
668      * @param userId Identifies the user's id.
669      * @param allowed Identifies the allowed flag.
670      * @return Returns ERR_OK on success, others on failure.
671      */
672     ErrCode IsSpecialUserAllowedNotify(const int32_t &userId, bool &allowed) override;
673 
674     /**
675      * @brief Sets whether to allow all applications to publish notifications on a specified device. The caller must
676      * have system permissions to call this method.
677      *
678      * @param deviceId Indicates the ID of the device running the application. At present, this parameter can only
679      *                 be null or an empty string, indicating the current device.
680      * @param enabled Specifies whether to allow all applications to publish notifications. The value true
681      *                indicates that notifications are allowed, and the value false indicates that notifications
682      *                are not allowed.
683      * @return Returns ERR_OK on success, others on failure.
684      */
685     ErrCode SetNotificationsEnabledByUser(const int32_t &userId, bool enabled) override;
686 
687     /**
688      * @brief Delete all notifications by user.
689      *
690      * @param userId Indicates the user id.
691      * @return Returns ERR_OK on success, others on failure.
692      */
693     ErrCode DeleteAllByUser(const int32_t &userId) override;
694 
695     /**
696      * @brief Set do not disturb date by user.
697      *
698      * @param userId Indicates the user id.
699      * @param date Indicates NotificationDoNotDisturbDate object.
700      * @return Returns ERR_OK on success, others on failure.
701      */
702     ErrCode SetDoNotDisturbDate(const int32_t &userId, const sptr<NotificationDoNotDisturbDate> &date) override;
703 
704     /**
705      * @brief Get the do not disturb date by user.
706      *
707      * @param userId Indicates the user id.
708      * @param date Indicates the NotificationDoNotDisturbDate object.
709      * @return Returns ERR_OK on success, others on failure.
710      */
711     ErrCode GetDoNotDisturbDate(const int32_t &userId, sptr<NotificationDoNotDisturbDate> &date) override;
712     ErrCode SetEnabledForBundleSlot(const sptr<NotificationBundleOption> &bundleOption,
713         const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) override;
714     ErrCode GetEnabledForBundleSlot(const sptr<NotificationBundleOption> &bundleOption,
715         const NotificationConstant::SlotType &slotType, bool &enabled) override;
716     ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) override;
717 
718     /**
719      * @brief Obtains specific datas via specified dump option.
720      *
721      * @param cmd Indicates the specified dump command.
722      * @param bundle Indicates the specified bundle name.
723      * @param userId Indicates the specified userId.
724      * @param dumpInfo Indicates the container containing datas.
725      * @return Returns check result.
726      */
727     ErrCode ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, int32_t recvUserId,
728         std::vector<std::string> &dumpInfo) override;
729 
730     /**
731      * @brief Set whether to sync notifications to devices that do not have the app installed.
732      *
733      * @param userId Indicates the specific user.
734      * @param enabled Allow or disallow sync notifications.
735      * @return Returns set enabled result.
736      */
737     ErrCode SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled) override;
738 
739     /**
740      * @brief Obtains whether to sync notifications to devices that do not have the app installed.
741      *
742      * @param userId Indicates the specific user.
743      * @param enabled Allow or disallow sync notifications.
744      * @return Returns get enabled result.
745      */
746     ErrCode GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled) override;
747 
748     /**
749      * @brief Set badge number.
750      *
751      * @param badgeNumber The badge number.
752      * @return Returns set badge number result.
753      */
754     ErrCode SetBadgeNumber(int32_t badgeNumber, const std::string &instanceKey) override;
755 
756     /**
757      * @brief Set badge number by bundle.
758      *
759      * @param bundleOption Indicates the bundle name and uid of the application.
760      * @param badgeNumber The badge number.
761      * @return Returns set badge number by bundle result.
762      */
763     ErrCode SetBadgeNumberByBundle(const sptr<NotificationBundleOption> &bundleOption, int32_t badgeNumber) override;
764 
765     /**
766      * @brief Set badge number for dh by bundle.
767      *
768      * @param bundleOption Indicates the bundle name and uid of the application.
769      * @param badgeNumber The badge number.
770      * @return Returns set badge number by bundle result.
771      */
772     ErrCode SetBadgeNumberForDhByBundle(
773         const sptr<NotificationBundleOption> &bundleOption, int32_t badgeNumber) override;
774 
775     /**
776      * @brief Get the slotFlags of slot.
777      *
778      * @param bundleOption Indicates the bundle name and uid of the application.
779      * @param slot      Indicates the specified slot object
780      * @param slotFlags Indicates the slogFlags of slot to get.
781      * @return Returns ERR_OK on success, others on failure.
782      */
783     ErrCode GetSlotFlagsAsBundle(const sptr<NotificationBundleOption> &bundleOption, uint32_t &slotFlags) override;
784 
785     /**
786      * @brief Set the slotFlags of slot.
787      *
788      * @param bundleOption Indicates the bundle name and uid of the application.
789      * @param slot      Indicates the specified slot object
790      * @param slotFlags Indicates the slogFlags of slot to set.
791      * @return Returns ERR_OK on success, others on failure.
792      */
793     ErrCode SetSlotFlagsAsBundle(const sptr<NotificationBundleOption> &bundleOption, uint32_t slotFlags) override;
794 
795     /**
796      * @brief Obtains allow notification application list.
797      *
798      * @param bundleOption Indicates the bundle bundleOption.
799      * @return Returns ERR_OK on success, others on failure.
800      */
801     ErrCode GetAllNotificationEnabledBundles(std::vector<NotificationBundleOption> &bundleOption) override;
802 
803     /**
804      * @brief Obtains allow liveview application list.
805      *
806      * @param bundleOption Indicates the bundle bundleOption.
807      * @return Returns ERR_OK on success, others on failure.
808      */
809     ErrCode GetAllLiveViewEnabledBundles(std::vector<NotificationBundleOption> &bundleOption) override;
810 
811     /**
812      * @brief Obtains allow distributed application list.
813      *
814      * @param deviceType Indicates device type.
815      * @param bundleOption Indicates the bundle bundleOption.
816      * @return Returns ERR_OK on success, others on failure.
817      */
818     ErrCode GetAllDistribuedEnabledBundles(const std::string& deviceType,
819         std::vector<NotificationBundleOption> &bundleOption) override;
820 
821     /**
822      * @brief Register Push Callback.
823      *
824      * @param pushCallback PushCallBack.
825      * @param notificationCheckRequest Filter conditions for push check.
826      * @return Returns register PushCallback result.
827      */
828     ErrCode RegisterPushCallback(const sptr<IRemoteObject> &pushCallback,
829         const sptr<NotificationCheckRequest> &notificationCheckRequest) override;
830 
831     /**
832      * @brief Unregister Push Callback.
833      *
834      * @return Returns unregister push Callback result.
835      */
836     ErrCode UnregisterPushCallback() override;
837 
838     /**
839      * @brief Set agent relationship.
840      *
841      * @param key Indicates storing agent relationship if the value is "PROXY_PKG".
842      * @param value Indicates key-value pair of agent relationship.
843      * @return Returns set result.
844      */
845     ErrCode SetAdditionConfig(const std::string &key, const std::string &value) override;
846 
847     /**
848      * @brief Sets whether to allow a specified application to publish notifications cross
849      * device collaboration. The caller must have system permissions to call this method.
850      *
851      * @param bundleOption Indicates the bundle name and uid of the application.
852      * @param deviceType Indicates the type of the device running the application.
853      * @param enabled Specifies whether to allow the given application to publish notifications. The value
854      *                true indicates that notifications are allowed, and the value false indicates that
855      *                notifications are not allowed.
856      * @return Returns set notifications enabled for specified bundle result.
857      */
858     ErrCode SetDistributedEnabledByBundle(
859         const sptr<NotificationBundleOption> &bundleOption, const std::string &deviceType, const bool enabled) override;
860 
861     /**
862      * @brief get whether to allow a specified application to publish notifications cross
863      * device collaboration. The caller must have system permissions to call this method.
864      *
865      * @param bundleOption Indicates the bundle name and uid of the application.
866      * @param deviceType Indicates the type of the device running the application.
867      * @param enabled Specifies whether to allow the given application to publish notifications. The value
868      *                true indicates that notifications are allowed, and the value false indicates that
869      *                notifications are not allowed.
870      * @return Returns set notifications enabled for specified bundle result.
871      */
872     ErrCode IsDistributedEnabledByBundle(
873         const sptr<NotificationBundleOption> &bundleOption, const std::string &deviceType, bool &enabled) override;
874 
875     /**
876      * @brief Get Enable smartphone to collaborate with other devices for intelligent reminders
877      *
878      * @param deviceType Indicates the type of the device running the application.
879      * @param enabled Specifies whether to allow the given device to publish notifications.
880      *                The value true indicates that notifications are allowed, and the value
881      *                false indicates that notifications are not allowed.
882      * @return Returns set notifications enabled for specified bundle result.
883      */
884     ErrCode IsSmartReminderEnabled(const std::string &deviceType, bool &enabled) override;
885 
886     /**
887      * @brief Set Enable smartphone to collaborate with other devices for intelligent reminders
888      *
889      * @param deviceType Indicates the type of the device running the application.
890      * @param enabled Specifies whether to allow the given device to publish notifications.
891      *                The value true indicates that notifications are allowed, and the value
892      *                false indicates that notifications are not allowed.
893      * @return Returns set notifications enabled for specified bundle result.
894      */
895     ErrCode SetSmartReminderEnabled(const std::string &deviceType, const bool enabled) override;
896 
897     /**
898      * @brief Set the channel switch for collaborative reminders.
899        The caller must have system permissions to call this method.
900      *
901      * @param slotType Indicates the slot type of the application.
902      * @param deviceType Indicates the type of the device running the application.
903      * @param enabled Indicates slot switch status.
904      * @return Returns set channel switch result.
905      */
906     ErrCode SetDistributedEnabledBySlot(
907         const NotificationConstant::SlotType &slotType, const std::string &deviceType, const bool enabled) override;
908 
909     /**
910      * @brief Query the channel switch for collaborative reminders.
911        The caller must have system permissions to call this method.
912      *
913      * @param slotType Indicates the slot type of the application.
914      * @param deviceType Indicates the type of the device running the application.
915      * @param enabled Indicates slot switch status.
916      * @return Returns channel switch result.
917      */
918     ErrCode IsDistributedEnabledBySlot(
919         const NotificationConstant::SlotType &slotType, const std::string &deviceType, bool &enabled) override;
920 
921     /**
922      * @brief Cancels a published agent notification.
923      *
924      * @param bundleOption Indicates the bundle name and uid of the application.
925      * @param id Indicates the unique notification ID in the application.
926      * @return Returns cancel result.
927      */
928     ErrCode CancelAsBundleWithAgent(const sptr<NotificationBundleOption> &bundleOption, const int32_t id) override;
929 
930     /**
931      * @brief Set the status of the target device.
932      *
933      * @param deviceType Type of the device whose status you want to set.
934      * @param status The status.
935      * @return Returns set result.
936      */
937     ErrCode SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status) override;
938 
939     /**
940      * @brief Set the status of the target device.
941      *
942      * @param deviceType Type of the device whose status you want to set.
943      * @param status The status.
944      * @param controlFlag The control flag.
945      * @return Returns set result.
946      */
947     ErrCode SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status,
948         const uint32_t controlFlag) override;
949 
950     /**
951      * @brief Get do not disturb profile by id.
952      *
953      * @param id Profile id.
954      * @param status Indicates the NotificationDoNotDisturbProfile objects.
955      * @return Returns ERR_OK on success, others on failure.
956      */
957     ErrCode GetDoNotDisturbProfile(int32_t id, sptr<NotificationDoNotDisturbProfile> &profile) override;
958 
959     /**
960      * @brief Whether reminders are allowed.
961      *
962      * @param bundleName app bundleName
963      * @param isAllowUseReminder is allow use reminder
964      * @return Returns ERR_OK on success, others on failure.
965      */
966     ErrCode AllowUseReminder(const std::string& bundleName, bool& isAllowUseReminder) override;
967 
968 #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED
969     /**
970      * @brief Register Swing Callback.
971      *
972      * @param swingCallback SwingCallBack.
973      * @return Returns register SwingCallback result.
974      */
975     ErrCode RegisterSwingCallback(const sptr<IRemoteObject> &swingCallback) override;
976 #endif
977 
978     /**
979      * @brief Update Notification Timer by uid.
980      *
981      * @param uid uid.
982      * @return Returns Update result.
983      */
984     ErrCode UpdateNotificationTimerByUid(const int32_t uid, const bool isPaused) override;
985 
986     /**
987      * @brief Set switch and bundle list of disable notification feature.
988      *
989      * @param notificationDisable Switch and bundle list of disable notification feature.
990      * @return Returns set result.
991      */
992     ErrCode DisableNotificationFeature(const sptr<NotificationDisable> &notificationDisable) override;
993 
994     /**
995      * @brief Get the status of the target device.
996      *
997      * @param deviceType Type of the device whose status you want to set.
998      * @param status The status.
999      * @return Returns set result.
1000      */
1001     ErrCode GetTargetDeviceStatus(const std::string &deviceType, int32_t &status) override;
1002 
1003     /**
1004      * @brief Distribution operation based on hashCode.
1005      *
1006      * @param hashCode Unique ID of the notification.
1007      * @return Returns ERR_OK on success, others on failure.
1008      */
1009     ErrCode DistributeOperation(sptr<NotificationOperationInfo>& operationInfo,
1010         const sptr<OperationCallbackInterface> &callback) override;
1011 
1012     /**
1013      * @brief Reply distribute operation.
1014      *
1015      * @param hashCode Unique ID of the notification.
1016      * @param result The result of the distribute operation.
1017      * @return Returns ERR_OK on success, others on failure.
1018      */
1019     ErrCode ReplyDistributeOperation(const std::string& hashCode, const int32_t result) override;
1020 
1021     /**
1022      * @brief Get notificationRequest by hashCode.
1023      *
1024      * @param hashCode Unique ID of the notification.
1025      * @param notificationRequest The request of of the notification.
1026      * @return Returns ERR_OK on success, others on failure.
1027      */
1028     ErrCode GetNotificationRequestByHashCode(
1029         const std::string& hashCode, sptr<NotificationRequest>& notificationRequest) override;
1030 
1031     /**
1032      * @brief set rule of generate hashCode.
1033      *
1034      * @param type generate hashCode.
1035      * @return Returns ERR_OK on success, others on failure.
1036      */
1037     ErrCode SetHashCodeRule(const uint32_t type) override;
1038 
1039 private:
1040     ErrCode InnerTransact(NotificationInterfaceCode code, MessageOption &flags,
1041         MessageParcel &data, MessageParcel &reply);
1042 
1043     template<typename T>
WriteParcelableVector(const std::vector<sptr<T>> & parcelableVector,MessageParcel & data)1044     bool WriteParcelableVector(const std::vector<sptr<T>> &parcelableVector, MessageParcel &data)
1045     {
1046         if (!data.WriteInt32(parcelableVector.size())) {
1047             ANS_LOGE("Failed to write ParcelableVector size.");
1048             return false;
1049         }
1050 
1051         for (auto &parcelable : parcelableVector) {
1052             if (!data.WriteStrongParcelable(parcelable)) {
1053                 ANS_LOGE("Failed to write ParcelableVector");
1054                 return false;
1055             }
1056         }
1057         return true;
1058     }
1059 
1060     template<typename T>
ReadParcelableVector(std::vector<sptr<T>> & parcelableInfos,MessageParcel & reply,ErrCode & result)1061     bool ReadParcelableVector(std::vector<sptr<T>> &parcelableInfos, MessageParcel &reply, ErrCode &result)
1062     {
1063         if (!reply.ReadInt32(result)) {
1064             ANS_LOGE("read result failed.");
1065             return false;
1066         }
1067 
1068         int32_t infoSize = 0;
1069         if (!reply.ReadInt32(infoSize)) {
1070             ANS_LOGE("read Parcelable size failed.");
1071             return false;
1072         }
1073 
1074         parcelableInfos.clear();
1075         infoSize = (infoSize < MAX_PARCELABLE_VECTOR_NUM) ? infoSize : MAX_PARCELABLE_VECTOR_NUM;
1076         for (int32_t index = 0; index < infoSize; index++) {
1077             sptr<T> info = reply.ReadStrongParcelable<T>();
1078             if (info == nullptr) {
1079                 ANS_LOGE("read Parcelable infos failed.");
1080                 return false;
1081             }
1082             parcelableInfos.emplace_back(info);
1083         }
1084 
1085         return true;
1086     }
1087     static inline BrokerDelegator<AnsManagerProxy> delegator_;
1088 
1089     ErrCode ReadReminders(uint8_t &count, MessageParcel &reply, std::vector<sptr<ReminderRequest>> &reminders);
1090 };
1091 }  // namespace Notification
1092 }  // namespace OHOS
1093 
1094 #endif  // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_MANAGER_PROXY_H
1095