1 /*
2  * Copyright (C) 2021 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 TIMER_INFO_H
17 #define TIMER_INFO_H
18 
19 #include <cstdint>
20 #include <string>
21 
22 #include "timer_manager_interface.h"
23 
24 namespace OHOS {
25 namespace MiscServices {
26 static const uint32_t HALF_SECEND = 2;
27 
28 class TimerInfo {
29 public:
30     const uint64_t id;
31     const int type;
32     const std::chrono::milliseconds origWhen;
33     const bool wakeup;
34     const std::function<int32_t (const uint64_t)> callback;
35     const std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent;
36     const uint32_t flags;
37     const int uid;
38     const int pid;
39 
40     std::chrono::milliseconds when;
41     std::chrono::milliseconds windowLength;
42     std::chrono::steady_clock::time_point originWhenElapsed;
43     std::chrono::steady_clock::time_point originMaxWhenElapsed;
44     std::chrono::steady_clock::time_point whenElapsed;
45     std::chrono::steady_clock::time_point maxWhenElapsed;
46     std::chrono::milliseconds repeatInterval;
47     std::chrono::milliseconds offset;
48     std::string bundleName;
49 
50     TimerInfo(uint64_t id, int type,
51         std::chrono::milliseconds when,
52         std::chrono::steady_clock::time_point whenElapsed,
53         std::chrono::milliseconds windowLength,
54         std::chrono::steady_clock::time_point maxWhen,
55         std::chrono::milliseconds interval,
56         std::function<int32_t (const uint64_t)> callback,
57         std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent,
58         uint32_t flags,
59         int uid,
60         int pid,
61         const std::string &bundleName);
62     virtual ~TimerInfo() = default;
63     bool operator==(const TimerInfo &other) const;
64     bool Matches(const std::string &packageName) const;
65     bool UpdateWhenElapsedFromNow(std::chrono::steady_clock::time_point now, std::chrono::nanoseconds offset);
66     bool AdjustTimer(const std::chrono::steady_clock::time_point &now, const uint32_t interval);
67     bool RestoreAdjustTimer();
68 };
69 } // MiscService
70 } // OHOS
71 #endif