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