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, bool isButtonClick = true); 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, const int8_t type); 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 std::vector<sptr<ReminderRequest>>& extensionReminders); 541 static bool StartExtensionAbility(const sptr <ReminderRequest> &reminder, const int8_t type); 542 static void AsyncStartExtensionAbility(const sptr<ReminderRequest> &reminder, 543 int32_t times, const int8_t type); 544 void InitServiceHandler(); 545 /** 546 * @brief Show the reminder on SystemUI. 547 * 548 * @param reminder Indicates the reminder to show. 549 * @param isNeedToPlaySound Indicates whether need to play sound. 550 * @param isNeedToStartNext Indicates whether need to start next reminder. 551 * @param isSysTimeChanged Indicates whether it is triggerred as system time changed by user. 552 * @param needScheduleTimeout Indicates whether need to control the ring duration. 553 */ 554 void ShowReminder(const sptr<ReminderRequest> &reminder, const bool &isNeedToPlaySound, 555 const bool &isNeedToStartNext, const bool &isSysTimeChanged, const bool &needScheduleTimeout); 556 557 void SnoozeReminderImpl(sptr<ReminderRequest> &reminder); 558 559 /** 560 * Starts timing actually. 561 * 562 * @param reminderRequest Indicates the reminder. 563 * @param type Indicates the timer type. 564 */ 565 void StartTimerLocked(const sptr<ReminderRequest> &reminderRequest, TimerType type); 566 void StartTimer(const sptr<ReminderRequest> &reminderRequest, TimerType type); 567 568 uint64_t HandleTriggerTimeInner(const sptr<ReminderRequest> &reminderRequest, TimerType type, 569 const sptr<MiscServices::TimeServiceClient> &timer); 570 571 uint64_t HandleAlertingTimeInner(const sptr<ReminderRequest> &reminderRequest, TimerType type, 572 const sptr<MiscServices::TimeServiceClient> &timer, time_t now); 573 574 /** 575 * @brief Stop the alerting timer and update reminder information. 576 * 577 * 1. Stop sound and vibrate. 578 * 2. Stop the alerting timer. 579 * 580 * @param reminder Indicates the target reminder. 581 */ 582 void StopAlertingReminder(const sptr<ReminderRequest> &reminder); 583 584 /** 585 * Stops timing. 586 * 587 * @param type Indicates the timer type. 588 */ 589 void StopTimer(TimerType type); 590 void StopTimerLocked(TimerType type); 591 592 /** 593 * @brief Terminate the alerting reminder. 594 * 595 * 1. Stop sound and vibrate. 596 * 2. Stop the alerting timer. 597 * 3. Update the reminder state. 598 * 4. Update the display content of the notification. 599 * 600 * @param reminder Indicates the reminder. 601 * @param reason Indicates the description information. 602 */ 603 void TerminateAlerting(const sptr<ReminderRequest> &reminder, const std::string &reason); 604 void TerminateAlerting(const uint16_t waitInSecond, const sptr<ReminderRequest> &reminder); 605 606 /** 607 * @brief Assign unique reminder id and save reminder in memory. 608 * 609 * @param reminder Indicates a reminder. 610 * @param bundleOption Indicates bundle option relative to the reminder. 611 */ 612 void UpdateAndSaveReminderLocked( 613 const sptr<ReminderRequest> &reminder, const sptr<NotificationBundleOption> &bundleOption); 614 615 void UpdateNotification(const sptr<ReminderRequest> &reminder, bool isSnooze); 616 617 static bool cmp(sptr<ReminderRequest> &reminderRequest, sptr<ReminderRequest> &other); 618 619 /** 620 * @brief Connect App Manager to get the current foreground application. 621 */ 622 bool ConnectAppMgr(); 623 624 /** 625 * @brief Check need to notify the application, if the current foreground application 626 * is the creator of the reminder, notify the application of the reminder status 627 * change; otherwise, do not noitfy. 628 * 629 * @param reminder Indicates a reminder. 630 * @param buttonType The type of button clicked by the user. 631 */ 632 void CheckNeedNotifyStatus(const sptr<ReminderRequest> &reminder, 633 const ReminderRequest::ActionButtonType buttonType); 634 635 std::string GetFullPath(const std::string& path); 636 637 /** 638 * @brief Check action button data share permission 639 */ 640 bool IsActionButtonDataShareValid(const sptr<ReminderRequest>& reminder, 641 const uint32_t callerTokenId); 642 643 /** 644 * @brief Get resource manager by bundlename and uid. 645 */ 646 std::shared_ptr<Global::Resource::ResourceManager> GetResourceMgr(const std::string& bundleName, 647 const int32_t uid); 648 649 /** 650 * @brief Get custom ring file desc. 651 * lock by resourceMutex_ in function 652 */ 653 bool GetCustomRingFileDesc(const sptr<ReminderRequest>& reminder, 654 Global::Resource::ResourceManager::RawFileDescriptor& desc); 655 656 /** 657 * @brief Close custom ring file desc. 658 * lock by resourceMutex_ in function 659 */ 660 void CloseCustomRingFileDesc(const int32_t reminderId, const std::string& customRingUri); 661 662 /** 663 * @brief report event to dfx 664 */ 665 void ReportSysEvent(const sptr<ReminderRequest>& reminder); 666 667 ErrCode PublishNotificationRequest(sptr<NotificationRequest>& request, 668 const sptr<NotificationBundleOption>& bundleOption); 669 670 bool CheckShowLimit(std::unordered_map<std::string, int32_t>& limits, int32_t& totalCount, 671 sptr<ReminderRequest>& reminder); 672 673 /** 674 * Single instance. 675 */ 676 static std::shared_ptr<ReminderDataManager> REMINDER_DATA_MANAGER; 677 678 /** 679 * Used for multi-thread synchronise. 680 */ 681 static std::mutex MUTEX; 682 static std::mutex SHOW_MUTEX; 683 static std::mutex ALERT_MUTEX; 684 static std::mutex TIMER_MUTEX; 685 static std::mutex ACTIVE_MUTEX; 686 687 /** 688 * Max number of reminders limit for the whole system. 689 */ 690 static constexpr int16_t MAX_NUM_REMINDER_LIMIT_SYSTEM = 12000; 691 692 /** 693 * Max number of reminders limit for one system application. 694 */ 695 static constexpr int16_t MAX_NUM_REMINDER_LIMIT_SYS_APP = 10000; 696 697 /** 698 * Max number of reminders limit for one application. 699 */ 700 static constexpr int16_t MAX_NUM_REMINDER_LIMIT_APP = 30; 701 702 bool isReminderAgentReady_ = false; 703 704 /** 705 * Vector used to record all the reminders in system. 706 */ 707 std::vector<sptr<ReminderRequest>> reminderVector_; 708 709 /** 710 * Vector used to record all the reminders which has been shown on panel. 711 */ 712 std::vector<sptr<ReminderRequest>> showedReminderVector_; 713 714 /** 715 * This timer is used to control the triggerTime of next reminder. 716 */ 717 uint64_t timerId_ {0}; 718 719 /** 720 * This timer is used to control the ringDuration of the alerting reminder. 721 */ 722 std::atomic<uint64_t> timerIdAlerting_ {0}; 723 724 /** 725 * Indicates the active reminder that timing is taking effect. 726 */ 727 std::atomic<int32_t> activeReminderId_ = -1; 728 sptr<ReminderRequest> activeReminder_ = nullptr; 729 730 /** 731 * Indicates the reminder which is playing sound or vibration. 732 */ 733 std::atomic<int32_t> alertingReminderId_ = -1; 734 sptr<ReminderRequest> alertingReminder_ = nullptr; 735 #ifdef PLAYER_FRAMEWORK_ENABLE 736 std::shared_ptr<Media::Player> soundPlayer_ = nullptr; 737 std::mutex resourceMutex_; // for soundResource_ 738 std::shared_ptr<Global::Resource::ResourceManager> soundResource_ = nullptr; 739 #endif 740 /** 741 * Indicates the total count of reminders in system. 742 */ 743 int16_t totalCount_ {0}; 744 int currentUserId_ {0}; 745 sptr<AdvancedNotificationService> advancedNotificationService_ = nullptr; 746 std::shared_ptr<ReminderStore> store_ = nullptr; 747 748 /** 749 * Indicates config change observer for language 750 */ 751 sptr<AppExecFwk::IConfigurationObserver> configChangeObserver_ = nullptr; 752 753 /** 754 * Indicates app mananger for get foreground application 755 */ 756 std::mutex appMgrMutex_; 757 sptr<AppExecFwk::IAppMgr> appMgrProxy_ = nullptr; 758 759 /** 760 * async queue 761 */ 762 std::shared_ptr<ffrt::queue> queue_ = nullptr; 763 764 /** 765 * Sa ready flag 766 */ 767 std::atomic<int32_t> saReadyFlag_{ 0 }; 768 }; 769 } // namespace OHOS 770 } // namespace Notification 771 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_FRAMEWORKS_ANS_CORE_INCLUDE_REMINDER_DATA_MANAGER_H 772