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 /** 45 * @brief Copy construct from an exist reminder. 46 * 47 * @param Indicates the exist reminder. 48 */ 49 explicit ReminderRequestTimer(const ReminderRequestTimer &other); 50 ReminderRequestTimer& operator = (const ReminderRequestTimer &other); ~ReminderRequestTimer()51 ~ReminderRequestTimer() override {}; 52 53 uint64_t GetInitInfo() const; 54 virtual bool OnDateTimeChange() override; 55 virtual bool OnTimeZoneChange() override; 56 virtual bool UpdateNextReminder() override; 57 58 /** 59 * Marshal a NotificationRequest object into a Parcel. 60 * @param parcel the object into the parcel 61 */ 62 virtual bool Marshalling(Parcel &parcel) const override; 63 64 /** 65 * Unmarshal object from a Parcel. 66 * @return the NotificationRequest 67 */ 68 static ReminderRequestTimer *Unmarshalling(Parcel &parcel); 69 70 bool ReadFromParcel(Parcel &parcel) override; 71 72 protected: 73 virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) const override; 74 75 private: ReminderRequestTimer()76 ReminderRequestTimer() {}; 77 void CheckParamsValid(const uint64_t countDownTimeInSeconds) const; 78 void UpdateTimeInfo(const std::string &description); 79 uint64_t countDownTimeInSeconds_ {0}; 80 uint64_t firstRealTimeInMilliSeconds_ {0}; 81 uint64_t whenToChangeSysTime_ {0}; 82 }; 83 } // namespace Reminder 84 } // namespace OHOS 85 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_TIMER_H