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 SetReminderType(ReminderType::ALARM); 52 }; 53 54 /** 55 * @brief Copy construct from an exist reminder. 56 * 57 * @param Indicates the exist alarm reminder. 58 */ 59 explicit ReminderRequestAlarm(const ReminderRequestAlarm &other); 60 ReminderRequestAlarm& operator = (const ReminderRequestAlarm &other); ~ReminderRequestAlarm()61 ~ReminderRequestAlarm() override {}; 62 63 /** 64 * @brief Obtains the setted {@link hour_}. 65 * 66 * @return setted hour. 67 */ 68 uint8_t GetHour() const; 69 70 /** 71 * @brief Obtains the setted {@link minute_}. 72 * 73 * @return setted minute. 74 */ 75 uint8_t GetMinute() const; 76 77 /** 78 * @brief Sets the hour. 79 * 80 * @param hour Indicates the hour. 81 */ 82 void SetHour(const uint8_t hour); 83 84 /** 85 * @brief Sets the minute. 86 * 87 * @param minute Indicates the minute. 88 */ 89 void SetMinute(const uint8_t minute); 90 91 virtual bool UpdateNextReminder() override; 92 93 /** 94 * Marshal a reminder object into a Parcel. 95 * 96 * @param parcel Indicates the Parcel. 97 */ 98 virtual bool Marshalling(Parcel &parcel) const override; 99 100 /** 101 * Unmarshal object from a Parcel. 102 * 103 * @param parcel Indicates the Parcel. 104 * @return reminder object. 105 */ 106 static ReminderRequestAlarm *Unmarshalling(Parcel &parcel); 107 108 /** 109 * Unmarshal unique properties of alarm from a Parcel. 110 * 111 * @param parcel Indicates the Parcel. 112 * @return true if read parcel success. 113 */ 114 bool ReadFromParcel(Parcel &parcel) override; 115 bool WriteParcel(Parcel &parcel) const override; 116 ReminderRequestAlarm()117 ReminderRequestAlarm() : ReminderRequest(ReminderType::ALARM) {}; 118 119 protected: 120 virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) override; 121 122 private: 123 void CheckParamValid() const; 124 125 /** 126 * Obtains the next trigger time. 127 * 128 * @param forceToGetNext Indicates whether force to get next reminder. 129 * When set the alarm firstly, you should set force with true, so if repeat information 130 * is not set, and the target time is overdue, the reminder will be set to next day. 131 * When change the time manually by user, you should set force with false, so if repeat 132 * information is not set, and target time is overdue, the reminder will not be set to 133 * next day. 134 * @return next trigger time in milli. 135 */ 136 uint64_t GetNextTriggerTime(bool forceToGetNext) const; 137 bool IsRepeatReminder() const; 138 139 static const uint8_t MINUTES_PER_HOUR; 140 static const int8_t DEFAULT_SNOOZE_TIMES; 141 142 uint8_t hour_ = {0}; 143 uint8_t minute_ = {0}; 144 }; 145 } // namespace Notification 146 } // namespace OHOS 147 148 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_ALARM_H