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