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