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_ALARM_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_ALARM_H
18 
19 #include "reminder_request.h"
20 
21 #include <vector>
22 
23 namespace OHOS {
24 namespace Notification {
25 class ReminderRequestAlarm : public ReminderRequest {
26 public:
27     /**
28      * @brief A {@link ReminderRequest} child class used for creating reminders of alarm clocks.
29      * You can use this class to publish alarm reminders at a specified time (accurate to minute) on a
30      * particular day or on particular days every week.
31      *
32      * @note The params must meet the following conditions,
33      * otherwise the application may crash due to an illegal parameter exception.
34      *
35      * @param hour The value must between [0, 23].
36      * @param minute The value must between [0, 59].
37      * @param daysOfWeek The value must between [1, 7], and the length of array can not be greater than 7.
38      *
39      * @see ReminderRequestTimer
40      */
41     ReminderRequestAlarm(uint8_t hour, uint8_t minute, std::vector<uint8_t> daysOfWeek);
42 
43     /**
44      * @brief This constructor should only be used in background proxy service process
45      * when reminder instance recovery from database.
46      *
47      * @param reminderId Indicates reminder id.
48      */
ReminderRequestAlarm(int32_t reminderId)49     explicit ReminderRequestAlarm(int32_t reminderId) : ReminderRequest(reminderId) {};
50 
51     /**
52      * @brief Copy construct from an exist reminder.
53      *
54      * @param Indicates the exist alarm reminder.
55      */
56     explicit ReminderRequestAlarm(const ReminderRequestAlarm &other);
57     ReminderRequestAlarm& operator = (const ReminderRequestAlarm &other);
~ReminderRequestAlarm()58     ~ReminderRequestAlarm() override {};
59 
60     /**
61      * @brief Obtains the setted {@link hour_}.
62      *
63      * @return setted hour.
64      */
65     uint8_t GetHour() const;
66 
67     /**
68      * @brief Obtains the setted {@link minute_}.
69      *
70      * @return setted minute.
71      */
72     uint8_t GetMinute() const;
73 
74     /**
75      * @brief Sets the hour.
76      *
77      * @param hour Indicates the hour.
78      */
79     void SetHour(const uint8_t hour);
80 
81     /**
82      * @brief Sets the minute.
83      *
84      * @param minute Indicates the minute.
85      */
86     void SetMinute(const uint8_t minute);
87 
88     virtual bool UpdateNextReminder() override;
89 
90     /**
91      * Marshal a reminder object into a Parcel.
92      *
93      * @param parcel Indicates the Parcel.
94      */
95     virtual bool Marshalling(Parcel &parcel) const override;
96 
97     /**
98      * Unmarshal object from a Parcel.
99      *
100      * @param parcel Indicates the Parcel.
101      * @return reminder object.
102      */
103     static ReminderRequestAlarm *Unmarshalling(Parcel &parcel);
104 
105     /**
106      * Unmarshal unique properties of alarm from a Parcel.
107      *
108      * @param parcel Indicates the Parcel.
109      * @return true if read parcel success.
110      */
111     bool ReadFromParcel(Parcel &parcel) override;
112 
113 protected:
114     virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) override;
115 
116 private:
ReminderRequestAlarm()117     ReminderRequestAlarm() : ReminderRequest() {};
118     void CheckParamValid() const;
119 
120     /**
121      * Obtains the next trigger time.
122      *
123      * @param forceToGetNext Indicates whether force to get next reminder.
124      *                       When set the alarm firstly, you should set force with true, so if repeat information
125      *                       is not set, and the target time is overdue, the reminder will be set to next day.
126      *                       When change the time manually by user, you should set force with false, so if repeat
127      *                       information is not set, and target time is overdue, the reminder will not be set to
128      *                       next day.
129      * @return next trigger time in milli.
130      */
131     uint64_t GetNextTriggerTime(bool forceToGetNext) const;
132     bool IsRepeatReminder() const;
133 
134     static const uint8_t MINUTES_PER_HOUR;
135     static const int8_t DEFAULT_SNOOZE_TIMES;
136 
137     uint8_t hour_ = {0};
138     uint8_t minute_ = {0};
139 };
140 }  // namespace Notification
141 }  // namespace OHOS
142 
143 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_ALARM_H