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 #include "time_service_client.h"
17
18 #include <cinttypes>
19 #include <mutex>
20
21 #include "iremote_object.h"
22 #include "iservice_registry.h"
23 #include "system_ability_definition.h"
24 #include "time_common.h"
25
26 namespace OHOS {
27 namespace MiscServices {
28 std::mutex TimeServiceClient::instanceLock_;
29 sptr<TimeServiceClient> TimeServiceClient::instance_;
30 sptr<TimeSaDeathRecipient> deathRecipient_;
TimeServiceClient()31 TimeServiceClient::TimeServiceClient()
32 {
33 }
34
~TimeServiceClient()35 TimeServiceClient::~TimeServiceClient()
36 {
37 auto proxy = GetProxy();
38 if (proxy != nullptr) {
39 auto remoteObject = proxy->AsObject();
40 if (remoteObject != nullptr) {
41 remoteObject->RemoveDeathRecipient(deathRecipient_);
42 }
43 }
44 }
45
GetInstance()46 sptr<TimeServiceClient> TimeServiceClient::GetInstance()
47 {
48 if (instance_ == nullptr) {
49 std::lock_guard<std::mutex> autoLock(instanceLock_);
50 if (instance_ == nullptr) {
51 instance_ = new TimeServiceClient;
52 }
53 }
54 return instance_;
55 }
56
ConnectService()57 bool TimeServiceClient::ConnectService()
58 {
59 if (GetProxy() != nullptr) {
60 return true;
61 }
62 sptr<ISystemAbilityManager> systemAbilityManager =
63 SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
64 if (systemAbilityManager == nullptr) {
65 TIME_HILOGE(TIME_MODULE_CLIENT, "Getting SystemAbilityManager failed.");
66 return false;
67 }
68
69 auto systemAbility = systemAbilityManager->GetSystemAbility(TIME_SERVICE_ID);
70 if (systemAbility == nullptr) {
71 TIME_HILOGE(TIME_MODULE_CLIENT, "Get SystemAbility failed.");
72 return false;
73 }
74 deathRecipient_ = new TimeSaDeathRecipient();
75 systemAbility->AddDeathRecipient(deathRecipient_);
76 sptr<ITimeService> proxy = iface_cast<ITimeService>(systemAbility);
77 if (proxy == nullptr) {
78 TIME_HILOGE(TIME_MODULE_CLIENT, "Get TimeServiceProxy from SA failed.");
79 return false;
80 }
81 SetProxy(proxy);
82 return true;
83 }
84
SetTime(const int64_t time)85 bool TimeServiceClient::SetTime(const int64_t time)
86 {
87 if (!ConnectService()) {
88 return false;
89 }
90 auto proxy = GetProxy();
91 if (proxy == nullptr) {
92 return false;
93 }
94 return proxy->SetTime(time) == ERR_OK;
95 }
96
SetTime(const int64_t milliseconds,int32_t & code)97 bool TimeServiceClient::SetTime(const int64_t milliseconds, int32_t &code)
98 {
99 if (!ConnectService()) {
100 code = E_TIME_SA_DIED;
101 return false;
102 }
103 auto proxy = GetProxy();
104 if (proxy == nullptr) {
105 code = E_TIME_NULLPTR;
106 return false;
107 }
108 code = proxy->SetTime(milliseconds);
109 return code == ERR_OK;
110 }
111
SetTimeV9(const int64_t & time)112 int32_t TimeServiceClient::SetTimeV9(const int64_t &time)
113 {
114 if (!ConnectService()) {
115 return E_TIME_SA_DIED;
116 }
117 auto proxy = GetProxy();
118 if (proxy == nullptr) {
119 return E_TIME_NULLPTR;
120 }
121 return proxy->SetTime(time, ITimeService::API_VERSION_9);
122 }
123
SetTimeZone(const std::string timezoneId)124 bool TimeServiceClient::SetTimeZone(const std::string timezoneId)
125 {
126 if (!ConnectService()) {
127 return false;
128 }
129 auto proxy = GetProxy();
130 if (proxy == nullptr) {
131 return false;
132 }
133 return proxy->SetTimeZone(timezoneId) == ERR_OK;
134 }
135
SetTimeZone(const std::string timezoneId,int32_t & code)136 bool TimeServiceClient::SetTimeZone(const std::string timezoneId, int32_t &code)
137 {
138 if (!ConnectService()) {
139 code = E_TIME_SA_DIED;
140 return false;
141 }
142 auto proxy = GetProxy();
143 if (proxy == nullptr) {
144 code = E_TIME_NULLPTR;
145 return false;
146 }
147 code = proxy->SetTimeZone(timezoneId);
148 TIME_HILOGI(TIME_MODULE_CLIENT, "settimezone end");
149 return code == ERR_OK;
150 }
151
SetTimeZoneV9(const std::string timezoneId)152 int32_t TimeServiceClient::SetTimeZoneV9(const std::string timezoneId)
153 {
154 if (!ConnectService()) {
155 return E_TIME_SA_DIED;
156 }
157 auto proxy = GetProxy();
158 if (proxy == nullptr) {
159 return E_TIME_NULLPTR;
160 }
161 return proxy->SetTimeZone(timezoneId, ITimeService::API_VERSION_9);
162 }
163
CreateTimer(std::shared_ptr<ITimerInfo> TimerOptions)164 uint64_t TimeServiceClient::CreateTimer(std::shared_ptr<ITimerInfo> TimerOptions)
165 {
166 uint64_t timerId = 0;
167 auto errCode = CreateTimerV9(TimerOptions, timerId);
168 TIME_HILOGI(TIME_MODULE_SERVICE, "CreateTimer id: %{public}" PRId64 "", timerId);
169 if (errCode != E_TIME_OK) {
170 TIME_HILOGE(TIME_MODULE_CLIENT, "Non-system applications, create timer failed");
171 return 0;
172 }
173 if (timerId == 0) {
174 TIME_HILOGE(TIME_MODULE_CLIENT, "Create timer failed");
175 return 0;
176 }
177 TIME_HILOGI(TIME_MODULE_SERVICE, "CreateTimer id: %{public}" PRId64 "", timerId);
178 return timerId;
179 }
180
CreateTimerV9(std::shared_ptr<ITimerInfo> timerOptions,uint64_t & timerId)181 int32_t TimeServiceClient::CreateTimerV9(std::shared_ptr<ITimerInfo> timerOptions, uint64_t &timerId)
182 {
183 if (timerOptions == nullptr) {
184 TIME_HILOGW(TIME_MODULE_CLIENT, "Input nullptr");
185 return E_TIME_NULLPTR;
186 }
187 if (!ConnectService()) {
188 return E_TIME_NULLPTR;
189 }
190 auto timerCallbackInfoObject = TimerCallback::GetInstance()->AsObject();
191 if (!timerCallbackInfoObject) {
192 TIME_HILOGE(TIME_MODULE_CLIENT, "New TimerCallback failed");
193 return E_TIME_NULLPTR;
194 }
195 auto proxy = GetProxy();
196 if (proxy == nullptr) {
197 return E_TIME_NULLPTR;
198 }
199 auto errCode = proxy->CreateTimer(timerOptions, timerCallbackInfoObject, timerId);
200 if (errCode != E_TIME_OK) {
201 TIME_HILOGE(TIME_MODULE_CLIENT, "create timer failed");
202 return errCode;
203 }
204 TIME_HILOGI(TIME_MODULE_SERVICE, "CreateTimer id: %{public}" PRId64 "", timerId);
205 auto ret = TimerCallback::GetInstance()->InsertTimerCallbackInfo(timerId, timerOptions);
206 if (!ret) {
207 return E_TIME_DEAL_FAILED;
208 }
209 return errCode;
210 }
211
StartTimer(uint64_t timerId,uint64_t triggerTime)212 bool TimeServiceClient::StartTimer(uint64_t timerId, uint64_t triggerTime)
213 {
214 int32_t errCode = StartTimerV9(timerId, triggerTime);
215 if (errCode != E_TIME_OK) {
216 return false;
217 }
218 return true;
219 }
220
StartTimerV9(uint64_t timerId,uint64_t triggerTime)221 int32_t TimeServiceClient::StartTimerV9(uint64_t timerId, uint64_t triggerTime)
222 {
223 if (!ConnectService()) {
224 return E_TIME_SA_DIED;
225 }
226 auto proxy = GetProxy();
227 if (proxy == nullptr) {
228 return E_TIME_NULLPTR;
229 }
230 return proxy->StartTimer(timerId, triggerTime);
231 }
232
StopTimer(uint64_t timerId)233 bool TimeServiceClient::StopTimer(uint64_t timerId)
234 {
235 int32_t errCode = StopTimerV9(timerId);
236 if (errCode != E_TIME_OK) {
237 return false;
238 }
239 return true;
240 }
241
StopTimerV9(uint64_t timerId)242 int32_t TimeServiceClient::StopTimerV9(uint64_t timerId)
243 {
244 if (!ConnectService()) {
245 return E_TIME_SA_DIED;
246 }
247 auto proxy = GetProxy();
248 if (proxy == nullptr) {
249 return E_TIME_NULLPTR;
250 }
251 return proxy->StopTimer(timerId);
252 }
253
DestroyTimer(uint64_t timerId)254 bool TimeServiceClient::DestroyTimer(uint64_t timerId)
255 {
256 int32_t errCode = DestroyTimerV9(timerId);
257 if (errCode != E_TIME_OK) {
258 return false;
259 }
260 return true;
261 }
262
DestroyTimerV9(uint64_t timerId)263 int32_t TimeServiceClient::DestroyTimerV9(uint64_t timerId)
264 {
265 if (!ConnectService()) {
266 return E_TIME_SA_DIED;
267 }
268 auto proxy = GetProxy();
269 if (proxy == nullptr) {
270 return E_TIME_NULLPTR;
271 }
272 auto errCode = proxy->DestroyTimer(timerId);
273 if (errCode == E_TIME_OK) {
274 TimerCallback::GetInstance()->RemoveTimerCallbackInfo(timerId);
275 return E_TIME_OK;
276 }
277 return errCode;
278 }
279
GetTimeZone()280 std::string TimeServiceClient::GetTimeZone()
281 {
282 std::string timeZoneId;
283 if (!ConnectService()) {
284 return std::string("");
285 }
286 auto proxy = GetProxy();
287 if (proxy == nullptr) {
288 return std::string("");
289 }
290 if (proxy->GetTimeZone(timeZoneId) != ERR_OK) {
291 TIME_HILOGE(TIME_MODULE_CLIENT, "get failed.");
292 return std::string("");
293 }
294 return timeZoneId;
295 }
296
GetTimeZone(std::string & timezoneId)297 int32_t TimeServiceClient::GetTimeZone(std::string &timezoneId)
298 {
299 if (!ConnectService()) {
300 return E_TIME_SA_DIED;
301 }
302 auto proxy = GetProxy();
303 if (proxy == nullptr) {
304 return E_TIME_NULLPTR;
305 }
306 if (proxy->GetTimeZone(timezoneId) != ERR_OK) {
307 TIME_HILOGE(TIME_MODULE_CLIENT, "get failed.");
308 return E_TIME_SA_DIED;
309 }
310 return E_TIME_OK;
311 }
312
GetWallTimeMs()313 int64_t TimeServiceClient::GetWallTimeMs()
314 {
315 int64_t time;
316 if (!ConnectService()) {
317 return -1;
318 }
319 auto proxy = GetProxy();
320 if (proxy == nullptr) {
321 return E_TIME_NULLPTR;
322 }
323 if (proxy->GetWallTimeMs(time) != ERR_OK) {
324 TIME_HILOGE(TIME_MODULE_CLIENT, "get failed.");
325 return -1;
326 }
327 TIME_HILOGI(TIME_MODULE_SERVICE, "Result: %{public}" PRId64 "", time);
328 return time;
329 }
330
GetWallTimeMs(int64_t & time)331 int32_t TimeServiceClient::GetWallTimeMs(int64_t &time)
332 {
333 if (!ConnectService()) {
334 return E_TIME_SA_DIED;
335 }
336 auto proxy = GetProxy();
337 if (proxy == nullptr) {
338 return E_TIME_NULLPTR;
339 }
340 if (proxy->GetWallTimeMs(time) != ERR_OK) {
341 TIME_HILOGE(TIME_MODULE_CLIENT, "get failed.");
342 return E_TIME_SA_DIED;
343 }
344 TIME_HILOGI(TIME_MODULE_SERVICE, "Result: %{public}" PRId64 "", time);
345 return E_TIME_OK;
346 }
347
GetWallTimeNs()348 int64_t TimeServiceClient::GetWallTimeNs()
349 {
350 int64_t time;
351 if (!ConnectService()) {
352 return -1;
353 }
354 auto proxy = GetProxy();
355 if (proxy == nullptr) {
356 return E_TIME_NULLPTR;
357 }
358 if (proxy->GetWallTimeNs(time) != ERR_OK) {
359 TIME_HILOGE(TIME_MODULE_CLIENT, "get failed.");
360 return -1;
361 }
362 TIME_HILOGI(TIME_MODULE_SERVICE, "Result: %{public}" PRId64 "", time);
363 return time;
364 }
365
GetWallTimeNs(int64_t & time)366 int32_t TimeServiceClient::GetWallTimeNs(int64_t &time)
367 {
368 if (!ConnectService()) {
369 return E_TIME_SA_DIED;
370 }
371 auto proxy = GetProxy();
372 if (proxy == nullptr) {
373 return E_TIME_NULLPTR;
374 }
375 if (proxy->GetWallTimeNs(time) != ERR_OK) {
376 TIME_HILOGE(TIME_MODULE_CLIENT, "get failed.");
377 return E_TIME_SA_DIED;
378 }
379 TIME_HILOGI(TIME_MODULE_SERVICE, "Result: %{public}" PRId64 "", time);
380 return E_TIME_OK;
381 }
382
GetBootTimeMs()383 int64_t TimeServiceClient::GetBootTimeMs()
384 {
385 int64_t time;
386 if (!ConnectService()) {
387 return -1;
388 }
389 auto proxy = GetProxy();
390 if (proxy == nullptr) {
391 return E_TIME_NULLPTR;
392 }
393 if (proxy->GetBootTimeMs(time) != ERR_OK) {
394 TIME_HILOGE(TIME_MODULE_CLIENT, "get failed.");
395 return -1;
396 }
397 TIME_HILOGI(TIME_MODULE_SERVICE, "Result: %{public}" PRId64 "", time);
398 return time;
399 }
400
GetBootTimeMs(int64_t & time)401 int32_t TimeServiceClient::GetBootTimeMs(int64_t &time)
402 {
403 if (!ConnectService()) {
404 return E_TIME_SA_DIED;
405 }
406 auto proxy = GetProxy();
407 if (proxy == nullptr) {
408 return E_TIME_NULLPTR;
409 }
410 if (proxy->GetBootTimeMs(time) != ERR_OK) {
411 TIME_HILOGE(TIME_MODULE_CLIENT, "get failed.");
412 return E_TIME_SA_DIED;
413 }
414 TIME_HILOGI(TIME_MODULE_SERVICE, "Result: %{public}" PRId64 "", time);
415 return E_TIME_OK;
416 }
417
GetBootTimeNs()418 int64_t TimeServiceClient::GetBootTimeNs()
419 {
420 int64_t time;
421 if (!ConnectService()) {
422 return -1;
423 }
424 auto proxy = GetProxy();
425 if (proxy == nullptr) {
426 return E_TIME_NULLPTR;
427 }
428 if (proxy->GetBootTimeNs(time) != ERR_OK) {
429 TIME_HILOGE(TIME_MODULE_CLIENT, "get failed.");
430 return -1;
431 }
432 TIME_HILOGI(TIME_MODULE_SERVICE, "Result: %{public}" PRId64 "", time);
433 return time;
434 }
435
GetBootTimeNs(int64_t & time)436 int32_t TimeServiceClient::GetBootTimeNs(int64_t &time)
437 {
438 if (!ConnectService()) {
439 return E_TIME_SA_DIED;
440 }
441 auto proxy = GetProxy();
442 if (proxy == nullptr) {
443 return E_TIME_NULLPTR;
444 }
445 if (proxy->GetBootTimeNs(time) != ERR_OK) {
446 TIME_HILOGE(TIME_MODULE_CLIENT, "get failed.");
447 return E_TIME_SA_DIED;
448 }
449 TIME_HILOGI(TIME_MODULE_SERVICE, "Result: %{public}" PRId64 "", time);
450 return E_TIME_OK;
451 }
452
GetMonotonicTimeMs()453 int64_t TimeServiceClient::GetMonotonicTimeMs()
454 {
455 int64_t time;
456 if (!ConnectService()) {
457 return -1;
458 }
459 auto proxy = GetProxy();
460 if (proxy == nullptr) {
461 return E_TIME_NULLPTR;
462 }
463 if (proxy->GetMonotonicTimeMs(time) != ERR_OK) {
464 TIME_HILOGE(TIME_MODULE_CLIENT, "get failed.");
465 return -1;
466 }
467 TIME_HILOGI(TIME_MODULE_SERVICE, "Result: %{public}" PRId64 "", time);
468 return time;
469 }
470
GetMonotonicTimeMs(int64_t & time)471 int32_t TimeServiceClient::GetMonotonicTimeMs(int64_t &time)
472 {
473 if (!ConnectService()) {
474 return E_TIME_SA_DIED;
475 }
476 auto proxy = GetProxy();
477 if (proxy == nullptr) {
478 return E_TIME_NULLPTR;
479 }
480 if (proxy->GetMonotonicTimeMs(time) != ERR_OK) {
481 TIME_HILOGE(TIME_MODULE_CLIENT, "get failed.");
482 return E_TIME_SA_DIED;
483 }
484 TIME_HILOGI(TIME_MODULE_SERVICE, "Result: %{public}" PRId64 "", time);
485 return E_TIME_OK;
486 }
487
GetMonotonicTimeNs()488 int64_t TimeServiceClient::GetMonotonicTimeNs()
489 {
490 int64_t time;
491 if (!ConnectService()) {
492 return -1;
493 }
494 auto proxy = GetProxy();
495 if (proxy == nullptr) {
496 return E_TIME_NULLPTR;
497 }
498 if (proxy->GetMonotonicTimeNs(time) != ERR_OK) {
499 TIME_HILOGE(TIME_MODULE_CLIENT, "get failed.");
500 return -1;
501 }
502 TIME_HILOGI(TIME_MODULE_SERVICE, "Result: %{public}" PRId64 "", time);
503 return time;
504 }
505
GetMonotonicTimeNs(int64_t & time)506 int32_t TimeServiceClient::GetMonotonicTimeNs(int64_t &time)
507 {
508 if (!ConnectService()) {
509 return E_TIME_SA_DIED;
510 }
511 auto proxy = GetProxy();
512 if (proxy == nullptr) {
513 return E_TIME_NULLPTR;
514 }
515 if (proxy->GetMonotonicTimeNs(time) != ERR_OK) {
516 TIME_HILOGE(TIME_MODULE_CLIENT, "get failed.");
517 return E_TIME_SA_DIED;
518 }
519 TIME_HILOGI(TIME_MODULE_SERVICE, "Result: %{public}" PRId64 "", time);
520 return E_TIME_OK;
521 }
522
GetThreadTimeMs()523 int64_t TimeServiceClient::GetThreadTimeMs()
524 {
525 int64_t time;
526 if (!ConnectService()) {
527 return -1;
528 }
529 auto proxy = GetProxy();
530 if (proxy == nullptr) {
531 return E_TIME_NULLPTR;
532 }
533 if (proxy->GetThreadTimeMs(time) != ERR_OK) {
534 TIME_HILOGE(TIME_MODULE_CLIENT, "get failed.");
535 return -1;
536 }
537 TIME_HILOGI(TIME_MODULE_SERVICE, "Result: %{public}" PRId64 "", time);
538 return time;
539 }
540
GetThreadTimeMs(int64_t & time)541 int32_t TimeServiceClient::GetThreadTimeMs(int64_t &time)
542 {
543 if (!ConnectService()) {
544 return E_TIME_SA_DIED;
545 }
546 auto proxy = GetProxy();
547 if (proxy == nullptr) {
548 return E_TIME_NULLPTR;
549 }
550 if (proxy->GetThreadTimeMs(time) != ERR_OK) {
551 TIME_HILOGE(TIME_MODULE_CLIENT, "get failed.");
552 return E_TIME_SA_DIED;
553 }
554 TIME_HILOGI(TIME_MODULE_SERVICE, "Result: %{public}" PRId64 "", time);
555 return E_TIME_OK;
556 }
557
GetThreadTimeNs()558 int64_t TimeServiceClient::GetThreadTimeNs()
559 {
560 int64_t time;
561 if (!ConnectService()) {
562 return -1;
563 }
564 auto proxy = GetProxy();
565 if (proxy == nullptr) {
566 return E_TIME_NULLPTR;
567 }
568 if (proxy->GetThreadTimeNs(time) != ERR_OK) {
569 TIME_HILOGE(TIME_MODULE_CLIENT, "get failed.");
570 return -1;
571 }
572 TIME_HILOGI(TIME_MODULE_SERVICE, "Result: %{public}" PRId64 "", time);
573 return time;
574 }
575
GetThreadTimeNs(int64_t & time)576 int32_t TimeServiceClient::GetThreadTimeNs(int64_t &time)
577 {
578 if (!ConnectService()) {
579 return E_TIME_SA_DIED;
580 }
581 auto proxy = GetProxy();
582 if (proxy == nullptr) {
583 return E_TIME_NULLPTR;
584 }
585 if (proxy->GetThreadTimeNs(time) != ERR_OK) {
586 TIME_HILOGE(TIME_MODULE_CLIENT, "get failed.");
587 return E_TIME_SA_DIED;
588 }
589 TIME_HILOGI(TIME_MODULE_SERVICE, "Result: %{public}" PRId64 "", time);
590 return E_TIME_OK;
591 }
592
OnRemoteSaDied(const wptr<IRemoteObject> & remote)593 void TimeServiceClient::OnRemoteSaDied(const wptr<IRemoteObject> &remote)
594 {
595 ConnectService();
596 }
597
TimeSaDeathRecipient()598 TimeSaDeathRecipient::TimeSaDeathRecipient()
599 {
600 }
601
OnRemoteDied(const wptr<IRemoteObject> & object)602 void TimeSaDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &object)
603 {
604 TIME_HILOGE(TIME_MODULE_CLIENT, "TimeSaDeathRecipient on remote systemAbility died.");
605 TimeServiceClient::GetInstance()->ClearProxy();
606 TimeServiceClient::GetInstance()->OnRemoteSaDied(object);
607 }
608
ProxyTimer(int32_t uid,bool isProxy,bool needRetrigger)609 bool TimeServiceClient::ProxyTimer(int32_t uid, bool isProxy, bool needRetrigger)
610 {
611 TIME_HILOGD(TIME_MODULE_CLIENT, "ProxyTimer start uid: %{public}d, isProxy: %{public}d", uid, isProxy);
612 if (!ConnectService()) {
613 return false;
614 }
615 auto proxy = GetProxy();
616 if (proxy == nullptr) {
617 return false;
618 }
619 return proxy->ProxyTimer(uid, isProxy, needRetrigger);
620 }
621
ResetAllProxy()622 bool TimeServiceClient::ResetAllProxy()
623 {
624 TIME_HILOGD(TIME_MODULE_CLIENT, "ResetAllProxy");
625 if (timeServiceProxy_ == nullptr) {
626 TIME_HILOGW(TIME_MODULE_CLIENT, "ResetAllProxy ConnectService");
627 ConnectService();
628 }
629 if (timeServiceProxy_ == nullptr) {
630 TIME_HILOGE(TIME_MODULE_CLIENT, "ResetAllProxy ConnectService failed.");
631 return false;
632 }
633 auto proxy = GetProxy();
634 if (proxy == nullptr) {
635 return false;
636 }
637 return proxy->ResetAllProxy();
638 }
639
GetProxy()640 sptr<ITimeService> TimeServiceClient::GetProxy()
641 {
642 std::lock_guard<std::mutex> autoLock(proxyLock_);
643 return timeServiceProxy_;
644 }
645
SetProxy(sptr<ITimeService> proxy)646 void TimeServiceClient::SetProxy(sptr<ITimeService> proxy)
647 {
648 std::lock_guard<std::mutex> autoLock(proxyLock_);
649 timeServiceProxy_ = proxy;
650 }
651
ClearProxy()652 void TimeServiceClient::ClearProxy()
653 {
654 std::lock_guard<std::mutex> autoLock(proxyLock_);
655 timeServiceProxy_ = nullptr;
656 }
657 } // namespace MiscServices
658 } // namespace OHOS