• 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_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      * Obtains the repeat days vector.
62      *
63      * @return vector of repeat days.
64      */
65     std::vector<int32_t> GetDaysOfWeek() const;
66 
67     /**
68      * @brief Obtains the setted {@link hour_}.
69      *
70      * @return setted hour.
71      */
72     uint8_t GetHour() const;
73 
74     /**
75      * @brief Obtains the setted {@link minute_}.
76      *
77      * @return setted minute.
78      */
79     uint8_t GetMinute() const;
80     uint8_t GetRepeatDay() const;
81     virtual bool OnDateTimeChange() override;
82     virtual bool OnTimeZoneChange() override;
83     virtual bool UpdateNextReminder() override;
84 
85     /**
86      * Marshal a reminder object into a Parcel.
87      *
88      * @param parcel Indicates the Parcel.
89      */
90     virtual bool Marshalling(Parcel &parcel) const override;
91 
92     /**
93      * Unmarshal object from a Parcel.
94      *
95      * @param parcel Indicates the Parcel.
96      * @return reminder object.
97      */
98     static ReminderRequestAlarm *Unmarshalling(Parcel &parcel);
99 
100     /**
101      * Unmarshal unique properties of alarm from a Parcel.
102      *
103      * @param parcel Indicates the Parcel.
104      * @return true if read parcel success.
105      */
106     bool ReadFromParcel(Parcel &parcel) override;
107     virtual void RecoverFromDb(const std::shared_ptr<NativeRdb::ResultSet> &resultSet) override;
108     static void AppendValuesBucket(const sptr<ReminderRequest> &reminder,
109         const sptr<NotificationBundleOption> &bundleOption, NativeRdb::ValuesBucket &values);
110 
111     // For database recovery.
112     static void InitDbColumns();
113 
114 protected:
115     virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) const override;
116 
117 private:
ReminderRequestAlarm()118     ReminderRequestAlarm() : ReminderRequest() {};
119     void CheckParamValid() const;
120 
121     /**
122      * Obtains the next trigger time.
123      *
124      * @param forceToGetNext Indicates whether force to get next reminder.
125      *                       When set the alarm firstly, you should set force with true, so if repeat information
126      *                       is not set, and the target time is overdue, the reminder will be set to next day.
127      *                       When change the time manually by user, you should set force with false, so if repeat
128      *                       information is not set, and target time is overdue, the reminder will not be set to
129      *                       next day.
130      * @return next trigger time in milli.
131      */
132     uint64_t GetNextTriggerTime(bool forceToGetNext) const;
133 
134     /**
135      * Judge is it the repeat day setted by user or not.
136      *
137      * @param day Indicates the day of week.
138      * @return true if it is a repeat day.
139      */
140     bool IsRepeatDay(int32_t day) const;
141     bool IsRepeatReminder() const;
142     void SetDaysOfWeek(bool set, std::vector<uint8_t> daysOfWeek);
143 
144     /**
145      * Obtains the next day interval if it is a week repeat alarm.
146      *
147      * @param now Indicates current time.
148      * @param now Indicatet target time.
149      * @return next day interval. Returns {@link INVALID_INT_VALUE} if it is not a week repeat alarm.
150      */
151     int8_t GetNextAlarm(const time_t now, const time_t target) const;
152 
153     static const uint8_t DAYS_PER_WEEK;
154     static const uint8_t MONDAY;
155     static const uint8_t SUNDAY;
156     static const uint8_t HOURS_PER_DAY;
157     static const uint16_t SECONDS_PER_HOUR;
158     static const uint8_t MINUTES_PER_HOUR;
159     static const int8_t INVALID_INT_VALUE;
160     static const int8_t DEFAULT_SNOOZE_TIMES;
161 
162     uint8_t hour_ = {0};
163     uint8_t minute_ = {0};
164     uint8_t repeatDays_ = {0};
165 
166     // For database recovery.
167     static const std::string REPEAT_DAYS_OF_WEEK;
168     static const std::string ALARM_HOUR;
169     static const std::string ALARM_MINUTE;
170 };
171 }  // namespace Notification
172 }  // namespace OHOS
173 
174 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_ALARM_H