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