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     void SetInitInfo(const uint64_t countDownTimeInSeconds);
55 
56     virtual bool OnDateTimeChange() override;
57     virtual bool OnTimeZoneChange() override;
58     virtual bool UpdateNextReminder() override;
59 
60     /**
61      * Marshal a NotificationRequest object into a Parcel.
62      * @param parcel the object into the parcel
63      */
64     virtual bool Marshalling(Parcel &parcel) const override;
65 
66     /**
67      * Unmarshal object from a Parcel.
68      * @return the NotificationRequest
69      */
70     static ReminderRequestTimer *Unmarshalling(Parcel &parcel);
71 
72     bool ReadFromParcel(Parcel &parcel) override;
73 
74 protected:
75     virtual uint64_t PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) override;
76 
77 private:
ReminderRequestTimer()78     ReminderRequestTimer() {};
79     void CheckParamsValid(const uint64_t countDownTimeInSeconds) const;
80     void UpdateTimeInfo(const std::string &description);
81     uint64_t countDownTimeInSeconds_ {0};
82     uint64_t firstRealTimeInMilliSeconds_ {0};
83     uint64_t whenToChangeSysTime_ {0};
84 };
85 }  // namespace Reminder
86 }  // namespace OHOS
87 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_REMINDER_REQUEST_TIMER_H