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 "timer_manager_interface.h" 20 21 namespace OHOS { 22 namespace MiscServices { 23 24 class TimerInfo { 25 public: 26 const std::string name; 27 const uint64_t id; 28 const int type; 29 const std::chrono::milliseconds origWhen; 30 const bool wakeup; 31 const bool autoRestore; 32 const std::function<int32_t (const uint64_t)> callback; 33 const std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent; 34 const uint32_t flags; 35 const int uid; 36 const int pid; 37 38 std::chrono::milliseconds when; 39 std::chrono::milliseconds windowLength; 40 std::chrono::steady_clock::time_point originWhenElapsed; 41 std::chrono::steady_clock::time_point originMaxWhenElapsed; 42 std::chrono::steady_clock::time_point originProxyWhenElapsed; 43 std::chrono::steady_clock::time_point originProxyMaxWhenElapsed; 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(std::string name, 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 bool autoRestore, 60 int uid, 61 int pid, 62 const std::string &bundleName); 63 virtual ~TimerInfo() = default; 64 bool operator==(const TimerInfo &other) const; 65 bool Matches(const std::string &packageName) const; 66 bool UpdateWhenElapsedFromNow(std::chrono::steady_clock::time_point now, std::chrono::nanoseconds offset); 67 bool AdjustTimer(const std::chrono::steady_clock::time_point &now, const uint32_t interval, const uint32_t delta); 68 bool RestoreAdjustTimer(); 69 }; 70 } // MiscService 71 } // OHOS 72 #endif