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