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     * GetThreadTimeMs
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 GetThreadTimeMs(int64_t &times) = 0;
63 
64     /**
65     * GetThreadTimeNs
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 GetThreadTimeNs(int64_t &times) = 0;
71 
72     /**
73      * CreateTimer
74      *
75      * @param type    timer type
76      * @param repeat  is repeat or not
77      * @param timerCallback remoteobject
78      * @return uint64_t > 0 on success, == 0 failure.
79      */
80     virtual int32_t CreateTimer(const std::shared_ptr<ITimerInfo> &timerOptions, sptr<IRemoteObject> &timerCallback,
81         uint64_t &timerId) = 0;
82 
83     /**
84     * StartTimer
85     *
86     * @param timerId indicate timerId
87     * @param treggerTime  trigger times
88     * @return bool true on success, false on failure.
89     */
90     virtual int32_t StartTimer(uint64_t timerId, uint64_t triggerTime) = 0;
91 
92     /**
93     * StopTimer
94     *
95     * @param timerId indicate timerId
96     * @return bool true on success, false on failure.
97     */
98     virtual int32_t StopTimer(uint64_t timerId) = 0;
99 
100     /**
101     * DestroyTimer
102     *
103     * @param timerId indicate timerId
104     * @param isAsync indicate is async or not.
105     * @return bool true on success, false on failure.
106     */
107     virtual int32_t DestroyTimer(uint64_t timerId, bool isAsync = false) = 0;
108 
109     /**
110      * ProxyTimer
111      * @param uid the uid
112      * @param isProxy true if proxy, false if not proxy
113      * @param needRetrigger true if need retrigger, false if not.
114      * @return bool true on success, false on failure.
115      */
116     virtual bool ProxyTimer(int32_t uid, bool isProxy, bool needRetrigger) = 0;
117 
118     /**
119      * ProxyTimer
120      * @param pidList the pidlist
121      * @param isProxy true if proxy, false if not proxy
122      * @param needRetrigger true if need retrigger, false if not.
123      * @return bool true on success, false on failure.
124      */
125     virtual bool ProxyTimer(int32_t uid, std::set<int> pidList, bool isProxy, bool needRetrigger) = 0;
126 
127     /**
128      * AdjustTimer
129      * @param isAdjust true if adjust, false if not adjust.
130      * @param interval adjust period.
131      * @return int32_t return error code.
132      */
133     virtual int32_t AdjustTimer(bool isAdjust, uint32_t interval) = 0;
134 
135     /**
136      * SetTimerExemption
137      * @param nameArr list for bundle name or proccess name.
138      * @param isExemption exemption or ctrl.
139      * @return int32_t return error code.
140      */
141     virtual int32_t SetTimerExemption(const std::unordered_set<std::string> &nameArr, bool isExemption) = 0;
142 
143     /**
144      * ResetAllProxy
145      * @return bool true on success, false on failure.
146      */
147     virtual bool ResetAllProxy() = 0;
148 
149     /**
150      * @brief GetNtpTimeMs
151      *
152      * Obtain the wall time through ntp.
153      *
154      * @param time the wall time(the UTC time from 1970 0H:0M:0S) in milliseconds.
155      * @return int32_t return error code.
156      */
157     virtual int32_t GetNtpTimeMs(int64_t &time) = 0;
158 
159     /**
160      * @brief GetRealTimeMs
161      *
162      * Obtain the wall time calculated based on the last NTP time.
163      *
164      * @param time the wall time(the UTC time from 1970 0H:0M:0S) in milliseconds.
165      * @return int32_t return error code.
166      */
167     virtual int32_t GetRealTimeMs(int64_t &time) = 0;
168 
169     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.time.ITimeService");
170 };
171 } // namespace MiscServices
172 } // namespace OHOS
173 #endif // SERVICES_INCLUDE_TIME_SERVICE_INTERFACE_H