• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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_device_state_manager.h"
17 
18 #include <pthread.h>
19 
20 #include "dm_adapter_manager.h"
21 #include "dm_anonymous.h"
22 #include "dm_constants.h"
23 #include "dm_crypto.h"
24 #include "dm_device_info.h"
25 #include "dm_distributed_hardware_load.h"
26 #include "dm_log.h"
27 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE))
28 #include "deviceprofile_connector.h"
29 #endif
30 
31 namespace OHOS {
32 namespace DistributedHardware {
33 const uint32_t DM_EVENT_QUEUE_CAPACITY = 20;
34 const uint32_t DM_EVENT_WAIT_TIMEOUT = 2;
35 constexpr const char* THREAD_LOOP = "ThreadLoop";
36 constexpr const char* STATE_TIMER_PREFIX = "deviceManagerTimer:stateTimer_";
DmDeviceStateManager(std::shared_ptr<SoftbusConnector> softbusConnector,std::shared_ptr<IDeviceManagerServiceListener> listener,std::shared_ptr<HiChainConnector> hiChainConnector,std::shared_ptr<HiChainAuthConnector> hiChainAuthConnector)37 DmDeviceStateManager::DmDeviceStateManager(std::shared_ptr<SoftbusConnector> softbusConnector,
38     std::shared_ptr<IDeviceManagerServiceListener> listener, std::shared_ptr<HiChainConnector> hiChainConnector,
39     std::shared_ptr<HiChainAuthConnector> hiChainAuthConnector)
40     : softbusConnector_(softbusConnector), listener_(listener), hiChainConnector_(hiChainConnector),
41     hiChainAuthConnector_(hiChainAuthConnector)
42 {
43     decisionSoName_ = "libdevicemanagerext_decision.z.so";
44     StartEventThread();
45     LOGI("DmDeviceStateManager constructor");
46 }
47 
~DmDeviceStateManager()48 DmDeviceStateManager::~DmDeviceStateManager()
49 {
50     LOGI("DmDeviceStateManager destructor");
51     softbusConnector_->UnRegisterSoftbusStateCallback();
52     StopEventThread();
53 }
54 
RegisterSoftbusStateCallback()55 int32_t DmDeviceStateManager::RegisterSoftbusStateCallback()
56 {
57     if (softbusConnector_ != nullptr) {
58         return softbusConnector_->RegisterSoftbusStateCallback(shared_from_this());
59     }
60     return DM_OK;
61 }
62 
SaveOnlineDeviceInfo(const DmDeviceInfo & info)63 void DmDeviceStateManager::SaveOnlineDeviceInfo(const DmDeviceInfo &info)
64 {
65     LOGI("SaveOnlineDeviceInfo begin, deviceId = %{public}s", GetAnonyString(std::string(info.deviceId)).c_str());
66     std::string udid;
67     if (SoftbusConnector::GetUdidByNetworkId(info.networkId, udid) == DM_OK) {
68         std::string uuid;
69         DmDeviceInfo saveInfo = info;
70         SoftbusConnector::GetUuidByNetworkId(info.networkId, uuid);
71         {
72             std::lock_guard<std::mutex> mutexLock(remoteDeviceInfosMutex_);
73             remoteDeviceInfos_[uuid] = saveInfo;
74             stateDeviceInfos_[udid] = saveInfo;
75         }
76         LOGI("SaveOnlineDeviceInfo complete, networkId = %{public}s, udid = %{public}s, uuid = %{public}s",
77              GetAnonyString(std::string(info.networkId)).c_str(),
78              GetAnonyString(udid).c_str(), GetAnonyString(uuid).c_str());
79     }
80 }
81 
DeleteOfflineDeviceInfo(const DmDeviceInfo & info)82 void DmDeviceStateManager::DeleteOfflineDeviceInfo(const DmDeviceInfo &info)
83 {
84     LOGI("DeleteOfflineDeviceInfo begin, deviceId = %{public}s", GetAnonyString(std::string(info.deviceId)).c_str());
85     std::lock_guard<std::mutex> mutexLock(remoteDeviceInfosMutex_);
86     std::string deviceId = std::string(info.deviceId);
87     for (auto iter: remoteDeviceInfos_) {
88         if (std::string(iter.second.deviceId) == deviceId) {
89             remoteDeviceInfos_.erase(iter.first);
90             LOGI("Delete remoteDeviceInfos complete");
91             break;
92         }
93     }
94     for (auto iter: stateDeviceInfos_) {
95         if (std::string(iter.second.deviceId) == deviceId) {
96             stateDeviceInfos_.erase(iter.first);
97             LOGI("Delete stateDeviceInfos complete");
98             break;
99         }
100     }
101 }
102 
OnDeviceOnline(std::string deviceId,int32_t authForm)103 void DmDeviceStateManager::OnDeviceOnline(std::string deviceId, int32_t authForm)
104 {
105     LOGI("DmDeviceStateManager::OnDeviceOnline, deviceId = %{public}s", GetAnonyString(deviceId).c_str());
106     DmDeviceInfo devInfo = softbusConnector_->GetDeviceInfoByDeviceId(deviceId);
107     if (devInfo.deviceId[0] == '\0') {
108         LOGE("deviceId is empty.");
109         return;
110     }
111     devInfo.authForm = static_cast<DmAuthForm>(authForm);
112     {
113         std::lock_guard<std::mutex> mutexLock(remoteDeviceInfosMutex_);
114         if (stateDeviceInfos_.find(deviceId) == stateDeviceInfos_.end()) {
115             stateDeviceInfos_[deviceId] = devInfo;
116         }
117     }
118     ProcessDeviceStateChange(DEVICE_STATE_ONLINE, devInfo);
119     softbusConnector_->ClearProcessInfo();
120 }
121 
OnDeviceOffline(std::string deviceId)122 void DmDeviceStateManager::OnDeviceOffline(std::string deviceId)
123 {
124     LOGI("DmDeviceStateManager::OnDeviceOffline, deviceId = %{public}s", GetAnonyString(deviceId).c_str());
125     DmDeviceInfo devInfo;
126     {
127         std::lock_guard<std::mutex> mutexLock(remoteDeviceInfosMutex_);
128         if (stateDeviceInfos_.find(deviceId) == stateDeviceInfos_.end()) {
129             LOGE("DmDeviceStateManager::OnDeviceOnline not find deviceId");
130             return;
131         }
132         devInfo = stateDeviceInfos_[deviceId];
133     }
134     ProcessDeviceStateChange(DEVICE_STATE_OFFLINE, devInfo);
135     softbusConnector_->ClearProcessInfo();
136 }
137 
HandleDeviceStatusChange(DmDeviceState devState,DmDeviceInfo & devInfo)138 void DmDeviceStateManager::HandleDeviceStatusChange(DmDeviceState devState, DmDeviceInfo &devInfo)
139 {
140     LOGI("Handle device status change: devState=%{public}d, deviceId=%{public}s.", devState,
141         GetAnonyString(devInfo.deviceId).c_str());
142     switch (devState) {
143         case DEVICE_STATE_ONLINE:
144             RegisterOffLineTimer(devInfo);
145             SaveOnlineDeviceInfo(devInfo);
146             DmDistributedHardwareLoad::GetInstance().LoadDistributedHardwareFwk();
147             ProcessDeviceStateChange(devState, devInfo);
148             softbusConnector_->ClearProcessInfo();
149             break;
150         case DEVICE_STATE_OFFLINE:
151             StartOffLineTimer(devInfo);
152             DeleteOfflineDeviceInfo(devInfo);
153             if (softbusConnector_ != nullptr) {
154                 std::string udid;
155                 softbusConnector_->GetUdidByNetworkId(devInfo.networkId, udid);
156                 softbusConnector_->EraseUdidFromMap(udid);
157             }
158             ProcessDeviceStateChange(devState, devInfo);
159             softbusConnector_->ClearProcessInfo();
160             break;
161         case DEVICE_INFO_CHANGED:
162             ChangeDeviceInfo(devInfo);
163             ProcessDeviceStateChange(devState, devInfo);
164             softbusConnector_->ClearProcessInfo();
165             break;
166         default:
167             LOGE("HandleDeviceStatusChange error, unknown device state = %{public}d", devState);
168             break;
169     }
170 }
171 
ProcessDeviceStateChange(const DmDeviceState devState,const DmDeviceInfo & devInfo)172 void DmDeviceStateManager::ProcessDeviceStateChange(const DmDeviceState devState, const DmDeviceInfo &devInfo)
173 {
174     LOGI("ProcessDeviceStateChange begin, devState = %{public}d", devState);
175     CHECK_NULL_VOID(softbusConnector_);
176     CHECK_NULL_VOID(listener_);
177     std::vector<ProcessInfo> processInfoVec = softbusConnector_->GetProcessInfo();
178     for (const auto &item : processInfoVec) {
179         if (!item.pkgName.empty()) {
180             LOGI("ProcessDeviceStateChange, pkgName = %{public}s", item.pkgName.c_str());
181             listener_->OnDeviceStateChange(item, devState, devInfo);
182         }
183     }
184 }
185 
OnDbReady(const std::string & pkgName,const std::string & uuid)186 void DmDeviceStateManager::OnDbReady(const std::string &pkgName, const std::string &uuid)
187 {
188     LOGI("OnDbReady function is called with pkgName: %{public}s and uuid = %{public}s",
189          pkgName.c_str(), GetAnonyString(uuid).c_str());
190     if (pkgName.empty() || uuid.empty()) {
191         LOGE("On db ready pkgName is empty or uuid is empty");
192         return;
193     }
194     LOGI("OnDbReady function is called with pkgName: %{public}s and uuid = %{public}s", pkgName.c_str(),
195          GetAnonyString(uuid).c_str());
196     DmDeviceInfo saveInfo;
197     {
198         std::lock_guard<std::mutex> mutexLock(remoteDeviceInfosMutex_);
199         auto iter = remoteDeviceInfos_.find(uuid);
200         if (iter == remoteDeviceInfos_.end()) {
201             LOGE("OnDbReady complete not find uuid: %{public}s", GetAnonyString(uuid).c_str());
202             return;
203         }
204         saveInfo = iter->second;
205     }
206     if (listener_ != nullptr) {
207         DmDeviceState state = DEVICE_INFO_READY;
208         ProcessInfo processInfo;
209         processInfo.pkgName = pkgName;
210         processInfo.userId = MultipleUserConnector::GetFirstForegroundUserId();
211         listener_->OnDeviceStateChange(processInfo, state, saveInfo);
212     }
213 }
214 
RegisterOffLineTimer(const DmDeviceInfo & deviceInfo)215 void DmDeviceStateManager::RegisterOffLineTimer(const DmDeviceInfo &deviceInfo)
216 {
217     std::string deviceUdid;
218     int32_t ret = softbusConnector_->GetUdidByNetworkId(deviceInfo.networkId, deviceUdid);
219     if (ret != DM_OK) {
220         LOGE("fail to get udid by networkId");
221         return;
222     }
223     char udidHash[DM_MAX_DEVICE_ID_LEN] = {0};
224     if (Crypto::GetUdidHash(deviceUdid, reinterpret_cast<uint8_t *>(udidHash)) != DM_OK) {
225         LOGE("get udidhash by udid: %{public}s failed.", GetAnonyString(deviceUdid).c_str());
226         return;
227     }
228     LOGI("Register offline timer for udidHash: %{public}s", GetAnonyString(std::string(udidHash)).c_str());
229     std::lock_guard<std::mutex> mutexLock(timerMapMutex_);
230     for (auto &iter : stateTimerInfoMap_) {
231         if ((iter.first == std::string(udidHash)) && (timer_ != nullptr)) {
232             timer_->DeleteTimer(iter.second.timerName);
233             stateTimerInfoMap_.erase(iter.first);
234             auto idIter = udidhash2udidMap_.find(udidHash);
235             if (idIter != udidhash2udidMap_.end()) {
236                 udidhash2udidMap_.erase(idIter->first);
237             }
238             break;
239         }
240     }
241     if (stateTimerInfoMap_.find(std::string(udidHash)) == stateTimerInfoMap_.end()) {
242         std::string timerName = std::string(STATE_TIMER_PREFIX) + GetAnonyString(std::string(udidHash));
243         StateTimerInfo stateTimer = {
244             .timerName = timerName,
245             .networkId = deviceInfo.networkId,
246             .isStart = false,
247         };
248         stateTimerInfoMap_[std::string(udidHash)] = stateTimer;
249     }
250     if (udidhash2udidMap_.find(std::string(udidHash)) == udidhash2udidMap_.end()) {
251         udidhash2udidMap_[std::string(udidHash)] = deviceUdid;
252     }
253 }
254 
StartOffLineTimer(const DmDeviceInfo & deviceInfo)255 void DmDeviceStateManager::StartOffLineTimer(const DmDeviceInfo &deviceInfo)
256 {
257     std::lock_guard<std::mutex> mutexLock(timerMapMutex_);
258     std::string networkId = deviceInfo.networkId;
259     LOGI("Start offline timer for networkId: %{public}s", GetAnonyString(networkId).c_str());
260     if (timer_ == nullptr) {
261         timer_ = std::make_shared<DmTimer>();
262     }
263     for (auto &iter : stateTimerInfoMap_) {
264         if ((iter.second.networkId == networkId) && !iter.second.isStart) {
265             timer_->StartTimer(iter.second.timerName, OFFLINE_TIMEOUT,
266                 [this] (std::string name) {
267                     DmDeviceStateManager::DeleteTimeOutGroup(name);
268                 });
269             iter.second.isStart = true;
270         }
271     }
272 }
273 
DeleteOffLineTimer(std::string udidHash)274 void DmDeviceStateManager::DeleteOffLineTimer(std::string udidHash)
275 {
276     std::lock_guard<std::mutex> mutexLock(timerMapMutex_);
277     LOGI("DELETE offline timer for networkId: %{public}s", GetAnonyString(udidHash).c_str());
278     if (timer_ == nullptr || udidHash.empty()) {
279         return;
280     }
281     auto iter = stateTimerInfoMap_.find(udidHash);
282     if (iter != stateTimerInfoMap_.end()) {
283         timer_->DeleteTimer(iter->second.timerName);
284         iter->second.isStart = false;
285         stateTimerInfoMap_.erase(iter->first);
286         auto idIter = udidhash2udidMap_.find(udidHash);
287         if (idIter != udidhash2udidMap_.end()) {
288             udidhash2udidMap_.erase(idIter->first);
289         }
290     }
291     return;
292 }
293 
DeleteTimeOutGroup(std::string name)294 void DmDeviceStateManager::DeleteTimeOutGroup(std::string name)
295 {
296     std::lock_guard<std::mutex> mutexLock(timerMapMutex_);
297     for (auto iter = stateTimerInfoMap_.begin(); iter != stateTimerInfoMap_.end(); iter++) {
298         if (((iter->second).timerName == name) && (hiChainConnector_ != nullptr)) {
299             auto idIter = udidhash2udidMap_.find(iter->first);
300             if (idIter == udidhash2udidMap_.end()) {
301                 LOGE("remove hichain group find deviceId: %{public}s failed.", GetAnonyString(iter->first).c_str());
302                 break;
303             }
304             LOGI("remove hichain group with deviceId: %{public}s", GetAnonyString(idIter->second).c_str());
305             hiChainConnector_->DeleteTimeOutGroup((idIter->second).c_str());
306 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE))
307             DeleteGroupByDP(idIter->second);
308             uint32_t res = DeviceProfileConnector::GetInstance().DeleteTimeOutAcl(idIter->second);
309             if (res == 0) {
310                 hiChainAuthConnector_->DeleteCredential(idIter->second,
311                                                         MultipleUserConnector::GetCurrentAccountUserID());
312             }
313 #endif
314             stateTimerInfoMap_.erase(iter);
315             break;
316         }
317     }
318 }
319 
StartEventThread()320 void DmDeviceStateManager::StartEventThread()
321 {
322     LOGI("StartEventThread begin");
323     eventTask_.threadRunning_ = true;
324     eventTask_.queueThread_ = std::thread([this]() { this->ThreadLoop(); });
325     LOGI("StartEventThread complete");
326 }
327 
StopEventThread()328 void DmDeviceStateManager::StopEventThread()
329 {
330     LOGI("StopEventThread begin");
331     eventTask_.threadRunning_ = false;
332     eventTask_.queueCond_.notify_all();
333     eventTask_.queueFullCond_.notify_all();
334     if (eventTask_.queueThread_.joinable()) {
335         eventTask_.queueThread_.join();
336     }
337     LOGI("StopEventThread complete");
338 }
339 
AddTask(const std::shared_ptr<NotifyEvent> & task)340 int32_t DmDeviceStateManager::AddTask(const std::shared_ptr<NotifyEvent> &task)
341 {
342     LOGI("AddTask begin, eventId: %{public}d", task->GetEventId());
343     {
344         std::unique_lock<std::mutex> lock(eventTask_.queueMtx_);
345         while (eventTask_.queue_.size() >= DM_EVENT_QUEUE_CAPACITY) {
346             eventTask_.queueFullCond_.wait_for(lock, std::chrono::seconds(DM_EVENT_WAIT_TIMEOUT));
347         }
348         eventTask_.queue_.push(task);
349     }
350     eventTask_.queueCond_.notify_one();
351     LOGI("AddTask complete");
352     return DM_OK;
353 }
354 
ThreadLoop()355 void DmDeviceStateManager::ThreadLoop()
356 {
357     LOGI("ThreadLoop begin");
358     int32_t ret = pthread_setname_np(pthread_self(), THREAD_LOOP);
359     if (ret != DM_OK) {
360         LOGE("ThreadLoop setname failed.");
361     }
362     while (eventTask_.threadRunning_) {
363         std::shared_ptr<NotifyEvent> task = nullptr;
364         {
365             std::unique_lock<std::mutex> lock(eventTask_.queueMtx_);
366             while (eventTask_.queue_.empty() && eventTask_.threadRunning_) {
367                 eventTask_.queueCond_.wait_for(lock, std::chrono::seconds(DM_EVENT_WAIT_TIMEOUT));
368             }
369             if (!eventTask_.queue_.empty()) {
370                 task = eventTask_.queue_.front();
371                 eventTask_.queue_.pop();
372                 eventTask_.queueFullCond_.notify_one();
373             }
374         }
375         if (task != nullptr) {
376             RunTask(task);
377         }
378     }
379     LOGI("ThreadLoop end");
380 }
381 
RunTask(const std::shared_ptr<NotifyEvent> & task)382 void DmDeviceStateManager::RunTask(const std::shared_ptr<NotifyEvent> &task)
383 {
384     LOGI("RunTask begin, eventId: %{public}d", task->GetEventId());
385     if (task->GetEventId() == DM_NOTIFY_EVENT_ONDEVICEREADY) {
386         OnDbReady(std::string(DM_PKG_NAME), task->GetDeviceId());
387     }
388     LOGI("RunTask complete");
389 }
390 
GetAuthForm(const std::string & networkId)391 DmAuthForm DmDeviceStateManager::GetAuthForm(const std::string &networkId)
392 {
393     LOGI("GetAuthForm start");
394     if (hiChainConnector_ == nullptr) {
395         LOGE("hiChainConnector_ is nullptr");
396         return DmAuthForm::INVALID_TYPE;
397     }
398 
399     if (networkId.empty()) {
400         LOGE("networkId is empty");
401         return DmAuthForm::INVALID_TYPE;
402     }
403 
404     std::string udid;
405     if (SoftbusConnector::GetUdidByNetworkId(networkId.c_str(), udid) == DM_OK) {
406         return hiChainConnector_->GetGroupType(udid);
407     }
408 
409     return DmAuthForm::INVALID_TYPE;
410 }
411 
ProcNotifyEvent(const int32_t eventId,const std::string & deviceId)412 int32_t DmDeviceStateManager::ProcNotifyEvent(const int32_t eventId, const std::string &deviceId)
413 {
414     LOGI("ProcNotifyEvent in, eventId: %{public}d", eventId);
415     return AddTask(std::make_shared<NotifyEvent>(eventId, deviceId));
416 }
417 
ChangeDeviceInfo(const DmDeviceInfo & info)418 void DmDeviceStateManager::ChangeDeviceInfo(const DmDeviceInfo &info)
419 {
420     std::lock_guard<std::mutex> mutexLock(remoteDeviceInfosMutex_);
421     for (auto iter : remoteDeviceInfos_) {
422         if (std::string(iter.second.deviceId) == std::string(info.deviceId)) {
423             if (memcpy_s(iter.second.deviceName, sizeof(iter.second.deviceName), info.deviceName,
424                          sizeof(info.deviceName)) != DM_OK) {
425                     LOGE("ChangeDeviceInfo remoteDeviceInfos copy deviceName failed");
426                     return;
427             }
428             if (memcpy_s(iter.second.networkId, sizeof(iter.second.networkId), info.networkId,
429                          sizeof(info.networkId)) != DM_OK) {
430                     LOGE("ChangeDeviceInfo remoteDeviceInfos copy networkId failed");
431                     return;
432             }
433             iter.second.deviceTypeId = info.deviceTypeId;
434             LOGI("Change remoteDeviceInfos complete");
435             break;
436         }
437     }
438     for (auto iter : stateDeviceInfos_) {
439         if (std::string(iter.second.deviceId) == std::string(info.deviceId)) {
440             if (memcpy_s(iter.second.deviceName, sizeof(iter.second.deviceName), info.deviceName,
441                          sizeof(info.deviceName)) != DM_OK) {
442                     LOGE("ChangeDeviceInfo stateDeviceInfos copy deviceName failed");
443                     return;
444             }
445             if (memcpy_s(iter.second.networkId, sizeof(iter.second.networkId), info.networkId,
446                          sizeof(info.networkId)) != DM_OK) {
447                     LOGE("ChangeDeviceInfo stateDeviceInfos copy networkId failed");
448                     return;
449             }
450             iter.second.deviceTypeId = info.deviceTypeId;
451             LOGI("Change stateDeviceInfos complete");
452             break;
453         }
454     }
455 }
456 
GetUdidByNetWorkId(std::string networkId)457 std::string DmDeviceStateManager::GetUdidByNetWorkId(std::string networkId)
458 {
459     LOGI("DmDeviceStateManager::GetUdidByNetWorkId networkId %{public}s", GetAnonyString(networkId).c_str());
460     {
461         std::lock_guard<std::mutex> mutexLock(remoteDeviceInfosMutex_);
462         for (auto &iter : stateDeviceInfos_) {
463             if (networkId == iter.second.networkId) {
464                 return iter.first;
465             }
466         }
467     }
468     LOGI("Not find udid by networkid in stateDeviceInfos.");
469     return "";
470 }
471 
472 #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE))
DeleteGroupByDP(const std::string & deviceId)473 int32_t DmDeviceStateManager::DeleteGroupByDP(const std::string &deviceId)
474 {
475     std::vector<DistributedDeviceProfile::AccessControlProfile> profiles =
476         DeviceProfileConnector::GetInstance().GetAccessControlProfile();
477     LOGI("DeleteGroupByDP, AccessControlProfile size is %{public}zu", profiles.size());
478     std::vector<std::string> delPkgNameVec;
479     for (auto &item : profiles) {
480         std::string trustDeviceId = item.GetTrustDeviceId();
481         if (trustDeviceId != deviceId) {
482             continue;
483         }
484         if (item.GetAuthenticationType() == ALLOW_AUTH_ONCE && !item.GetAccesser().GetAccesserBundleName().empty()) {
485             delPkgNameVec.push_back(item.GetAccesser().GetAccesserBundleName());
486         }
487     }
488     if (delPkgNameVec.size() == 0) {
489         LOGI("delPkgNameVec is empty");
490         return DM_OK;
491     }
492     if (hiChainConnector_ == nullptr) {
493         LOGE("hiChainConnector_ is nullptr");
494         return ERR_DM_POINT_NULL;
495     }
496     std::vector<GroupInfo> groupListExt;
497     hiChainConnector_->GetRelatedGroupsExt(deviceId, groupListExt);
498     for (auto &iter : groupListExt) {
499         for (auto &pkgName : delPkgNameVec) {
500             if (iter.groupName.find(pkgName) != std::string::npos) {
501                 int32_t ret = hiChainConnector_->DeleteGroupExt(iter.groupId);
502                 LOGI("DeleteGroupByDP delete groupId %{public}s ,result %{public}d.",
503                     GetAnonyString(iter.groupId).c_str(), ret);
504             }
505         }
506     }
507     return DM_OK;
508 }
509 #endif
510 
CheckIsOnline(const std::string & udid)511 bool DmDeviceStateManager::CheckIsOnline(const std::string &udid)
512 {
513     LOGI("DmDeviceStateManager::CheckIsOnline start.");
514     {
515         std::lock_guard<std::mutex> mutexLock(remoteDeviceInfosMutex_);
516         if (stateDeviceInfos_.find(udid) != stateDeviceInfos_.end()) {
517             return true;
518         }
519     }
520     return false;
521 }
522 
HandleDeviceScreenStatusChange(DmDeviceInfo & devInfo)523 void DmDeviceStateManager::HandleDeviceScreenStatusChange(DmDeviceInfo &devInfo)
524 {
525     CHECK_NULL_VOID(softbusConnector_);
526     CHECK_NULL_VOID(listener_);
527     std::vector<ProcessInfo> processInfos = softbusConnector_->GetProcessInfo();
528     softbusConnector_->ClearProcessInfo();
529     LOGI("pkgName size: %{public}zu", processInfos.size());
530     for (const auto &item : processInfos) {
531         listener_->OnDeviceScreenStateChange(item, devInfo);
532     }
533 }
534 } // namespace DistributedHardware
535 } // namespace OHOS