• 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 #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 &times) = 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 &times) = 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 &times) = 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 &times) = 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 &times) = 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 &times) = 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 &times) = 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 &times) = 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     * @param isAsync indicate is async or not.
153     * @return bool true on success, false on failure.
154     */
155     virtual int32_t DestroyTimer(uint64_t timerId, bool isAsync = false) = 0;
156 
157     /**
158      * ProxyTimer
159      * @param uid the uid
160      * @param isProxy true if proxy, false if not proxy
161      * @param needRetrigger true if need retrigger, false if not.
162      * @return bool true on success, false on failure.
163      */
164     virtual bool ProxyTimer(int32_t uid, bool isProxy, bool needRetrigger) = 0;
165 
166     /**
167      * ProxyTimer
168      * @param pidList the pidlist
169      * @param isProxy true if proxy, false if not proxy
170      * @param needRetrigger true if need retrigger, false if not.
171      * @return bool true on success, false on failure.
172      */
173     virtual bool ProxyTimer(int32_t uid, std::set<int> pidList, bool isProxy, bool needRetrigger) = 0;
174 
175     /**
176      * AdjustTimer
177      * @param isAdjust true if adjust, false if not adjust.
178      * @param interval adjust period.
179      * @return int32_t return error code.
180      */
181     virtual int32_t AdjustTimer(bool isAdjust, uint32_t interval) = 0;
182 
183     /**
184      * SetTimerExemption
185      * @param nameArr list for bundle name or proccess name.
186      * @param isExemption exemption or ctrl.
187      * @return int32_t return error code.
188      */
189     virtual int32_t SetTimerExemption(const std::unordered_set<std::string> &nameArr, bool isExemption) = 0;
190 
191     /**
192      * ResetAllProxy
193      * @return bool true on success, false on failure.
194      */
195     virtual bool ResetAllProxy() = 0;
196 
197     /**
198      * @brief GetNtpTimeMs
199      *
200      * Obtain the wall time through ntp.
201      *
202      * @param time the wall time(the UTC time from 1970 0H:0M:0S) in milliseconds.
203      * @return int32_t return error code.
204      */
205     virtual int32_t GetNtpTimeMs(int64_t &time) = 0;
206 
207     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.time.ITimeService");
208 };
209 } // namespace MiscServices
210 } // namespace OHOS
211 #endif // SERVICES_INCLUDE_TIME_SERVICE_INTERFACE_H