1cf69771bSopenharmony_ci/*
2cf69771bSopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd.
3cf69771bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4cf69771bSopenharmony_ci * you may not use this file except in compliance with the License.
5cf69771bSopenharmony_ci * You may obtain a copy of the License at
6cf69771bSopenharmony_ci *
7cf69771bSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8cf69771bSopenharmony_ci *
9cf69771bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10cf69771bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11cf69771bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12cf69771bSopenharmony_ci * See the License for the specific language governing permissions and
13cf69771bSopenharmony_ci * limitations under the License.
14cf69771bSopenharmony_ci */
15cf69771bSopenharmony_ci
16cf69771bSopenharmony_ci#ifndef TIMER_MANAGER_INTERFACE_H
17cf69771bSopenharmony_ci#define TIMER_MANAGER_INTERFACE_H
18cf69771bSopenharmony_ci
19cf69771bSopenharmony_ci#include <memory>
20cf69771bSopenharmony_ci#include <unordered_set>
21cf69771bSopenharmony_ci#include "want_agent_helper.h"
22cf69771bSopenharmony_ci#include "time_common.h"
23cf69771bSopenharmony_ci
24cf69771bSopenharmony_cinamespace OHOS {
25cf69771bSopenharmony_cinamespace MiscServices {
26cf69771bSopenharmony_cistruct TimerEntry {
27cf69771bSopenharmony_ci    uint64_t id;
28cf69771bSopenharmony_ci    int type;
29cf69771bSopenharmony_ci    int64_t windowLength;
30cf69771bSopenharmony_ci    uint64_t interval;
31cf69771bSopenharmony_ci    int flag;
32cf69771bSopenharmony_ci    std::function<int32_t (const uint64_t)> callback;
33cf69771bSopenharmony_ci    std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent;
34cf69771bSopenharmony_ci    int uid;
35cf69771bSopenharmony_ci    int pid;
36cf69771bSopenharmony_ci    std::string bundleName;
37cf69771bSopenharmony_ci};
38cf69771bSopenharmony_ci
39cf69771bSopenharmony_ciclass ITimerManager {
40cf69771bSopenharmony_cipublic:
41cf69771bSopenharmony_ci    enum TimerFlag {
42cf69771bSopenharmony_ci        STANDALONE = 1 << 0,
43cf69771bSopenharmony_ci        WAKE_FROM_IDLE = 1 << 1,
44cf69771bSopenharmony_ci        ALLOW_WHILE_IDLE = 1 << 2,
45cf69771bSopenharmony_ci        ALLOW_WHILE_IDLE_UNRESTRICTED = 1 << 3,
46cf69771bSopenharmony_ci        IDLE_UNTIL = 1 << 4,
47cf69771bSopenharmony_ci        INEXACT_REMINDER = 1 << 5,
48cf69771bSopenharmony_ci        IS_DISPOSABLE = 1 << 6,
49cf69771bSopenharmony_ci    };
50cf69771bSopenharmony_ci
51cf69771bSopenharmony_ci    enum TimerType {
52cf69771bSopenharmony_ci        RTC_WAKEUP = 0,
53cf69771bSopenharmony_ci        RTC = 1,
54cf69771bSopenharmony_ci        ELAPSED_REALTIME_WAKEUP = 2,
55cf69771bSopenharmony_ci        ELAPSED_REALTIME = 3
56cf69771bSopenharmony_ci    };
57cf69771bSopenharmony_ci
58cf69771bSopenharmony_ci    virtual int32_t CreateTimer(TimerPara &paras,
59cf69771bSopenharmony_ci                                std::function<int32_t (const uint64_t)> callback,
60cf69771bSopenharmony_ci                                std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent,
61cf69771bSopenharmony_ci                                int uid, int pid, uint64_t &timerId, DatabaseType type) = 0;
62cf69771bSopenharmony_ci
63cf69771bSopenharmony_ci    virtual int32_t StartTimer(uint64_t timerId, uint64_t triggerTime) = 0;
64cf69771bSopenharmony_ci    virtual int32_t StopTimer(uint64_t timerId) = 0;
65cf69771bSopenharmony_ci    virtual int32_t DestroyTimer(uint64_t timerId) = 0;
66cf69771bSopenharmony_ci    virtual ~ITimerManager() = default;
67cf69771bSopenharmony_ci    virtual bool ProxyTimer(int32_t uid, bool isProxy, bool needRetrigger) = 0;
68cf69771bSopenharmony_ci    virtual bool ProxyTimer(std::set<int> pidList, bool isProxy, bool needRetrigger) = 0;
69cf69771bSopenharmony_ci    virtual bool AdjustTimer(bool isAdjust, uint32_t interval) = 0;
70cf69771bSopenharmony_ci    virtual void SetTimerExemption(const std::unordered_set<std::string> &nameArr, bool isExemption) = 0;
71cf69771bSopenharmony_ci    virtual bool ResetAllProxy() = 0;
72cf69771bSopenharmony_ci}; // ITimerManager
73cf69771bSopenharmony_ci} // MiscService
74cf69771bSopenharmony_ci} // OHOS
75cf69771bSopenharmony_ci
76cf69771bSopenharmony_ci#endif