1 /*
2 * Copyright (c) 2024 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 "dm_softbus_cache.h"
17 #include "dm_anonymous.h"
18 #include "dm_crypto.h"
19 #include "dm_constants.h"
20 #include "dm_device_info.h"
21 #include "dm_log.h"
22 #include <atomic>
23 namespace OHOS {
24 namespace DistributedHardware {
25 DM_IMPLEMENT_SINGLE_INSTANCE(SoftbusCache);
26 std::atomic<bool> g_online{false};
27 std::atomic<bool> g_getLocalDevInfo{false};
28 DmDeviceInfo localDeviceInfo_;
29 std::mutex localDevInfoMutex_;
SaveLocalDeviceInfo()30 void SoftbusCache::SaveLocalDeviceInfo()
31 {
32 LOGI("start");
33 std::lock_guard<std::mutex> mutexLock(localDevInfoMutex_);
34 if (g_online) {
35 return;
36 }
37 NodeBasicInfo nodeBasicInfo;
38 int32_t ret = GetLocalNodeDeviceInfo(DM_PKG_NAME, &nodeBasicInfo);
39 if (ret != DM_OK) {
40 LOGE("[SOFTBUS]GetLocalNodeDeviceInfo failed, ret: %{public}d.", ret);
41 return;
42 }
43 ConvertNodeBasicInfoToDmDevice(nodeBasicInfo, localDeviceInfo_);
44 LOGI("networkid %{public}s.", GetAnonyString(std::string(localDeviceInfo_.networkId)).c_str());
45 SaveDeviceInfo(localDeviceInfo_);
46 SaveDeviceSecurityLevel(localDeviceInfo_.networkId);
47 g_online = true;
48 g_getLocalDevInfo = true;
49 }
50
DeleteLocalDeviceInfo()51 void SoftbusCache::DeleteLocalDeviceInfo()
52 {
53 LOGI("networkid %{public}s.", GetAnonyString(std::string(localDeviceInfo_.networkId)).c_str());
54 std::lock_guard<std::mutex> mutexLock(localDevInfoMutex_);
55 g_online = false;
56 g_getLocalDevInfo = false;
57 if (memset_s(&localDeviceInfo_, sizeof(DmDeviceInfo), 0, sizeof(DmDeviceInfo)) != DM_OK) {
58 LOGE("DeleteLocalDeviceInfo memset_s failed.");
59 return;
60 }
61 }
62
GetLocalDeviceInfo(DmDeviceInfo & nodeInfo)63 int32_t SoftbusCache::GetLocalDeviceInfo(DmDeviceInfo &nodeInfo)
64 {
65 std::lock_guard<std::mutex> mutexLock(localDevInfoMutex_);
66 if (g_getLocalDevInfo) {
67 nodeInfo = localDeviceInfo_;
68 LOGD("dm cache success.");
69 return DM_OK;
70 }
71 NodeBasicInfo nodeBasicInfo;
72 int32_t ret = GetLocalNodeDeviceInfo(DM_PKG_NAME, &nodeBasicInfo);
73 if (ret != DM_OK) {
74 LOGE("[SOFTBUS]GetLocalNodeDeviceInfo failed, ret: %{public}d.", ret);
75 return ret;
76 }
77 ConvertNodeBasicInfoToDmDevice(nodeBasicInfo, localDeviceInfo_);
78 nodeInfo = localDeviceInfo_;
79 SaveDeviceInfo(localDeviceInfo_);
80 SaveDeviceSecurityLevel(localDeviceInfo_.networkId);
81 g_getLocalDevInfo = true;
82 LOGI("from softbus success.");
83 return DM_OK;
84 }
85
UpDataLocalDevInfo()86 void SoftbusCache::UpDataLocalDevInfo()
87 {
88 LOGI("start");
89 NodeBasicInfo nodeBasicInfo;
90 int32_t ret = GetLocalNodeDeviceInfo(DM_PKG_NAME, &nodeBasicInfo);
91 if (ret != DM_OK) {
92 LOGE("[SOFTBUS]GetLocalNodeDeviceInfo failed, ret: %{public}d.", ret);
93 return;
94 }
95 std::lock_guard<std::mutex> mutexLock(localDevInfoMutex_);
96 ConvertNodeBasicInfoToDmDevice(nodeBasicInfo, localDeviceInfo_);
97 ChangeDeviceInfo(localDeviceInfo_);
98 }
99
GetUdidByNetworkId(const char * networkId,std::string & udid)100 int32_t SoftbusCache::GetUdidByNetworkId(const char *networkId, std::string &udid)
101 {
102 uint8_t mUdid[UDID_BUF_LEN] = {0};
103 int32_t ret = GetNodeKeyInfo(DM_PKG_NAME, networkId, NodeDeviceInfoKey::NODE_KEY_UDID, mUdid, sizeof(mUdid));
104 if (ret != DM_OK) {
105 LOGE("[SOFTBUS]GetNodeKeyInfo failed, ret: %{public}d.", ret);
106 return ret;
107 }
108 udid = reinterpret_cast<char *>(mUdid);
109 return ret;
110 }
111
GetUuidByNetworkId(const char * networkId,std::string & uuid)112 int32_t SoftbusCache::GetUuidByNetworkId(const char *networkId, std::string &uuid)
113 {
114 uint8_t mUuid[UUID_BUF_LEN] = {0};
115 int32_t ret = GetNodeKeyInfo(DM_PKG_NAME, networkId, NodeDeviceInfoKey::NODE_KEY_UUID, mUuid, sizeof(mUuid));
116 if (ret != DM_OK) {
117 LOGE("[SOFTBUS]GetNodeKeyInfo failed, ret: %{public}d.", ret);
118 return ret;
119 }
120 uuid = reinterpret_cast<char *>(mUuid);
121 return ret;
122 }
123
SaveDeviceInfo(DmDeviceInfo deviceInfo)124 void SoftbusCache::SaveDeviceInfo(DmDeviceInfo deviceInfo)
125 {
126 LOGI("start");
127 std::string udid = "";
128 std::string uuid = "";
129 if (deviceInfo.networkId[0] == '\0') {
130 LOGE("networkId is empty.");
131 return;
132 }
133 GetUdidByNetworkId(deviceInfo.networkId, udid);
134 GetUuidByNetworkId(deviceInfo.networkId, uuid);
135 if (udid.empty()) {
136 LOGE("udid is empty.");
137 return;
138 }
139 char udidHash[DM_MAX_DEVICE_ID_LEN] = {0};
140 if (Crypto::GetUdidHash(udid, reinterpret_cast<uint8_t *>(udidHash)) != DM_OK) {
141 LOGE("get udidhash by udid: %{public}s failed.", GetAnonyString(udid).c_str());
142 return;
143 }
144 if (memcpy_s(deviceInfo.deviceId, sizeof(deviceInfo.deviceId), udidHash,
145 std::min(sizeof(deviceInfo.deviceId), sizeof(udidHash))) != DM_OK) {
146 LOGE("SaveDeviceInfo copy deviceId failed.");
147 return;
148 }
149 std::lock_guard<std::mutex> mutexLock(deviceInfosMutex_);
150 CHECK_SIZE_VOID(deviceInfo_);
151 deviceInfo_[udid] = std::pair<std::string, DmDeviceInfo>(uuid, deviceInfo);
152 LOGI("success udid %{public}s, networkId %{public}s",
153 GetAnonyString(udid).c_str(), GetAnonyString(std::string(deviceInfo.networkId)).c_str());
154 }
155
DeleteDeviceInfo(const DmDeviceInfo & nodeInfo)156 void SoftbusCache::DeleteDeviceInfo(const DmDeviceInfo &nodeInfo)
157 {
158 LOGI("networkId %{public}s", GetAnonyString(std::string(nodeInfo.networkId)).c_str());
159 std::lock_guard<std::mutex> mutexLock(deviceInfosMutex_);
160 for (const auto &item : deviceInfo_) {
161 if (std::string(item.second.second.networkId) == std::string(nodeInfo.networkId)) {
162 LOGI("success udid %{public}s", GetAnonyString(item.first).c_str());
163 deviceInfo_.erase(item.first);
164 break;
165 }
166 }
167 }
168
DeleteDeviceInfo()169 void SoftbusCache::DeleteDeviceInfo()
170 {
171 std::lock_guard<std::mutex> mutexLock(deviceInfosMutex_);
172 deviceInfo_.clear();
173 }
174
ChangeDeviceInfo(const DmDeviceInfo deviceInfo)175 void SoftbusCache::ChangeDeviceInfo(const DmDeviceInfo deviceInfo)
176 {
177 LOGI("start");
178 std::string udid = "";
179 GetUdidByNetworkId(deviceInfo.networkId, udid);
180 std::lock_guard<std::mutex> mutexLock(deviceInfosMutex_);
181 if (deviceInfo_.find(udid) != deviceInfo_.end()) {
182 if (memcpy_s(deviceInfo_[udid].second.deviceName, sizeof(deviceInfo_[udid].second.deviceName),
183 deviceInfo.deviceName, sizeof(deviceInfo.deviceName)) != DM_OK) {
184 LOGE("ChangeDeviceInfo deviceInfo copy deviceName failed");
185 return;
186 }
187 if (memcpy_s(deviceInfo_[udid].second.networkId, sizeof(deviceInfo_[udid].second.networkId),
188 deviceInfo.networkId, sizeof(deviceInfo.networkId)) != DM_OK) {
189 LOGE("ChangeDeviceInfo deviceInfo copy networkId failed");
190 return;
191 }
192 deviceInfo_[udid].second.deviceTypeId = deviceInfo.deviceTypeId;
193 std::string uuid = "";
194 GetUuidByNetworkId(deviceInfo.networkId, uuid);
195 deviceInfo_[udid].first = uuid;
196 }
197 LOGI("sucess udid %{public}s, networkId %{public}s.",
198 GetAnonyString(udid).c_str(), GetAnonyString(std::string(deviceInfo.networkId)).c_str());
199 }
200
GetDeviceInfoFromCache(std::vector<DmDeviceInfo> & deviceInfoList)201 int32_t SoftbusCache::GetDeviceInfoFromCache(std::vector<DmDeviceInfo> &deviceInfoList)
202 {
203 std::lock_guard<std::mutex> mutexLock(deviceInfosMutex_);
204 for (const auto &item : deviceInfo_) {
205 if (std::string(item.second.second.networkId) == std::string(localDeviceInfo_.networkId)) {
206 continue;
207 }
208 deviceInfoList.push_back(item.second.second);
209 }
210 return DM_OK;
211 }
212
UpdateDeviceInfoCache()213 void SoftbusCache::UpdateDeviceInfoCache()
214 {
215 LOGI("start");
216 int32_t deviceCount = 0;
217 NodeBasicInfo *nodeInfo = nullptr;
218 int32_t ret = GetAllNodeDeviceInfo(DM_PKG_NAME, &nodeInfo, &deviceCount);
219 if (ret != DM_OK) {
220 LOGE("[SOFTBUS]GetAllNodeDeviceInfo failed, ret: %{public}d.", ret);
221 return;
222 }
223 SaveLocalDeviceInfo();
224 for (int32_t i = 0; i < deviceCount; ++i) {
225 NodeBasicInfo *nodeBasicInfo = nodeInfo + i;
226 DmDeviceInfo deviceInfo;
227 ConvertNodeBasicInfoToDmDevice(*nodeBasicInfo, deviceInfo);
228 SaveDeviceInfo(deviceInfo);
229 }
230 FreeNodeInfo(nodeInfo);
231 LOGI("success, deviceCount: %{public}d.", deviceCount);
232 return;
233 }
234
GetUdidFromCache(const char * networkId,std::string & udid)235 int32_t SoftbusCache::GetUdidFromCache(const char *networkId, std::string &udid)
236 {
237 std::lock_guard<std::mutex> mutexLock(deviceInfosMutex_);
238 for (const auto &item : deviceInfo_) {
239 if (std::string(item.second.second.networkId) == std::string(networkId)) {
240 udid = item.first;
241 LOGI("Get udid from cache success, networkId %{public}s, udid %{public}s.",
242 GetAnonyString(std::string(networkId)).c_str(), GetAnonyString(udid).c_str());
243 return DM_OK;
244 }
245 }
246 int32_t ret = GetUdidByNetworkId(networkId, udid);
247 if (ret == DM_OK) {
248 LOGI("Get udid from bus success, networkId %{public}s, udid %{public}s.",
249 GetAnonyString(std::string(networkId)).c_str(), GetAnonyString(udid).c_str());
250 return DM_OK;
251 }
252 return ret;
253 }
254
GetUuidFromCache(const char * networkId,std::string & uuid)255 int32_t SoftbusCache::GetUuidFromCache(const char *networkId, std::string &uuid)
256 {
257 std::lock_guard<std::mutex> mutexLock(deviceInfosMutex_);
258 for (const auto &item : deviceInfo_) {
259 if (std::string(item.second.second.networkId) == std::string(networkId)) {
260 uuid = item.second.first;
261 LOGI("Get uuid from cache success, networkId %{public}s, uuid %{public}s.",
262 GetAnonyString(std::string(networkId)).c_str(), GetAnonyString(uuid).c_str());
263 return DM_OK;
264 }
265 }
266 int32_t ret = GetUuidByNetworkId(networkId, uuid);
267 if (ret == DM_OK) {
268 LOGI("Get uuid from bus success, networkId %{public}s, uuid %{public}s.",
269 GetAnonyString(std::string(networkId)).c_str(), GetAnonyString(uuid).c_str());
270 return DM_OK;
271 }
272 return ret;
273 }
274
ConvertNodeBasicInfoToDmDevice(const NodeBasicInfo & nodeInfo,DmDeviceInfo & devInfo)275 int32_t SoftbusCache::ConvertNodeBasicInfoToDmDevice(const NodeBasicInfo &nodeInfo, DmDeviceInfo &devInfo)
276 {
277 if (memset_s(&devInfo, sizeof(DmDeviceInfo), 0, sizeof(DmDeviceInfo)) != DM_OK) {
278 LOGE("ConvertNodeBasicInfoToDmDevice memset_s failed.");
279 return ERR_DM_FAILED;
280 }
281
282 if (memcpy_s(devInfo.networkId, sizeof(devInfo.networkId), nodeInfo.networkId,
283 std::min(sizeof(devInfo.networkId), sizeof(nodeInfo.networkId))) != DM_OK) {
284 LOGE("ConvertNodeBasicInfoToDmDevice copy networkId data failed.");
285 return ERR_DM_FAILED;
286 }
287
288 if (memcpy_s(devInfo.deviceName, sizeof(devInfo.deviceName), nodeInfo.deviceName,
289 std::min(sizeof(devInfo.deviceName), sizeof(nodeInfo.deviceName))) != DM_OK) {
290 LOGE("ConvertNodeBasicInfoToDmDevice copy deviceName data failed.");
291 return ERR_DM_FAILED;
292 }
293
294 devInfo.deviceTypeId = nodeInfo.deviceTypeId;
295 JsonObject extraJson;
296 extraJson[PARAM_KEY_OS_TYPE] = nodeInfo.osType;
297 extraJson[PARAM_KEY_OS_VERSION] = ConvertCharArray2String(nodeInfo.osVersion, OS_VERSION_BUF_LEN);
298 devInfo.extraData = ToString(extraJson);
299 return DM_OK;
300 }
301
SaveDeviceSecurityLevel(const char * networkId)302 void SoftbusCache::SaveDeviceSecurityLevel(const char *networkId)
303 {
304 LOGI("networkId %{public}s.", GetAnonyString(std::string(networkId)).c_str());
305 std::lock_guard<std::mutex> mutexLock(deviceSecurityLevelMutex_);
306 if (deviceSecurityLevel_.find(std::string(networkId)) != deviceSecurityLevel_.end()) {
307 return;
308 }
309 CHECK_SIZE_VOID(deviceSecurityLevel_);
310 int32_t tempSecurityLevel = -1;
311 if (GetNodeKeyInfo(DM_PKG_NAME, networkId, NodeDeviceInfoKey::NODE_KEY_DEVICE_SECURITY_LEVEL,
312 reinterpret_cast<uint8_t *>(&tempSecurityLevel), LNN_COMMON_LEN) != DM_OK) {
313 LOGE("[SOFTBUS]GetNodeKeyInfo networkType failed.");
314 return;
315 }
316 deviceSecurityLevel_[std::string(networkId)] = tempSecurityLevel;
317 }
318
DeleteDeviceSecurityLevel(const char * networkId)319 void SoftbusCache::DeleteDeviceSecurityLevel(const char *networkId)
320 {
321 LOGI("networkId %{public}s.", GetAnonyString(std::string(networkId)).c_str());
322 std::lock_guard<std::mutex> mutexLock(deviceSecurityLevelMutex_);
323 if (deviceSecurityLevel_.find(std::string(networkId)) != deviceSecurityLevel_.end()) {
324 deviceSecurityLevel_.erase(std::string(networkId));
325 }
326 }
327
GetSecurityDeviceLevel(const char * networkId,int32_t & securityLevel)328 int32_t SoftbusCache::GetSecurityDeviceLevel(const char *networkId, int32_t &securityLevel)
329 {
330 std::lock_guard<std::mutex> mutexLock(deviceSecurityLevelMutex_);
331 for (const auto &item : deviceSecurityLevel_) {
332 if (item.first == std::string(networkId)) {
333 securityLevel = item.second;
334 LOGI("Get dev level from cache success, networkId is %{public}s.",
335 GetAnonyString(std::string(networkId)).c_str());
336 return DM_OK;
337 }
338 }
339 int32_t ret = GetDevLevelFromBus(networkId, securityLevel);
340 if (ret == DM_OK) {
341 LOGI("Get dev level from softbus success.");
342 return DM_OK;
343 }
344 return ret;
345 }
346
GetDevLevelFromBus(const char * networkId,int32_t & securityLevel)347 int32_t SoftbusCache::GetDevLevelFromBus(const char *networkId, int32_t &securityLevel)
348 {
349 int32_t tempSecurityLevel = -1;
350 if (GetNodeKeyInfo(DM_PKG_NAME, networkId, NodeDeviceInfoKey::NODE_KEY_DEVICE_SECURITY_LEVEL,
351 reinterpret_cast<uint8_t *>(&tempSecurityLevel), LNN_COMMON_LEN) != DM_OK) {
352 LOGE("[SOFTBUS]GetNodeKeyInfo networkType failed.");
353 return ERR_DM_FAILED;
354 }
355 CHECK_SIZE_RETURN(deviceSecurityLevel_, ERR_DM_FAILED);
356 securityLevel = tempSecurityLevel;
357 deviceSecurityLevel_[std::string(networkId)] = tempSecurityLevel;
358 LOGI("Get dev level from softbus success, networkId is %{public}s.",
359 GetAnonyString(std::string(networkId)).c_str());
360 return DM_OK;
361 }
362
GetDevInfoByNetworkId(const std::string & networkId,DmDeviceInfo & nodeInfo)363 int32_t SoftbusCache::GetDevInfoByNetworkId(const std::string &networkId, DmDeviceInfo &nodeInfo)
364 {
365 {
366 std::lock_guard<std::mutex> mutexLock(deviceInfosMutex_);
367 for (const auto &item : deviceInfo_) {
368 if (std::string(item.second.second.networkId) == networkId) {
369 nodeInfo = item.second.second;
370 LOGI("success networkId %{public}s, udid %{public}s.",
371 GetAnonyString(networkId).c_str(), GetAnonyString(item.first).c_str());
372 return DM_OK;
373 }
374 }
375 }
376 int32_t ret = GetDevInfoFromBus(networkId, nodeInfo);
377 if (ret != DM_OK) {
378 LOGE("GetDevInfoFromBus failed.");
379 return ret;
380 }
381 SaveDeviceInfo(nodeInfo);
382 return DM_OK;
383 }
384
GetDevInfoFromBus(const std::string & networkId,DmDeviceInfo & devInfo)385 int32_t SoftbusCache::GetDevInfoFromBus(const std::string &networkId, DmDeviceInfo &devInfo)
386 {
387 int32_t nodeInfoCount = 0;
388 NodeBasicInfo *nodeInfo = nullptr;
389 int32_t ret = GetAllNodeDeviceInfo(DM_PKG_NAME, &nodeInfo, &nodeInfoCount);
390 if (ret != DM_OK) {
391 LOGE("[SOFTBUS]GetAllNodeDeviceInfo failed, ret: %{public}d.", ret);
392 return ret;
393 }
394 for (int32_t i = 0; i < nodeInfoCount; ++i) {
395 NodeBasicInfo *nodeBasicInfo = nodeInfo + i;
396 if (networkId == std::string(nodeBasicInfo->networkId)) {
397 ConvertNodeBasicInfoToDmDevice(*nodeBasicInfo, devInfo);
398 break;
399 }
400 }
401 FreeNodeInfo(nodeInfo);
402 LOGI("GetDeviceInfo complete, deviceName : %{public}s, deviceTypeId : %{public}d.",
403 GetAnonyString(devInfo.deviceName).c_str(), devInfo.deviceTypeId);
404 return ret;
405 }
406
GetUdidByUdidHash(const std::string & udidHash,std::string & udid)407 int32_t SoftbusCache::GetUdidByUdidHash(const std::string &udidHash, std::string &udid)
408 {
409 {
410 std::lock_guard<std::mutex> mutexLock(deviceInfosMutex_);
411 for (const auto &item : deviceInfo_) {
412 if (std::string(item.second.second.deviceId) == udidHash) {
413 udid = item.first;
414 LOGI("success udid %{public}s.", GetAnonyString(udid).c_str());
415 return DM_OK;
416 }
417 }
418 }
419 LOGI("failed udidHash %{public}s.", GetAnonyString(udidHash).c_str());
420 return ERR_DM_FAILED;
421 }
422
GetUuidByUdid(const std::string & udid,std::string & uuid)423 int32_t SoftbusCache::GetUuidByUdid(const std::string &udid, std::string &uuid)
424 {
425 {
426 std::lock_guard<std::mutex> mutexLock(deviceInfosMutex_);
427 if (deviceInfo_.find(udid) != deviceInfo_.end()) {
428 uuid = deviceInfo_[udid].first;
429 LOGI("success uuid %{public}s.", GetAnonyString(uuid).c_str());
430 return DM_OK;
431 }
432 }
433 LOGI("failed udid %{public}s.", GetAnonyString(udid).c_str());
434 return ERR_DM_FAILED;
435 }
436
GetNetworkIdFromCache(const std::string & udid,std::string & networkId)437 int32_t SoftbusCache::GetNetworkIdFromCache(const std::string &udid, std::string &networkId)
438 {
439 {
440 std::lock_guard<std::mutex> mutexLock(deviceInfosMutex_);
441 if (deviceInfo_.find(udid) != deviceInfo_.end()) {
442 networkId = deviceInfo_[udid].second.networkId;
443 LOGI("success networkId %{public}s, udid %{public}s.",
444 GetAnonyString(networkId).c_str(), GetAnonyString(udid).c_str());
445 return DM_OK;
446 }
447 }
448 LOGI("failed udid %{public}s.", GetAnonyString(udid).c_str());
449 return ERR_DM_FAILED;
450 }
451
GetDeviceNameFromCache(const std::string & udid,std::string & deviceName)452 int32_t SoftbusCache::GetDeviceNameFromCache(const std::string &udid, std::string &deviceName)
453 {
454 {
455 std::lock_guard<std::mutex> mutexLock(deviceInfosMutex_);
456 if (deviceInfo_.find(udid) != deviceInfo_.end()) {
457 deviceName = deviceInfo_[udid].second.deviceName;
458 LOGI("success deviceName: %{public}s, udid: %{public}s.",
459 deviceName.c_str(), GetAnonyString(udid).c_str());
460 return DM_OK;
461 }
462 }
463 LOGI("failed udid %{public}s.", GetAnonyString(udid).c_str());
464 return ERR_DM_FAILED;
465 }
466
CheckIsOnline(const std::string & udidHash)467 bool SoftbusCache::CheckIsOnline(const std::string &udidHash)
468 {
469 {
470 std::lock_guard<std::mutex> mutexLock(deviceInfosMutex_);
471 for (const auto &item : deviceInfo_) {
472 LOGI("deviceId %{public}s, cache udidHash %{public}s.", GetAnonyString(udidHash).c_str(),
473 GetAnonyString(std::string(item.second.second.deviceId)).c_str());
474 if (std::string(item.second.second.deviceId) == udidHash) {
475 LOGI("CheckIsOnline is true.");
476 return true;
477 }
478 }
479 }
480 return false;
481 }
482
CheckIsOnlineByPeerUdid(const std::string & peerUdid)483 bool SoftbusCache::CheckIsOnlineByPeerUdid(const std::string &peerUdid)
484 {
485 {
486 std::lock_guard<std::mutex> mutexLock(deviceInfosMutex_);
487 if (deviceInfo_.find(peerUdid) != deviceInfo_.end()) {
488 LOGI("peerUdid %{public}s is online.", GetAnonyString(peerUdid).c_str());
489 return true;
490 }
491 }
492 LOGI("peerUdid %{public}s is not online.", GetAnonyString(peerUdid).c_str());
493 return false;
494 }
495 } // namespace DistributedHardware
496 } // namespace OHOS