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 SERVICES_INCLUDE_TIME_SERVICE_INTERFACE_H 17 #define SERVICES_INCLUDE_TIME_SERVICE_INTERFACE_H 18 19 #include "iremote_broker.h" 20 #include "itimer_info.h" 21 #include "want_agent_helper.h" 22 #include <unordered_set> 23 24 namespace OHOS { 25 namespace MiscServices { 26 class ITimeService : public IRemoteBroker { 27 public: 28 29 enum APIVersion : int8_t { 30 API_VERSION_7 = 0, 31 API_VERSION_9 = 1, 32 }; 33 /** 34 * SetTime 35 * 36 * @param time int64_t set milliseconds 37 * @return int32_t ERR_OK on success, other on failure. 38 */ 39 virtual int32_t SetTime(int64_t time, APIVersion apiVersion = APIVersion::API_VERSION_7) = 0; 40 /** 41 * SetTimeZone 42 * 43 * @param timezoneId std::string &timezoneId string 44 * @return int32_t ERR_OK on success, other on failure. 45 */ 46 virtual int32_t SetTimeZone(const std::string &timezoneId, APIVersion apiVersion = APIVersion::API_VERSION_7) = 0; 47 48 /** 49 * GetTimeZone 50 * 51 * @param timezoneId std::string &timezoneId string 52 * @return int32_t ERR_OK on success, other on failure. 53 */ 54 virtual int32_t GetTimeZone(std::string &timezoneId) = 0; 55 56 /** 57 * GetWallTimeMs 58 * 59 * @param times result of times ,unit: millisecond 60 * @return int32_t ERR_OK on success, other on failure. 61 */ 62 virtual int32_t GetWallTimeMs(int64_t ×) = 0; 63 64 /** 65 * GetWallTimeNs 66 * 67 * @param times result of times ,unit: Nanosecond 68 * @return int32_t ERR_OK on success, other on failure. 69 */ 70 virtual int32_t GetWallTimeNs(int64_t ×) = 0; 71 72 /** 73 * GetBootTimeMs 74 * 75 * @param times result of times ,unit: millisecond 76 * @return int32_t ERR_OK on success, other on failure. 77 */ 78 virtual int32_t GetBootTimeMs(int64_t ×) = 0; 79 80 /** 81 * GetBootTimeNs 82 * 83 * @param times result of times ,unit: millisecond 84 * @return int32_t ERR_OK on success, other on failure. 85 */ 86 virtual int32_t GetBootTimeNs(int64_t ×) = 0; 87 88 /** 89 * GetMonotonicTimeMs 90 * 91 * @param times result of times ,unit: millisecond 92 * @return int32_t ERR_OK on success, other on failure. 93 */ 94 virtual int32_t GetMonotonicTimeMs(int64_t ×) = 0; 95 96 /** 97 * GetMonotonicTimeNs 98 * 99 * @param times result of times ,unit: Nanosecond 100 * @return int32_t ERR_OK on success, other on failure. 101 */ 102 virtual int32_t GetMonotonicTimeNs(int64_t ×) = 0; 103 104 /** 105 * GetThreadTimeMs 106 * 107 * @param times result of times ,unit: millisecond 108 * @return int32_t ERR_OK on success, other on failure. 109 */ 110 virtual int32_t GetThreadTimeMs(int64_t ×) = 0; 111 112 /** 113 * GetThreadTimeNs 114 * 115 * @param times result of times ,unit: Nanosecond 116 * @return int32_t ERR_OK on success, other on failure. 117 */ 118 virtual int32_t GetThreadTimeNs(int64_t ×) = 0; 119 120 /** 121 * CreateTimer 122 * 123 * @param type timer type 124 * @param repeat is repeat or not 125 * @param timerCallback remoteobject 126 * @return uint64_t > 0 on success, == 0 failure. 127 */ 128 virtual int32_t CreateTimer(const std::shared_ptr<ITimerInfo> &timerOptions, sptr<IRemoteObject> &timerCallback, 129 uint64_t &timerId) = 0; 130 131 /** 132 * StartTimer 133 * 134 * @param timerId indicate timerId 135 * @param treggerTime trigger times 136 * @return bool true on success, false on failure. 137 */ 138 virtual int32_t StartTimer(uint64_t timerId, uint64_t triggerTime) = 0; 139 140 /** 141 * StopTimer 142 * 143 * @param timerId indicate timerId 144 * @return bool true on success, false on failure. 145 */ 146 virtual int32_t StopTimer(uint64_t timerId) = 0; 147 148 /** 149 * DestroyTimer 150 * 151 * @param timerId indicate timerId 152 * @return bool true on success, false on failure. 153 */ 154 virtual int32_t DestroyTimer(uint64_t timerId) = 0; 155 156 /** 157 * ProxyTimer 158 * @param uid the uid 159 * @param isProxy true if proxy, false if not proxy 160 * @param needRetrigger true if need retrigger, false if not. 161 * @return bool true on success, false on failure. 162 */ 163 virtual bool ProxyTimer(int32_t uid, bool isProxy, bool needRetrigger) = 0; 164 165 /** 166 * ProxyTimer 167 * @param pidList the pidlist 168 * @param isProxy true if proxy, false if not proxy 169 * @param needRetrigger true if need retrigger, false if not. 170 * @return bool true on success, false on failure. 171 */ 172 virtual bool ProxyTimer(std::set<int> pidList, bool isProxy, bool needRetrigger) = 0; 173 174 /** 175 * AdjustTimer 176 * @param isAdjust true if adjust, false if not adjust. 177 * @param interval adjust period. 178 * @return int32_t return error code. 179 */ 180 virtual int32_t AdjustTimer(bool isAdjust, uint32_t interval) = 0; 181 182 /** 183 * SetTimerExemption 184 * @param nameArr list for bundle name or proccess name. 185 * @param isExemption exemption or ctrl. 186 * @return int32_t return error code. 187 */ 188 virtual int32_t SetTimerExemption(const std::unordered_set<std::string> &nameArr, bool isExemption) = 0; 189 190 /** 191 * ResetAllProxy 192 * @return bool true on success, false on failure. 193 */ 194 virtual bool ResetAllProxy() = 0; 195 196 DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.time.ITimeService"); 197 }; 198 } // namespace MiscServices 199 } // namespace OHOS 200 #endif // SERVICES_INCLUDE_TIME_SERVICE_INTERFACE_H