• 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      * @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     virtual bool UpdateNextReminder() override;
75 
76     /**
77      * Marshal a reminder object into a Parcel.
78      *
79      * @param parcel Indicates the Parcel.
80      */
81     virtual bool Marshalling(Parcel &parcel) const override;
82 
83     /**
84      * Unmarshal object from a Parcel.
85      *
86      * @param parcel Indicates the Parcel.
87      * @return reminder object.
88      */
89     static ReminderRequestAlarm *Unmarshalling(Parcel &parcel);
90 
91     /**
92      * Unmarshal unique properties of alarm from a Parcel.
93      *
94      * @param parcel Indicates the Parcel.
95      * @return true if read parcel success.
96      */
97     bool ReadFromParcel(Parcel &parcel) override;
98     virtual void RecoverFromDb(const std::shared_ptr<NativeRdb::ResultSet> &resultSet) override;
99     static void AppendValuesBucket(const sptr<ReminderRequest> &reminder,
100         const sptr<NotificationBundleOption> &bundleOption, NativeRdb::ValuesBucket &values);
101 
102     // For database recovery.
103     static void InitDbColumns();
104 
105 protected:
106     virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) const override;
107 
108 private:
ReminderRequestAlarm()109     ReminderRequestAlarm() : ReminderRequest() {};
110     void CheckParamValid() const;
111 
112     /**
113      * Obtains the next trigger time.
114      *
115      * @param forceToGetNext Indicates whether force to get next reminder.
116      *                       When set the alarm firstly, you should set force with true, so if repeat information
117      *                       is not set, and the target time is overdue, the reminder will be set to next day.
118      *                       When change the time manually by user, you should set force with false, so if repeat
119      *                       information is not set, and target time is overdue, the reminder will not be set to
120      *                       next day.
121      * @return next trigger time in milli.
122      */
123     uint64_t GetNextTriggerTime(bool forceToGetNext) const;
124     bool IsRepeatReminder() const;
125 
126     static const uint8_t MINUTES_PER_HOUR;
127     static const int8_t DEFAULT_SNOOZE_TIMES;
128 
129     uint8_t hour_ = {0};
130     uint8_t minute_ = {0};
131 };
132 }  // namespace Notification
133 }  // namespace OHOS
134 
135 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_ALARM_H