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