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_TIMER_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_TIMER_H 18 19 #include "reminder_request.h" 20 21 namespace OHOS { 22 namespace Notification { 23 class ReminderRequestTimer : public ReminderRequest { 24 public: 25 /** 26 * A constructor used to create a ReminderRequestTimer instance. The countdown timer reminder 27 * will be triggered after a specified duration. 28 * 29 * @note The input parameter must be larger than 0 and less than UINT64_MAX/1000, 30 * otherwise, the application may crash due to an illegal parameter exception. 31 * 32 * @param countDownTimeInSeconds Indicates the duration after which this timer reminder will be triggered. 33 */ 34 explicit ReminderRequestTimer(uint64_t countDownTimeInSeconds); 35 36 /** 37 * @brief This constructor should only be used in background proxy service process 38 * when reminder instance recovery from database. 39 * 40 * @param reminderId Indicates reminder id. 41 */ ReminderRequestTimer(int32_t reminderId)42 explicit ReminderRequestTimer(int32_t reminderId) : ReminderRequest(reminderId) 43 { 44 SetReminderType(ReminderType::TIMER); 45 }; 46 47 /** 48 * @brief Copy construct from an exist reminder. 49 * 50 * @param Indicates the exist reminder. 51 */ 52 explicit ReminderRequestTimer(const ReminderRequestTimer &other); 53 ReminderRequestTimer& operator = (const ReminderRequestTimer &other); ~ReminderRequestTimer()54 ~ReminderRequestTimer() override {}; 55 56 uint64_t GetInitInfo() const; 57 void SetInitInfo(const uint64_t countDownTimeInSeconds); 58 59 virtual bool OnDateTimeChange() override; 60 virtual bool OnTimeZoneChange() override; 61 virtual bool UpdateNextReminder() override; 62 63 /** 64 * Marshal a NotificationRequest object into a Parcel. 65 * @param parcel the object into the parcel 66 */ 67 virtual bool Marshalling(Parcel &parcel) const override; 68 69 /** 70 * Unmarshal object from a Parcel. 71 * @return the NotificationRequest 72 */ 73 static ReminderRequestTimer *Unmarshalling(Parcel &parcel); 74 75 bool ReadFromParcel(Parcel &parcel) override; 76 bool WriteParcel(Parcel &parcel) const override; 77 ReminderRequestTimer()78 ReminderRequestTimer() : ReminderRequest(ReminderType::TIMER) {}; 79 80 protected: 81 virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) override; 82 83 private: 84 void CheckParamsValid(const uint64_t countDownTimeInSeconds) const; 85 void UpdateTimeInfo(const std::string &description); 86 uint64_t countDownTimeInSeconds_ {0}; 87 uint64_t firstRealTimeInMilliSeconds_ {0}; 88 uint64_t whenToChangeSysTime_ {0}; 89 }; 90 } // namespace Reminder 91 } // namespace OHOS 92 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_TIMER_H