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 "want_agent_helper.h" 20 #include "time_common.h" 21 22 namespace OHOS { 23 namespace MiscServices { 24 struct TimerEntry { 25 std::string name; 26 uint64_t id; 27 int type; 28 int64_t windowLength; 29 uint64_t interval; 30 uint32_t flag; 31 bool autoRestore; 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 : uint8_t { 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 : uint8_t { 52 RTC_WAKEUP = 0, 53 RTC = 1, 54 ELAPSED_REALTIME_WAKEUP = 2, 55 ELAPSED_REALTIME = 3, 56 #ifdef SET_AUTO_REBOOT_ENABLE 57 POWER_ON_ALARM = 6, 58 #endif 59 TIMER_TYPE_BUTT 60 }; 61 62 virtual int32_t CreateTimer(TimerPara ¶s, 63 std::function<int32_t (const uint64_t)> callback, 64 std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent, 65 int uid, int pid, uint64_t &timerId, DatabaseType type) = 0; 66 67 virtual int32_t StartTimer(uint64_t timerId, uint64_t triggerTime) = 0; 68 virtual int32_t StopTimer(uint64_t timerId) = 0; 69 virtual int32_t DestroyTimer(uint64_t timerId) = 0; 70 virtual ~ITimerManager() = default; 71 virtual bool ProxyTimer(int32_t uid, std::set<int> pidList, bool isProxy, bool needRetrigger) = 0; 72 virtual bool AdjustTimer(bool isAdjust, uint32_t interval, uint32_t delta) = 0; 73 virtual void SetTimerExemption(const std::unordered_set<std::string> &nameArr, bool isExemption) = 0; 74 virtual bool ResetAllProxy() = 0; 75 }; // ITimerManager 76 } // MiscService 77 } // OHOS 78 79 #endif