• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         NETWORK_TIME_ON = 15,
45         NETWORK_TIME_OFF = 16,
46         PROXY_TIMER = 17,
47         RESET_ALL_PROXY = 18
48     };
49 
50     enum APIVersion : int8_t {
51         API_VERSION_7 = 0,
52         API_VERSION_9 = 1,
53     };
54     /**
55    * SetTime
56    *
57    * @param time int64_t set milliseconds
58    * @return int32_t ERR_OK on success, other on failure.
59    */
60     virtual int32_t SetTime(int64_t time, APIVersion apiVersion = APIVersion::API_VERSION_7) = 0;
61     /**
62      * SetTimeZone
63      *
64      * @param timezoneId std::string &timezoneId string
65      * @return int32_t ERR_OK on success, other on failure.
66      */
67     virtual int32_t SetTimeZone(const std::string &timezoneId, APIVersion apiVersion = APIVersion::API_VERSION_7) = 0;
68 
69     /**
70      * GetTimeZone
71      *
72      * @param timezoneId std::string &timezoneId string
73      * @return int32_t ERR_OK on success, other on failure.
74      */
75     virtual int32_t GetTimeZone(std::string &timezoneId) = 0;
76 
77      /**
78      * GetWallTimeMs
79      *
80      * @param times result of times ,unit: millisecond
81      * @return int32_t ERR_OK on success, other on failure.
82      */
83     virtual int32_t GetWallTimeMs(int64_t &times) = 0;
84 
85      /**
86      * GetWallTimeNs
87      *
88      * @param times result of times ,unit: Nanosecond
89      * @return int32_t ERR_OK on success, other on failure.
90      */
91     virtual int32_t GetWallTimeNs(int64_t &times) = 0;
92 
93      /**
94      * GetBootTimeMs
95      *
96      * @param times result of times ,unit: millisecond
97      * @return int32_t ERR_OK on success, other on failure.
98      */
99     virtual int32_t GetBootTimeMs(int64_t &times) = 0;
100 
101      /**
102      * GetBootTimeNs
103      *
104      * @param times result of times ,unit: millisecond
105      * @return int32_t ERR_OK on success, other on failure.
106      */
107     virtual int32_t GetBootTimeNs(int64_t &times) = 0;
108 
109      /**
110      * GetMonotonicTimeMs
111      *
112      * @param times result of times ,unit: millisecond
113      * @return int32_t ERR_OK on success, other on failure.
114      */
115     virtual int32_t GetMonotonicTimeMs(int64_t &times) = 0;
116 
117      /**
118      * GetMonotonicTimeNs
119      *
120      * @param times result of times ,unit: Nanosecond
121      * @return int32_t ERR_OK on success, other on failure.
122      */
123     virtual int32_t GetMonotonicTimeNs(int64_t &times) = 0;
124 
125      /**
126      * GetThreadTimeMs
127      *
128      * @param times result of times ,unit: millisecond
129      * @return int32_t ERR_OK on success, other on failure.
130      */
131     virtual int32_t GetThreadTimeMs(int64_t &times) = 0;
132 
133      /**
134      * GetThreadTimeNs
135      *
136      * @param times result of times ,unit: Nanosecond
137      * @return int32_t ERR_OK on success, other on failure.
138      */
139     virtual int32_t GetThreadTimeNs(int64_t &times) = 0;
140 
141     /**
142      * CreateTimer
143      *
144      * @param type    timer type
145      * @param repeat  is repeat or not
146      * @param timerCallback remoteobject
147      * @return uint64_t > 0 on success, == 0 failure.
148      */
149     virtual int32_t CreateTimer(const std::shared_ptr<ITimerInfo> &timerOptions, sptr<IRemoteObject> &timerCallback,
150         uint64_t &timerId) = 0;
151 
152     /**
153     * StartTimer
154     *
155     * @param timerId indicate timerId
156     * @param treggerTime  trigger times
157     * @return bool true on success, false on failure.
158     */
159     virtual int32_t StartTimer(uint64_t timerId, uint64_t triggerTime) = 0;
160 
161     /**
162     * StopTimer
163     *
164     * @param timerId indicate timerId
165     * @return bool true on success, false on failure.
166     */
167     virtual int32_t StopTimer(uint64_t timerId) = 0;
168 
169     /**
170     * DestroyTimer
171     *
172     * @param timerId indicate timerId
173     * @return bool true on success, false on failure.
174     */
175     virtual int32_t DestroyTimer(uint64_t timerId) = 0;
176 
177      /**
178      * NetworkTimeStatusOff
179      * @return void.
180      */
181     virtual void NetworkTimeStatusOff() = 0;
182 
183      /**
184      * NetworkTimeStatusOn
185      * @return void.
186      */
187     virtual void NetworkTimeStatusOn() = 0;
188 
189     /**
190      * ProxyTimer
191      * @param uid the uid
192      * @param isProxy true if proxy, false if not proxy
193      * @param needRetrigger true if need retrigger, false if not.
194      * @return bool true on success, false on failure.
195      */
196     virtual bool ProxyTimer(int32_t uid, bool isProxy, bool needRetrigger) = 0;
197 
198     /**
199      * ResetAllProxy
200      * @return bool true on success, false on failure.
201      */
202     virtual bool ResetAllProxy() = 0;
203 
204     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.time.ITimeService");
205 };
206 } // namespace MiscServices
207 } // namespace OHOS
208 #endif // SERVICES_INCLUDE_TIME_SERVICE_INTERFACE_H