• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_ADVANCED_NOTIFICATION_SERVICE_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_ADVANCED_NOTIFICATION_SERVICE_H
18 
19 #include <ctime>
20 #include <set>
21 #include <list>
22 #include <memory>
23 #include <mutex>
24 
25 #include "event_handler.h"
26 #include "event_runner.h"
27 #include "ffrt.h"
28 #include "refbase.h"
29 
30 #include "ans_const_define.h"
31 #include "ans_manager_stub.h"
32 #include "common_notification_publish_process.h"
33 #include "distributed_kv_data_manager.h"
34 #include "distributed_kvstore_death_recipient.h"
35 #include "live_publish_process.h"
36 #include "notification.h"
37 #include "notification_bundle_option.h"
38 #include "distributed_bundle_option.h"
39 #include "notification_dialog_manager.h"
40 #include "notification_do_not_disturb_profile.h"
41 #include "notification_record.h"
42 #include "notification_slot_filter.h"
43 #include "notification_sorting_map.h"
44 #include "permission_filter.h"
45 #include "push_callback_interface.h"
46 #include "system_event_observer.h"
47 #include "notification_subscriber_manager.h"
48 #include "distributed_device_status.h"
49 #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED
50 #include "reminder_swing_decision_center.h"
51 #endif
52 #include "notification_clone_bundle_info.h"
53 
54 namespace OHOS {
55 namespace Notification {
56 
57 static const uint32_t DEFAULT_SLOT_FLAGS = 59; // 0b111011
58 static const uint32_t SILENT_REMINDER__SLOT_FLAGS = 32; // 0b100000
59 constexpr char REMINDER_CAPABILITY[] = "reminder_capability";
60 constexpr char SOUND_CAPABILITY[] = "sound_capability";
61 class AdvancedNotificationService final : public AnsManagerStub,
62     public std::enable_shared_from_this<AdvancedNotificationService> {
63 public:
64     struct NotificationRequestDb {
65         sptr<NotificationRequest> request {nullptr};
66         sptr<NotificationBundleOption> bundleOption {nullptr};
67     };
68 
69     struct RecentNotification {
70         sptr<Notification> notification = nullptr;
71         bool isActive = false;
72         int32_t deleteReason = 0;
73         int64_t deleteTime = 0;
74     };
75 
76     ~AdvancedNotificationService() override;
77 
78     DISALLOW_COPY_AND_MOVE(AdvancedNotificationService);
79 
80     /**
81      * @brief Get the instance of service.
82      *
83      * @return Returns the instance.
84      */
85     static sptr<AdvancedNotificationService> GetInstance();
86 
87     static std::map<std::string, uint32_t>& GetDefaultSlotConfig();
88 
89     void SelfClean();
90 
91     /**
92      * @brief Get notification_svr_queue of service.
93      *
94      * @return Returns the queue.
95      */
96     std::shared_ptr<ffrt::queue> GetNotificationSvrQueue();
97 
98     /**
99      * @brief Submit an async task into notification_svr_queue.
100      *
101      * @param func Indicates the function.
102      */
103     void SubmitAsyncTask(const std::function<void()>& func);
104     /**
105      * @brief Submit a sync task into notification_svr_queue.
106      *
107      * @param func Indicates the function.
108      */
109     void SubmitSyncTask(const std::function<void()>& func);
110 
111     // AnsManagerStub
112 
113     /**
114      * @brief Publishes a notification with a specified label.
115      * @note If a notification with the same ID has been published by the current application and has not been deleted,
116      *       this method will update the notification.
117      *
118      * @param label Indicates the label of the notification to publish.
119      * @param notification Indicates the NotificationRequest object for setting the notification content.
120      *                This parameter must be specified.
121      * @return Returns ERR_OK on success, others on failure.
122      */
123     ErrCode Publish(const std::string &label, const sptr<NotificationRequest> &request) override;
124 
125     ErrCode PublishWithMaxCapacity(const std::string& label, const sptr<NotificationRequest>& request) override;
126 
127     /**
128      * @brief Publishes a notification.
129      * @note If a notification with the same ID has been published by the current application and has not been deleted,
130      *       this method will update the notification.
131      *
132      * @param notification Indicates the NotificationRequest object for setting the notification content.
133      *                This parameter must be specified.
134      * @return Returns ERR_OK on success, others on failure.
135      */
136     ErrCode PublishNotificationForIndirectProxy(const sptr<NotificationRequest> &request) override;
137 
138     ErrCode PublishNotificationForIndirectProxyWithMaxCapacity(const sptr<NotificationRequest> &request) override;
139 
140     /**
141      * @brief Cancels a published notification matching the specified label and notificationId.
142      *
143      * @param notificationId Indicates the ID of the notification to cancel.
144      * @param label Indicates the label of the notification to cancel.
145      * @param instanceKey Indicates the application instance key.
146      * @return Returns cancel notification result.
147      */
148     ErrCode Cancel(int32_t notificationId, const std::string &label, const std::string &instanceKey) override;
149 
150     /**
151      * @brief Cancels all the published notifications.
152      *
153      * @param instanceKey Indicates the application instance key.
154      * @return Returns ERR_OK on success, others on failure.
155      */
156     ErrCode CancelAll(const std::string &instanceKey) override;
157 
158     /**
159      * @brief Cancels a published agent notification.
160      *
161      * @param notificationId Indicates the unique notification ID in the application.
162      *                       The value must be the ID of a published notification.
163      *                       Otherwise, this method does not take effect.
164      * @param representativeBundle Indicates the name of application bundle your application is representing.
165      * @param userId Indicates the specific user.
166      * @return Returns cancel notification result.
167      */
168     ErrCode CancelAsBundle(
169         int32_t notificationId, const std::string &representativeBundle, int32_t userId) override;
170 
171     /**
172      * @brief Cancels a published agent notification.
173      *
174      * @param bundleOption Indicates the bundle of application bundle your application is representing.
175      * @param notificationId Indicates the unique notification ID in the application.
176      *                       The value must be the ID of a published notification.
177      *                       Otherwise, this method does not take effect.
178      * @return Returns cancel notification result.
179      */
180     ErrCode CancelAsBundle(const sptr<NotificationBundleOption> &bundleOption, int32_t notificationId) override;
181 
182     /**
183      * @brief Cancels a published agent notification.
184      *
185      * @param bundleOption Indicates the bundle of application bundle your application is representing.
186      * @param notificationId Indicates the unique notification ID in the application.
187      *                       The value must be the ID of a published notification.
188      *                       Otherwise, this method does not take effect.
189      * @param userId Indicates the specific user.
190      * @return Returns cancel notification result.
191      */
192     ErrCode CancelAsBundle(
193         const sptr<NotificationBundleOption> &bundleOption, int32_t notificationId, int32_t userId) override;
194 
195     /**
196      * @brief Adds a notification slot by type.
197      *
198      * @param slotType Indicates the notification slot type to be added.
199      * @return Returns ERR_OK on success, others on failure.
200      */
201     ErrCode AddSlotByType(int32_t slotTypeInt) override;
202 
203     /**
204      * @brief Creates multiple notification slots.
205      *
206      * @param slots Indicates the notification slots to create.
207      * @return Returns ERR_OK on success, others on failure.
208      */
209     ErrCode AddSlots(const std::vector<sptr<NotificationSlot>> &slots) override;
210 
211     /**
212      * @brief Deletes a created notification slot based on the slot ID.
213      *
214      * @param slotType Indicates the type of the slot, which is created by AddNotificationSlot
215      *                 This parameter must be specified.
216      * @return Returns ERR_OK on success, others on failure.
217      */
218     ErrCode RemoveSlotByType(int32_t slotTypeInt) override;
219 
220     /**
221      * @brief Deletes all notification slots.
222      *
223      * @return Returns ERR_OK on success, others on failure.
224      */
225     ErrCode RemoveAllSlots() override;
226 
227     /**
228      * @brief Queries a created notification slot.
229      *
230      * @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot(NotificationSlot). This
231      *        parameter must be specified.
232      * @param slot Indicates the created NotificationSlot.
233      * @return Returns ERR_OK on success, others on failure.
234      */
235     ErrCode GetSlotByType(int32_t slotTypeInt, sptr<NotificationSlot> &slot) override;
236 
237     /**
238      * @brief Obtains all notification slots of this application.
239      *
240      * @param slots Indicates the created NotificationSlot.
241      * @return Returns ERR_OK on success, others on failure.
242      */
243     ErrCode GetSlots(std::vector<sptr<NotificationSlot>> &slots) override;
244 
245     /**
246      * @brief Obtains the number of slot.
247      *
248      * @param bundleOption Indicates the bundle name and uid of the application.
249      * @param num Indicates the number of slot.
250      * @return Returns ERR_OK on success, others on failure.
251      */
252     ErrCode GetSlotNumAsBundle(const sptr<NotificationBundleOption> &bundleOption, uint64_t &num) override;
253 
254     /**
255      * @brief Obtains active notifications of the current application in the system.
256      *
257      * @param notifications Indicates active NotificationRequest objects of the current application.
258      * @param instanceKey Indicates the application instance key.
259      * @return Returns ERR_OK on success, others on failure.
260      */
261     ErrCode GetActiveNotifications(std::vector<sptr<NotificationRequest>> &notifications,
262         const std::string &instanceKey) override;
263 
264     /**
265      * @brief Obtains the number of active notifications of the current application in the system.
266      *
267      * @param num Indicates the number of active notifications of the current application.
268      * @return Returns ERR_OK on success, others on failure.
269      */
270     ErrCode GetActiveNotificationNums(uint64_t &num) override;
271 
272     /**
273      * @brief Obtains all active notifications by slot type in the current system. The caller must have system
274      * permissions to call this method.
275      *
276      * @param notification Indicates all active notifications of this application.
277      * @return Returns get all active notifications
278      */
279     ErrCode GetAllNotificationsBySlotType(std::vector<sptr<Notification>> &notifications,
280         int32_t slotTypeInt) override;
281 
282     /**
283      * @brief Obtains all active notifications in the current system. The caller must have system permissions to
284      * call this method.
285      *
286      * @param notifications Indicates all active notifications of this application.
287      * @return Returns ERR_OK on success, others on failure.
288      */
289     ErrCode GetAllActiveNotifications(std::vector<sptr<Notification>> &notifications) override;
290 
291     /**
292      * @brief Obtains the active notifications corresponding to the specified key in the system. To call this method
293      * to obtain particular active notifications, you must have received the notifications and obtained the key
294      * via {Notification::GetKey()}.
295      *
296      * @param key Indicates the key array for querying corresponding active notifications.
297      *            If this parameter is null, this method returns all active notifications in the system.
298      * @param notification Indicates the set of active notifications corresponding to the specified key.
299      * @return Returns ERR_OK on success, others on failure.
300      */
301     ErrCode GetSpecialActiveNotifications(
302         const std::vector<std::string> &key, std::vector<sptr<Notification>> &notifications) override;
303 
304     ErrCode GetActiveNotificationByFilter(
305         const sptr<NotificationBundleOption> &bundleOption, int32_t notificationId, const std::string &label,
306         int32_t userId, const std::vector<std::string> &extraInfoKeys, sptr<NotificationRequest> &request) override;
307 
308     /**
309      * @brief Checks whether your application has permission to publish notifications by calling
310      * PublishNotificationAsBundle(string, NotificationRequest) in the name of another application indicated by the
311      * given representativeBundle.
312      *
313      * @param representativeBundle Indicates the name of application bundle your application is representing.
314      * @param canPublish Indicates whether your application has permission to publish notifications.
315      * @return Returns ERR_OK on success, others on failure.
316      */
317     ErrCode CanPublishAsBundle(const std::string &representativeBundle, bool &canPublish) override;
318 
319     /**
320      * @brief Publishes a notification in the name of a specified application bundle.
321      * @note If the notification to be published has the same ID as a published notification that has not been canceled,
322      * the existing notification will be replaced by the new one.
323      *
324      * @param notification Indicates the NotificationRequest object for setting the notification content.
325      *                This parameter must be specified.
326      * @param representativeBundle Indicates the name of the application bundle that allows your application to publish
327      *                             notifications for it by calling setNotificationAgent.
328      * @return Returns ERR_OK on success, others on failure.
329      */
330     ErrCode PublishAsBundle(
331         const sptr<NotificationRequest>& notification, const std::string &representativeBundle) override;
332 
333     ErrCode PublishAsBundleWithMaxCapacity(
334         const sptr<NotificationRequest>& notification, const std::string &representativeBundle) override;
335 
336     /**
337      * @brief Sets the number of active notifications of the current application as the number to be displayed on the
338      * notification badge.
339      *
340      * @param num Indicates the badge number.
341      * @return Returns ERR_OK on success, others on failure.
342      */
343     ErrCode SetNotificationBadgeNum(int32_t num) override;
344 
345     /**
346      * @brief Obtains the importance level of this application.
347      *
348      * @param importance Indicates the importance level of this application, which can be LEVEL_NONE,
349                LEVEL_MIN, LEVEL_LOW, LEVEL_DEFAULT, LEVEL_HIGH, or LEVEL_UNDEFINED.
350      * @return Returns ERR_OK on success, others on failure.
351      */
352     ErrCode GetBundleImportance(int32_t &importance) override;
353 
354     /**
355      * @brief Checks whether this application has permission to modify the Do Not Disturb (DND) notification policy.
356      *
357      * @param granted True if the application has permission; false for otherwise.
358      * @return Returns ERR_OK on success, others on failure.
359      */
360     ErrCode HasNotificationPolicyAccessPermission(bool &granted) override;
361 
362     /**
363      * @brief Trigger the local live view after the button has been clicked.
364      * @note Your application must have platform signature to use this method.
365      *
366      * @param bundleOption Indicates the bundle name and uid of the application whose notifications has been clicked.
367      * @param notificationId Indicates the id of the notification.
368      * @param buttonOption Indicates which button has been clicked.
369      * @return Returns trigger localLiveView result.
370      */
371     ErrCode TriggerLocalLiveView(const sptr<NotificationBundleOption> &bundleOption,
372         const int32_t notificationId, const sptr<NotificationButtonOption> &buttonOption) override;
373 
374     /**
375      * @brief Delete notification.
376      *
377      * @param bundleOption Indicates the NotificationBundleOption of the notification.
378      * @param notificationId Indicates the id of the notification.
379      * @param label Indicates the label of the notification.
380      * @param removeReason Indicates the reason of remove notification.
381      * @return Returns ERR_OK on success, others on failure.
382      */
383     ErrCode RemoveNotification(const sptr<NotificationBundleOption> &bundleOption, int32_t notificationId,
384         const std::string &label, int32_t removeReason) override;
385 
386     /**
387      * @brief Delete all notifications.
388      *
389      * @param bundleOption Indicates the NotificationBundleOption of notifications.
390      * @return Returns ERR_OK on success, others on failure.
391      */
392     ErrCode RemoveAllNotifications(const sptr<NotificationBundleOption> &bundleOption) override;
393 
394     ErrCode RemoveAllNotificationsForDisable(const sptr<NotificationBundleOption> &bundleOption);
395 
396     ErrCode RemoveNotifications(const std::vector<std::string> &keys, int32_t removeReason) override;
397 
398     /**
399      * @brief Removes Distributed notifications in the system.
400      * @note Your application must have platform signature to use this method.
401      * @return Returns remove notifications result.
402      */
403     ErrCode RemoveDistributedNotifications(const std::vector<std::string>& hashcodes,
404         const int32_t slotTypeInt, const int32_t deleteTypeInt,
405         const int32_t removeReason, const std::string& deviceId = "") override;
406 
407     ErrCode GetUnifiedGroupInfoFromDb(std::string &enable);
408 
409     /**
410      * @brief Delete notification based on key.
411      *
412      * @param key Indicates the key to delete notification.
413      * @param removeReason Indicates the reason of remove notification.
414      * @return Returns ERR_OK on success, others on failure.
415      */
416     ErrCode Delete(const std::string &key, int32_t removeReason) override;
417 
418     /**
419      * @brief Remove notifications based on bundle.
420      *
421      * @param bundleOption Indicates the NotificationBundleOption of notifications.
422      * @return Returns ERR_OK on success, others on failure.
423      */
424     ErrCode DeleteByBundle(const sptr<NotificationBundleOption> &bundleOption) override;
425 
426     /**
427      * @brief Remove all notifications.
428      *
429      * @return Returns ERR_OK on success, others on failure.
430      */
431     ErrCode DeleteAll() override;
432 
433     /**
434      * @brief Get all the slots corresponding to the bundle.
435      *
436      * @param bundleOption Indicates the NotificationBundleOption object.
437      * @param slots Indicates the notification slots.
438      * @return Returns ERR_OK on success, others on failure.
439      */
440     ErrCode GetSlotsByBundle(
441         const sptr<NotificationBundleOption> &bundleOption, std::vector<sptr<NotificationSlot>> &slots) override;
442 
443     /**
444      * @brief Get the specified slot corresponding to the bundle.
445      *
446      * @param bundleOption Indicates the NotificationBundleOption object.
447      * @param slotType Indicates the ID of the slot, which is created by AddNotificationSlot(NotificationSlot). This
448      *        parameter must be specified.
449      * @param slot Indicates the notification slot.
450      * @return Returns ERR_OK on success, others on failure.
451      */
452     ErrCode GetSlotByBundle(
453         const sptr<NotificationBundleOption> &bundleOption, int32_t slotTypeInt,
454         sptr<NotificationSlot> &slot) override;
455 
456     /**
457      * @brief Update slots according to bundle.
458      *
459      * @param bundleOption Indicates the NotificationBundleOption object.
460      * @param slots Indicates the notification slots to be updated.
461      * @return Returns ERR_OK on success, others on failure.
462      */
463     ErrCode UpdateSlots(
464         const sptr<NotificationBundleOption> &bundleOption, const std::vector<sptr<NotificationSlot>> &slots) override;
465 
466     /**
467      * @brief Allow notifications to be sent based on the deviceId.
468      *
469      * @param deviceId Indicates the device Id.
470      * @return Returns ERR_OK on success, others on failure.
471      */
472     ErrCode RequestEnableNotification(const std::string &deviceId,
473         const sptr<IAnsDialogCallback> &callback,
474         const sptr<IRemoteObject> &callerToken) override;
475 
476     ErrCode RequestEnableNotification(const std::string &deviceId,
477         const sptr<IAnsDialogCallback> &callback) override;
478 
479     /**
480      * @brief Allow application to publish notifications.
481      *
482      * @param bundleName bundle name.
483      * @param uid uid.
484      * @return Returns set notifications enabled for the bundle result.
485      */
486     ErrCode RequestEnableNotification(const std::string& bundleName, int32_t uid) override;
487 
488     /**
489      * @brief Set whether to allow the specified deviceId to send notifications for current bundle.
490      *
491      * @param deviceId Indicates the device Id.
492      * @param enabled Indicates the flag that allows notification to be pulished.
493      * @return Returns ERR_OK on success, others on failure.
494      */
495     ErrCode SetNotificationsEnabledForBundle(const std::string &deviceId, bool enabled) override;
496 
497     /**
498      * @brief Set whether to allow the specified deviceId to send notifications for all bundles.
499      *
500      * @param deviceId Indicates the device Id.
501      * @param enabled Indicates the flag that allows notification to be pulished.
502      * @return Returns ERR_OK on success, others on failure.
503      */
504     ErrCode SetNotificationsEnabledForAllBundles(const std::string &deviceId, bool enabled) override;
505 
506     /**
507      * @brief Set whether to allow the specified bundle to send notifications.
508      *
509      * @param bundleOption Indicates the NotificationBundleOption object.
510      * @param enabled Indicates the flag that allows notification to be pulished.
511      * @param updateUnEnableTime Indicates whether update the unenable time.
512      * @return Returns ERR_OK on success, others on failure.
513      */
514     ErrCode SetNotificationsEnabledForSpecialBundle(
515         const std::string &deviceId, const sptr<NotificationBundleOption> &bundleOption,
516         bool enabled, bool updateUnEnableTime = true) override;
517 
518     /**
519      * @brief Set whether to allow the specified bundle to send notifications.
520      *
521      * @param bundleOption Indicates the NotificationBundleOption object.
522      * @param enabled Indicates the flag that allows notification to be pulished.
523      * @param updateUnEnableTime Indicates whether update the unenable time.
524      * @return Returns ERR_OK on success, others on failure.
525      */
526     ErrCode SetNotificationsSystemEnabledForSpecialBundle(
527         const std::string &deviceId, const sptr<NotificationBundleOption> &bundleOption, bool enabled,
528         bool updateUnEnableTime = true);
529 
530     /**
531      * @brief Sets whether the bundle allows the banner to display notification.
532      *
533      * @param bundleOption Indicates the NotificationBundleOption object.
534      * @param enabled Indicates the flag that allows badge to be shown.
535      * @return Returns ERR_OK on success, others on failure.
536      */
537     ErrCode SetShowBadgeEnabledForBundle(const sptr<NotificationBundleOption> &bundleOption, bool enabled) override;
538 
539     /**
540      * @brief Gets whether the bundle allows the badge to display the status of notifications.
541      *
542      * @param bundleOption Indicates the NotificationBundleOption object.
543      * @param enabled Indicates the flag that allows badge to be shown.
544      * @return Returns ERR_OK on success, others on failure.
545      */
546     ErrCode GetShowBadgeEnabledForBundle(const sptr<NotificationBundleOption> &bundleOption, bool &enabled) override;
547 
548     /**
549      * @brief Gets whether allows the badge to display the status of notifications.
550      *
551      * @param enabled Indicates the flag that allows badge to be shown.
552      * @return Returns ERR_OK on success, others on failure.
553      */
554     ErrCode GetShowBadgeEnabled(bool &enabled) override;
555 
556     /**
557      * @brief Subscribes notifications.
558      *
559      * @param subscriber Indicates the subscriber.
560      * @param info Indicates the NotificationSubscribeInfo object.
561      * @return Returns ERR_OK on success, others on failure.
562      */
563     ErrCode Subscribe(const sptr<IAnsSubscriber> &subscriber,
564         const sptr<NotificationSubscribeInfo> &info) override;
565 
566     ErrCode Subscribe(const sptr<IAnsSubscriber> &subscriber) override;
567 
568     /**
569      * @brief Subscribes notifications self.
570      *
571      * @param subscriber Indicates the subscriber.
572      * @return Returns ERR_OK on success, others on failure.
573      */
574     ErrCode SubscribeSelf(const sptr<IAnsSubscriber> &subscriber) override;
575 
576     /**
577      * @brief Subscribes notifications.
578      *
579      * @param subscriber Indicates the subscriber.
580      * @param info Indicates the NotificationSubscribeInfo object.
581      * @return Returns ERR_OK on success, others on failure.
582      */
583     ErrCode SubscribeLocalLiveView(const sptr<IAnsSubscriberLocalLiveView> &subscriber,
584         const sptr<NotificationSubscribeInfo> &info, const bool isNative) override;
585 
586     ErrCode SubscribeLocalLiveView(const sptr<IAnsSubscriberLocalLiveView> &subscriber, const bool isNative) override;
587 
588     /**
589      * @brief Unsubscribes notifications.
590      *
591      * @param subscriber Indicates the subscriber.
592      * @param info Indicates the NotificationSubscribeInfo object.
593      * @return Returns ERR_OK on success, others on failure.
594      */
595     ErrCode Unsubscribe(const sptr<IAnsSubscriber> &subscriber,
596         const sptr<NotificationSubscribeInfo> &info) override;
597 
598     ErrCode Unsubscribe(const sptr<IAnsSubscriber> &subscriber) override;
599 
600     /**
601      * @brief Checks whether this device is allowed to publish notifications.
602      *
603      * @param allowed Indicates the flag that allows notification.
604      * @return Returns ERR_OK on success, others on failure.
605      */
606     ErrCode IsAllowedNotify(bool &allowed) override;
607 
608     /**
609      * @brief Checks whether this application is allowed to publish notifications.
610      *
611      * @param allowed Indicates the flag that allows notification.
612      * @return Returns ERR_OK on success, others on failure.
613      */
614     ErrCode IsAllowedNotifySelf(bool &allowed) override;
615 
616     /**
617      * @brief Checks whether this application can pop enable notification dialog.
618      *
619      * @param  canPop True if can pop enable notification dialog
620      * @return Returns is canPop result.
621      */
622     ErrCode CanPopEnableNotificationDialog(const sptr<IAnsDialogCallback> &callback,
623         bool &canPop, std::string &bundleName) override;
624 
625     /**
626      * @brief remove enable notification dialog.
627      *
628      * @return Returns remove dialog result.
629      */
630     ErrCode RemoveEnableNotificationDialog() override;
631 
632     ErrCode RemoveEnableNotificationDialog(const sptr<NotificationBundleOption> &bundleOption);
633 
634     /**
635      * @brief Checks whether notifications are allowed for a specific bundle.
636      *
637      * @param bundleOption Indicates the NotificationBundleOption object.
638      * @param allowed Indicates the flag that allows notification.
639      * @return Returns ERR_OK on success, others on failure.
640      */
641     ErrCode IsSpecialBundleAllowedNotify(const sptr<NotificationBundleOption> &bundleOption, bool &allowed) override;
642 
643     /**
644      * @brief Set do not disturb date.
645      *
646      * @param date Indicates the NotificationDoNotDisturbDate object.
647      * @return Returns ERR_OK on success, others on failure.
648      */
649     ErrCode SetDoNotDisturbDate(const sptr<NotificationDoNotDisturbDate> &date) override;
650 
651     /**
652      * @brief Get do not disturb date.
653      *
654      * @param date Indicates the NotificationDoNotDisturbDate object.
655      * @return Returns ERR_OK on success, others on failure.
656      */
657     ErrCode GetDoNotDisturbDate(sptr<NotificationDoNotDisturbDate> &date) override;
658 
659     /**
660      * @brief Add Do Not Disturb profiles.
661      *
662      * @param profiles Indicates the list of NotificationDoNotDisturbProfile objects to add.
663      * @return Returns ERR_OK on success, others on failure.
664      */
665     ErrCode AddDoNotDisturbProfiles(const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles) override;
666 
667     /**
668      * @brief Remove Do Not Disturb profiles.
669      *
670      * @param profiles Indicates the list of NotificationDoNotDisturbProfile objects to remove.
671      * @return Returns ERR_OK on success, others on failure.
672      */
673     ErrCode RemoveDoNotDisturbProfiles(const std::vector<sptr<NotificationDoNotDisturbProfile>> &profiles) override;
674 
675     /**
676      * @brief Get whether Do Not Disturb mode is supported.
677      *
678      * @param doesSupport Indicates the flag that supports DND mode.
679      * @return Returns ERR_OK on success, others on failure.
680      */
681     ErrCode DoesSupportDoNotDisturbMode(bool &doesSupport) override;
682 
683     /**
684      * @brief Is coming call need silent in do not disturb mode.
685      *
686      * @param phoneNumber the calling format number.
687      * @return Returns silent in do not disturb mode.
688      */
689     ErrCode IsNeedSilentInDoNotDisturbMode(const std::string &phoneNumber, int32_t callerType) override;
690 
691     /**
692      * @brief Cancel notifications according to group.
693      *
694      * @param groupName Indicates the group name.
695      * @param instanceKey Indicates the application instance key.
696      * @return Returns ERR_OK on success, others on failure.
697      */
698     ErrCode CancelGroup(const std::string &groupName, const std::string &instanceKey) override;
699 
700     /**
701      * @brief Delete notifications according to bundle and group.
702      *
703      * @param bundleOption Indicates the NotificationBundleOption object.
704      * @param groupName Indicates the group name.
705      * @return Returns ERR_OK on success, others on failure.
706      */
707     ErrCode RemoveGroupByBundle(
708         const sptr<NotificationBundleOption> &bundleOption, const std::string &groupName) override;
709 
710     /**
711      * @brief Gets whether distributed notification is enabled.
712      *
713      * @param enabled Indicates the enabled flag.
714      * @return Returns ERR_OK on success, others on failure.
715      */
716     ErrCode IsDistributedEnabled(bool &enabled) override;
717 
718     /**
719      * @brief Sets distributed notification enabled or disabled.
720      *
721      * @param enabled Indicates the enabled flag.
722      * @return Returns ERR_OK on success, others on failure.
723      */
724     ErrCode EnableDistributed(bool enabled) override;
725 
726     /**
727      * @brief Sets distributed notification enabled or disabled for specific bundle.
728      *
729      * @param bundleOption Indicates the NotificationBundleOption object.
730      * @param enabled Indicates the enabled flag.
731      * @return Returns ERR_OK on success, others on failure.
732      */
733     ErrCode EnableDistributedByBundle(const sptr<NotificationBundleOption> &bundleOption, bool enabled) override;
734 
735     /**
736      * @brief Sets distributed notification enabled or disabled for current bundle.
737      *
738      * @param enabled Indicates the enabled flag.
739      * @return Returns ERR_OK on success, others on failure.
740      */
741     ErrCode EnableDistributedSelf(bool enabled) override;
742 
743     /**
744      * @brief Gets whether distributed notification is enabled for specific bundle.
745      *
746      * @param bundleOption Indicates the NotificationBundleOption object.
747      * @param enabled Indicates the enabled flag.
748      * @return Returns ERR_OK on success, others on failure.
749      */
750     ErrCode IsDistributedEnableByBundle(const sptr<NotificationBundleOption> &bundleOption, bool &enabled) override;
751 
752     /**
753      * @brief Get the reminder type of the current device.
754      *
755      * @param remindType Reminder type for the device.
756      * @return Returns ERR_OK on success, others on failure.
757      */
758     ErrCode GetDeviceRemindType(int32_t& remindTypeInt) override;
759 
760     /**
761      * @brief Publishes a continuous notification.
762      *
763      * @param request Notification requests that need to be posted.
764      * @return Returns ERR_OK on success, others on failure.
765      */
766     ErrCode PublishContinuousTaskNotification(const sptr<NotificationRequest> &request) override;
767 
768     /**
769      * @brief Cancels a continuous notification.
770      *
771      * @param label Identifies the label of the specified notification.
772      * @param notificationId Identifies the id of the specified notification.
773      * @return Returns ERR_OK on success, others on failure.
774      */
775     ErrCode CancelContinuousTaskNotification(const std::string &label, int32_t notificationId) override;
776 
777     /**
778      * @brief Check reminder permission
779      */
780     bool CheckReminderPermission();
781 
782     /**
783      * @brief Checks whether this device is support template.
784      *
785      * @param templateName Identifies the template name for searching as a condition.
786      * @param support Identifies the support flag.
787      * @return Returns ERR_OK on success, others on failure.
788      */
789     ErrCode IsSupportTemplate(const std::string &templateName, bool &support) override;
790 
791     /**
792      * @brief Checks Whether the specified users is allowed to publish notifications.
793      *
794      * @param userId Identifies the user's id.
795      * @param allowed Identifies the allowed flag.
796      * @return Returns ERR_OK on success, others on failure.
797      */
798     ErrCode IsSpecialUserAllowedNotify(int32_t userId, bool &allowed) override;
799 
800     /**
801      * @brief Sets whether to allow all applications to publish notifications on a specified device. The caller must
802      * have system permissions to call this method.
803      *
804      * @param deviceId Indicates the ID of the device running the application. At present, this parameter can only
805      *                 be null or an empty string, indicating the current device.
806      * @param enabled Specifies whether to allow all applications to publish notifications. The value true
807      *                indicates that notifications are allowed, and the value false indicates that notifications
808      *                are not allowed.
809      * @return Returns ERR_OK on success, others on failure.
810      */
811     ErrCode SetNotificationsEnabledByUser(int32_t userId, bool enabled) override;
812 
813     /**
814      * @brief Delete all notifications by user.
815      *
816      * @param userId Indicates the user id.
817      * @return Returns ERR_OK on success, others on failure.
818      */
819     ErrCode DeleteAllByUser(int32_t userId) override;
820 
821     /**
822      * @brief Set do not disturb date by user.
823      *
824      * @param userId Indicates the user id.
825      * @param date Indicates NotificationDoNotDisturbDate object.
826      * @return Returns ERR_OK on success, others on failure.
827      */
828     ErrCode SetDoNotDisturbDate(int32_t userId, const sptr<NotificationDoNotDisturbDate> &date) override;
829 
830     /**
831      * @brief Get the do not disturb date by user.
832      *
833      * @param userId Indicates the user id.
834      * @param date Indicates the NotificationDoNotDisturbDate object.
835      * @return Returns ERR_OK on success, others on failure.
836      */
837     ErrCode GetDoNotDisturbDate(int32_t userId, sptr<NotificationDoNotDisturbDate> &date) override;
838 
839     ErrCode SetEnabledForBundleSlot(const sptr<NotificationBundleOption> &bundleOption,
840         int32_t slotTypeInt, bool enabled, bool isForceControl) override;
841 
842     ErrCode GetEnabledForBundleSlot(const sptr<NotificationBundleOption> &bundleOption,
843         int32_t slotTypeInt, bool &enabled) override;
844 
845     ErrCode GetEnabledForBundleSlotSelf(int32_t slotTypeInt, bool &enabled) override;
846 
847     // SystemEvent
848 
849     /**
850      * @brief Obtains the event of bundle removed.
851      *
852      * @param bundleOption Indicates the bundle info.
853      */
854     void OnBundleRemoved(const sptr<NotificationBundleOption> &bundleOption);
855 
856     /**
857      * @brief Obtains the event of bundle batch removed.
858      *
859      * @param notifications Notification vector.
860      */
861     void ExecBatchCancel(std::vector<sptr<Notification>> &notifications, int32_t &reason);
862 
863     /**
864      * @brief Obtains the event of user removed.
865      *
866      * @param userId Indicates the user.
867      */
868     void OnUserRemoved(const int32_t &userId);
869 
870     /**
871      * @brief Set whether to sync notifications to devices that do not have the app installed.
872      *
873      * @param userId Indicates the specific user.
874      * @param enabled Allow or disallow sync notifications.
875      * @return Returns set enabled result.
876      */
877     ErrCode SetSyncNotificationEnabledWithoutApp(const int32_t userId, const bool enabled) override;
878 
879     /**
880      * @brief Obtains whether to sync notifications to devices that do not have the app installed.
881      *
882      * @param userId Indicates the specific user.
883      * @param enabled Allow or disallow sync notifications.
884      * @return Returns get enabled result.
885      */
886     ErrCode GetSyncNotificationEnabledWithoutApp(const int32_t userId, bool &enabled) override;
887 
888     /**
889      * @brief Obtains the number of slotFlags.
890      *
891      * @param bundleOption Indicates the bundle name and uid of the application.
892      * @param slot      Indicates the specified slot object
893      * @param slotFlags Indicates the slogFlags of slot.
894      * @return Returns ERR_OK on success, others on failure.
895      */
896     virtual ErrCode GetSlotFlagsAsBundle(const sptr<NotificationBundleOption>& bundleOption,
897         uint32_t &slotFlags) override;
898 
899     /**
900      * @brief Obtains the number of slotFlags.
901      *
902      * @param slotFlags Indicates the slogFlags of slot.
903      * @return Returns ERR_OK on success, others on failure.
904      */
905     virtual ErrCode GetNotificationSettings(uint32_t &slotFlags) override;
906 
907     /**
908      * @brief Set the slotFlags of slot.
909      *
910      * @param bundleOption Indicates the bundle name and uid of the application.
911      * @param slot      Indicates the specified slot object
912      * @param slotFlags Indicates the slogFlags of slot to set.
913      * @return Returns ERR_OK on success, others on failure.
914      */
915     virtual ErrCode SetSlotFlagsAsBundle(const sptr<NotificationBundleOption>& bundleOption,
916         uint32_t slotFlags) override;
917 
918 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
919     /**
920      * @brief Obtains the event of turn on screen.
921      */
922     void OnScreenOn();
923 
924     /**
925      * @brief Obtains the event of turn off screen.
926      */
927     void OnScreenOff();
928 #endif
929     void OnResourceRemove(int32_t userId);
930     void OnUserStopped(int32_t userId);
931     void OnBundleDataCleared(const sptr<NotificationBundleOption> &bundleOption);
932     void DeleteAllByUserStopped(int32_t userId);
933 
934     /**
935      * @brief Obtains the event of bundle install.
936      *
937      * @param bundleOption Indicates the bundle info.
938      */
939     void OnBundleDataAdd(const sptr<NotificationBundleOption> &bundleOption);
940 
941     /**
942      * @brief Obtains the event of bundle update.
943      *
944      * @param bundleOption Indicates the bundle info.
945      */
946     void OnBundleDataUpdate(const sptr<NotificationBundleOption> &bundleOption);
947 
948     /**
949      * @brief Boot system completed event callback.
950      */
951     void OnBootSystemCompleted();
952 
953     // Distributed KvStore
954 
955     /**
956      * @brief Obtains the death event of the Distributed KvStore service.
957      */
958     void OnDistributedKvStoreDeathRecipient();
959 
960     ErrCode CancelPreparedNotification(int32_t notificationId, const std::string &label,
961         const sptr<NotificationBundleOption> &bundleOption, const int32_t reason);
962 
963     ErrCode PrepareNotificationInfo(
964         const sptr<NotificationRequest> &request, sptr<NotificationBundleOption> &bundleOption);
965     ErrCode PublishPreparedNotification(const sptr<NotificationRequest> &request,
966         const sptr<NotificationBundleOption> &bundleOption, bool isUpdateByOwner = false);
967 
968     /**
969      * @brief Dump current running status for debuging.
970      *
971      * @param cmd Indicates the specified dump command.
972      * @param bundle Indicates the specified bundle name.
973      * @param userId Indicates the specified userId.
974      * @param dumpInfo Indicates the container containing datas.
975      * @return Returns ERR_OK on success, others on failure.
976      */
977     ErrCode ShellDump(const std::string &cmd, const std::string &bundle, int32_t userId, int32_t recvUserId,
978         std::vector<std::string> &dumpInfo) override;
979 
980     /**
981      * @brief Set badge number.
982      *
983      * @param badgeNumber The badge number.
984      * @param instanceKey The application instance key.
985      * @return Returns set badge number result.
986      */
987     ErrCode SetBadgeNumber(int32_t badgeNumber, const std::string &instanceKey) override;
988 
989     /**
990      * @brief Set badge number by bundle.
991      *
992      * @param bundleOption Indicates the bundle name and uid of the application.
993      * @param badgeNumber The badge number.
994      * @return Returns set badge number by bundle result.
995      */
996     ErrCode SetBadgeNumberByBundle(const sptr<NotificationBundleOption> &bundleOption, int32_t badgeNumber) override;
997 
998     /**
999      * @brief Set badge number for dh by bundle.
1000      *
1001      * @param bundleOption Indicates the bundle name and uid of the application.
1002      * @param badgeNumber The badge number.
1003      * @return Returns set badge number by bundle result.
1004      */
1005     ErrCode SetBadgeNumberForDhByBundle(
1006         const sptr<NotificationBundleOption> &bundleOption, int32_t badgeNumber) override;
1007 
1008     /**
1009      * @brief Obtains allow notification application list.
1010      *
1011      * @param bundleOption Indicates the bundle bundleOption.
1012      * @return Returns ERR_OK on success, others on failure.
1013      */
1014     ErrCode GetAllNotificationEnabledBundles(std::vector<NotificationBundleOption> &bundleOption) override;
1015 
1016     /**
1017      * @brief Obtains allow liveview application list.
1018      *
1019      * @param bundleOption Indicates the bundle bundleOption.
1020      * @return Returns ERR_OK on success, others on failure.
1021      */
1022     ErrCode GetAllLiveViewEnabledBundles(std::vector<NotificationBundleOption> &bundleOption) override;
1023 
1024     /**
1025      * @brief Obtains allow distribued application list.
1026      *
1027      * @param deviceType Indicates device type.
1028      * @param bundleOption Indicates the bundle bundleOption.
1029      * @return Returns ERR_OK on success, others on failure.
1030      */
1031     ErrCode GetAllDistribuedEnabledBundles(const std::string &deviceType,
1032         std::vector<NotificationBundleOption> &bundleOption) override;
1033 
1034     /**
1035      * @brief Register Push Callback.
1036      *
1037      * @param pushCallback PushCallBack.
1038      * @param notificationCheckRequest Filter conditions for push check
1039      * @return Returns register push Callback result.
1040      */
1041     ErrCode RegisterPushCallback(const sptr<IRemoteObject>& pushCallback,
1042         const sptr<NotificationCheckRequest> &notificationCheckRequest) override;
1043 
1044     /**
1045      * @brief Unregister Push Callback.
1046      *
1047      * @return Returns unregister push Callback result.
1048      */
1049     ErrCode UnregisterPushCallback() override;
1050 
1051     /**
1052      * @brief Sets whether to allow a specified application to publish notifications cross
1053      * device collaboration. The caller must have system permissions to call this method.
1054      *
1055      * @param bundleOption Indicates the bundle name and uid of the application.
1056      * @param deviceType Indicates the type of the device running the application.
1057      * @param enabled Specifies whether to allow the given application to publish notifications. The value
1058      *                true indicates that notifications are allowed, and the value false indicates that
1059      *                notifications are not allowed.
1060      * @return Returns set notifications enabled for specified bundle result.
1061      */
1062     ErrCode SetDistributedEnabledByBundle(const sptr<NotificationBundleOption> &bundleOption,
1063         const std::string &deviceType, const bool enabled) override;
1064 
1065     /**
1066      * @brief Sets whether to allow a specified application to publish notifications cross
1067      * device collaboration. The caller must have system permissions to call this method.
1068      *
1069      * @param bundles Indicates the bundles.
1070      * @param deviceType Indicates the type of the device running the application.
1071      * @return Returns set distributed enabled for specified bundle result.
1072      */
1073     ErrCode SetDistributedBundleOption(const std::vector<sptr<DistributedBundleOption>> &bundles,
1074         const std::string &deviceType) override;
1075 
1076     /**
1077      * @brief Get whether to allow a specified application to publish notifications cross
1078      * device collaboration. The caller must have system permissions to call this method.
1079      *
1080      * @param bundleOption Indicates the bundle name and uid of the application.
1081      * @param deviceType Indicates the type of the device running the application.
1082      * @param enabled Specifies whether to allow the given application to publish notifications. The value
1083      *                true indicates that notifications are allowed, and the value false indicates that
1084      *                notifications are not allowed.
1085      * @return Returns set notifications enabled for specified bundle result.
1086      */
1087     ErrCode IsDistributedEnabledByBundle(const sptr<NotificationBundleOption> &bundleOption,
1088         const std::string &deviceType, bool &enabled) override;
1089 
1090     /**
1091      * @brief Sets whether to allow a specified application to publish notifications cross
1092      * device collaboration. The caller must have system permissions to call this method.
1093      *
1094      * @param bundleOption Indicates the bundle name and uid of the application.
1095      * @param enabled Specifies whether to allow the given application to publish notifications. The value
1096      *                true indicates that notifications are allowed, and the value false indicates that
1097      *                notifications are not allowed.
1098      * @return Returns set notifications enabled for specified bundle result.
1099      */
1100     ErrCode SetSilentReminderEnabled(const sptr<NotificationBundleOption> &bundleOption, const bool enabled) override;
1101 
1102     /*
1103      * @brief Get whether to allow a specified application to publish notifications cross
1104      * device collaboration. The caller must have system permissions to call this method.
1105      *
1106      * @param bundleOption Indicates the bundle name and uid of the application.
1107      * @param enabled Specifies whether to allow the given application to publish notifications. The value
1108      *                true indicates that notifications are allowed, and the value false indicates that
1109      *                notifications are not allowed.
1110      * @return Returns set notifications enabled for specified bundle result.
1111      */
1112     ErrCode IsSilentReminderEnabled(const sptr<NotificationBundleOption> &bundleOption, int32_t &enableStatus) override;
1113 
1114     /**
1115      * @brief configuring Whether to Synchronize Common Notifications to Target Devices.
1116      *
1117      * @param deviceType Target device type.
1118      * @param enabled Whether to Synchronize Common Notifications to Target Devices.
1119      * @return Returns configuring Whether to Synchronize Common Notifications to Target Devices result.
1120      */
1121     ErrCode SetDistributedEnabled(const std::string &deviceType, const bool enabled) override;
1122 
1123     /**
1124      * @brief querying Whether to Synchronize Common Devices to Target Devices.
1125      *
1126      * @param deviceType Target device type.
1127      * @param enabled Whether to Synchronize Common Notifications to Target Devices.
1128      * @return Returns Whether to Synchronize Common Notifications to Target Devices result.
1129      */
1130     ErrCode IsDistributedEnabled(const std::string &deviceType, bool &enabled) override;
1131 
1132     /**
1133      * @brief Obtains the set of supported distributed abilities.
1134      *
1135      * @param abilityId The set of supported distributed abilities.
1136      * @return Returns result in Obtains the set of supported distributed abilities.
1137      */
1138     ErrCode GetDistributedAbility(int32_t &abilityId) override;
1139 
1140     /**
1141      * @brief Get the target device's authorization status.
1142      *
1143      * @param deviceType Type of the target device whose status you want to set.
1144      * @param deviceId The id of the target device.
1145      * @param userId The userid of the target device.
1146      * @param isAuth Return The authorization status.
1147      * @return Returns get result.
1148      */
1149     ErrCode GetDistributedAuthStatus(
1150         const std::string &deviceType, const std::string &deviceId, int32_t userId, bool &isAuth) override;
1151 
1152     /**
1153      * @brief Set the target device's authorization status.
1154      *
1155      * @param deviceType Type of the target device whose status you want to set.
1156      * @param deviceId The id of the target device.
1157      * @param userId The userid of the target device.
1158      * @param isAuth The authorization status.
1159      * @return Returns set result.
1160      */
1161     ErrCode SetDistributedAuthStatus(
1162         const std::string &deviceType, const std::string &deviceId, int32_t userId, bool isAuth) override;
1163 
1164     /**
1165      * @brief get distributed device list.
1166      *
1167      * @param deviceTypes Indicates device types.
1168      * @return Returns ERR_OK on success, others on failure.
1169      */
1170     ErrCode GetDistributedDevicelist(std::vector<std::string> &deviceTypes) override;
1171 
1172     /**
1173      * @brief Get Enable smartphone to collaborate with other devices for intelligent reminders
1174      *
1175      * @param deviceType Indicates the type of the device running the application.
1176      * @param enabled Specifies whether to allow the given device to publish notifications.
1177      *                The value true indicates that notifications are allowed, and the value
1178      *                false indicates that notifications are not allowed.
1179      * @return Returns set notifications enabled for specified bundle result.
1180      */
1181     ErrCode IsSmartReminderEnabled(const std::string &deviceType, bool &enabled) override;
1182 
1183     /**
1184      * @brief Set Enable smartphone to collaborate with other devices for intelligent reminders
1185      *
1186      * @param deviceType Indicates the type of the device running the application.
1187      * @param enabled Specifies whether to allow the given device to publish notifications.
1188      *                The value true indicates that notifications are allowed, and the value
1189      *                false indicates that notifications are not allowed.
1190      * @return Returns set notifications enabled for specified bundle result.
1191      */
1192     ErrCode SetSmartReminderEnabled(const std::string &deviceType, const bool enabled) override;
1193 
1194     /**
1195      * @brief Set the channel switch for collaborative reminders.
1196        The caller must have system permissions to call this method.
1197      *
1198      * @param slotType Indicates the slot type of the application.
1199      * @param deviceType Indicates the type of the device running the application.
1200      * @param enabled Indicates slot switch status.
1201      * @return Returns set channel switch result.
1202      */
1203     ErrCode SetDistributedEnabledBySlot(
1204         int32_t slotTypeInt, const std::string &deviceType, bool enabled) override;
1205 
1206     /**
1207      * @brief Query the channel switch for collaborative reminders.
1208        The caller must have system permissions to call this method.
1209      *
1210      * @param slotType Indicates the slot type of the application.
1211      * @param deviceType Indicates the type of the device running the application.
1212      * @param enabled Indicates slot switch status.
1213      * @return Returns channel switch result.
1214      */
1215     ErrCode IsDistributedEnabledBySlot(
1216         int32_t slotTypeInt, const std::string &deviceType, bool &enabled) override;
1217 
1218     /**
1219      * @brief Set the status of the target device.
1220      *
1221      * @param deviceType Type of the device whose status you want to set.
1222      * @param status The status.
1223      * @return Returns set result.
1224      */
1225     ErrCode SetTargetDeviceStatus(const std::string &deviceType, uint32_t status,
1226         const std::string &deviceId) override;
1227 
1228     /**
1229      * @brief Set the status of the target device.
1230      *
1231      * @param deviceType Type of the device whose status you want to set.
1232      * @param status The status.
1233      * @return Returns set result.
1234      */
1235     ErrCode SetTargetDeviceStatus(const std::string &deviceType, uint32_t status,
1236         uint32_t controlFlag, const std::string &deviceId, int32_t userId) override;
1237 
1238     ErrCode SetTargetDeviceBundleList(const std::string& deviceType, const std::string& deviceId,
1239         int operatorType, const std::vector<std::string>& bundleList,
1240         const std::vector<std::string>& labelList) override;
1241 
1242     ErrCode SetTargetDeviceSwitch(const std::string& deviceType, const std::string& deviceId,
1243         bool notificaitonEnable, bool liveViewEnable) override;
1244 
1245     ErrCode GetTargetDeviceBundleList(const std::string& deviceType, const std::string& deviceId,
1246         std::vector<std::string>& bundleList, std::vector<std::string>& labelList) override;
1247 
1248     ErrCode GetMutilDeviceStatus(const std::string &deviceType, const uint32_t status,
1249         std::string& deviceId, int32_t& userId) override;
1250 
1251     /**
1252      * @brief clear notification when aggregate local switch close.
1253      */
1254     void ClearAllNotificationGroupInfo(std::string localSwitch);
1255 
1256     /**
1257      * @brief Reset pushcallback proxy
1258      */
1259     void ResetPushCallbackProxy(NotificationConstant::SlotType slotType);
1260 
1261     /**
1262      * @brief Set the notification SlotFlags whitelist.
1263      */
1264     void SetSlotFlagsTrustlistsAsBundle(const sptr<NotificationBundleOption> &bundleOption);
1265 
1266     /**
1267      * @brief Init The Default Installation Package Notification Enabled.
1268      */
1269     void InitNotificationEnableList();
1270     /**
1271      * @brief Remove Local Live Notifications
1272      */
1273     ErrCode RemoveSystemLiveViewNotifications(const std::string& bundleName, const int32_t uid);
1274 
1275     /**
1276      * @brief Remove Local Live Notifications created by sa.
1277      */
1278     ErrCode RemoveSystemLiveViewNotificationsOfSa(int32_t uid);
1279 
1280     /**
1281      * @brief Set the notification flags by soltType.
1282      */
1283     void SetRequestBySlotType(const sptr<NotificationRequest> &request,
1284         const sptr<NotificationBundleOption> &bundleOption);
1285 
1286     void HandleFlagsWithRequest(const sptr<NotificationRequest> &request,
1287         const sptr<NotificationBundleOption> &bundleOption);
1288 
1289     // Might fail if ces subscribe failed, if failed, dialogManager_ will be set nullptr
1290     bool CreateDialogManager();
1291 
1292     /**
1293      * @brief Set agent relationship.
1294      *
1295      * @param key Indicates storing agent relationship if the value is "PROXY_PKG".
1296      * @param value Indicates key-value pair of agent relationship.
1297      * @return Returns set result.
1298      */
1299     ErrCode SetAdditionConfig(const std::string &key, const std::string &value) override;
1300 
1301     /**
1302      * @brief Cancels a published agent notification.
1303      *
1304      * @param bundleOption Indicates the bundle name and uid of the application.
1305      * @param id Indicates the unique notification ID in the application.
1306      * @return Returns cancel result.
1307      */
1308     ErrCode CancelAsBundleWithAgent(const sptr<NotificationBundleOption> &bundleOption, const int32_t id) override;
1309 
1310     /**
1311      * @brief Get the status of the target device.
1312      *
1313      * @param deviceType Type of the device whose status you want to set.
1314      * @param status The status.
1315      * @return Returns set result.
1316      */
1317     ErrCode GetTargetDeviceStatus(const std::string &deviceType, int32_t &status) override;
1318 
1319     /**
1320      * @brief Init publish process.
1321      */
1322     bool InitPublishProcess();
1323 
1324     /**
1325     * @brief Recover LiveView from DB.
1326     */
1327     void RecoverLiveViewFromDb(int32_t userId = -1);
1328 
1329 #ifdef NOTIFICATION_SMART_REMINDER_SUPPORTED
1330     /**
1331      * @brief Register Swing Callback.
1332      *
1333      * @param swingCallback SwingCallBack.
1334      * @return Returns register swing Callback result.
1335      */
1336     ErrCode RegisterSwingCallback(const sptr<IRemoteObject>& swingCallback) override;
1337 #endif
1338 
1339     /**
1340      * @brief update unified group info.
1341      */
1342     void UpdateUnifiedGroupInfo(const std::string &key, std::shared_ptr<NotificationUnifiedGroupInfo> &groupInfo);
1343 
1344     /**
1345      * @brief Whether reminders are allowed.
1346      */
1347     bool AllowUseReminder(const std::string& bundleName);
1348 
1349     /**
1350      * @brief Whether reminders are allowed.
1351      *
1352      * @param bundleName app bundleName
1353      * @param isAllowUseReminder is allow use reminder
1354      * @return Returns ERR_OK on success, others on failure.
1355      */
1356     ErrCode AllowUseReminder(const std::string& bundleName, bool& isAllowUseReminder) override;
1357 
1358     /**
1359      * @brief Get do not disturb profile by id.
1360      *
1361      * @param id Profile id.
1362      * @param status Indicates the NotificationDoNotDisturbProfile object.
1363      * @return Returns ERR_OK on success, others on failure.
1364      */
1365     ErrCode GetDoNotDisturbProfile(int64_t id, sptr<NotificationDoNotDisturbProfile> &profile) override;
1366 
1367     /**
1368      * @brief Distribution operation based on hashCode.
1369      *
1370      * @param hashCode Unique ID of the notification.
1371      * @return Returns ERR_OK on success, others on failure.
1372      */
1373     ErrCode DistributeOperation(const sptr<NotificationOperationInfo>& operationInfo,
1374         const sptr<IAnsOperationCallback> &callback) override;
1375 
1376     /**
1377      * @brief Reply distribute operation.
1378      *
1379      * @param hashCode Unique ID of the notification.
1380      * @param result The result of the distribute operation.
1381      * @return Returns ERR_OK on success, others on failure.
1382      */
1383     ErrCode ReplyDistributeOperation(const std::string& hashCode, const int32_t result) override;
1384 
1385     /**
1386      * @brief Get notificationRequest by hashCode.
1387      *
1388      * @param hashCode Unique ID of the notification.
1389      * @param notificationRequest The request of of the notification.
1390      * @return Returns ERR_OK on success, others on failure.
1391      */
1392     ErrCode GetNotificationRequestByHashCode(
1393         const std::string& hashCode, sptr<NotificationRequest>& notificationRequest) override;
1394 
1395     int32_t OnBackup(MessageParcel& data, MessageParcel& reply);
1396 
1397     int32_t OnRestore(MessageParcel& data, MessageParcel& reply);
1398 
1399     void ResetDistributedEnabled();
1400 
1401     ErrCode UpdateNotificationTimerByUid(const int32_t uid, const bool isPaused) override;
1402 
1403     void UpdateCloneBundleInfo(const NotificationCloneBundleInfo cloneBundleInfo);
1404 
1405     void UpdateCloneBundleInfoForEnable(
1406         const NotificationCloneBundleInfo cloneBundleInfo, const sptr<NotificationBundleOption> bundle);
1407 
1408     void UpdateCloneBundleInfoFoSlot(
1409         const NotificationCloneBundleInfo cloneBundleInfo, const sptr<NotificationBundleOption> bundle);
1410 
1411     void UpdateCloneBundleInfoFoSilentReminder(
1412         const NotificationCloneBundleInfo cloneBundleInfo, const sptr<NotificationBundleOption> bundle);
1413 
1414     void TryStartReminderAgentService();
1415 
1416     static sptr<NotificationBundleOption> GenerateBundleOption();
1417     static sptr<NotificationBundleOption> GenerateValidBundleOption(const sptr<NotificationBundleOption> &bundleOption);
1418 
1419     ErrCode DisableNotificationFeature(const sptr<NotificationDisable> &notificationDisable) override;
1420 
1421     bool IsDisableNotification(const std::string &bundleName);
1422 
1423     bool IsDisableNotificationByKiosk(const std::string &bundleName);
1424 
1425     bool IsDisableNotificationForSaByKiosk(const std::string &bundleName, bool directAgency);
1426 
1427     bool IsNeedToControllerByDisableNotification(const sptr<NotificationRequest> &request);
1428 
1429     void SetAndPublishSubscriberExistFlag(const std::string& deviceType, bool existFlag);
1430     ErrCode RemoveAllNotificationsByBundleName(const std::string &bundleName, int32_t reason);
1431 
1432     /**
1433      * @brief set rule of generate hashCode.
1434      *
1435      * @param type generate hashCode.
1436      * @return Returns ERR_OK on success, others on failure.
1437      */
1438     ErrCode SetHashCodeRule(const uint32_t type) override;
1439 
1440     ErrCode AtomicServicePublish(const sptr<NotificationRequest> &request);
1441 
1442 protected:
1443     /**
1444      * @brief Query whether there is a agent relationship between the two apps.
1445      *
1446      * @param agentBundleName The bundleName of the agent app.
1447      * @param sourceBundleName The bundleName of the source app.
1448      * @return Returns true if There is an agent relationship; returns false otherwise.
1449      */
1450     bool IsAgentRelationship(const std::string &agentBundleName, const std::string &sourceBundleName);
1451 
1452 public:
1453     bool CheckApiCompatibility(const sptr<NotificationBundleOption> &bundleOption);
1454     ErrCode SetDefaultNotificationEnabled(
1455         const sptr<NotificationBundleOption> &bundleOption, bool enabled);
1456     ErrCode RemoveNotificationBySlot(const sptr<NotificationBundleOption> &bundleOption,
1457         const sptr<NotificationSlot> &slot, const int reason);
1458     bool PublishSlotChangeCommonEvent(const sptr<NotificationBundleOption> &bundleOption);
1459 private:
1460     struct RecentInfo {
1461         std::list<std::shared_ptr<RecentNotification>> list;
1462         size_t recentCount = 16;
1463     };
1464 
1465     struct SoundPermissionInfo {
1466         std::set<std::string> bundleName_;
1467         std::atomic<bool> needUpdateCache_ = true;
1468         bool allPackage_ = false;
1469         ffrt::mutex dbMutex_;
1470     };
1471 
1472     enum UploadStatus {
1473         CREATE,
1474         FIRST_UPDATE_TIME_OUT,
1475         CONTINUOUS_UPDATE_TIME_OUT,
1476         END,
1477         FINISH
1478     };
1479 
1480     enum ContactPolicy {
1481         FORBID_EVERYONE = 1,
1482         ALLOW_EVERYONE = 2,
1483         ALLOW_EXISTING_CONTACTS = 3,
1484         ALLOW_FAVORITE_CONTACTS = 4,
1485         ALLOW_SPECIFIED_CONTACTS = 5,
1486         FORBID_SPECIFIED_CONTACTS = 6,
1487     };
1488 
1489     /**
1490      * @brief Set whether to allow the specified bundle to send notifications.
1491      *
1492      * @param bundleOption Indicates the NotificationBundleOption object.
1493      * @param enabled Indicates the flag that allows notification to be pulished.
1494      * @param updateUnEnableTime Indicates whether update the unenable time.
1495      * @param isSystemCall Indicates whether set by system.
1496      * @return Returns ERR_OK on success, others on failure.
1497      */
1498     ErrCode SetNotificationsEnabledForSpecialBundleImpl(
1499         const std::string &deviceId, const sptr<NotificationBundleOption> &bundleOption, bool enabled,
1500         bool updateUnEnableTime = true, bool isSystemCall = false);
1501 
1502     AdvancedNotificationService();
1503 
1504     void StartFilters();
1505     void StopFilters();
1506     ErrCode Filter(const std::shared_ptr<NotificationRecord> &record, bool isRecover = false);
1507     void ChangeNotificationByControlFlags(const std::shared_ptr<NotificationRecord> &record,
1508         const bool isAgentController);
1509     ErrCode CheckPublishPreparedNotification(const std::shared_ptr<NotificationRecord> &record, bool isSystemApp);
1510     void AddToNotificationList(const std::shared_ptr<NotificationRecord> &record);
1511     void AddToDelayNotificationList(const std::shared_ptr<NotificationRecord> &record);
1512     ErrCode UpdateInNotificationList(const std::shared_ptr<NotificationRecord> &record);
1513     void UpdateInDelayNotificationList(const std::shared_ptr<NotificationRecord> &record);
1514     ErrCode AssignToNotificationList(const std::shared_ptr<NotificationRecord> &record);
1515     ErrCode RemoveFromNotificationList(const sptr<NotificationBundleOption> &bundleOption,
1516         NotificationKey notificationKey, sptr<Notification> &notification, int32_t removeReason,
1517         bool isCancel = false);
1518     ErrCode RemoveFromNotificationList(const std::string &key, sptr<Notification> &notification,
1519         bool isCancel, int32_t removeReason);
1520     ErrCode RemoveFromNotificationListForDeleteAll(const std::string &key,
1521         const int32_t &userId, sptr<Notification> &notification, bool removeAll = false);
1522     bool RemoveFromDelayedNotificationList(const std::string &key);
1523     std::shared_ptr<NotificationRecord> GetFromNotificationList(const std::string &key);
1524     std::shared_ptr<NotificationRecord> GetFromNotificationList(const int32_t ownerUid, const int32_t notificationId);
1525     std::shared_ptr<NotificationRecord> GetFromDelayedNotificationList(
1526         const int32_t ownerUid, const int32_t notificationId);
1527     std::vector<std::string> GetNotificationKeys(const sptr<NotificationBundleOption> &bundleOption);
1528     std::vector<std::string> GetNotificationKeysByBundle(const sptr<NotificationBundleOption> &bundleOption);
1529     bool IsNotificationExists(const std::string &key);
1530     void SortNotificationList();
1531     static bool NotificationCompare(
1532         const std::shared_ptr<NotificationRecord> &first, const std::shared_ptr<NotificationRecord> &second);
1533     ErrCode PublishInNotificationList(const std::shared_ptr<NotificationRecord> &record);
1534 
1535     sptr<NotificationSortingMap> GenerateSortingMap();
1536 
1537     std::string TimeToString(int64_t time);
1538     void ExtendDumpForFlags(std::shared_ptr<NotificationFlags>, std::stringstream &stream);
1539     ErrCode ActiveNotificationDump(const std::string& bundle, int32_t userId, int32_t recvUserId,
1540         std::vector<std::string> &dumpInfo);
1541     ErrCode RecentNotificationDump(const std::string& bundle, int32_t userId, int32_t recvUserId,
1542         std::vector<std::string> &dumpInfo);
1543 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
1544     ErrCode DistributedNotificationDump(const std::string& bundle, int32_t userId, int32_t recvUserId,
1545         std::vector<std::string> &dumpInfo);
1546 #endif
1547     ErrCode SetRecentNotificationCount(const std::string arg);
1548     void UpdateRecentNotification(sptr<Notification> &notification, bool isDelete, int32_t reason);
1549 
1550     void AdjustDateForDndTypeOnce(int64_t &beginDate, int64_t &endDate);
1551     ErrCode PrepareNotificationRequest(const sptr<NotificationRequest> &request);
1552     ErrCode PrepareContinuousTaskNotificationRequest(const sptr<NotificationRequest> &request, const int32_t &uid);
1553 
1554     void TriggerRemoveWantAgent(const sptr<NotificationRequest> &request, int32_t removeReason, bool isThirdParty);
1555 
1556     ErrCode IsAllowedNotifySelf(const sptr<NotificationBundleOption> &bundleOption, bool &allowed);
1557 
1558     ErrCode SetNotificationRemindType(sptr<Notification> notification, bool isLocal);
1559 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
1560     std::vector<std::string> GetLocalNotificationKeys(const sptr<NotificationBundleOption> &bundleOption);
1561     NotificationConstant::RemindType GetRemindType();
1562     ErrCode DoDistributedPublish(
1563         const sptr<NotificationBundleOption> bundleOption, const std::shared_ptr<NotificationRecord> record);
1564     ErrCode DoDistributedDelete(
1565         const std::string deviceId, const std::string bundleName, const sptr<Notification> notification);
1566     void GetDistributedInfo(const std::string &key, std::string &deviceId, std::string &bundleName);
1567     bool CheckDistributedNotificationType(const sptr<NotificationRequest> &request);
1568     void OnDistributedPublish(
1569         const std::string &deviceId, const std::string &bundleName, sptr<NotificationRequest> &request);
1570     void OnDistributedUpdate(
1571         const std::string &deviceId, const std::string &bundleName, sptr<NotificationRequest> &request);
1572     void OnDistributedDelete(
1573         const std::string &deviceId, const std::string &bundleName, const std::string &label, int32_t id);
1574     static ErrCode GetDistributedEnableInApplicationInfo(
1575         const sptr<NotificationBundleOption> bundleOption, bool &enable);
1576     bool CheckPublishWithoutApp(const int32_t userId, const sptr<NotificationRequest> &request);
1577     void InitDistributeCallBack();
1578 #endif
1579 
1580     ErrCode SetDoNotDisturbDateByUser(const int32_t &userId, const sptr<NotificationDoNotDisturbDate> &date);
1581     ErrCode GetDoNotDisturbDateByUser(const int32_t &userId, sptr<NotificationDoNotDisturbDate> &date);
1582     ErrCode GetHasPoppedDialog(const sptr<NotificationBundleOption> bundleOption, bool &hasPopped);
1583     static ErrCode GetAppTargetBundle(const sptr<NotificationBundleOption> &bundleOption,
1584         sptr<NotificationBundleOption> &targetBundle);
1585     void ReportInfoToResourceSchedule(const int32_t userId, const std::string &bundleName);
1586     int Dump(int fd, const std::vector<std::u16string> &args) override;
1587     void GetDumpInfo(const std::vector<std::u16string> &args, std::string &result);
1588 
1589     static void SendSubscribeHiSysEvent(int32_t pid, int32_t uid, const sptr<NotificationSubscribeInfo> &info,
1590         ErrCode errCode);
1591     static void SendUnSubscribeHiSysEvent(int32_t pid, int32_t uid, const sptr<NotificationSubscribeInfo> &info);
1592     void SendPublishHiSysEvent(const sptr<NotificationRequest> &request, ErrCode errCode);
1593     void SendCancelHiSysEvent(int32_t notificationId, const std::string &label,
1594         const sptr<NotificationBundleOption> &bundleOption, ErrCode errCode);
1595     void SendRemoveHiSysEvent(int32_t notificationId, const std::string &label,
1596         const sptr<NotificationBundleOption> &bundleOption, ErrCode errCode);
1597     void SendEnableNotificationHiSysEvent(const sptr<NotificationBundleOption> &bundleOption, bool enabled,
1598         ErrCode errCode);
1599     void SendEnableNotificationSlotHiSysEvent(const sptr<NotificationBundleOption> &bundleOption,
1600         const NotificationConstant::SlotType &slotType, bool enabled, ErrCode errCode);
1601     void SendFlowControlOccurHiSysEvent(const std::shared_ptr<NotificationRecord> &record);
1602     void SendLiveViewUploadHiSysEvent(const std::shared_ptr<NotificationRecord> &record, int32_t uploadStatus);
1603 
1604     ErrCode SetRequestBundleInfo(const sptr<NotificationRequest> &request, int32_t uid, std::string &bundle);
1605     ErrCode PrePublishNotificationBySa(const sptr<NotificationRequest> &request, int32_t uid, std::string &bundle);
1606     ErrCode PrePublishRequest(const sptr<NotificationRequest> &request);
1607     ErrCode PublishNotificationBySa(const sptr<NotificationRequest> &request);
1608     bool IsNeedPushCheck(const sptr<NotificationRequest> &request);
1609     void FillExtraInfoToJson(const sptr<NotificationRequest> &request,
1610         sptr<NotificationCheckRequest> &checkRequest, nlohmann::json &jsonObject);
1611     void CreatePushCheckJson(const sptr<NotificationRequest> &request,
1612         sptr<NotificationCheckRequest> &checkRequest, nlohmann::json &jsonObject);
1613     ErrCode PushCheck(const sptr<NotificationRequest> &request);
1614     uint64_t StartAutoDelete(const std::shared_ptr<NotificationRecord> &record,
1615         int64_t deleteTimePoint, int32_t reason);
1616     void TriggerAutoDelete(const std::string &hashCode, int32_t reason);
1617     void SendNotificationsOnCanceled(std::vector<sptr<Notification>> &notifications,
1618         const sptr<NotificationSortingMap> &notificationMap, int32_t deleteReason);
1619     void SetAgentNotification(sptr<NotificationRequest>& notificationRequest, std::string& bundleName);
1620     static bool GetBundleInfoByNotificationBundleOption(
1621         const sptr<NotificationBundleOption> &bundleOption, AppExecFwk::BundleInfo &bundleInfo);
1622 
1623     ErrCode GetTargetRecordList(const int32_t uid, NotificationConstant::SlotType slotType,
1624         NotificationContent::Type contentType, std::vector<std::shared_ptr<NotificationRecord>>& recordList);
1625     ErrCode GetCommonTargetRecordList(const int32_t uid, NotificationConstant::SlotType slotType,
1626         NotificationContent::Type contentType, std::vector<std::shared_ptr<NotificationRecord>>& recordList);
1627     ErrCode RemoveNotificationFromRecordList(const std::vector<std::shared_ptr<NotificationRecord>>& recordList);
1628     ErrCode OnSubscriberAdd(const std::shared_ptr<NotificationSubscriberManager::SubscriberRecord> &record,
1629         const int32_t userId);
1630     bool IsLiveViewCanRecover(const sptr<NotificationRequest> request);
1631     ErrCode FillNotificationRecord(const NotificationRequestDb &requestdbObj,
1632         std::shared_ptr<NotificationRecord> record);
1633     static int32_t SetNotificationRequestToDb(const NotificationRequestDb &requestDb);
1634     static int32_t GetBatchNotificationRequestsFromDb(std::vector<NotificationRequestDb> &requests,
1635         int32_t userId = -1);
1636     static int32_t DoubleDeleteNotificationFromDb(const std::string &key,
1637         const std::string &secureKey, const int32_t userId);
1638     static int32_t DeleteNotificationRequestFromDb(const std::string &key, const int32_t userId);
1639     void CancelTimer(uint64_t timerId);
1640     void BatchCancelTimer(std::vector<uint64_t> timerIds);
1641     ErrCode UpdateNotificationTimerInfo(const std::shared_ptr<NotificationRecord> &record);
1642     ErrCode SetFinishTimer(const std::shared_ptr<NotificationRecord> &record);
1643     ErrCode StartFinishTimer(const std::shared_ptr<NotificationRecord> &record,
1644         int64_t expireTimePoint, const int32_t reason);
1645     void CancelFinishTimer(const std::shared_ptr<NotificationRecord> &record);
1646     ErrCode SetUpdateTimer(const std::shared_ptr<NotificationRecord> &record);
1647     ErrCode StartUpdateTimer(const std::shared_ptr<NotificationRecord> &record,
1648         int64_t expireTimePoint, const int32_t reason);
1649     void CancelUpdateTimer(const std::shared_ptr<NotificationRecord> &record);
1650     void StartArchiveTimer(const std::shared_ptr<NotificationRecord> &record);
1651     void CancelArchiveTimer(const std::shared_ptr<NotificationRecord> &record);
1652     ErrCode StartAutoDeletedTimer(const std::shared_ptr<NotificationRecord> &record);
1653     void ProcForDeleteLiveView(const std::shared_ptr<NotificationRecord> &record);
1654     void QueryDoNotDisturbProfile(const int32_t &userId, std::string &enable, std::string &profileId);
1655     void QueryIntelligentExperienceEnable(const int32_t &userId, std::string &enable);
1656     void CheckDoNotDisturbProfile(const std::shared_ptr<NotificationRecord> &record);
1657     void ReportDoNotDisturbModeChanged(const int32_t &userId, std::string &enable);
1658     void DoNotDisturbUpdataReminderFlags(const std::shared_ptr<NotificationRecord> &record);
1659     ErrCode CheckCommonParams();
1660     std::shared_ptr<NotificationRecord> GetRecordFromNotificationList(
1661         int32_t notificationId, int32_t uid, const std::string &label, const std::string &bundleName, int32_t userId);
1662     std::shared_ptr<NotificationRecord> MakeNotificationRecord(
1663         const sptr<NotificationRequest> &request, const sptr<NotificationBundleOption> &bundleOption);
1664     ErrCode IsAllowedNotifyForBundle(const sptr<NotificationBundleOption> &bundleOption, bool &allowed);
1665     void FillActionButtons(const sptr<NotificationRequest> &request);
1666     ErrCode IsAllowedGetNotificationByFilter(const std::shared_ptr<NotificationRecord> &record,
1667         const sptr<NotificationBundleOption> &bundleOption);
1668     ErrCode FillRequestByKeys(const sptr<NotificationRequest> &oldRequest,
1669         const std::vector<std::string> extraInfoKeys, sptr<NotificationRequest> &newRequest);
1670     ErrCode IsAllowedRemoveSlot(const sptr<NotificationBundleOption> &bundleOption,
1671         const NotificationConstant::SlotType &slotType);
1672     void HandleBadgeEnabledChanged(const sptr<NotificationBundleOption> &bundleOption, bool enabled);
1673     ErrCode CheckBundleOptionValid(sptr<NotificationBundleOption> &bundleOption);
1674     bool IsNeedNotifyConsumed(const sptr<NotificationRequest> &request);
1675     ErrCode AddRecordToMemory(const std::shared_ptr<NotificationRecord> &record,
1676         bool isSystemApp, bool isUpdateByOwner, const bool isAgentController);
1677     ErrCode DuplicateMsgControl(const sptr<NotificationRequest> &request);
1678     void RemoveExpiredUniqueKey();
1679     void RemoveExpiredDistributedUniqueKey();
1680     void RemoveExpiredLocalUniqueKey();
1681     bool IsDuplicateMsg(const std::list<std::pair<std::chrono::system_clock::time_point, std::string>> &msglist,
1682         const std::string &key);
1683     void DeleteDuplicateMsgs(const sptr<NotificationBundleOption> &bundleOption);
1684     ErrCode PublishRemoveDuplicateEvent(const std::shared_ptr<NotificationRecord> &record);
1685     ErrCode UpdateSlotAuthInfo(const std::shared_ptr<NotificationRecord> &record);
1686     std::vector<AppExecFwk::BundleInfo> GetBundlesOfActiveUser();
1687     void RemoveNotificationList(const std::shared_ptr<NotificationRecord> &record);
1688     void FillLockScreenPicture(const sptr<NotificationRequest> &newRequest,
1689         const sptr<NotificationRequest> &oldRequest);
1690     static ErrCode SetLockScreenPictureToDb(const sptr<NotificationRequest> &request);
1691     static ErrCode GetLockScreenPictureFromDb(NotificationRequest *request);
1692     void RemoveDoNotDisturbProfileTrustList(const sptr<NotificationBundleOption> &bundleOption);
1693     ErrCode DeleteAllByUserInner(const int32_t &userId, int32_t reason, bool isAsync = false, bool removeAll = false);
1694     ErrCode RemoveAllNotificationsInner(const sptr<NotificationBundleOption> &bundleOption, int32_t reason);
1695     void ExcuteRemoveAllNotificationsInner(const sptr<NotificationBundleOption> &bundleOption,
1696         const sptr<NotificationBundleOption> &bundle, int32_t &reason);
1697     void GetRemoveListForRemoveAll(const sptr<NotificationBundleOption> &bundleOption,
1698         const sptr<NotificationBundleOption> &bundle, std::vector<std::shared_ptr<NotificationRecord>> &removeList);
1699     ErrCode ValidRightsForCancelAsBundle(int32_t notificationId, int32_t &reason);
1700     ErrCode ExcuteRemoveNotification(const sptr<NotificationBundleOption> &bundle,
1701         int32_t notificationId, const std::string &label, int32_t &removeReason);
1702     void ExcuteRemoveNotifications(const std::vector<std::string> &keys, int32_t removeReason);
1703     void GetRemoveListForRemoveNtfBySlot(const sptr<NotificationBundleOption> &bundle,
1704         const sptr<NotificationSlot> &slot, std::vector<std::shared_ptr<NotificationRecord>> &removeList);
1705     void ExcuteDeleteAll(ErrCode &result, const int32_t reason);
1706     ErrCode GetNotificationById(const sptr<NotificationBundleOption> &bundle,
1707         const int32_t notificationId, sptr<Notification> &notification);
1708     ErrCode AssignValidNotificationSlot(const std::shared_ptr<NotificationRecord> &record,
1709         const sptr<NotificationBundleOption> &bundleOption);
1710     ErrCode UpdateSlotReminderModeBySlotFlags(const sptr<NotificationBundleOption> &bundle, uint32_t slotFlags);
1711         bool VerifyCloudCapability(const int32_t &uid, const std::string &capability);
1712     ErrCode CheckSoundPermission(const sptr<NotificationRequest> &request,
1713         sptr<NotificationBundleOption> &bundleOption);
1714     void GenerateSlotReminderMode(const sptr<NotificationSlot> &slot, const sptr<NotificationBundleOption> &bundle,
1715         bool isSpecifiedSlot = false, uint32_t defaultSlotFlags = DEFAULT_SLOT_FLAGS);
1716     static void CloseAlert(const std::shared_ptr<NotificationRecord> &record);
1717     bool IsUpdateSystemLiveviewByOwner(const sptr<NotificationRequest> &request);
1718     bool IsSaCreateSystemLiveViewAsBundle(const std::shared_ptr<NotificationRecord> &record, int32_t ipcUid);
1719     ErrCode SaPublishSystemLiveViewAsBundle(const std::shared_ptr<NotificationRecord> &record);
1720     bool IsNotificationExistsInDelayList(const std::string &key);
1721     uint64_t StartDelayPublishTimer(const int32_t ownerUid, const int32_t notificationId, const uint32_t delayTime);
1722     ErrCode StartPublishDelayedNotification(const std::shared_ptr<NotificationRecord> &record);
1723     void StartPublishDelayedNotificationTimeOut(const int32_t ownerUid, const int32_t notificationId);
1724     void UpdateRecordByOwner(const std::shared_ptr<NotificationRecord> &record, bool isSystemApp);
1725     void StartFinishTimerForUpdate(const std::shared_ptr<NotificationRecord> &record, uint64_t process);
1726     ErrCode CheckLongTermLiveView(const sptr<NotificationRequest> &request, const std::string &key);
1727     void ExcuteCancelGroupCancel(const sptr<NotificationBundleOption>& bundleOption,
1728         const std::string &groupName, const int32_t reason);
1729     ErrCode ExcuteCancelAll(const sptr<NotificationBundleOption>& bundleOption, const int32_t reason);
1730     ErrCode ExcuteDelete(const std::string &key, const int32_t removeReason);
1731     ErrCode CheckNeedSilent(const std::string &phoneNumber, int32_t callerType, int32_t userId);
1732     ErrCode QueryContactByProfileId(const std::string &phoneNumber, const std::string &policy, int32_t userId);
1733     uint32_t GetDefaultSlotFlags(const sptr<NotificationRequest> &request);
1734     bool IsSystemUser(int32_t userId);
1735     ErrCode CollaboratePublish(const sptr<NotificationRequest> &request);
1736     ErrCode SetCollaborateRequest(const sptr<NotificationRequest> &request);
1737     void SetCollaborateReminderFlag(const sptr<NotificationRequest> &request);
1738     ErrCode SetEnabledForBundleSlotInner(const sptr<NotificationBundleOption> &bundleOption,
1739         const sptr<NotificationBundleOption> &bundle,
1740         const NotificationConstant::SlotType &slotType, bool enabled, bool isForceControl);
1741     ErrCode AddSlotThenPublishEvent(
1742         const sptr<NotificationSlot> &slot,
1743         const sptr<NotificationBundleOption> &bundle,
1744         bool enabled, bool isForceControl);
1745     ErrCode OnRecoverLiveView(const std::vector<std::string> &keys);
1746     ErrCode CollaborateFilter(const sptr<NotificationRequest> &request);
1747     void HandleUpdateLiveViewNotificationTimer(const int32_t uid, const bool isPaused);
1748     void CancelWantAgent(const sptr<Notification> &notification);
1749     void CancelOnceWantAgent(const std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> &wantAgent);
1750     void PublishSubscriberExistFlagEvent(bool headsetExistFlag, bool wearableExistFlag);
1751     void UpdateDistributedDeviceList(const std::string &deviceType, int32_t userId);
1752     void SetClassificationWithVoip(const sptr<NotificationRequest> &request);
1753     void UpdateCollaborateTimerInfo(const std::shared_ptr<NotificationRecord> &record);
1754 #ifdef ENABLE_ANS_PRIVILEGED_MESSAGE_EXT_WRAPPER
1755     void SetDialogPoppedUnEnableTime(const sptr<NotificationBundleOption> &bundleOption);
1756 #endif
1757     ErrCode CommonRequestEnableNotification(const std::string &deviceId,
1758         const sptr<IAnsDialogCallback> &callback,
1759         const sptr<IRemoteObject> &callerToken,
1760         const sptr<NotificationBundleOption> bundleOption,
1761         const bool innerLake,
1762         const bool easyAbroad);
1763     void ClearSlotTypeData(const sptr<NotificationRequest> &request, int32_t callingUid, int32_t sourceType);
1764     ErrCode RegisterPushCallbackTokenCheck();
1765     ErrCode RemoveDistributedNotifications(const std::vector<std::string>& hashcodes,
1766         const int32_t removeReason);
1767     ErrCode RemoveDistributedNotifications(const NotificationConstant::SlotType& slotType,
1768         const int32_t removeReason,
1769         const NotificationConstant::DistributedDeleteType& deleteType);
1770     ErrCode RemoveDistributedNotificationsByDeviceId(const std::string& deviceId,
1771         const int32_t removeReason);
1772     ErrCode RemoveAllDistributedNotifications(const int32_t removeReason);
1773     bool ExecuteDeleteDistributedNotification(std::shared_ptr<NotificationRecord>& record,
1774         std::vector<sptr<Notification>>& notifications, const int32_t removeReason);
1775     bool IsDistributedNotification(sptr<NotificationRequest> request);
1776     bool IsEnableNotificationByKioskAppTrustList(const std::string &bundleName);
1777 
1778     template<typename T>
WriteParcelableVector(const std::vector<sptr<T>> & parcelableVector,MessageParcel & data)1779     bool WriteParcelableVector(const std::vector<sptr<T>> &parcelableVector, MessageParcel &data)
1780     {
1781         if (!data.WriteInt32(parcelableVector.size())) {
1782             ANS_LOGE("Failed to write ParcelableVector size.");
1783             return false;
1784         }
1785 
1786         for (auto &parcelable : parcelableVector) {
1787             if (!data.WriteStrongParcelable(parcelable)) {
1788                 ANS_LOGE("Failed to write ParcelableVector");
1789                 return false;
1790             }
1791         }
1792         return true;
1793     }
1794 
1795     void SetChainIdToExtraInfo(const sptr<NotificationRequest> &request, OHOS::HiviewDFX::HiTraceId traceId);
1796 
1797     ErrCode CheckNotificationRequest(const sptr<NotificationRequest> &request);
1798     ErrCode CheckNotificationRequestLineWantAgents(const std::shared_ptr<NotificationContent> &content,
1799         bool isAgentController, bool isSystemComp);
1800     bool IsReasonClickDelete(const int32_t removeReason);
1801     void CheckRemovalWantAgent(const sptr<NotificationRequest> &request);
1802     ErrCode SetCreatorInfoWithAtomicService(const sptr<NotificationRequest> &request);
1803     AnsStatus CheckAndPrepareNotificationInfoWithAtomicService(
1804         const sptr<NotificationRequest> &request, sptr<NotificationBundleOption> &bundleOption);
1805     AnsStatus ExecutePublishProcess(
1806         const sptr<NotificationRequest> &request, bool isUpdateByOwnerAllowed);
1807 
1808     ErrCode UpdateNotificationSwitchState(
1809         const sptr<NotificationBundleOption> &bundleOption, const AppExecFwk::BundleInfo &bundleInfo);
1810 private:
1811     static sptr<AdvancedNotificationService> instance_;
1812     static ffrt::mutex instanceMutex_;
1813     static ffrt::mutex pushMutex_;
1814     static std::map<NotificationConstant::SlotType, sptr<IPushCallBack>> pushCallBacks_;
1815     static std::map<NotificationConstant::SlotType, sptr<NotificationCheckRequest>> checkRequests_;
1816     bool aggregateLocalSwitch_ = false;
1817     std::set<int32_t> currentUserId;
1818     std::shared_ptr<OHOS::AppExecFwk::EventRunner> runner_ = nullptr;
1819     std::shared_ptr<OHOS::AppExecFwk::EventHandler> handler_ = nullptr;
1820     std::list<std::shared_ptr<NotificationRecord>> notificationList_;
1821     std::shared_ptr<RecentInfo> recentInfo_ = nullptr;
1822     std::shared_ptr<DistributedKvStoreDeathRecipient> distributedKvStoreDeathRecipient_ = nullptr;
1823     std::shared_ptr<SystemEventObserver> systemEventObserver_ = nullptr;
1824     DistributedKv::DistributedKvDataManager dataManager_;
1825     sptr<IRemoteObject::DeathRecipient> pushRecipient_ = nullptr;
1826     std::shared_ptr<ffrt::queue> notificationSvrQueue_ = nullptr;
1827     std::map<NotificationConstant::SlotType, std::shared_ptr<BasePublishProcess>> publishProcess_;
1828 #ifdef DISTRIBUTED_NOTIFICATION_SUPPORTED
1829     NotificationConstant::DistributedReminderPolicy distributedReminderPolicy_ = DEFAULT_DISTRIBUTED_REMINDER_POLICY;
1830     bool localScreenOn_ = true;
1831 #endif
1832     std::shared_ptr<SoundPermissionInfo> soundPermissionInfo_ = nullptr;
1833     std::shared_ptr<PermissionFilter> permissonFilter_ = nullptr;
1834     std::shared_ptr<NotificationSlotFilter> notificationSlotFilter_ = nullptr;
1835     std::shared_ptr<NotificationDialogManager> dialogManager_ = nullptr;
1836     std::list<std::pair<std::chrono::system_clock::time_point, std::string>> uniqueKeyList_;
1837     std::list<std::pair<std::chrono::system_clock::time_point, std::string>> distributedUniqueKeyList_;
1838     std::list<std::pair<std::chrono::system_clock::time_point, std::string>> localUniqueKeyList_;
1839     std::list<std::pair<std::shared_ptr<NotificationRecord>, uint64_t>> delayNotificationList_;
1840     ffrt::mutex delayNotificationMutext_;
1841     static ffrt::mutex doNotDisturbMutex_;
1842     std::map<int32_t, std::string> doNotDisturbEnableRecord_;
1843     bool isCachedAppAndDeviceRelationMap_ = false;
1844     std::map<std::string, std::string> appAndDeviceRelationMap_;
1845 };
1846 
1847 /**
1848  * @class PushCallbackRecipient
1849  * PushCallbackRecipient notices IRemoteBroker died.
1850  */
1851 class PushCallbackRecipient : public IRemoteObject::DeathRecipient {
1852 public:
1853     PushCallbackRecipient();
1854     PushCallbackRecipient(const NotificationConstant::SlotType slotType);
1855     virtual ~PushCallbackRecipient();
1856     void OnRemoteDied(const wptr<IRemoteObject> &remote);
1857 private:
1858     NotificationConstant::SlotType slotType_;
1859 };
1860 }  // namespace Notification
1861 }  // namespace OHOS
1862 
1863 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_ANS_INCLUDE_ADVANCED_NOTIFICATION_SERVICE_H
1864