• 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     /**
197      * @brief Obtains the active notifications corresponding to the specified key in the system. To call this method
198      * to obtain particular active notifications, you must have received the notifications and obtained the key
199      * via {Notification::GetKey()}.
200      *
201      * @param key Indicates the key array for querying corresponding active notifications.
202      *            If this parameter is null, this method returns all active notifications in the system.
203      * @param notification Indicates the set of active notifications corresponding to the specified key.
204      * @return Returns ERR_OK on success, others on failure.
205      */
206     ErrCode GetSpecialActiveNotifications(
207         const std::vector<std::string> &key, std::vector<sptr<Notification>> &notifications) override;
208 
209     /**
210      * @brief Obtains the live view notification extra info by the extraInfoKeys. To call this method
211      * to obtain particular live view notification extra info, you must have received the
212      *
213      * @param bundleOption Indicates the bundle name and uid of the application.
214      * @param notificationId Indicates the id of the notification to get the extra info by extra info keys.
215      * @param label
216      * @param extraInfoKeys
217      * @param extraInfo
218      * @return
219      */
220     ErrCode GetActiveNotificationByFilter(
221         const sptr<NotificationBundleOption> &bundleOption, const int32_t notificationId, const std::string &label,
222         const std::vector<std::string> extraInfoKeys, sptr<NotificationRequest> &request) override;
223 
224     /**
225      * @brief Allows another application to act as an agent to publish notifications in the name of your application
226      * bundle.
227      *
228      * @param agent Indicates the name of the application bundle that can publish notifications for your application.
229      * @return Returns ERR_OK on success, others on failure.
230      */
231     ErrCode SetNotificationAgent(const std::string &agent) override;
232 
233     /**
234      * @brief Obtains the name of the application bundle that can publish notifications in the name of your application.
235      *
236      * @param agent Indicates the name of the application bundle that can publish notifications for your application if
237      * any; returns null otherwise.
238      * @return Returns ERR_OK on success, others on failure.
239      */
240     ErrCode GetNotificationAgent(std::string &agent) override;
241 
242     /**
243      * @brief Checks whether your application has permission to publish notifications by calling
244      * PublishNotificationAsBundle(string, NotificationRequest) in the name of another application indicated by the
245      * given representativeBundle.
246      *
247      * @param representativeBundle Indicates the name of application bundle your application is representing.
248      * @param canPublish Indicates whether your application has permission to publish notifications.
249      * @return Returns ERR_OK on success, others on failure.
250      */
251     ErrCode CanPublishAsBundle(const std::string &representativeBundle, bool &canPublish) override;
252 
253     /**
254      * @brief Publishes a notification in the name of a specified application bundle.
255      * @note If the notification to be published has the same ID as a published notification that has not been canceled,
256      * the existing notification will be replaced by the new one.
257      *
258      * @param notification Indicates the NotificationRequest object for setting the notification content.
259      *                This parameter must be specified.
260      * @param representativeBundle Indicates the name of the application bundle that allows your application to publish
261      *                             notifications for it by calling setNotificationAgent.
262      * @return Returns ERR_OK on success, others on failure.
263      */
264     ErrCode PublishAsBundle(
265         const sptr<NotificationRequest> notification, const std::string &representativeBundle) override;
266 
267     /**
268      * @brief Sets the number of active notifications of the current application as the number to be displayed on the
269      * notification badge.
270      *
271      * @param num Indicates the badge number.
272      * @return Returns ERR_OK on success, others on failure.
273      */
274     ErrCode SetNotificationBadgeNum(int32_t num) override;
275 
276     /**
277      * @brief Obtains the importance level of this application.
278      *
279      * @param importance Indicates the importance level of this application, which can be LEVEL_NONE,
280                LEVEL_MIN, LEVEL_LOW, LEVEL_DEFAULT, LEVEL_HIGH, or LEVEL_UNDEFINED.
281      * @return Returns ERR_OK on success, others on failure.
282      */
283     ErrCode GetBundleImportance(int32_t &importance) override;
284 
285     /**
286      * @brief Checks whether this application has permission to modify the Do Not Disturb (DND) notification policy.
287      *
288      * @param granted True if the application has permission; false for otherwise.
289      * @return Returns ERR_OK on success, others on failure.
290      */
291     ErrCode HasNotificationPolicyAccessPermission(bool &granted) override;
292 
293     /**
294      * @brief Trigger the local live view after the button has been clicked.
295      * @note Your application must have platform signature to use this method.
296      *
297      * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked.
298      * @param notificationId Indicates the id of the notification.
299      * @param buttonOption Indicates which button has been clicked.
300      * @return Returns trigger localLiveView result.
301      */
302     ErrCode TriggerLocalLiveView(const sptr<NotificationBundleOption> &bundleOption,
303         const int32_t notificationId, const sptr<NotificationButtonOption> &buttonOption) override;
304 
305     /**
306      * @brief Delete notification.
307      *
308      * @param bundleOption Indicates the NotificationBundleOption of the notification.
309      * @param notificationId Indicates the id of the notification.
310      * @param label Indicates the label of the notification.
311      * @param removeReason Indicates the reason of remove notification.
312      * @return Returns ERR_OK on success, others on failure.
313      */
314     ErrCode RemoveNotification(const sptr<NotificationBundleOption> &bundleOption, int32_t notificationId,
315         const std::string &label, int32_t removeReason) override;
316 
317     /**
318      * @brief Delete all notifications.
319      *
320      * @param bundleOption Indicates the NotificationBundleOption of notifications.
321      * @return Returns ERR_OK on success, others on failure.
322      */
323     ErrCode RemoveAllNotifications(const sptr<NotificationBundleOption> &bundleOption) override;
324 
325     ErrCode RemoveNotifications(const std::vector<std::string> &hashcodes, int32_t removeReason) override;
326 
327     /**
328      * @brief Delete notification based on key.
329      *
330      * @param key Indicates the key to delete notification.
331      * @param removeReason Indicates the reason of remove notification.
332      * @return Returns ERR_OK on success, others on failure.
333      */
334     ErrCode Delete(const std::string &key, int32_t removeReason) override;
335 
336     /**
337      * @brief Remove notifications based on bundle.
338      *
339      * @param bundleOption Indicates the NotificationBundleOption of notifications.
340      * @return Returns ERR_OK on success, others on failure.
341      */
342     ErrCode DeleteByBundle(const sptr<NotificationBundleOption> &bundleOption) override;
343 
344     /**
345      * @brief Remove all notifications.
346      *
347      * @return Returns ERR_OK on success, others on failure.
348      */
349     ErrCode DeleteAll() override;
350 
351     /**
352      * @brief Get all the slots corresponding to the bundle.
353      *
354      * @param bundleOption Indicates the NotificationBundleOption object.
355      * @param slots Indicates the notification slots.
356      * @return Returns ERR_OK on success, others on failure.
357      */
358     ErrCode GetSlotsByBundle(
359         const sptr<NotificationBundleOption> &bundleOption, std::vector<sptr<NotificationSlot>> &slots) override;
360 
361     /**
362      * @brief Get the specified slot corresponding to the bundle.
363      *
364      * @param bundleOption Indicates the NotificationBundleOption object.
365      * @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot(NotificationSlot). This
366      *        parameter must be specified.
367      * @param slot Indicates the notification slot.
368      * @return Returns ERR_OK on success, others on failure.
369      */
370     ErrCode GetSlotByBundle(
371         const sptr<NotificationBundleOption> &bundleOption, const NotificationConstant::SlotType &slotType,
372         sptr<NotificationSlot> &slot) override;
373 
374     /**
375      * @brief Update slots according to bundle.
376      *
377      * @param bundleOption Indicates the NotificationBundleOption object.
378      * @param slots Indicates the notification slots to be updated.
379      * @return Returns ERR_OK on success, others on failure.
380      */
381     ErrCode UpdateSlots(
382         const sptr<NotificationBundleOption> &bundleOption, const std::vector<sptr<NotificationSlot>> &slots) override;
383 
384     /**
385      * @brief Allow notifications to be sent based on the deviceId.
386      *
387      * @param deviceId Indicates the device Id.
388      * @return Returns ERR_OK on success, others on failure.
389      */
390     ErrCode RequestEnableNotification(const std::string &deviceId,
391         const sptr<AnsDialogCallback> &callback,
392         const sptr<IRemoteObject> &callerToken) override;
393 
394     /**
395      * @brief Set whether to allow the specified deviceId to send notifications for current bundle.
396      *
397      * @param deviceId Indicates the device Id.
398      * @param enabled Indicates the flag that allows notification to be pulished.
399      * @return Returns ERR_OK on success, others on failure.
400      */
401     ErrCode SetNotificationsEnabledForBundle(const std::string &deviceId, bool enabled) override;
402 
403     /**
404      * @brief Set whether to allow the specified deviceId to send notifications for all bundles.
405      *
406      * @param deviceId Indicates the device Id.
407      * @param enabled Indicates the flag that allows notification to be pulished.
408      * @return Returns ERR_OK on success, others on failure.
409      */
410     ErrCode SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled) override;
411 
412     /**
413      * @brief Set whether to allow the specified bundle to send notifications.
414      *
415      * @param bundleOption Indicates the NotificationBundleOption object.
416      * @param enabled Indicates the flag that allows notification to be pulished.
417      * @return Returns ERR_OK on success, others on failure.
418      */
419     ErrCode SetNotificationsEnabledForSpecialBundle(
420         const std::string &deviceId, const sptr<NotificationBundleOption> &bundleOption, bool enabled) override;
421 
422     /**
423      * @brief Sets whether the bundle allows the banner to display notification.
424      *
425      * @param bundleOption Indicates the NotificationBundleOption object.
426      * @param enabled Indicates the flag that allows badge to be shown.
427      * @return Returns ERR_OK on success, others on failure.
428      */
429     ErrCode SetShowBadgeEnabledForBundle(const sptr<NotificationBundleOption> &bundleOption, bool enabled) override;
430 
431     /**
432      * @brief Gets whether the bundle allows the badge to display the status of notifications.
433      *
434      * @param bundleOption Indicates the NotificationBundleOption object.
435      * @param enabled Indicates the flag that allows badge to be shown.
436      * @return Returns ERR_OK on success, others on failure.
437      */
438     ErrCode GetShowBadgeEnabledForBundle(const sptr<NotificationBundleOption> &bundleOption, bool &enabled) override;
439 
440     /**
441      * @brief Gets whether allows the badge to display the status of notifications.
442      *
443      * @param enabled Indicates the flag that allows badge to be shown.
444      * @return Returns ERR_OK on success, others on failure.
445      */
446     ErrCode GetShowBadgeEnabled(bool &enabled) override;
447 
448     /**
449      * @brief Subscribes notifications.
450      *
451      * @param subscriber Indicates the subscriber.
452      * @param info Indicates the NotificationSubscribeInfo object.
453      * @return Returns ERR_OK on success, others on failure.
454      */
455     ErrCode Subscribe(const sptr<AnsSubscriberInterface> &subscriber,
456         const sptr<NotificationSubscribeInfo> &info) override;
457 
458     /**
459      * @brief Subscribes notifications self.
460      *
461      * @param subscriber Indicates the subscriber.
462      * @param info Indicates the NotificationSubscribeInfo object.
463      * @return Returns ERR_OK on success, others on failure.
464      */
465     ErrCode SubscribeSelf(const sptr<AnsSubscriberInterface> &subscriber) override;
466 
467     /**
468      * @brief Subscribes notifications.
469      *
470      * @param subscriber Indicates the subscriber.
471      * @param info Indicates the NotificationSubscribeInfo object.
472      * @return Returns ERR_OK on success, others on failure.
473      */
474     ErrCode SubscribeLocalLiveView(const sptr<AnsSubscriberLocalLiveViewInterface> &subscriber,
475         const sptr<NotificationSubscribeInfo> &info, const bool isNative) override;
476 
477     /**
478      * @brief Unsubscribes notifications.
479      *
480      * @param subscriber Indicates the subscriber.
481      * @param info Indicates the NotificationSubscribeInfo object.
482      * @return Returns ERR_OK on success, others on failure.
483      */
484     ErrCode Unsubscribe(const sptr<AnsSubscriberInterface> &subscriber,
485         const sptr<NotificationSubscribeInfo> &info) override;
486 
487     /**
488      * @brief Checks whether this device is allowed to publish notifications.
489      *
490      * @param allowed Indicates the flag that allows notification.
491      * @return Returns ERR_OK on success, others on failure.
492      */
493     ErrCode IsAllowedNotify(bool &allowed) override;
494 
495     /**
496      * @brief Checks whether this application is allowed to publish notifications.
497      *
498      * @param allowed Indicates the flag that allows notification.
499      * @return Returns ERR_OK on success, others on failure.
500      */
501     ErrCode IsAllowedNotifySelf(bool &allowed) override;
502 
503     /**
504      * @brief Checks whether this application can pop enable notification dialog.
505      *
506      * @param  canPop True if can pop enable notification dialog
507      * @return Returns is canPop result.
508      */
509     ErrCode CanPopEnableNotificationDialog(const sptr<AnsDialogCallback> &callback,
510         bool &canPop, std::string &bundleName) override;
511 
512     /**
513      * @brief remove enable notification dialog.
514      *
515      * @return Returns remove dialog result.
516      */
517     ErrCode RemoveEnableNotificationDialog() override;
518 
519     /**
520      * @brief Checks whether notifications are allowed for a specific bundle.
521      *
522      * @param bundleOption Indicates the NotificationBundleOption object.
523      * @param allowed Indicates the flag that allows notification.
524      * @return Returns ERR_OK on success, others on failure.
525      */
526     ErrCode IsSpecialBundleAllowedNotify(const sptr<NotificationBundleOption> &bundleOption, bool &allowed) override;
527 
528     /**
529      * @brief Set do not disturb date.
530      *
531      * @param date Indicates the NotificationDoNotDisturbDate object.
532      * @return Returns ERR_OK on success, others on failure.
533      */
534     ErrCode SetDoNotDisturbDate(const sptr<NotificationDoNotDisturbDate> &date) override;
535 
536     /**
537      * @brief Get do not disturb date.
538      *
539      * @param date Indicates the NotificationDoNotDisturbDate object.
540      * @return Returns ERR_OK on success, others on failure.
541      */
542     ErrCode GetDoNotDisturbDate(sptr<NotificationDoNotDisturbDate> &date) override;
543 
544     /**
545      * @brief Add do not disturb Profiles.
546      *
547      * @param profiles Indicates the NotificationDoNotDisturbProfile objects.
548      * @return Returns ERR_OK on success, others on failure.
549      */
550     ErrCode AddDoNotDisturbProfiles(const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles) override;
551 
552     /**
553      * @brief Remove do not disturb Profiles.
554      *
555      * @param profiles Indicates the NotificationDoNotDisturbProfile objects.
556      * @return Returns ERR_OK on success, others on failure.
557      */
558     ErrCode RemoveDoNotDisturbProfiles(const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles) override;
559 
560     /**
561      * @brief Get whether Do Not Disturb mode is supported.
562      *
563      * @param doesSupport Indicates the flag that supports DND mode.
564      * @return Returns ERR_OK on success, others on failure.
565      */
566     ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport) override;
567 
568     /**
569      * @brief Is coming call need silent in do not disturb mode.
570      *
571      * @param phoneNumber the calling format number.
572      * @return Returns silent in do not disturb mode.
573      */
574     ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType) override;
575 
576     /**
577      * @brief Cancel notifications according to group.
578      *
579      * @param groupName Indicates the group name.
580      * @param instanceKey Indicates the application instance key.
581      * @return Returns ERR_OK on success, others on failure.
582      */
583     ErrCode CancelGroup(const std::string &groupName, const std::string &instanceKey) override;
584 
585     /**
586      * @brief Delete notifications according to bundle and group.
587      *
588      * @param bundleOption Indicates the NotificationBundleOption object.
589      * @param groupName Indicates the group name.
590      * @return Returns ERR_OK on success, others on failure.
591      */
592     ErrCode RemoveGroupByBundle(
593         const sptr<NotificationBundleOption> &bundleOption, const std::string &groupName) override;
594 
595     /**
596      * @brief Gets whether distributed notification is enabled.
597      *
598      * @param enabled Indicates the enabled flag.
599      * @return Returns ERR_OK on success, others on failure.
600      */
601     ErrCode IsDistributedEnabled(bool &enabled) override;
602 
603     /**
604      * @brief Sets distributed notification enabled or disabled.
605      *
606      * @param enabled Indicates the enabled flag.
607      * @return Returns ERR_OK on success, others on failure.
608      */
609     ErrCode EnableDistributed(bool enabled) override;
610 
611     /**
612      * @brief Sets distributed notification enabled or disabled for specific bundle.
613      *
614      * @param bundleOption Indicates the NotificationBundleOption object.
615      * @param enabled Indicates the enabled flag.
616      * @return Returns ERR_OK on success, others on failure.
617      */
618     ErrCode EnableDistributedByBundle(const sptr<NotificationBundleOption> &bundleOption, bool enabled) override;
619 
620     /**
621      * @brief Sets distributed notification enabled or disabled for current bundle.
622      *
623      * @param enabled Indicates the enabled flag.
624      * @return Returns ERR_OK on success, others on failure.
625      */
626     ErrCode EnableDistributedSelf(bool enabled) override;
627 
628     /**
629      * @brief Gets whether distributed notification is enabled for specific bundle.
630      *
631      * @param bundleOption Indicates the NotificationBundleOption object.
632      * @param enabled Indicates the enabled flag.
633      * @return Returns ERR_OK on success, others on failure.
634      */
635     ErrCode IsDistributedEnableByBundle(const sptr<NotificationBundleOption> &bundleOption, bool &enabled) override;
636 
637     /**
638      * @brief Get the reminder type of the current device.
639      *
640      * @param remindType Reminder type for the device.
641      * @return Returns ERR_OK on success, others on failure.
642      */
643     ErrCode GetDeviceRemindType(NotificationConstant::RemindType &remindType) override;
644 
645     /**
646      * @brief Publishes a continuous notification.
647      *
648      * @param request Notification requests that need to be posted.
649      * @return Returns ERR_OK on success, others on failure.
650      */
651     ErrCode PublishContinuousTaskNotification(const sptr<NotificationRequest> &request) override;
652 
653     /**
654      * @brief Cancels a continuous notification.
655      *
656      * @param label Identifies the label of the specified notification.
657      * @param notificationId Identifies the id of the specified notification.
658      * @return Returns ERR_OK on success, others on failure.
659      */
660     ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) override;
661 
662     /**
663      * @brief Checks whether this device is support template.
664      *
665      * @param templateName Identifies the template name for searching as a condition.
666      * @param support Identifies the support flag.
667      * @return Returns ERR_OK on success, others on failure.
668      */
669     ErrCode IsSupportTemplate(const std::string &templateName, bool &support) override;
670 
671     /**
672      * @brief Publishes a reminder notification.
673      *
674      * @param reminder Identifies the reminder notification request that needs to be published.
675      * @return Returns ERR_OK on success, others on failure.
676      */
677     ErrCode PublishReminder(sptr<ReminderRequest> &reminder) override;
678 
679     /**
680      * @brief Cancel a reminder notifications.
681      *
682      * @param reminderId Identifies the reminders id that needs to be canceled.
683      * @return Returns ERR_OK on success, others on failure.
684      */
685     ErrCode CancelReminder(const int32_t reminderId) override;
686 
687     /**
688      * @brief Get all valid reminder notifications.
689      *
690      * @param reminders Identifies the list of all valid notifications.
691      * @return Returns ERR_OK on success, others on failure.
692      */
693     ErrCode GetValidReminders(std::vector<sptr<ReminderRequest>> &reminders) override;
694 
695     /**
696      * @brief Cancel all reminder notifications.
697      *
698      * @return Returns ERR_OK on success, others on failure.
699      */
700     ErrCode CancelAllReminders() override;
701 
702     /**
703      * @brief Add exclude date for reminder
704      *
705      * @param reminderId Identifies the reminders id.
706      * @param date exclude date
707      * @return Returns ERR_OK on success, others on failure.
708      */
709     ErrCode AddExcludeDate(const int32_t reminderId, const uint64_t date) override;
710 
711     /**
712      * @brief Clear exclude date for reminder
713      *
714      * @param reminderId Identifies the reminders id.
715      * @return Returns ERR_OK on success, others on failure.
716      */
717     ErrCode DelExcludeDates(const int32_t reminderId) override;
718 
719     /**
720      * @brief Get exclude date for reminder
721      *
722      * @param reminderId Identifies the reminders id.
723      * @param dates exclude dates
724      * @return Returns ERR_OK on success, others on failure.
725      */
726     ErrCode GetExcludeDates(const int32_t reminderId, std::vector<uint64_t>& dates) override;
727 
728     /**
729      * @brief Checks Whether the specified users is allowed to publish notifications.
730      *
731      * @param userId Identifies the user's id.
732      * @param allowed Identifies the allowed flag.
733      * @return Returns ERR_OK on success, others on failure.
734      */
735     ErrCode IsSpecialUserAllowedNotify(const int32_t &userId, bool &allowed) override;
736 
737     /**
738      * @brief Sets whether to allow all applications to publish notifications on a specified device. The caller must
739      * have system permissions to call this method.
740      *
741      * @param deviceId Indicates the ID of the device running the application. At present, this parameter can only
742      *                 be null or an empty string, indicating the current device.
743      * @param enabled Specifies whether to allow all applications to publish notifications. The value true
744      *                indicates that notifications are allowed, and the value false indicates that notifications
745      *                are not allowed.
746      * @return Returns ERR_OK on success, others on failure.
747      */
748     ErrCode SetNotificationsEnabledByUser(const int32_t &userId, bool enabled) override;
749 
750     /**
751      * @brief Delete all notifications by user.
752      *
753      * @param userId Indicates the user id.
754      * @return Returns ERR_OK on success, others on failure.
755      */
756     ErrCode DeleteAllByUser(const int32_t &userId) override;
757 
758     /**
759      * @brief Set do not disturb date by user.
760      *
761      * @param userId Indicates the user id.
762      * @param date Indicates NotificationDoNotDisturbDate object.
763      * @return Returns ERR_OK on success, others on failure.
764      */
765     ErrCode SetDoNotDisturbDate(const int32_t &userId, const sptr<NotificationDoNotDisturbDate> &date) override;
766 
767     /**
768      * @brief Get the do not disturb date by user.
769      *
770      * @param userId Indicates the user id.
771      * @param date Indicates the NotificationDoNotDisturbDate object.
772      * @return Returns ERR_OK on success, others on failure.
773      */
774     ErrCode GetDoNotDisturbDate(const int32_t &userId, sptr<NotificationDoNotDisturbDate> &date) override;
775     ErrCode SetEnabledForBundleSlot(const sptr<NotificationBundleOption> &bundleOption,
776         const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl) override;
777     ErrCode GetEnabledForBundleSlot(const sptr<NotificationBundleOption> &bundleOption,
778         const NotificationConstant::SlotType &slotType, bool &enabled) override;
779     ErrCode GetEnabledForBundleSlotSelf(const NotificationConstant::SlotType &slotType, bool &enabled) override;
780 
781     /**
782      * @brief Obtains specific datas via specified dump option.
783      *
784      * @param cmd Indicates the specified dump command.
785      * @param bundle Indicates the specified bundle name.
786      * @param userId Indicates the specified userId.
787      * @param dumpInfo Indicates the container containing datas.
788      * @return Returns check result.
789      */
790     ErrCode ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, int32_t recvUserId,
791         std::vector<std::string> &dumpInfo) override;
792 
793     /**
794      * @brief Set whether to sync notifications to devices that do not have the app installed.
795      *
796      * @param userId Indicates the specific user.
797      * @param enabled Allow or disallow sync notifications.
798      * @return Returns set enabled result.
799      */
800     ErrCode SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled) override;
801 
802     /**
803      * @brief Obtains whether to sync notifications to devices that do not have the app installed.
804      *
805      * @param userId Indicates the specific user.
806      * @param enabled Allow or disallow sync notifications.
807      * @return Returns get enabled result.
808      */
809     ErrCode GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled) override;
810 
811     /**
812      * @brief Set badge number.
813      *
814      * @param badgeNumber The badge number.
815      * @return Returns set badge number result.
816      */
817     ErrCode SetBadgeNumber(int32_t badgeNumber, const std::string &instanceKey) override;
818 
819     /**
820      * @brief Set badge number by bundle.
821      *
822      * @param bundleOption Indicates the bundle name and uid of the application.
823      * @param badgeNumber The badge number.
824      * @return Returns set badge number by bundle result.
825      */
826     ErrCode SetBadgeNumberByBundle(const sptr<NotificationBundleOption> &bundleOption, int32_t badgeNumber) override;
827 
828     /**
829      * @brief Get the slotFlags of slot.
830      *
831      * @param bundleOption Indicates the bundle name and uid of the application.
832      * @param slot      Indicates the specified slot object
833      * @param slotFlags Indicates the slogFlags of slot to get.
834      * @return Returns ERR_OK on success, others on failure.
835      */
836     ErrCode GetSlotFlagsAsBundle(const sptr<NotificationBundleOption> &bundleOption, uint32_t &slotFlags) override;
837 
838     /**
839      * @brief Set the slotFlags of slot.
840      *
841      * @param bundleOption Indicates the bundle name and uid of the application.
842      * @param slot      Indicates the specified slot object
843      * @param slotFlags Indicates the slogFlags of slot to set.
844      * @return Returns ERR_OK on success, others on failure.
845      */
846     ErrCode SetSlotFlagsAsBundle(const sptr<NotificationBundleOption> &bundleOption, uint32_t slotFlags) override;
847 
848     /**
849      * @brief Obtains allow notification application list.
850      *
851      * @param bundleOption Indicates the bundle bundleOption.
852      * @return Returns ERR_OK on success, others on failure.
853      */
854     ErrCode GetAllNotificationEnabledBundles(std::vector<NotificationBundleOption> &bundleOption) override;
855 
856     /**
857      * @brief Register Push Callback.
858      *
859      * @param pushCallback PushCallBack.
860      * @param notificationCheckRequest Filter conditions for push check.
861      * @return Returns register PushCallback result.
862      */
863     ErrCode RegisterPushCallback(const sptr<IRemoteObject> &pushCallback,
864         const sptr<NotificationCheckRequest> &notificationCheckRequest) override;
865 
866     /**
867      * @brief Unregister Push Callback.
868      *
869      * @return Returns unregister push Callback result.
870      */
871     ErrCode UnregisterPushCallback() override;
872 
873     /**
874      * @brief Set agent relationship.
875      *
876      * @param key Indicates storing agent relationship if the value is "PROXY_PKG".
877      * @param value Indicates key-value pair of agent relationship.
878      * @return Returns set result.
879      */
880     ErrCode SetAdditionConfig(const std::string &key, const std::string &value) override;
881 
882     /**
883      * @brief Sets whether to allow a specified application to publish notifications cross
884      * device collaboration. The caller must have system permissions to call this method.
885      *
886      * @param bundleOption Indicates the bundle name and uid of the application.
887      * @param deviceType Indicates the type of the device running the application.
888      * @param enabled Specifies whether to allow the given application to publish notifications. The value
889      *                true indicates that notifications are allowed, and the value false indicates that
890      *                notifications are not allowed.
891      * @return Returns set notifications enabled for specified bundle result.
892      */
893     ErrCode SetDistributedEnabledByBundle(
894         const sptr<NotificationBundleOption> &bundleOption, const std::string &deviceType, const bool enabled) override;
895 
896     /**
897      * @brief get whether to allow a specified application to publish notifications cross
898      * device collaboration. The caller must have system permissions to call this method.
899      *
900      * @param bundleOption Indicates the bundle name and uid of the application.
901      * @param deviceType Indicates the type of the device running the application.
902      * @param enabled Specifies whether to allow the given application to publish notifications. The value
903      *                true indicates that notifications are allowed, and the value false indicates that
904      *                notifications are not allowed.
905      * @return Returns set notifications enabled for specified bundle result.
906      */
907     ErrCode IsDistributedEnabledByBundle(
908         const sptr<NotificationBundleOption> &bundleOption, const std::string &deviceType, bool &enabled) override;
909 
910     /**
911      * @brief Get Enable smartphone to collaborate with other devices for intelligent reminders
912      *
913      * @param deviceType Indicates the type of the device running the application.
914      * @param enabled Specifies whether to allow the given device to publish notifications.
915      *                The value true indicates that notifications are allowed, and the value
916      *                false indicates that notifications are not allowed.
917      * @return Returns set notifications enabled for specified bundle result.
918      */
919     ErrCode IsSmartReminderEnabled(const std::string &deviceType, bool &enabled) override;
920 
921     /**
922      * @brief Set Enable smartphone to collaborate with other devices for intelligent reminders
923      *
924      * @param deviceType Indicates the type of the device running the application.
925      * @param enabled Specifies whether to allow the given device to publish notifications.
926      *                The value true indicates that notifications are allowed, and the value
927      *                false indicates that notifications are not allowed.
928      * @return Returns set notifications enabled for specified bundle result.
929      */
930     ErrCode SetSmartReminderEnabled(const std::string &deviceType, const bool enabled) override;
931 
932     /**
933      * @brief Cancels a published agent notification.
934      *
935      * @param bundleOption Indicates the bundle name and uid of the application.
936      * @param id Indicates the unique notification ID in the application.
937      * @return Returns cancel result.
938      */
939     ErrCode CancelAsBundleWithAgent(const sptr<NotificationBundleOption> &bundleOption, const int32_t id) override;
940 
941     /**
942      * @brief Set the status of the target device.
943      *
944      * @param deviceType Type of the device whose status you want to set.
945      * @param status The status.
946      * @return Returns set result.
947      */
948     ErrCode SetTargetDeviceStatus(const std::string &deviceType, const uint32_t status) 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 #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED
960     /**
961      * @brief Register Swing Callback.
962      *
963      * @param swingCallback SwingCallBack.
964      * @return Returns register SwingCallback result.
965      */
966     ErrCode RegisterSwingCallback(const sptr<IRemoteObject> &swingCallback) override;
967 #endif
968 
969     /**
970      * @brief Update Notification Timer by uid.
971      *
972      * @param uid uid.
973      * @return Returns Update result.
974      */
975     ErrCode UpdateNotificationTimerByUid(const int32_t uid, const bool isPaused) override;
976 
977     /**
978      * @brief set rule of generate hashCode.
979      *
980      * @param type generate hashCode.
981      * @return Returns ERR_OK on success, others on failure.
982      */
983     ErrCode SetHashCodeRule(const uint32_t type) override;
984 
985 private:
986     ErrCode InnerTransact(NotificationInterfaceCode code, MessageOption &flags,
987         MessageParcel &data, MessageParcel &reply);
988 
989     template<typename T>
WriteParcelableVector(const std::vector<sptr<T>> & parcelableVector,MessageParcel & data)990     bool WriteParcelableVector(const std::vector<sptr<T>> &parcelableVector, MessageParcel &data)
991     {
992         if (!data.WriteInt32(parcelableVector.size())) {
993             ANS_LOGE("Failed to write ParcelableVector size.");
994             return false;
995         }
996 
997         for (auto &parcelable : parcelableVector) {
998             if (!data.WriteStrongParcelable(parcelable)) {
999                 ANS_LOGE("Failed to write ParcelableVector");
1000                 return false;
1001             }
1002         }
1003         return true;
1004     }
1005 
1006     template<typename T>
ReadParcelableVector(std::vector<sptr<T>> & parcelableInfos,MessageParcel & reply,ErrCode & result)1007     bool ReadParcelableVector(std::vector<sptr<T>> &parcelableInfos, MessageParcel &reply, ErrCode &result)
1008     {
1009         if (!reply.ReadInt32(result)) {
1010             ANS_LOGE("read result failed.");
1011             return false;
1012         }
1013 
1014         int32_t infoSize = 0;
1015         if (!reply.ReadInt32(infoSize)) {
1016             ANS_LOGE("read Parcelable size failed.");
1017             return false;
1018         }
1019 
1020         parcelableInfos.clear();
1021         infoSize = (infoSize < MAX_PARCELABLE_VECTOR_NUM) ? infoSize : MAX_PARCELABLE_VECTOR_NUM;
1022         for (int32_t index = 0; index < infoSize; index++) {
1023             sptr<T> info = reply.ReadStrongParcelable<T>();
1024             if (info == nullptr) {
1025                 ANS_LOGE("read Parcelable infos failed.");
1026                 return false;
1027             }
1028             parcelableInfos.emplace_back(info);
1029         }
1030 
1031         return true;
1032     }
1033     static inline BrokerDelegator<AnsManagerProxy> delegator_;
1034 
1035     ErrCode ReadReminders(uint8_t &count, MessageParcel &reply, std::vector<sptr<ReminderRequest>> &reminders);
1036 };
1037 }  // namespace Notification
1038 }  // namespace OHOS
1039 
1040 #endif  // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_MANAGER_PROXY_H
1041