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_MANAGER_INTERFACE_H
17 #define TIMER_MANAGER_INTERFACE_H
18 
19 #include <memory>
20 #include <unordered_set>
21 #include "want_agent_helper.h"
22 #include "time_common.h"
23 
24 namespace OHOS {
25 namespace MiscServices {
26 struct TimerEntry {
27     uint64_t id;
28     int type;
29     int64_t windowLength;
30     uint64_t interval;
31     int flag;
32     std::function<int32_t (const uint64_t)> callback;
33     std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent;
34     int uid;
35     int pid;
36     std::string bundleName;
37 };
38 
39 class ITimerManager {
40 public:
41     enum TimerFlag {
42         STANDALONE = 1 << 0,
43         WAKE_FROM_IDLE = 1 << 1,
44         ALLOW_WHILE_IDLE = 1 << 2,
45         ALLOW_WHILE_IDLE_UNRESTRICTED = 1 << 3,
46         IDLE_UNTIL = 1 << 4,
47         INEXACT_REMINDER = 1 << 5,
48         IS_DISPOSABLE = 1 << 6,
49     };
50 
51     enum TimerType {
52         RTC_WAKEUP = 0,
53         RTC = 1,
54         ELAPSED_REALTIME_WAKEUP = 2,
55         ELAPSED_REALTIME = 3
56     };
57 
58     virtual int32_t CreateTimer(TimerPara &paras,
59                                 std::function<int32_t (const uint64_t)> callback,
60                                 std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent,
61                                 int uid, int pid, uint64_t &timerId, DatabaseType type) = 0;
62 
63     virtual int32_t StartTimer(uint64_t timerId, uint64_t triggerTime) = 0;
64     virtual int32_t StopTimer(uint64_t timerId) = 0;
65     virtual int32_t DestroyTimer(uint64_t timerId) = 0;
66     virtual ~ITimerManager() = default;
67     virtual bool ProxyTimer(int32_t uid, bool isProxy, bool needRetrigger) = 0;
68     virtual bool ProxyTimer(int32_t uid, std::set<int> pidList, bool isProxy, bool needRetrigger) = 0;
69     virtual bool AdjustTimer(bool isAdjust, uint32_t interval) = 0;
70     virtual void SetTimerExemption(const std::unordered_set<std::string> &nameArr, bool isExemption) = 0;
71     virtual bool ResetAllProxy() = 0;
72 }; // ITimerManager
73 } // MiscService
74 } // OHOS
75 
76 #endif