• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_REMINDER_INCLUDE_REMINDER_DATA_MANAGER_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_DATA_MANAGER_H
18 
19 #include <map>
20 #include <vector>
21 
22 #include "ans_inner_errors.h"
23 #ifdef PLAYER_FRAMEWORK_ENABLE
24 #include "player.h"
25 #endif
26 #include "ffrt.h"
27 #include "app_mgr_client.h"
28 #include "reminder_request.h"
29 #include "reminder_request_adaptation.h"
30 #include "reminder_store.h"
31 #include "reminder_timer_info.h"
32 #include "reminder_config_change_observer.h"
33 #include "datashare_predicates.h"
34 #include "datashare_values_bucket.h"
35 #include "app_mgr_interface.h"
36 #include "time_service_client.h"
37 
38 namespace OHOS {
39 namespace Notification {
40 class ReminderDataManager final {
41 public:
42     ReminderDataManager();
43     ~ReminderDataManager();
44 
45     ReminderDataManager(ReminderDataManager &other) = delete;
46     ReminderDataManager& operator = (const ReminderDataManager &other) = delete;
47 
48     /**
49      * @brief Cancels all the reminders relative to the bundle option.
50      *
51      * @param packageName Indicates the package name.
52      * @param userId Indicates the user id which the bundle belong to.
53      * @param uid Indicates the uid which the bundle belong to.
54      * @return ERR_OK if success, else not.
55      */
56     ErrCode CancelAllReminders(const std::string& packageName, const int32_t userId, const int32_t uid);
57 
58     /**
59      * @brief Cancels the target reminder relative to the reminder id and bundle option.
60      *
61      * @param reminderId Indicates the reminder id.
62      * @param bundleOption Indicates the bundle option.
63      * @return ERR_OK if success, else not.
64      */
65     ErrCode CancelReminder(const int32_t &reminderId, const int32_t callingUid);
66 
67     sptr<ReminderRequest> CheckExcludeDateParam(const int32_t reminderId,
68         const int32_t callingUid);
69 
70     /**
71      * @brief Add exclude date for reminder
72      *
73      * @param reminderId Identifies the reminders id.
74      * @param date exclude date
75      * @return Returns ERR_OK on success, others on failure.
76      */
77     ErrCode AddExcludeDate(const int32_t reminderId, const int64_t date,
78         const int32_t callingUid);
79 
80     /**
81      * @brief Clear exclude date for reminder
82      *
83      * @param reminderId Identifies the reminders id.
84      * @return Returns ERR_OK on success, others on failure.
85      */
86     ErrCode DelExcludeDates(const int32_t reminderId, const int32_t callingUid);
87 
88     /**
89      * @brief Get exclude date for reminder
90      *
91      * @param reminderId Identifies the reminders id.
92      * @param dates exclude dates
93      * @return Returns ERR_OK on success, others on failure.
94      */
95     ErrCode GetExcludeDates(const int32_t reminderId, const int32_t callingUid,
96         std::vector<int64_t>& dates);
97 
98     /**
99      * @brief Close the target reminder which is showing on panel.
100      *        This is manul operation by user: 1.Click close button of the reminder, 2.remove reminder notification.
101      *
102      * @param want Want information that transferred when the event trigger by user.
103      * @param cancelNotification Indicates whether need to cancel notification or not.
104      */
105     void CloseReminder(const OHOS::EventFwk::Want &want, bool cancelNotification, bool isButtonClick = true);
106 
107     /**
108      * Dump all the reminders information.
109      *
110      * @return reminders informations.
111      */
112     std::string Dump() const;
113 
114     /**
115      * Obtains the single instance.
116      *
117      * @return Single instance of ReminderDataManager.
118      */
119     static std::shared_ptr<ReminderDataManager> GetInstance();
120     static std::shared_ptr<ReminderDataManager> InitInstance();
121 
122     /**
123      * Obtains all the valid reminders (which are not expired) relative to the bundle option.
124      *
125      * @param bundleOption Indicates the bundle option.
126      * @param[out] reminders return the valid reminders.
127      */
128     void GetValidReminders(
129         const int32_t callingUid, std::vector<ReminderRequestAdaptation> &reminders);
130 
131     /**
132      * @brief Inits and recovery data from database.
133      */
134     void Init();
135 
136     void InitUserId();
137 
138     /**
139      * @brief Check all reminders, Whether an immediate reminder is needed;
140      * whether a pull up service extension is required.
141      * Use when powering on and changing the system time.
142      */
143     void CheckReminderTime(std::vector<sptr<ReminderRequest>>& immediatelyReminders,
144         std::vector<sptr<ReminderRequest>>& extensionReminders);
145 
146     /**
147      * @brief Register configuration observer, the listening system language is changed.
148      */
149     bool RegisterConfigurationObserver();
150 
151     void OnUserRemove(const int32_t& userId);
152 
153     /**
154      * @brief Notify UNLOCK_SCREEN event.
155      */
156     void OnUnlockScreen();
157 
158     /**
159      * @brief Bundle manager service start.
160      */
161     void OnBundleMgrServiceStart();
162 
163     /**
164      * @brief Ability manager service start.
165      */
166     void OnAbilityMgrServiceStart();
167 
168     void OnUserSwitch(const int32_t& userId);
169 
170     /**
171      * @brief Triggered when third party application died.
172      *
173      * @param bundleOption Indicates the bundleOption of third party application.
174      */
175     void OnProcessDiedLocked(const int32_t callingUid);
176 
177     /**
178      * Publishs a scheduled reminder.
179      *
180      * @param reminder Indicates the reminder.
181      * @param bundleOption Indicates bundle option the reminder belongs to.
182      * @return ERR_OK if success, else not.
183      */
184     ErrCode PublishReminder(const sptr<ReminderRequest> &reminder,
185         const int32_t callingUid);
186 
187     /**
188      * @brief Refresh all reminders when date/time or timeZone of device changed by user.
189      *
190      * @param type Indicates it is triggered by dateTime change or timeZone change.
191      */
192     void RefreshRemindersDueToSysTimeChange(uint8_t type);
193 
194     bool ShouldAlert(const sptr<ReminderRequest> &reminder) const;
195 
196     /**
197      * @brief Show the reminder.
198      *
199      * @param isSysTimeChanged Indicates it is triggered as dateTime changed by user or not.
200      * @param want Which contains the given reminder.
201      */
202     void ShowActiveReminder(const EventFwk::Want &want);
203 
204     /**
205      * @brief Snooze the reminder by manual.
206      * 1) Snooze the trigger time to the next.
207      * 2) Update the notification(Update notification lable/content...; Stop audio player and vibrator)
208      * 3) Show the notification dialog in the SystemUI
209      * 4) Start a new reminder, which is recent one now.
210      *
211      * @param want Which contains the given reminder.
212      */
213     void SnoozeReminder(const OHOS::EventFwk::Want &want);
214 
215     /**
216      * Starts the recent reminder timing.
217      */
218     void StartRecentReminder();
219 
220     /**
221      * Handle custom button click event.
222      */
223     void HandleCustomButtonClick(const OHOS::EventFwk::Want &want);
224 
225     /**
226      * Handle click notification, no button.
227      */
228     void ClickReminder(const OHOS::EventFwk::Want &want);
229 
230     /**
231      * @brief Load reminder event.
232      */
233     void OnLoadReminderEvent();
234 
235     /**
236      * @brief Load reminder event for ffrt.
237      */
238     void OnLoadReminderInFfrt();
239 
240     /**
241      * @brief datashare notify, share reminder insert or delete.
242      */
243     void OnDataShareInsertOrDelete();
244 
245     /**
246      * @brief datashare notify, share reminder update.
247      */
248     void OnDataShareUpdate(const std::map<std::string, sptr<ReminderRequest>>& reminders);
249 
250     /**
251      * Handle auto delete time
252      */
253     void HandleAutoDeleteReminder(const int32_t notificationId, const int32_t uid, const int64_t autoDeletedTime);
254 
255     /**
256      * @brief Terminate the alerting reminder.
257      *
258      * 1. Stop sound and vibrate.
259      * 2. Stop the alerting timer.
260      * 3. Update the reminder state.
261      * 4. Update the display content of the notification.
262      *
263      * @param want Which contains the given reminder.
264      */
265     void TerminateAlerting(const OHOS::EventFwk::Want &want);
266 
267     /**
268      * @brief Update reminders based on the system language.
269      *
270      * Update action button title.
271      */
272     void UpdateReminderLanguageLocked(const int32_t uid, const std::vector<sptr<ReminderRequest>>& reminders);
273 
274     /**
275      * @brief System language change
276      */
277     void OnLanguageChanged();
278 
279     /**
280      * @brief When OnRemoveSystemAbility occurs.
281      */
282     void OnRemoveAppMgr();
283 
284     /**
285      * @brief Whether the device is ready or not.
286      */
287     bool IsSystemReady();
288 
289     int32_t QueryActiveReminderCount();
290 
291     void StartLoadTimer();
292 
293     /**
294      * @brief When the device boot complete, need delay for 5 seconds,
295      * then load the reminder.
296      */
297     void InitShareReminders(const bool registerObserver);
298 
299     static constexpr uint8_t TIME_ZONE_CHANGE = 0;
300     static constexpr uint8_t DATE_TIME_CHANGE = 1;
301 
302 private:
303     enum class TimerType : uint8_t {
304         TRIGGER_TIMER,
305         ALERTING_TIMER
306     };
307 
308     static std::shared_ptr<ffrt::queue> serviceQueue_;
309     /**
310      * Add default slot to the reminder if no slot set by user.
311      *
312      * @param reminder Indicates the reminder.
313      */
314     void AddDefaultSlotIfNeeded(sptr<ReminderRequest> &reminder);
315 
316     /**
317      * Add reminder to showed reminder vector.
318      *
319      * @param reminder Indicates the showed reminder.
320      */
321     void AddToShowedReminders(const sptr<ReminderRequest> &reminder);
322 
323     void CancelAllReminders(const int32_t userId);
324 
325     /**
326      * @brief Check the update conditions.
327      *
328      * @param reminder Indicates the showed reminder.
329      * @param actionButtonType Button type of the button.
330      * @param actionButtonMap Button map.
331      * @return True if check successful.
332      */
333     bool CheckUpdateConditions(const sptr<ReminderRequest> &reminder,
334         const ReminderRequest::ActionButtonType &actionButtonType,
335         const std::map<ReminderRequest::ActionButtonType, ReminderRequest::ActionButtonInfo> &actionButtonMap);
336 
337     /**
338      * @brief update app database.
339      *
340      * @param reminder Indicates the showed reminder.
341      * @param actionButtonType Button type of the button.
342      */
343     void UpdateAppDatabase(const sptr<ReminderRequest> &reminder,
344         const ReminderRequest::ActionButtonType &actionButtonType);
345 
346     /**
347      * @brief generate Predicates for dataShare.
348      *
349      * @param predicates find fields from database.
350      * @param equalToVector Split from dataShareUpdate->equaleTo.
351      */
352     void GenPredicates(DataShare::DataSharePredicates &predicates, const std::vector<std::string> &equalToVector);
353 
354     /**
355      * @brief generate ValuesBucket for dataShare.
356      *
357      * @param valuesBucket update fields at database.
358      * @param valuesBucketVector Split from dataShareUpdate->valuesBucket.
359      */
360     void GenValuesBucket(DataShare::DataShareValuesBucket &valuesBucket,
361         const std::vector<std::string> &valuesBucketVector);
362 
363     /**
364      * @brief get bundleName from uri.
365      *
366      * @param dstBundleName The package name required to update the database.
367      * @param uri Database address.
368      */
369     void GenDstBundleName(std::string &dstBundleName, const std::string &uri) const;
370 
371     /**
372      * @brief Cancels all the reminders of the target bundle or user.
373      *
374      * @param packageName Indicates the packageName need to cancel.
375      * @param userId Indicates the userId to cancel.
376      */
377     void CancelRemindersImplLocked(const std::string& bundleName,
378         const int32_t userId, const int32_t uid, bool isCancelAllPackage = false);
379 
380     /**
381      * @brief Close reminders with the same group id.
382      *
383      * @param oldReminderId Indicates the reminderId that are currently bing showed.
384      * @param packageName Indicates the packageName need to cancel.
385      * @param groupId Indicates the group id to cancel.
386      */
387     void CloseRemindersByGroupId(const int32_t &oldReminderId, const std::string &packageName,
388         const std::string &groupId);
389 
390     /**
391      * Cancels the notification relative to the reminder.
392      *
393      * @param reminder Indicates the reminder.
394      */
395     void CancelNotification(const sptr<ReminderRequest> &reminder) const;
396 
397     /**
398      * Check whether the number limit of reminders if exceeded.
399      *
400      * @param bundleName Indicates the target bundle.
401      * @return true if number limit is exceeded.
402      */
403     bool CheckReminderLimitExceededLocked(const int32_t callingUid,
404         const sptr<ReminderRequest>& reminder) const;
405     void CloseReminder(const sptr<ReminderRequest> &reminder, bool cancelNotification);
406 
407     /**
408      * Create a information for timer, such as timer type, repeat policy, interval and want agent.
409      *
410      * @param type Indicates the timer type.
411      * @param reminderRequest Indicates the reminder request.
412      * @return pointer of ReminderTimerInfo.
413      */
414     std::shared_ptr<ReminderTimerInfo> CreateTimerInfo(TimerType type,
415         const sptr<ReminderRequest> &reminderRequest) const;
416     void InitTimerInfo(std::shared_ptr<ReminderTimerInfo> &timerInfo,
417         const sptr<ReminderRequest> &reminderRequest, TimerType reminderType) const;
418 
419     void GetImmediatelyShowRemindersLocked(std::vector<sptr<ReminderRequest>> &reminders) const;
420 
421     /**
422      * Find the reminder from reminderVector_ by reminder id.
423      *
424      * @param reminderId Indicates the reminder id.
425      * @param isShare Indicates the reminder datashare flag.
426      * @return pointer of reminder request or nullptr.
427      */
428     sptr<ReminderRequest> FindReminderRequestLocked(const int32_t reminderId, const bool isShare);
429 
430     /**
431      * Obtains the recent reminder which is not expired from reminder vector.
432      *
433      * The expired reminders will be removed from reminderVector_ and notificationBundleOptionMap_.
434      *
435      * @return pointer of reminder object.
436      */
437     sptr<ReminderRequest> GetRecentReminder();
438 
439     void HandleImmediatelyShow(std::vector<sptr<ReminderRequest>> &showImmediately, bool isSysTimeChanged);
440     void HandleExtensionReminder(std::vector<sptr<ReminderRequest>> &extensionReminders, const int8_t type);
441 
442     /**
443      * @brief Refresh the reminder due to date/time or timeZone change by user.
444      *
445      * @param type Indicates it is date/time change or timeZone change.
446      * @param reminder Indicates the target reminder.
447      * @return sptr<ReminderRequest> Returns the target reminder if it is need to show immediately, otherwise nullptr.
448      */
449     sptr<ReminderRequest> HandleRefreshReminder(const uint8_t &type, sptr<ReminderRequest> &reminder);
450 
451     /**
452      * @brief Handles all the reminders that have the same notification id and belong to same application
453      *        with the current reminder. Unset the state of "showing".
454      *
455      * @param reminder Indicates the current reminder.
456      */
457     void HandleSameNotificationIdShowing(const sptr<ReminderRequest> reminder);
458 
459     bool HandleSysTimeChange(const sptr<ReminderRequest> reminder) const;
460 
461     /**
462      * @brief Judge the two reminders is belong to the same application or not.
463      *
464      * @param bundleOption Indicates the bundleOption of first reminder.
465      * @param other Indicates the bundleOption of second reminder.
466      * @return true if the two reminders belong to the same application.
467      */
468     bool IsBelongToSameApp(const int32_t uidSrc, const int32_t uidTar) const;
469     bool CheckIsSameApp(const sptr<ReminderRequest> &reminder, const int32_t callingUid) const;
470 
471     /**
472      * @brief Judges whether the reminder is matched with the bundleOption or userId.
473      *
474      * @param reminder Indicates the target reminder.
475      * @param packageName Indicates the package name.
476      * @param userId Indicates the user id.
477      * @param uid Indicates the uid.
478      * @return true If the reminder is matched with the bundleOption or userId.
479      */
480     bool IsMatched(const sptr<ReminderRequest> &reminder, const int32_t userId, const int32_t uid,
481         bool isCancelAllPackage = false) const;
482 
483     /**
484      * @brief Judges whether the reminder is matched with the packageName or groupId.
485      *
486      * @param reminder Indicates the target reminder.
487      * @param packageName Indicates the package name.
488      * @param groupId Indicates the group id.
489      * @return true If the reminder is matched with the packageName and groupId.
490      */
491     bool IsMatchedForGroupIdAndPkgName(const sptr<ReminderRequest> &reminder, const std::string &packageName,
492         const std::string &groupId) const;
493 
494     bool IsAllowedNotify(const sptr<ReminderRequest> &reminder) const;
495 
496     bool IsReminderAgentReady() const;
497 
498     void LoadReminderFromDb();
499 
500     void PlaySoundAndVibrationLocked(const sptr<ReminderRequest> &reminder);
501     void PlaySoundAndVibration(const sptr<ReminderRequest> &reminder);
502     void StopSoundAndVibrationLocked(const sptr<ReminderRequest> &reminder);
503     void StopSoundAndVibration(const sptr<ReminderRequest> &reminder);
504 
505     /**
506      * Remove from showed reminder vector.
507      *
508      * @param reminder Indicates the reminder need to remove.
509      */
510     void RemoveFromShowedReminders(const sptr<ReminderRequest> &reminder);
511 
512     /**
513      * @brief Refresh the all reminders due to date/time or timeZone change by user.
514      *
515      * @param type Indicates it is date/time change or timeZone change.
516      * @return reminders that need to show immediately.
517      */
518     void RefreshRemindersLocked(uint8_t type, std::vector<sptr<ReminderRequest>>& immediatelyReminders,
519         std::vector<sptr<ReminderRequest>>& extensionReminders);
520 
521     /**
522      * Removes the reminder.
523      * 1. removes the reminder from reminderVector_ and notificationBundleOptionMap_.
524      * 2. cancels the notification.
525      *
526      * @param reminderId Indicates the reminder id.
527      * @param isShare Indicates the reminder datashare flag.
528      */
529     void RemoveReminderLocked(const int32_t reminderId, const bool isShare);
530 
531     /**
532      * Resets timer status.
533      * 1. Sets timerId_ or timerIdAlerting_ with 0.
534      * 2. Sets activeReminderId_ or alertingReminderId with -1.
535      *
536      * @param type Indicates the timer type.
537      */
538     void ResetStates(TimerType type);
539 
540     void SetActiveReminder(const sptr<ReminderRequest> &reminder);
541     void SetAlertingReminder(const sptr<ReminderRequest> &reminder);
542     void ShowActiveReminderExtendLocked(sptr<ReminderRequest> &reminder,
543         std::vector<sptr<ReminderRequest>>& extensionReminders);
544     static bool StartExtensionAbility(const sptr <ReminderRequest> &reminder, const int8_t type);
545     static void AsyncStartExtensionAbility(const sptr<ReminderRequest> &reminder,
546         int32_t times, const int8_t type, int32_t& count);
547     void InitServiceHandler();
548     /**
549      * @brief Show the reminder on SystemUI.
550      *
551      * @param reminder Indicates the reminder to show.
552      * @param isNeedToPlaySound Indicates whether need to play sound.
553      * @param isNeedToStartNext Indicates whether need to start next reminder.
554      * @param isSysTimeChanged Indicates whether it is triggerred as system time changed by user.
555      * @param needScheduleTimeout Indicates whether need to control the ring duration.
556      */
557     void ShowReminder(const sptr<ReminderRequest> &reminder, const bool &isNeedToPlaySound,
558         const bool &isNeedToStartNext, const bool &isSysTimeChanged, const bool &needScheduleTimeout);
559 
560     void SnoozeReminderImpl(sptr<ReminderRequest> &reminder);
561 
562     /**
563      * Starts timing actually.
564      *
565      * @param reminderRequest Indicates the reminder.
566      * @param type Indicates the timer type.
567      */
568     void StartTimerLocked(const sptr<ReminderRequest> &reminderRequest, TimerType type);
569     void StartTimer(const sptr<ReminderRequest> &reminderRequest, TimerType type);
570 
571     uint64_t HandleTriggerTimeInner(const sptr<ReminderRequest> &reminderRequest, TimerType type,
572         const sptr<MiscServices::TimeServiceClient> &timer);
573 
574     uint64_t HandleAlertingTimeInner(const sptr<ReminderRequest> &reminderRequest, TimerType type,
575         const sptr<MiscServices::TimeServiceClient> &timer, time_t now);
576 
577     /**
578      * @brief Stop the alerting timer and update reminder information.
579      *
580      * 1. Stop sound and vibrate.
581      * 2. Stop the alerting timer.
582      *
583      * @param reminder Indicates the target reminder.
584      */
585     void StopAlertingReminder(const sptr<ReminderRequest> &reminder);
586 
587     /**
588      * Stops timing.
589      *
590      * @param type Indicates the timer type.
591      */
592     void StopTimer(TimerType type);
593     void StopTimerLocked(TimerType type);
594 
595     /**
596      * @brief Terminate the alerting reminder.
597      *
598      * 1. Stop sound and vibrate.
599      * 2. Stop the alerting timer.
600      * 3. Update the reminder state.
601      * 4. Update the display content of the notification.
602      *
603      * @param reminder Indicates the reminder.
604      * @param reason Indicates the description information.
605      */
606     void TerminateAlerting(const sptr<ReminderRequest> &reminder, const std::string &reason);
607     void TerminateAlerting(const uint16_t waitInSecond, const sptr<ReminderRequest> &reminder);
608 
609     /**
610      * @brief Assign unique reminder id and save reminder in memory.
611      *
612      * @param reminder Indicates a reminder.
613      */
614     void UpdateAndSaveReminderLocked(const sptr<ReminderRequest> &reminder);
615 
616     static bool cmp(sptr<ReminderRequest> &reminderRequest, sptr<ReminderRequest> &other);
617 
618     /**
619      * @brief Connect App Manager to get the current foreground application.
620      */
621     bool ConnectAppMgr();
622 
623     /**
624      * @brief Check need to notify the application, if the current foreground application
625      *     is the creator of the reminder, notify the application of the reminder status
626      *     change; otherwise, do not noitfy.
627      *
628      * @param reminder Indicates a reminder.
629      * @param buttonType The type of button clicked by the user.
630      */
631     void CheckNeedNotifyStatus(const sptr<ReminderRequest> &reminder,
632         const ReminderRequest::ActionButtonType buttonType);
633 
634     std::string GetFullPath(const std::string& path);
635 
636     /**
637      * @brief Check action button data share permission
638     */
639     bool IsActionButtonDataShareValid(const sptr<ReminderRequest>& reminder,
640         const uint32_t callerTokenId);
641 
642     /**
643      * @brief Get resource manager by bundlename and uid.
644      */
645     std::shared_ptr<Global::Resource::ResourceManager> GetResourceMgr(const std::string& bundleName,
646         const int32_t uid);
647 
648     /**
649      * @brief Get custom ring file desc.
650      *    lock by resourceMutex_ in function
651      */
652     bool GetCustomRingFileDesc(const sptr<ReminderRequest>& reminder,
653         Global::Resource::ResourceManager::RawFileDescriptor& desc);
654 
655     /**
656      * @brief Close custom ring file desc.
657      *    lock by resourceMutex_ in function
658      */
659     void CloseCustomRingFileDesc(const int32_t reminderId, const std::string& customRingUri);
660 
661     /**
662      * @brief report event to dfx
663      */
664     void ReportSysEvent(const sptr<ReminderRequest>& reminder);
665 
666     /**
667      * @brief Create load reminder timer.
668      */
669     uint64_t CreateTimer(const sptr<MiscServices::TimeServiceClient>& timer);
670 
671     /**
672      * @brief Load reminder from datashare.
673      */
674     void LoadShareReminders();
675 
676     /**
677      * @brief Load reminder from datashare.
678      */
679     void UpdateShareReminders(const std::map<std::string, sptr<ReminderRequest>>& reminders);
680 
681     bool CheckShowLimit(std::unordered_map<std::string, int32_t>& limits, int32_t& totalCount,
682         sptr<ReminderRequest>& reminder);
683 
684    /**
685     * Single instance.
686     */
687     static std::shared_ptr<ReminderDataManager> REMINDER_DATA_MANAGER;
688 
689     /**
690      * Used for multi-thread synchronise.
691      */
692     static std::mutex MUTEX;
693     static std::mutex SHOW_MUTEX;
694     static std::mutex ALERT_MUTEX;
695     static std::mutex TIMER_MUTEX;
696     static std::mutex ACTIVE_MUTEX;
697 
698     /**
699      * Max number of reminders limit for the whole system.
700      */
701     static constexpr int16_t MAX_NUM_REMINDER_LIMIT_SYSTEM = 12000;
702 
703     /**
704      * Max number of reminders limit for one system application.
705      */
706     static constexpr int16_t MAX_NUM_REMINDER_LIMIT_SYS_APP = 10000;
707 
708     /**
709      * Max number of reminders limit for one application.
710      */
711     static constexpr int16_t MAX_NUM_REMINDER_LIMIT_APP = 30;
712 
713     bool isReminderAgentReady_ = false;
714 
715     // first recv UNLOCK_SCREEN event.
716     std::atomic<bool> isScreenUnLocked_ {false};
717 
718     /**
719      * Vector used to record all the reminders in system.
720      */
721     std::vector<sptr<ReminderRequest>> reminderVector_;
722 
723     /**
724      * Vector used to record all the reminders which has been shown on panel.
725      */
726     std::vector<sptr<ReminderRequest>> showedReminderVector_;
727 
728     /**
729      * This timer is used to control the triggerTime of next reminder.
730      */
731     uint64_t timerId_ {0};
732 
733     /**
734      * This timer is used to control the ringDuration of the alerting reminder.
735      */
736     std::atomic<uint64_t> timerIdAlerting_ {0};
737 
738     /**
739      * Indicates the active reminder that timing is taking effect.
740      */
741     std::atomic<int32_t> activeReminderId_ = -1;
742     sptr<ReminderRequest> activeReminder_ = nullptr;
743 
744     /**
745      * Indicates the reminder which is playing sound or vibration.
746      */
747     std::atomic<int32_t> alertingReminderId_ = -1;
748     sptr<ReminderRequest> alertingReminder_ = nullptr;
749 #ifdef PLAYER_FRAMEWORK_ENABLE
750     std::shared_ptr<Media::Player> soundPlayer_ = nullptr;
751     std::mutex resourceMutex_;  // for soundResource_
752     std::shared_ptr<Global::Resource::ResourceManager> soundResource_ = nullptr;
753 #endif
754     /**
755      * Indicates the total count of reminders in system.
756      */
757     int16_t totalCount_ {0};
758     int currentUserId_ {0};
759     std::shared_ptr<ReminderStore> store_ = nullptr;
760 
761     /**
762      * Indicates config change observer for language
763      */
764     sptr<AppExecFwk::IConfigurationObserver> configChangeObserver_ = nullptr;
765 
766     /**
767      * Indicates app mananger for get foreground application
768      */
769     std::mutex appMgrMutex_;
770     sptr<AppExecFwk::IAppMgr> appMgrProxy_ = nullptr;
771 
772     /**
773      * async queue
774      */
775     std::shared_ptr<ffrt::queue> queue_ = nullptr;
776 
777     /**
778      * Sa ready flag
779      */
780     std::atomic<int32_t> saReadyFlag_{ 0 };
781 
782     std::mutex timeLoadMutex_;
783     uint64_t reminderLoadtimerId_ {0};
784 
785     // Last time the calendardata was launched.
786     std::atomic<int64_t> lastStartTime_ {0};
787 };
788 }  // namespace OHOS
789 }  // namespace Notification
790 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_SERVICES_REMINDER_INCLUDE_REMINDER_DATA_MANAGER_H
791