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