• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     std::string name;
28     uint64_t id;
29     int type;
30     int64_t windowLength;
31     uint64_t interval;
32     int flag;
33     bool autoRestore;
34     std::function<int32_t (const uint64_t)> callback;
35     std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent;
36     int uid;
37     int pid;
38     std::string bundleName;
39 };
40 
41 class ITimerManager {
42 public:
43     enum TimerFlag {
44         STANDALONE = 1 << 0,
45         WAKE_FROM_IDLE = 1 << 1,
46         ALLOW_WHILE_IDLE = 1 << 2,
47         ALLOW_WHILE_IDLE_UNRESTRICTED = 1 << 3,
48         IDLE_UNTIL = 1 << 4,
49         INEXACT_REMINDER = 1 << 5,
50         IS_DISPOSABLE = 1 << 6,
51     };
52 
53     enum TimerType {
54         RTC_WAKEUP = 0,
55         RTC = 1,
56         ELAPSED_REALTIME_WAKEUP = 2,
57         ELAPSED_REALTIME = 3
58     };
59 
60     virtual int32_t CreateTimer(TimerPara &paras,
61                                 std::function<int32_t (const uint64_t)> callback,
62                                 std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent,
63                                 int uid, int pid, uint64_t &timerId, DatabaseType type) = 0;
64 
65     virtual int32_t StartTimer(uint64_t timerId, uint64_t triggerTime) = 0;
66     virtual int32_t StopTimer(uint64_t timerId) = 0;
67     virtual int32_t DestroyTimer(uint64_t timerId) = 0;
68     virtual ~ITimerManager() = default;
69     virtual bool ProxyTimer(int32_t uid, bool isProxy, bool needRetrigger) = 0;
70     virtual bool ProxyTimer(int32_t uid, std::set<int> pidList, bool isProxy, bool needRetrigger) = 0;
71     virtual bool AdjustTimer(bool isAdjust, uint32_t interval) = 0;
72     virtual void SetTimerExemption(const std::unordered_set<std::string> &nameArr, bool isExemption) = 0;
73     virtual bool ResetAllProxy() = 0;
74 }; // ITimerManager
75 } // MiscService
76 } // OHOS
77 
78 #endif