• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "atm_device_state_callback.h"
17 
18 #include <vector>
19 #include <thread>
20 
21 #include "accesstoken_log.h"
22 #include "constant.h"
23 #include "device_manager.h"
24 #include "dm_device_info.h"
25 #include "token_sync_manager_client.h"
26 #include "accesstoken_manager_service.h"
27 
28 namespace OHOS {
29 namespace Security {
30 namespace AccessToken {
31 using OHOS::DistributedHardware::DeviceStateCallback;
32 using OHOS::DistributedHardware::DmDeviceInfo;
33 using OHOS::DistributedHardware::DmInitCallback;
34 
35 namespace {
36 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
37     LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AtmDeviceStateCallback"};
38 }
39 
AtmDeviceStateCallback()40 AtmDeviceStateCallback::AtmDeviceStateCallback()
41 {
42     ACCESSTOKEN_LOG_DEBUG(LABEL, "AtmDeviceStateCallback()");
43 }
44 
~AtmDeviceStateCallback()45 AtmDeviceStateCallback::~AtmDeviceStateCallback()
46 {
47     ACCESSTOKEN_LOG_DEBUG(LABEL, "~AtmDeviceStateCallback()");
48 }
49 
OnDeviceOnline(const DmDeviceInfo & deviceInfo)50 void AtmDeviceStateCallback::OnDeviceOnline(const DmDeviceInfo &deviceInfo)
51 {
52     ACCESSTOKEN_LOG_DEBUG(LABEL, "device online");
53 
54     // when remote device online and token sync remote object is null, start a thread to load token sync
55     if (TokenSyncManagerClient::GetInstance().GetRemoteObject() == nullptr) {
56         std::function<void()> runner = [&]() {
57             TokenSyncManagerClient::GetInstance().LoadTokenSync();
58 
59             ACCESSTOKEN_LOG_INFO(LABEL, "load tokensync.");
60 
61             return;
62         };
63 
64         std::thread initThread(runner);
65         initThread.detach();
66     }
67 }
68 
OnDeviceOffline(const DmDeviceInfo & deviceInfo)69 void AtmDeviceStateCallback::OnDeviceOffline(const DmDeviceInfo &deviceInfo)
70 {
71     ACCESSTOKEN_LOG_DEBUG(LABEL, "device offline");
72 }
73 
OnDeviceReady(const DmDeviceInfo & deviceInfo)74 void AtmDeviceStateCallback::OnDeviceReady(const DmDeviceInfo &deviceInfo)
75 {
76     ACCESSTOKEN_LOG_DEBUG(LABEL, "device ready");
77 }
78 
OnDeviceChanged(const DmDeviceInfo & deviceInfo)79 void AtmDeviceStateCallback::OnDeviceChanged(const DmDeviceInfo &deviceInfo)
80 {
81     ACCESSTOKEN_LOG_DEBUG(LABEL, "device changed");
82 }
83 } // namespace AccessToken
84 } // namespace Security
85 } // namespace OHOS
86