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_INTERFACES_INNER_API_REMINDER_REQUEST_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_H 18 19 #include <map> 20 #include <string> 21 22 #include "notification_constant.h" 23 #include "notification_request.h" 24 #include "want_params.h" 25 26 namespace OHOS { 27 namespace Notification { 28 29 #define READ_STRING_RETURN_FALSE_LOG(parcel, value, msg) \ 30 if (!((parcel).ReadString(value))) { \ 31 ANSR_LOGE("Failed to read %s", msg); \ 32 return false; \ 33 } \ 34 35 #define READ_BOOL_RETURN_FALSE_LOG(parcel, value, msg) \ 36 if (!((parcel).ReadBool(value))) { \ 37 ANSR_LOGE("Failed to read %s", msg); \ 38 return false; \ 39 } \ 40 41 #define READ_INT64_RETURN_FALSE_LOG(parcel, value, msg) \ 42 if (!((parcel).ReadInt64(value))) { \ 43 ANSR_LOGE("Failed to read %s", msg); \ 44 return false; \ 45 } \ 46 47 #define READ_INT32_RETURN_FALSE_LOG(parcel, value, msg) \ 48 if (!((parcel).ReadInt32(value))) { \ 49 ANSR_LOGE("Failed to read %s", msg); \ 50 return false; \ 51 } \ 52 53 #define READ_UINT64_RETURN_FALSE_LOG(parcel, value, msg) \ 54 if (!((parcel).ReadUint64(value))) { \ 55 ANSR_LOGE("Failed to read %s", msg); \ 56 return false; \ 57 } \ 58 59 #define READ_UINT32_RETURN_FALSE_LOG(parcel, value, msg) \ 60 if (!((parcel).ReadUint32(value))) { \ 61 ANSR_LOGE("Failed to read %s", msg); \ 62 return false; \ 63 } \ 64 65 #define READ_UINT16_RETURN_FALSE_LOG(parcel, value, msg) \ 66 if (!((parcel).ReadUint16(value))) { \ 67 ANSR_LOGE("Failed to read %s", msg); \ 68 return false; \ 69 } \ 70 71 #define READ_UINT8_RETURN_FALSE_LOG(parcel, value, msg) \ 72 if (!((parcel).ReadUint8(value))) { \ 73 ANSR_LOGE("Failed to read %s", msg); \ 74 return false; \ 75 } \ 76 77 #define WRITE_STRING_RETURN_FALSE_LOG(parcel, value, msg) \ 78 if (!((parcel).WriteString(value))) { \ 79 ANSR_LOGE("Failed to write %s", msg); \ 80 return false; \ 81 } \ 82 83 #define WRITE_BOOL_RETURN_FALSE_LOG(parcel, value, msg) \ 84 if (!((parcel).WriteBool(value))) { \ 85 ANSR_LOGE("Failed to write %s", msg); \ 86 return false; \ 87 } \ 88 89 #define WRITE_INT64_RETURN_FALSE_LOG(parcel, value, msg) \ 90 if (!((parcel).WriteInt64(value))) { \ 91 ANSR_LOGE("Failed to write %s", msg); \ 92 return false; \ 93 } \ 94 95 #define WRITE_INT32_RETURN_FALSE_LOG(parcel, value, msg) \ 96 if (!((parcel).WriteInt32(value))) { \ 97 ANSR_LOGE("Failed to write %s", msg); \ 98 return false; \ 99 } \ 100 101 #define WRITE_UINT64_RETURN_FALSE_LOG(parcel, value, msg) \ 102 if (!((parcel).WriteUint64(value))) { \ 103 ANSR_LOGE("Failed to write %s", msg); \ 104 return false; \ 105 } \ 106 107 #define WRITE_UINT32_RETURN_FALSE_LOG(parcel, value, msg) \ 108 if (!((parcel).WriteUint32(value))) { \ 109 ANSR_LOGE("Failed to write %s", msg); \ 110 return false; \ 111 } \ 112 113 #define WRITE_UINT16_RETURN_FALSE_LOG(parcel, value, msg) \ 114 if (!((parcel).WriteUint16(value))) { \ 115 ANSR_LOGE("Failed to write %s", msg); \ 116 return false; \ 117 } \ 118 119 #define WRITE_UINT8_RETURN_FALSE_LOG(parcel, value, msg) \ 120 if (!((parcel).WriteUint8(value))) { \ 121 ANSR_LOGE("Failed to write %s", msg); \ 122 return false; \ 123 } \ 124 125 class ReminderRequest : public Parcelable { 126 public: 127 /** 128 * @brief Supported reminder type. 129 */ 130 enum class ReminderType : uint8_t { 131 /** 132 * Indicates the classification of reminder for timer. 133 */ 134 TIMER, 135 136 /** 137 * Indicates the classification of reminder for calendar. 138 */ 139 CALENDAR, 140 141 /** 142 * Indicates the classification of reminder for alarm. 143 */ 144 ALARM, 145 INVALID 146 }; 147 148 /** 149 * @brief Supported action button type. 150 */ 151 enum class ActionButtonType : uint8_t { 152 /** 153 * @brief Indicates that this action button is used to close reminder's notification. 154 * It always works well, whether the application is running at the time. 155 * 156 */ 157 CLOSE, 158 159 /** 160 * @brief Indicates that this action button is used to snooze reminder. 161 * It always work well, whether the application is running at the time. 162 * 163 */ 164 SNOOZE, 165 166 /** 167 * @brief Indicates that this action button is custom. 168 * 169 */ 170 CUSTOM, 171 INVALID 172 }; 173 174 /** 175 * @brief Supported notification update type. 176 */ 177 enum class UpdateNotificationType : uint8_t { 178 COMMON, 179 REMOVAL_WANT_AGENT, 180 WANT_AGENT, 181 MAX_SCREEN_WANT_AGENT, 182 BUNDLE_INFO, 183 CONTENT 184 }; 185 186 /** 187 * @brief Enumerates the Time type for converting between c time and acture time. 188 */ 189 enum class TimeTransferType : uint8_t { 190 YEAR, 191 MONTH, 192 WEEK 193 }; 194 195 /** 196 * @brief Enumerates the Time format for print. 197 */ 198 enum class TimeFormat : uint8_t { 199 YMDHMS, 200 HM 201 }; 202 203 /** 204 * @brief audio stream type 205 */ 206 enum class RingChannel : uint8_t { 207 ALARM, 208 MEDIA, 209 NOTIFICATION, // for calendar 210 }; 211 212 struct ButtonWantAgent { 213 std::string pkgName = ""; 214 std::string abilityName = ""; 215 }; 216 217 struct ButtonDataShareUpdate { 218 std::string uri = ""; 219 std::string equalTo = ""; 220 std::string valuesBucket = ""; 221 }; 222 /** 223 * @brief Attributes of action button. 224 */ 225 struct ActionButtonInfo { 226 /** 227 * Type of the button. 228 */ 229 ActionButtonType type; 230 231 /** 232 * Content show on the button. 233 */ 234 std::string title = ""; 235 236 /** 237 * resource key(for language) 238 */ 239 std::string resource = ""; 240 241 /** 242 * The ability that is redirected to when the button is clicked. 243 */ 244 std::shared_ptr<ButtonWantAgent> wantAgent; 245 246 /** 247 * The ability that is updata App rdb. 248 */ 249 std::shared_ptr<ButtonDataShareUpdate> dataShareUpdate; 250 }; 251 252 /** 253 * @brief Want agent information. Indicates the package and the ability to switch to. 254 */ 255 struct WantAgentInfo { 256 std::string pkgName = ""; 257 std::string abilityName = ""; 258 std::string uri = ""; 259 AAFwk::WantParams parameters; 260 }; 261 262 struct MaxScreenAgentInfo { 263 std::string pkgName = ""; 264 std::string abilityName = ""; 265 }; 266 267 /** 268 * @brief Copy construct from an exist reminder. 269 * 270 * @param Indicates the exist reminder. 271 */ 272 explicit ReminderRequest(const ReminderRequest &other); 273 274 /** 275 * @brief This constructor should only be used in background proxy service process 276 * when reminder instance recovery from database. 277 * 278 * @param reminderId Indicates reminder id. 279 */ 280 explicit ReminderRequest(int32_t reminderId); 281 ReminderRequest& operator = (const ReminderRequest &other); ~ReminderRequest()282 virtual ~ReminderRequest() override {}; 283 284 /** 285 * @brief Marshal a NotificationRequest object into a Parcel. 286 * 287 * @param parcel the object into the parcel 288 */ 289 virtual bool Marshalling(Parcel &parcel) const override; 290 291 /** 292 * @brief Unmarshal object from a Parcel. 293 * 294 * @return the NotificationRequest 295 */ 296 static ReminderRequest *Unmarshalling(Parcel &parcel); 297 virtual bool ReadFromParcel(Parcel &parcel); 298 virtual bool WriteParcel(Parcel &parcel) const; 299 /** 300 * @brief If the reminder is showing on the notification panel, it should not be removed automatically. 301 * 302 * @return true if it can be removed automatically. 303 */ 304 bool CanRemove() const; 305 306 bool CanShow() const; 307 308 /** 309 * @brief Obtains all the information of the reminder. 310 * 311 * @return Information of the reminder. 312 */ 313 std::string Dump() const; 314 315 /** 316 * @brief Obtains the configured action buttons. 317 * 318 * @return map of action buttons. 319 */ 320 std::map<ActionButtonType, ActionButtonInfo> GetActionButtons() const; 321 322 /** 323 * @brief Set the reminder action buttons. 324 */ 325 void SetActionButtons(const std::map<ActionButtonType, ActionButtonInfo>& buttons); 326 327 /** 328 * @brief Obtains creator bundle name 329 * 330 * @return creator bundle name 331 */ 332 std::string GetCreatorBundleName() const; 333 334 /** 335 * @brief Obtains creator uid 336 * 337 * @return creator uid 338 */ 339 int32_t GetCreatorUid() const; 340 341 /** 342 * @brief Obtains the configured content. 343 * 344 * @return content text. 345 */ 346 std::string GetContent() const; 347 348 /** 349 * @brief Obtains the configured expired content. 350 * 351 * @return expired content text. 352 */ 353 std::string GetExpiredContent() const; 354 355 std::shared_ptr<MaxScreenAgentInfo> GetMaxScreenWantAgentInfo() const; 356 357 /** 358 * @brief Obtains notification id. 359 * 360 * @return notification id. 361 */ 362 int32_t GetNotificationId() const; 363 364 /** 365 * @brief Obtains group id. 366 * 367 * @return group id. 368 */ 369 std::string GetGroupId() const; 370 371 /** 372 * @brief Obtains reminder id. 373 * 374 * @return reminder id. 375 */ 376 int32_t GetReminderId() const; 377 378 uint64_t GetReminderTimeInMilli() const; 379 380 /** 381 * @brief Obtains reminder type. 382 * 383 * @return reminder type. 384 */ 385 ReminderType GetReminderType() const; 386 387 /** 388 * @brief Obtains the ringing or vibration duration configured for this reminder. 389 * 390 * @return uint16_t The ringing or vibration duration in seconds. 391 */ 392 uint16_t GetRingDuration() const; 393 394 /** 395 * @brief Obtains slot type. 396 * 397 * @return slot type. 398 */ 399 NotificationConstant::SlotType GetSlotType() const; 400 401 /** 402 * @brief Obtains snoozeSlot type. 403 * 404 * @return snoozeSlot type. 405 */ 406 NotificationConstant::SlotType GetSnoozeSlotType() const; 407 408 std::string GetSnoozeContent() const; 409 uint8_t GetSnoozeTimes() const; 410 uint8_t GetSnoozeTimesDynamic() const; 411 uint8_t GetState() const; 412 413 /** 414 * @brief Obtains the Time Interval in seconds. 415 * 416 * @return uint64_t Time Interval in seconds. 417 */ 418 uint64_t GetTimeInterval() const; 419 420 /** 421 * @brief Obtains title. 422 * 423 * @return title. 424 */ 425 std::string GetTitle() const; 426 427 /** 428 * @brief Obtains trigger time in milli. 429 * 430 * @return trigger time. 431 */ 432 uint64_t GetTriggerTimeInMilli() const; 433 GetTitleResourceId()434 int32_t GetTitleResourceId() const 435 { 436 return titleResourceId_; 437 } GetContentResourceId()438 int32_t GetContentResourceId() const 439 { 440 return contentResourceId_; 441 } GetExpiredContentResourceId()442 int32_t GetExpiredContentResourceId() const 443 { 444 return expiredContentResourceId_; 445 } GetSnoozeContentResourceId()446 int32_t GetSnoozeContentResourceId() const 447 { 448 return snoozeContentResourceId_; 449 } 450 SetTitleResourceId(const int32_t titleResourceId)451 void SetTitleResourceId(const int32_t titleResourceId) 452 { 453 titleResourceId_ = titleResourceId; 454 } SetContentResourceId(const int32_t contentResourceId)455 void SetContentResourceId(const int32_t contentResourceId) 456 { 457 contentResourceId_ = contentResourceId; 458 } SetExpiredContentResourceId(const int32_t expiredContentResourceId)459 void SetExpiredContentResourceId(const int32_t expiredContentResourceId) 460 { 461 expiredContentResourceId_ = expiredContentResourceId; 462 } SetSnoozeContentResourceId(const int32_t snoozeContentResourceId)463 void SetSnoozeContentResourceId(const int32_t snoozeContentResourceId) 464 { 465 snoozeContentResourceId_ = snoozeContentResourceId; 466 } 467 468 /** 469 * @brief Set/Get ring channel. 470 */ 471 void SetRingChannel(const RingChannel channel); 472 RingChannel GetRingChannel() const; 473 474 /** 475 * @brief Set/Get ring loop. 476 */ 477 void SetRingLoop(const bool isRingLoop); 478 bool IsRingLoop() const; 479 480 int32_t GetUserId() const; 481 int32_t GetUid() const; 482 483 /** 484 * @brief Obtains bundle name 485 * 486 * @return bundle name 487 */ 488 std::string GetBundleName() const; 489 490 /** 491 * @brief Set the reminder type. 492 * 493 * @param reminderType the reminder type. 494 */ 495 void SetReminderType(const ReminderType type); 496 497 /** 498 * @brief Set the reminder state. 499 * 500 * @param state the reminder state. 501 */ 502 void SetState(const uint8_t state); 503 504 /** 505 * @brief Set the reminder repeat days of week. 506 * 507 * @param state the reminder repeat days of week. 508 */ 509 void SetRepeatDaysOfWeek(const uint8_t repeatDaysOfWeek); 510 511 /** 512 * @brief Set the app system. 513 * 514 */ 515 void SetSystemApp(bool isSystem); 516 517 /** 518 * @brief Check the app is system or not. 519 * 520 * @return true is the app is system. 521 */ 522 bool IsSystemApp() const; 523 524 /** 525 * @brief Obtains want agent information. 526 * 527 * @return want agent information. 528 */ 529 std::shared_ptr<WantAgentInfo> GetWantAgentInfo() const; 530 531 /** 532 * @brief Inites reminder creator bundle name when publish reminder success. 533 * 534 * @param creatorBundleName Indicates the creator bundle name which the reminder belong to 535 */ 536 void InitCreatorBundleName(const std::string &creatorBundleName); 537 538 /** 539 * @brief Inites reminder creator uid when publish reminder success. 540 * 541 * @param uid Indicates the creator uid which the reminder belong to 542 */ 543 void InitCreatorUid(const int32_t creatorUid); 544 545 /** 546 * @brief Inits reminder id when publish reminder success. 547 * Assign a unique reminder id for each reminder. 548 */ 549 void InitReminderId(); 550 551 /** 552 * @brief Inits reminder userId when publish reminder success. 553 * 554 * When package remove, user id is sended by wantAgent, but we cannot get the uid according user id as the 555 * package has been removed, and the bundleOption can not be create with correct uid. so we need to record 556 * the user id, and use it to judge which user the reminder belong to. 557 * 558 * @param userId Indicates the userId which the reminder belong to. 559 */ 560 void InitUserId(const int32_t &userId); 561 562 /** 563 * @brief Inites reminder uid when publish reminder success. 564 * 565 * When system reboot and recovery from database, we cannot get the uid according user id as BMS has not be 566 * ready. So we need to record the uid in order to create correct bundleOption. 567 * 568 * @param uid Indicates the uid which the reminder belong to. 569 */ 570 void InitUid(const int32_t &uid); 571 572 /** 573 * @brief Inites reminder bundle name when publish reminder success. 574 * 575 * @param bundleName Indicates the bundle name which the reminder belong to 576 */ 577 void InitBundleName(const std::string &bundleName); 578 579 /** 580 * @brief Check the reminder is alerting or not. 581 * 582 * @return true if the reminder is playing sound or vibrating. 583 */ 584 bool IsAlerting() const; 585 586 /** 587 * @brief Check the reminder is expired or not. 588 * 589 * @return true is the reminder is expired. 590 */ 591 bool IsExpired() const; 592 593 /** 594 * @brief Check the reminder is showing on the panel. 595 * 596 * @return true if the reminder is showing on the panel. 597 */ 598 bool IsShowing() const; 599 600 /** 601 * @brief Closes the reminder by manual. 602 * 603 * 1) Resets the state of "Alering/Showing/Snooze" 604 * 2) Resets snoozeTimesDynamic_ if update to next trigger time, otherwise set reminder to expired. 605 * 606 * @param updateNext Whether to update to next reminder. 607 */ 608 void OnClose(bool updateNext); 609 610 /** 611 * @brief When date/time change, reminder need to refresh next trigger time. 612 * 613 * @return true if need to show reminder immediately. 614 */ 615 virtual bool OnDateTimeChange(); 616 617 /** 618 * When shown notification is covered by a new notification with the same id, we should remove 619 * the state of showing, so that the reminder can be removed automatically when it is expired. 620 */ 621 void OnSameNotificationIdCovered(); 622 623 /** 624 * Set the reminder state is InActive, so that it will be removed when expired 625 */ 626 void SetStateToInActive(); 627 628 /** 629 * @brief Shows the reminder on panel. TriggerTime will be updated to next. 630 * 631 * @param isPlaySoundOrVibration true means it is play sound or vibration. 632 * @param isSysTimeChanged true means it is called when the system time is changed by user, otherwise false. 633 * @param allowToNotify true means that the notification will be shown as normal, otherwise false. 634 */ 635 void OnShow(bool isPlaySoundOrVibration, bool isSysTimeChanged, bool allowToNotify); 636 637 /** 638 * @brief Reset the state of "Showing" when the reminder is shown failed. 639 */ 640 void OnShowFail(); 641 642 /** 643 * @brief Snooze the reminder by manual. 644 * 645 * 1) Updates the trigger time to the next one. 646 * 2) Updates the notification content for "Snooze". 647 * 3) Switches the state from "Showing[, Alerting]" to "Snooze". 648 */ 649 bool OnSnooze(); 650 651 /** 652 * @brief Starts the reminder 653 * 654 * Sets the state from "Inactive" to "Active". 655 */ 656 void OnStart(); 657 658 /** 659 * @brief Stops the reminder. 660 * 661 * Sets the state from "Active" to "Inactive". 662 */ 663 void OnStop(); 664 665 /** 666 * @brief Terminate the alerting reminder, which is executed when the ring duration is over. 667 * 668 * 1) Disables the state of "Alerting". 669 * 2) Updates the notification content for "Alert". 670 * 671 * @return false if alerting state has already been set false before calling the method. 672 */ 673 bool OnTerminate(); 674 675 /** 676 * @brief When timezone change, reminder need to refresh next trigger time. 677 * 678 * @return true if need to show reminder immediately. 679 */ 680 virtual bool OnTimeZoneChange(); 681 682 /** 683 * @brief Sets action button. 684 * 685 * @param title Indicates the title of the button. 686 * @param type Indicates the type of the button. 687 * @param resource Indicates the resource of the button. 688 * @return Current reminder self. 689 */ 690 ReminderRequest& SetActionButton(const std::string &title, const ActionButtonType &type, 691 const std::string &resource, const std::shared_ptr<ButtonWantAgent> &buttonWantAgent = nullptr, 692 const std::shared_ptr<ButtonDataShareUpdate> &buttonDataShareUpdate = nullptr); 693 694 /** 695 * @brief Sets reminder content. 696 * 697 * @param content Indicates content text. 698 * @return Current reminder self. 699 */ 700 ReminderRequest& SetContent(const std::string &content); 701 702 /** 703 * @brief Sets reminder is expired or not. 704 * 705 * @param isExpired Indicates the reminder is expired or not. 706 */ 707 void SetExpired(bool isExpired); 708 709 /** 710 * @brief Sets expired content. 711 * 712 * @param expiredContent Indicates expired content. 713 * @return Current reminder self. 714 */ 715 ReminderRequest& SetExpiredContent(const std::string &expiredContent); 716 717 ReminderRequest& SetMaxScreenWantAgentInfo(const std::shared_ptr<MaxScreenAgentInfo> &maxScreenWantAgentInfo); 718 719 /** 720 * @brief Sets notification id. 721 * 722 * @param notificationId Indicates notification id. 723 * @return Current reminder self. 724 */ 725 ReminderRequest& SetNotificationId(int32_t notificationId); 726 727 /** 728 * @brief Sets group id. 729 * 730 * @param notificationId Indicates group id. 731 * @return Current reminder self. 732 */ 733 ReminderRequest& SetGroupId(const std::string &groupId); 734 735 /** 736 * @brief Sets reminder id. 737 * 738 * @param reminderId Indicates reminder id. 739 */ 740 void SetReminderId(int32_t reminderId); 741 742 void SetReminderTimeInMilli(const uint64_t reminderTimeInMilli); 743 744 /** 745 * @brief Sets the ringing or vibration duration for this reminder, in seconds. 746 * 747 * @param ringDurationInSeconds Indicates the duration. The default is 1 second. 748 * @return Current reminder self. 749 */ 750 ReminderRequest& SetRingDuration(const uint64_t ringDurationInSeconds); 751 752 /** 753 * @brief Sets slot type. 754 * 755 * @param slotType Indicates slot type. 756 * @return Current reminder self. 757 */ 758 ReminderRequest& SetSlotType(const NotificationConstant::SlotType &slotType); 759 ReminderRequest& SetSnoozeSlotType(const NotificationConstant::SlotType &snoozeSlotType); 760 ReminderRequest& SetSnoozeContent(const std::string &snoozeContent); 761 762 /** 763 * @brief Set the number of snooze times for this reminder. 764 * 765 * @note If the value of snoozeTimes is less than or equals to 0, this reminder is a one-shot 766 * reminder and will not be snoozed. 767 * 768 * It the value of snoozeTimes is greater than 0, for example, snoozeTimes=3, this reminder 769 * will be snoozed three times after the first alarm, that is, this reminder will be triggered 770 * for four times. 771 * 772 * This method does not take affect on the reminders for countdown timers. 773 * 774 * @param snoozeTimes Indicates the number of times that the reminder will be snoozed. 775 * @return ReminderRequest& Current reminder self. 776 */ 777 ReminderRequest& SetSnoozeTimes(const uint8_t snoozeTimes); 778 779 ReminderRequest& SetSnoozeTimesDynamic(const uint8_t snooziTimes); 780 781 /** 782 * @brief Sets the Time Interval for this reminder, in seconds. The default value is 0. 783 * 784 * @note The minimum snooze interval is 5 minute. If the snooze interval is set to a value greater 785 * than 0 and less than 5 minutes, the system converts it to 5 minutes by default. 786 * 787 * This method does not take effect on the reminders for countdown timers. 788 * 789 * @param timeIntervalInSeconds Indicates the snooze interval to set. If the value is less or equals to 0, 790 * the reminder will not be snoozed. 791 * @return ReminderRequest& Current reminder self. 792 */ 793 ReminderRequest& SetTimeInterval(const uint64_t timeIntervalInSeconds); 794 795 /** 796 * @brief Sets title. 797 * 798 * @param title Indicates title. 799 * @return Current reminder self. 800 */ 801 ReminderRequest& SetTitle(const std::string &title); 802 803 /** 804 * @brief Sets trigger time. 805 * 806 * @param triggerTimeInMilli Indicates trigger time in milli. 807 */ 808 void SetTriggerTimeInMilli(uint64_t triggerTimeInMilli); 809 SetIdentifier(const std::string & identifier)810 void SetIdentifier(const std::string& identifier) 811 { 812 identifier_ = identifier; 813 } 814 GetIdentifier()815 std::string GetIdentifier() const 816 { 817 return identifier_; 818 } 819 820 /** 821 * @brief Sets want agent information. 822 * 823 * @param wantAgentInfo Indicates want agent information. 824 * @return Current reminder self. 825 */ 826 ReminderRequest& SetWantAgentInfo(const std::shared_ptr<WantAgentInfo> &wantAgentInfo); 827 828 bool ShouldShowImmediately() const; 829 830 /** 831 * @brief Updates {@link triggerTimeInMilli_} to next. 832 * @note If next trigger time not exist, {@link isExpired_} flag will be set with true. 833 * 834 * @return true if next trigger time exist and set success. 835 */ 836 virtual bool UpdateNextReminder(); 837 virtual bool SetNextTriggerTime(); 838 839 /** 840 * @brief Check reminder request is repeat 841 */ IsRepeat()842 virtual bool IsRepeat() const 843 { 844 return false; 845 } 846 847 /** 848 * @brief Check reminder request is in exclude date 849 */ CheckExcludeDate()850 virtual bool CheckExcludeDate() 851 { 852 return false; 853 } 854 855 /** 856 * @brief Check rrule want agent, pull up service extension 857 * 858 * @return true if need pull up service extension 859 */ IsPullUpService()860 virtual bool IsPullUpService() 861 { 862 return false; 863 } 864 865 /** 866 * @brief Check need notification reminder. due to system timer. 867 * When change system time to later, more than the trigger time, system timer must trigger. 868 */ IsNeedNotification()869 virtual bool IsNeedNotification() 870 { 871 return true; 872 } 873 874 void SetWantAgentStr(const std::string& wantStr); 875 std::string GetWantAgentStr(); 876 void SetMaxWantAgentStr(const std::string& maxWantStr); 877 std::string GetMaxWantAgentStr(); 878 879 /** 880 * @brief Sets tapDismissed. 881 * 882 * @param tapDismissed Indicates tapDismissed. 883 */ 884 void SetTapDismissed(bool tapDismissed); 885 886 /** 887 * @brief Gets tapDismissed. 888 * 889 * @return True if tapDismissed. 890 */ 891 bool IsTapDismissed() const; 892 893 /** 894 * @brief Sets autoDeletedTime. 895 * 896 * @param autoDeletedTime Indicates autoDeletedTime. 897 */ 898 void SetAutoDeletedTime(int64_t autoDeletedTime); 899 900 /** 901 * @brief Gets autoDeletedTime. 902 * 903 * @return AutoDeletedTime. 904 */ 905 int64_t GetAutoDeletedTime() const; 906 907 /** 908 * @brief Sets custom button uri. 909 * 910 * @param uri Indicates uri. 911 */ 912 void SetCustomButtonUri(const std::string &uri); 913 914 /** 915 * @brief Gets custom button uri. 916 * 917 * @return custom button uri. 918 */ 919 std::string GetCustomButtonUri() const; 920 921 /** 922 * @brief Is the reminder from datashare. 923 */ 924 bool IsShare() const; 925 926 /** 927 * @brief Set the reminder from datashare. 928 */ 929 void SetShare(const bool isShare); 930 931 /** 932 * @brief Gets custom ring uri. 933 * 934 * @return custom ring uri. 935 */ 936 std::string GetCustomRingUri() const; 937 938 /** 939 * @brief Sets custom ring uri. 940 * 941 * @param uri Indicates uri. 942 */ 943 void SetCustomRingUri(const std::string &uri); 944 945 /** 946 * @brief Update notification attributes. 947 * 948 * Some attributes need to be updated after the reminder published or before the notification publish. 949 * For example, action button should not init until the reminder is published successfully, as the reminder id is 950 * assigned after that. 951 * 952 * @param notificationRequest notification request object 953 * @param isSnooze isSnooze 954 */ 955 void UpdateNotificationRequest(NotificationRequest& notificationRequest, bool isSnooze); 956 957 /** 958 * @brief Get repeated days of the week. 959 * 960 * @return Array of the int type. 961 */ 962 std::vector<int32_t> GetDaysOfWeek() const; 963 964 /** 965 * @brief Gets repeat days of week 966 */ 967 uint8_t GetRepeatDaysOfWeek() const; 968 969 /** 970 * @brief When system language change, will call this function. 971 * need load resource to update button title 972 * @param resMgr Indicates the resource manager for get button title 973 */ 974 void OnLanguageChange(const std::shared_ptr<Global::Resource::ResourceManager> &resMgr); 975 976 public: 977 /** 978 * @brief Serialize want agent info and max want agent info to string. 979 * Persist to the rdb. 980 */ 981 void SerializeWantAgent(std::string& wantInfoStr, std::string& maxWantInfoStr); 982 983 /** 984 * @brief Deserialize want agent info and max want agent info from string. 985 * Recover from the rdb. 986 */ 987 void DeserializeWantAgent(const std::string& wantAgentInfo, const uint8_t type); 988 989 /** 990 * @brief Serialize action button info to string. 991 * Persist to the rdb. 992 */ 993 std::string SerializeButtonInfo() const; 994 995 /** 996 * @brief Deserialize action button info from string. 997 * Recover from the rdb. 998 */ 999 void DeserializeButtonInfo(const std::string& buttonInfoStr); 1000 void DeserializeButtonInfoFromJson(const std::string& jsonString); 1001 1002 static int32_t GetActualTime(const TimeTransferType &type, int32_t cTime); 1003 static int32_t GetCTime(const TimeTransferType &type, int32_t actualTime); 1004 static uint64_t GetDurationSinceEpochInMilli(const time_t target); 1005 static std::vector<std::string> StringSplit(std::string source, const std::string &split); 1006 static double StringToDouble(const std::string& str); 1007 static int32_t StringToInt(const std::string& str); 1008 1009 static bool ReadReminderTypeFormParcel(Parcel &parcel, ReminderType& tarReminderType); 1010 1011 static int32_t GLOBAL_ID; 1012 static const uint64_t INVALID_LONG_LONG_VALUE; 1013 static const uint16_t INVALID_U16_VALUE; 1014 static const uint8_t INVALID_U8_VALUE; 1015 static const uint16_t MILLI_SECONDS; 1016 static const uint16_t SAME_TIME_DISTINGUISH_MILLISECONDS; 1017 static const std::string NOTIFICATION_LABEL; 1018 static const uint8_t MONDAY; 1019 static const uint8_t SUNDAY; 1020 static const uint8_t DAYS_PER_WEEK; 1021 static const uint8_t HOURS_PER_DAY; 1022 static const uint16_t SECONDS_PER_HOUR; 1023 static const uint8_t MINUTES_PER_HOUR; 1024 /** 1025 * @brief Show the reminder with a notification. 1026 */ 1027 static const std::string REMINDER_EVENT_ALARM_ALERT; 1028 1029 /** 1030 * @brief Close the reminder when click the close button of notification. 1031 */ 1032 static const std::string REMINDER_EVENT_CLOSE_ALERT; 1033 1034 /** 1035 * @brief Snooze the reminder when click the snooze button of notification. 1036 */ 1037 static const std::string REMINDER_EVENT_SNOOZE_ALERT; 1038 1039 static const std::string REMINDER_EVENT_CUSTOM_ALERT; 1040 1041 /** 1042 * @biref Close the reminder when click the notification, not button. 1043 */ 1044 static const std::string REMINDER_EVENT_CLICK_ALERT; 1045 1046 /** 1047 * @brief Used to control ring duration. 1048 */ 1049 static const std::string REMINDER_EVENT_ALERT_TIMEOUT; 1050 1051 /** 1052 * @brief Update the reminder when remove notification from the systemUI. 1053 */ 1054 static const std::string REMINDER_EVENT_REMOVE_NOTIFICATION; 1055 static const std::string PARAM_REMINDER_ID; 1056 static const std::string PARAM_REMINDER_SHARE; 1057 static const uint8_t REMINDER_STATUS_INACTIVE; 1058 static const uint8_t REMINDER_STATUS_ACTIVE; 1059 static const uint8_t REMINDER_STATUS_ALERTING; 1060 static const uint8_t REMINDER_STATUS_SHOWING; 1061 static const uint8_t REMINDER_STATUS_SNOOZE; 1062 static const uint8_t TIME_HOUR_OFFSET; 1063 1064 // For ActionButtonDataShare. 1065 static const std::string SEP_BUTTON_VALUE_TYPE; 1066 static const std::string SEP_BUTTON_VALUE; 1067 static const std::string SEP_BUTTON_VALUE_BLOB; 1068 1069 // no object in parcel 1070 static constexpr int32_t VALUE_NULL = -1; 1071 // object exist in parcel 1072 static constexpr int32_t VALUE_OBJECT = 1; 1073 // wantAgent flag 1074 static constexpr int32_t WANT_AGENT_FLAG = 0; 1075 // maxWantAgent flag 1076 static constexpr int32_t MAX_WANT_AGENT_FLAG = 1; 1077 1078 // max ring duration 1079 static constexpr uint64_t MAX_RING_DURATION = 30 * 60 * 1000; // 30 min 1080 1081 protected: 1082 enum class DbRecoveryType : uint8_t { 1083 INT, 1084 LONG 1085 }; 1086 ReminderRequest(); 1087 explicit ReminderRequest(ReminderType reminderType); 1088 std::string GetDateTimeInfo(const time_t &timeInSecond) const; PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat,bool forceToGetNext)1089 virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) 1090 { 1091 return INVALID_LONG_LONG_VALUE; 1092 } 1093 1094 uint8_t repeatDaysOfWeek_{0}; 1095 1096 /** 1097 * Obtains the next triggerTime if it is a week repeat. 1098 * 1099 * @param now Indicates current time. 1100 * @param now Indicatet target time. 1101 * @return nextTriggerTime. 1102 */ 1103 int64_t GetNextDaysOfWeek(const time_t now, const time_t target) const; 1104 void SetRepeatDaysOfWeek(bool set, const std::vector<uint8_t> &daysOfWeek); 1105 time_t GetTriggerTimeWithDST(const time_t now, const time_t nextTriggerTime) const; 1106 uint64_t GetTriggerTime(const time_t now, const time_t nextTriggerTime) const; 1107 uint64_t GetNowInstantMilli() const; 1108 1109 private: 1110 1111 std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> CreateWantAgent(AppExecFwk::ElementName &element) const; 1112 std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> CreateMaxWantAgent(AppExecFwk::ElementName &element) const; 1113 std::string GetShowTime(const uint64_t showTime) const; 1114 std::string GetTimeInfoInner(const time_t &timeInSecond, const TimeFormat &format, bool keep24Hour) const; 1115 std::string GetState(const uint8_t state) const; 1116 bool HandleSysTimeChange(uint64_t oriTriggerTime, uint64_t optTriggerTime); 1117 bool HandleTimeZoneChange(uint64_t oldZoneTriggerTime, uint64_t newZoneTriggerTime, uint64_t optTriggerTime); 1118 void InitServerObj(); 1119 void SetMaxScreenWantAgent(AppExecFwk::ElementName &element); 1120 void SetState(bool deSet, const uint8_t newState, std::string function); 1121 void SetWantAgent(AppExecFwk::ElementName &element); 1122 void SetExtraInfo(const AAFwk::WantParams& params); 1123 void UpdateActionButtons(NotificationRequest& notificationRequest, const bool &setSnooze); 1124 bool UpdateNextReminder(const bool &force); 1125 void AddActionButtons(NotificationRequest& notificationRequest, const bool includeSnooze); 1126 void UpdateNotificationContent(NotificationRequest& notificationRequest, const bool &setSnooze); 1127 void UpdateNotificationCommon(NotificationRequest& notificationRequest, bool isSnooze); 1128 void UpdateNotificationAddRemovalWantAgent(NotificationRequest& notificationRequest); 1129 void UpdateNotificationWantAgent(NotificationRequest& notificationRequest); 1130 void UpdateNotificationMaxScreenWantAgent(NotificationRequest& notificationRequest); 1131 void UpdateNotificationBundleInfo(NotificationRequest& notificationRequest); 1132 1133 /** 1134 * @brief Determine whether it is repeated every week. 1135 * 1136 * @return True if repeate. 1137 */ 1138 bool IsRepeatDaysOfWeek(int32_t day) const; 1139 1140 /** 1141 * @brief Update the notification, which will be shown for the "Alerting" reminder. 1142 * 1. Update the notification label/content. 1143 * 2. Restore the snooze action button. 1144 */ 1145 void UpdateNotificationStateForAlert(NotificationRequest& notificationRequest); 1146 1147 /** 1148 * @brief Update the notification, which will be shown when user do a snooze. 1149 * 1. Update the notification label/content. 1150 * 2. Remove the snooze action button. 1151 */ 1152 void UpdateNotificationStateForSnooze(NotificationRequest& notificationRequest); 1153 1154 bool MarshallingWantParameters(Parcel& parcel, const AAFwk::WantParams& params) const; 1155 bool MarshallingActionButton(Parcel& parcel) const; 1156 bool ReadWantParametersFromParcel(Parcel& parcel, AAFwk::WantParams& wantParams); 1157 bool ReadActionButtonFromParcel(Parcel& parcel); 1158 1159 void RecoverActionButtonJsonMode(const std::string& jsonString); 1160 void RecoverWantAgentByJson(const std::string& wantAgentInfo, const uint8_t& type); 1161 1162 static const uint32_t MIN_TIME_INTERVAL_IN_MILLI; 1163 static const std::string SEP_BUTTON_SINGLE; 1164 static const std::string SEP_BUTTON_MULTI; 1165 static const std::string SEP_WANT_AGENT; 1166 1167 std::string content_ {}; 1168 std::string expiredContent_ {}; 1169 std::string snoozeContent_ {}; 1170 std::string displayContent_ {}; 1171 std::string title_ {}; 1172 std::string bundleName_ {}; 1173 bool isExpired_ {false}; 1174 bool isShare_ {false}; 1175 uint8_t snoozeTimes_ {0}; 1176 uint8_t snoozeTimesDynamic_ {0}; 1177 uint8_t state_ {0}; 1178 RingChannel ringChannel_ {RingChannel::ALARM}; 1179 int32_t notificationId_ {0}; 1180 std::string groupId_ {}; 1181 int32_t reminderId_ {-1}; 1182 int32_t userId_ {-1}; 1183 int32_t uid_ {-1}; 1184 bool isSystemApp_ {false}; 1185 bool tapDismissed_ {true}; 1186 bool isRingLoop_ {true}; 1187 int64_t autoDeletedTime_ {0}; 1188 std::string customButtonUri_ {}; 1189 std::string customRingUri_ {}; 1190 std::string creatorBundleName_ {}; 1191 int32_t creatorUid_ {-1}; 1192 1193 // Indicates the reminder has been shown in the past time. 1194 // When the reminder has been created but not showed, it is equals to 0. 1195 uint64_t reminderTimeInMilli_ {0}; 1196 uint64_t ringDurationInMilli_ {MILLI_SECONDS}; 1197 uint64_t triggerTimeInMilli_ {0}; 1198 uint64_t timeIntervalInMilli_ {0}; 1199 ReminderType reminderType_ {ReminderType::INVALID}; 1200 NotificationConstant::SlotType slotType_ {NotificationConstant::SlotType::SOCIAL_COMMUNICATION}; 1201 NotificationConstant::SlotType snoozeSlotType_ {NotificationConstant::SlotType::OTHER}; 1202 std::shared_ptr<WantAgentInfo> wantAgentInfo_ = nullptr; 1203 std::shared_ptr<MaxScreenAgentInfo> maxScreenWantAgentInfo_ = nullptr; 1204 std::map<ActionButtonType, ActionButtonInfo> actionButtonMap_ {}; 1205 1206 std::vector<std::shared_ptr<NotificationActionButton>> actionButtons_ {}; 1207 std::string wantAgentStr_{}; 1208 std::string maxWantAgentStr_{}; 1209 std::string identifier_; 1210 1211 int32_t titleResourceId_ {0}; 1212 int32_t contentResourceId_ {0}; 1213 int32_t expiredContentResourceId_ {0}; 1214 int32_t snoozeContentResourceId_ {0}; 1215 }; 1216 } // namespace Notification 1217 } // namespace OHOS 1218 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_H