1 /*
2 * Copyright (c) 2021-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 "component_manager.h"
17
18 #include <cinttypes>
19 #include <future>
20 #include <string>
21 #include <thread>
22
23 #include "ipc_object_stub.h"
24 #include "iservice_registry.h"
25 #include "system_ability_definition.h"
26
27 #include "anonymous_string.h"
28 #include "capability_info_manager.h"
29 #include "component_disable.h"
30 #include "component_enable.h"
31 #include "component_loader.h"
32 #include "constants.h"
33 #include "dh_context.h"
34 #include "dh_utils_hitrace.h"
35 #include "dh_utils_hisysevent.h"
36 #include "dh_utils_tool.h"
37 #include "distributed_hardware_errno.h"
38 #include "distributed_hardware_log.h"
39 #include "enabled_comps_dump.h"
40 #include "monitor_task_timer.h"
41 #include "task_executor.h"
42 #include "task_factory.h"
43 #include "version_info_manager.h"
44 #include "version_manager.h"
45
46 namespace OHOS {
47 namespace DistributedHardware {
48 #undef DH_LOG_TAG
49 #define DH_LOG_TAG "ComponentManager"
50
51 IMPLEMENT_SINGLE_INSTANCE(ComponentManager);
52
53 namespace {
54 constexpr int32_t ENABLE_RETRY_MAX_TIMES = 30;
55 constexpr int32_t DISABLE_RETRY_MAX_TIMES = 30;
56 constexpr int32_t ENABLE_PARAM_RETRY_TIME = 500 * 1000;
57 const int32_t INVALID_SA_ID = -1;
58 }
59
ComponentManager()60 ComponentManager::ComponentManager() : compSource_({}), compSink_({}), compSrcSaId_({}),
61 compMonitorPtr_(std::make_shared<ComponentMonitor>())
62 {
63 DHLOGI("Ctor ComponentManager");
64 }
65
~ComponentManager()66 ComponentManager::~ComponentManager()
67 {
68 DHLOGD("Dtor ComponentManager");
69 }
70
Init()71 int32_t ComponentManager::Init()
72 {
73 DHLOGI("start.");
74 DHTraceStart(COMPONENT_INIT_START);
75 if (!InitCompSource()) {
76 DHLOGE("InitCompSource failed.");
77 DHTraceEnd();
78 return ERR_DH_FWK_COMPONENT_INIT_SOURCE_FAILED;
79 }
80 if (!InitCompSink()) {
81 DHLOGE("InitCompSink failed.");
82 compSource_.clear();
83 DHTraceEnd();
84 return ERR_DH_FWK_COMPONENT_INIT_SINK_FAILED;
85 }
86
87 if (compMonitorPtr_ == nullptr) {
88 DHLOGE("compMonitorPtr_ is null.");
89 return ERR_DH_FWK_COMPONENT_MONITOR_NULL;
90 }
91 for (const auto &comp : compSource_) {
92 if (compSrcSaId_.find(comp.first) == compSrcSaId_.end()) {
93 continue;
94 }
95 compMonitorPtr_->AddSAMonitor(compSrcSaId_.at(comp.first));
96 }
97
98 auto sourceResult = StartSource();
99 auto sinkResult = StartSink();
100
101 if (!WaitForResult(Action::START_SOURCE, sourceResult)) {
102 DHLOGE("StartSource failed, some virtual components maybe cannot work, but want to continue");
103 HiSysEventWriteMsg(DHFWK_INIT_FAIL, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
104 "dhfwk start source failed.");
105 }
106 if (!WaitForResult(Action::START_SINK, sinkResult)) {
107 DHLOGE("StartSink failed, some virtual components maybe cannot work, but want to continue");
108 HiSysEventWriteMsg(DHFWK_INIT_FAIL, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
109 "dhfwk start sink failed.");
110 }
111 MonitorTaskTimer::GetInstance().StartTimer();
112 DHLOGI("Init component success");
113 DHTraceEnd();
114 return DH_FWK_SUCCESS;
115 }
116
UnInit()117 int32_t ComponentManager::UnInit()
118 {
119 DHLOGI("start.");
120 if (compMonitorPtr_ == nullptr) {
121 DHLOGE("compMonitorPtr_ is null.");
122 return ERR_DH_FWK_COMPONENT_MONITOR_NULL;
123 }
124 for (const auto &comp : compSource_) {
125 if (compSrcSaId_.find(comp.first) == compSrcSaId_.end()) {
126 continue;
127 }
128 compMonitorPtr_->RemoveSAMonitor(compSrcSaId_.at(comp.first));
129 }
130 auto sourceResult = StopSource();
131 auto sinkResult = StopSink();
132
133 if (!WaitForResult(Action::STOP_SOURCE, sourceResult)) {
134 DHLOGE("StopSource failed, but want to continue");
135 }
136 if (!WaitForResult(Action::STOP_SINK, sinkResult)) {
137 DHLOGE("StopSource failed, but want to continue");
138 }
139
140 compSource_.clear();
141 compSink_.clear();
142
143 MonitorTaskTimer::GetInstance().StopTimer();
144 DHLOGI("Release component success");
145 return DH_FWK_SUCCESS;
146 }
147
StartSource()148 ActionResult ComponentManager::StartSource()
149 {
150 DHLOGI("start.");
151 std::unordered_map<DHType, std::shared_future<int32_t>> futures;
152 std::string uuid = DHContext::GetInstance().GetDeviceInfo().uuid;
153 for (const auto &item : compSource_) {
154 CompVersion compversion;
155 VersionManager::GetInstance().GetCompVersion(uuid, item.first, compversion);
156 auto params = compversion.sourceVersion;
157 auto future = std::async(std::launch::async, [item, params]() { return item.second->InitSource(params); });
158 futures.emplace(item.first, future.share());
159 }
160 return futures;
161 }
162
StartSource(DHType dhType)163 ActionResult ComponentManager::StartSource(DHType dhType)
164 {
165 DHLOGI("Start Source, dhType: %" PRIu32, (uint32_t)dhType);
166 std::unordered_map<DHType, std::shared_future<int32_t>> futures;
167 if (compSource_.find(dhType) == compSource_.end()) {
168 DHLOGE("Component for DHType: %" PRIu32 " not init source handler", (uint32_t)dhType);
169 return futures;
170 }
171
172 std::string uuid = DHContext::GetInstance().GetDeviceInfo().uuid;
173 CompVersion compVersion;
174 VersionManager::GetInstance().GetCompVersion(uuid, dhType, compVersion);
175 auto params = compVersion.sourceVersion;
176 auto future = std::async(std::launch::async, [this, dhType, params]() {
177 return compSource_[dhType]->InitSource(params);
178 });
179 futures.emplace(dhType, future.share());
180
181 return futures;
182 }
183
StartSink()184 ActionResult ComponentManager::StartSink()
185 {
186 DHLOGI("start.");
187 std::unordered_map<DHType, std::shared_future<int32_t>> futures;
188 std::string uuid = DHContext::GetInstance().GetDeviceInfo().uuid;
189 for (const auto &item : compSink_) {
190 CompVersion compversion;
191 VersionManager::GetInstance().GetCompVersion(uuid, item.first, compversion);
192 auto params = compversion.sinkVersion;
193 auto future = std::async(std::launch::async, [item, params]() { return item.second->InitSink(params); });
194 futures.emplace(item.first, future.share());
195 }
196 return futures;
197 }
198
StartSink(DHType dhType)199 ActionResult ComponentManager::StartSink(DHType dhType)
200 {
201 DHLOGI("Start Sink, dhType: %" PRIu32, (uint32_t)dhType);
202 std::unordered_map<DHType, std::shared_future<int32_t>> futures;
203 if (compSink_.find(dhType) == compSink_.end()) {
204 DHLOGE("Component for DHType: %" PRIu32 " not init sink handler", (uint32_t)dhType);
205 return futures;
206 }
207
208 std::string uuid = DHContext::GetInstance().GetDeviceInfo().uuid;
209 CompVersion compVersion;
210 VersionManager::GetInstance().GetCompVersion(uuid, dhType, compVersion);
211 auto params = compVersion.sinkVersion;
212 auto future = std::async(std::launch::async, [this, dhType, params]() {
213 return compSink_[dhType]->InitSink(params);
214 });
215 futures.emplace(dhType, future.share());
216
217 return futures;
218 }
219
StopSource()220 ActionResult ComponentManager::StopSource()
221 {
222 DHLOGI("start.");
223 std::unordered_map<DHType, std::shared_future<int32_t>> futures;
224 for (const auto &item : compSource_) {
225 auto future = std::async(std::launch::async, [item]() { return item.second->ReleaseSource(); });
226 futures.emplace(item.first, future.share());
227 }
228 return futures;
229 }
230
StopSink()231 ActionResult ComponentManager::StopSink()
232 {
233 DHLOGI("start.");
234 std::unordered_map<DHType, std::shared_future<int32_t>> futures;
235 for (const auto &item : compSink_) {
236 auto future = std::async(std::launch::async, [item]() {
237 int32_t status = item.second->ReleaseSink();
238 IHardwareHandler *hardwareHandler = nullptr;
239 status = ComponentLoader::GetInstance().GetHardwareHandler(item.first, hardwareHandler);
240 if (status != DH_FWK_SUCCESS || hardwareHandler == nullptr) {
241 DHLOGE("GetHardwareHandler %#X failed", item.first);
242 return status;
243 }
244 hardwareHandler->UnRegisterPluginListener();
245 return status;
246 });
247
248 futures.emplace(item.first, future.share());
249 }
250 return futures;
251 }
252
WaitForResult(const Action & action,ActionResult actionsResult)253 bool ComponentManager::WaitForResult(const Action &action, ActionResult actionsResult)
254 {
255 DHLOGD("start.");
256 auto ret = true;
257 for (auto &iter : actionsResult) {
258 auto result = iter.second.get();
259 DHLOGI("action = %d, compType = %#X, ret = %d.", static_cast<int32_t>(action), iter.first, result);
260 if (result != DH_FWK_SUCCESS) {
261 ret = false;
262 DHLOGE("there is error, but want to continue.");
263 }
264 }
265 DHLOGD("end.");
266 return ret;
267 }
268
InitCompSource()269 bool ComponentManager::InitCompSource()
270 {
271 auto compTypes = ComponentLoader::GetInstance().GetAllCompTypes();
272 for (const auto &type : compTypes) {
273 IDistributedHardwareSource *sourcePtr = nullptr;
274 auto ret = ComponentLoader::GetInstance().GetSource(type, sourcePtr);
275 if (ret != DH_FWK_SUCCESS) {
276 DHLOGW("GetSource failed, compType = %#X, ret = %d.", type, ret);
277 continue;
278 }
279 if (sourcePtr == nullptr) {
280 DHLOGW("sourcePtr is null, compType = %#X.", type);
281 continue;
282 }
283 compSource_.insert(std::make_pair(type, sourcePtr));
284
285 int32_t saId = ComponentLoader::GetInstance().GetSourceSaId(type);
286 if (saId != INVALID_SA_ID) {
287 compSrcSaId_.insert(std::make_pair(type, saId));
288 }
289 }
290 return !compSource_.empty();
291 }
292
InitCompSink()293 bool ComponentManager::InitCompSink()
294 {
295 auto compTypes = ComponentLoader::GetInstance().GetAllCompTypes();
296 for (const auto &type : compTypes) {
297 IDistributedHardwareSink *sinkPtr = nullptr;
298 auto ret = ComponentLoader::GetInstance().GetSink(type, sinkPtr);
299 if (ret != DH_FWK_SUCCESS) {
300 DHLOGW("GetSink failed, compType = %#X, ret = %d.", type, ret);
301 continue;
302 }
303 if (sinkPtr == nullptr) {
304 DHLOGW("sinkPtr is null, compType = %#X.", type);
305 continue;
306 }
307 compSink_.insert(std::make_pair(type, sinkPtr));
308 }
309 return !compSink_.empty();
310 }
311
Enable(const std::string & networkId,const std::string & uuid,const std::string & dhId,const DHType dhType)312 int32_t ComponentManager::Enable(const std::string &networkId, const std::string &uuid, const std::string &dhId,
313 const DHType dhType)
314 {
315 DHLOGI("start.");
316 auto find = compSource_.find(dhType);
317 if (find == compSource_.end()) {
318 DHLOGE("can not find handler for dhId = %s.", GetAnonyString(dhId).c_str());
319 return ERR_DH_FWK_PARA_INVALID;
320 }
321 EnableParam param;
322 auto ret = GetEnableParam(networkId, uuid, dhId, dhType, param);
323 if (ret != DH_FWK_SUCCESS) {
324 DHLOGE("GetEnableParam failed, uuid = %s, dhId = %s, errCode = %d", GetAnonyString(uuid).c_str(),
325 GetAnonyString(dhId).c_str(), ret);
326 for (int32_t retryCount = 0; retryCount < ENABLE_RETRY_MAX_TIMES; retryCount++) {
327 if (!DHContext::GetInstance().IsDeviceOnline(uuid)) {
328 DHLOGE("device is already offline, no need try GetEnableParam, uuid = %s",
329 GetAnonyString(uuid).c_str());
330 return ret;
331 }
332 if (GetEnableParam(networkId, uuid, dhId, dhType, param) == DH_FWK_SUCCESS) {
333 DHLOGE("GetEnableParam success, retryCount = %d", retryCount);
334 break;
335 }
336 DHLOGE("GetEnableParam failed, retryCount = %d", retryCount);
337 usleep(ENABLE_PARAM_RETRY_TIME);
338 }
339 }
340
341 auto compEnable = std::make_shared<ComponentEnable>();
342 auto result = compEnable->Enable(networkId, dhId, param, find->second);
343 if (result != DH_FWK_SUCCESS) {
344 for (int32_t retryCount = 0; retryCount < ENABLE_RETRY_MAX_TIMES; retryCount++) {
345 if (!DHContext::GetInstance().IsDeviceOnline(uuid)) {
346 DHLOGE("device is already offline, no need try enable, uuid = %s", GetAnonyString(uuid).c_str());
347 return result;
348 }
349 if (compEnable->Enable(networkId, dhId, param, find->second) == DH_FWK_SUCCESS) {
350 DHLOGE("enable success, retryCount = %d", retryCount);
351 EnabledCompsDump::GetInstance().DumpEnabledComp(networkId, dhType, dhId);
352 return DH_FWK_SUCCESS;
353 }
354 DHLOGE("enable failed, retryCount = %d", retryCount);
355 }
356 return result;
357 }
358 DHLOGI("enable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(),
359 GetAnonyString(dhId).c_str());
360 EnabledCompsDump::GetInstance().DumpEnabledComp(networkId, dhType, dhId);
361
362 return result;
363 }
364
Disable(const std::string & networkId,const std::string & uuid,const std::string & dhId,const DHType dhType)365 int32_t ComponentManager::Disable(const std::string &networkId, const std::string &uuid, const std::string &dhId,
366 const DHType dhType)
367 {
368 auto find = compSource_.find(dhType);
369 if (find == compSource_.end()) {
370 DHLOGE("can not find handler for dhId = %s.", dhId.c_str());
371 return ERR_DH_FWK_PARA_INVALID;
372 }
373
374 auto compDisable = std::make_shared<ComponentDisable>();
375 auto result = compDisable->Disable(networkId, dhId, find->second);
376 if (result != DH_FWK_SUCCESS) {
377 for (int32_t retryCount = 0; retryCount < DISABLE_RETRY_MAX_TIMES; retryCount++) {
378 if (DHContext::GetInstance().IsDeviceOnline(uuid)) {
379 DHLOGE("device is already online, no need try disable, uuid = %s", GetAnonyString(uuid).c_str());
380 return result;
381 }
382 if (compDisable->Disable(networkId, dhId, find->second) == DH_FWK_SUCCESS) {
383 DHLOGE("disable success, retryCount = %d", retryCount);
384 EnabledCompsDump::GetInstance().DumpDisabledComp(networkId, dhType, dhId);
385 return DH_FWK_SUCCESS;
386 }
387 DHLOGE("disable failed, retryCount = %d", retryCount);
388 }
389 return result;
390 }
391 DHLOGI("disable result is %d, uuid = %s, dhId = %s", result, GetAnonyString(uuid).c_str(),
392 GetAnonyString(dhId).c_str());
393 EnabledCompsDump::GetInstance().DumpDisabledComp(networkId, dhType, dhId);
394
395 return result;
396 }
397
GetDHType(const std::string & uuid,const std::string & dhId) const398 DHType ComponentManager::GetDHType(const std::string &uuid, const std::string &dhId) const
399 {
400 std::shared_ptr<CapabilityInfo> capability = nullptr;
401 auto ret = CapabilityInfoManager::GetInstance()->GetCapability(GetDeviceIdByUUID(uuid), dhId, capability);
402 if ((ret == DH_FWK_SUCCESS) && (capability != nullptr)) {
403 return capability->GetDHType();
404 }
405 DHLOGE("get dhType failed, uuid = %s, dhId = %s", GetAnonyString(uuid).c_str(),
406 GetAnonyString(dhId).c_str());
407 return DHType::UNKNOWN;
408 }
409
GetEnableParam(const std::string & networkId,const std::string & uuid,const std::string & dhId,DHType dhType,EnableParam & param)410 int32_t ComponentManager::GetEnableParam(const std::string &networkId, const std::string &uuid,
411 const std::string &dhId, DHType dhType, EnableParam ¶m)
412 {
413 std::shared_ptr<CapabilityInfo> capability = nullptr;
414 auto ret = CapabilityInfoManager::GetInstance()->GetCapability(GetDeviceIdByUUID(uuid), dhId, capability);
415 if ((ret != DH_FWK_SUCCESS) || (capability == nullptr)) {
416 DHLOGE("GetCapability failed, uuid =%s, dhId = %s, errCode = %d", GetAnonyString(uuid).c_str(),
417 GetAnonyString(dhId).c_str(), ret);
418 return ret;
419 }
420
421 param.attrs = capability->GetDHAttrs();
422 std::string sinkVersion("");
423 ret = GetSinkVersion(networkId, uuid, dhType, sinkVersion);
424 if (ret != DH_FWK_SUCCESS) {
425 DHLOGE("Get sink version failed, uuid = %s, dhId = %s, dhType = %#X,", GetAnonyString(uuid).c_str(),
426 GetAnonyString(dhId).c_str(), dhType);
427 return ERR_DH_FWK_COMPONENT_GET_SINK_VERSION_FAILED;
428 }
429 param.version = sinkVersion;
430 DHLOGI("success. uuid =%s, dhId = %s, version = %s", GetAnonyString(uuid).c_str(),
431 GetAnonyString(dhId).c_str(), param.version.c_str());
432
433 return DH_FWK_SUCCESS;
434 }
435
GetSinkVersionFromVerMgr(const std::string & uuid,const DHType dhType,std::string & sinkVersion)436 int32_t ComponentManager::GetSinkVersionFromVerMgr(const std::string &uuid, const DHType dhType,
437 std::string &sinkVersion)
438 {
439 CompVersion compversion;
440 int32_t ret = VersionManager::GetInstance().GetCompVersion(uuid, dhType, compversion);
441 if (ret != DH_FWK_SUCCESS) {
442 DHLOGE("Get sink version from version Manager failed, uuid =%s, dhType = %#X, errCode = %d",
443 GetAnonyString(uuid).c_str(), dhType, ret);
444 return ret;
445 }
446 DHLOGI("Get sink version from version mgr success, sinkVersion = %s, uuid = %s, dhType = %#X",
447 compversion.sinkVersion.c_str(), GetAnonyString(uuid).c_str(), dhType);
448 sinkVersion = compversion.sinkVersion;
449 return DH_FWK_SUCCESS;
450 }
451
GetSinkVersionFromVerInfoMgr(const std::string & uuid,const DHType dhType,std::string & sinkVersion)452 int32_t ComponentManager::GetSinkVersionFromVerInfoMgr(const std::string &uuid, const DHType dhType,
453 std::string &sinkVersion)
454 {
455 VersionInfo versionInfo;
456 int32_t ret = VersionInfoManager::GetInstance()->GetVersionInfoByDeviceId(GetDeviceIdByUUID(uuid), versionInfo);
457 if (ret != DH_FWK_SUCCESS) {
458 DHLOGE("Get sink version from Version info Manager failed, uuid =%s, dhType = %#X, errCode = %d",
459 GetAnonyString(uuid).c_str(), dhType, ret);
460 return ret;
461 }
462 auto iter = versionInfo.compVersions.find(dhType);
463 if (iter == versionInfo.compVersions.end()) {
464 DHLOGE("can not find component version for dhType = %d", dhType);
465 return ERR_DH_FWK_COMPONENT_DHTYPE_NOT_FOUND;
466 }
467 DHLOGI("Get SinkVersion from version info mgr success, sinkVersion = %s, uuid = %s, dhType = %#X",
468 iter->second.sinkVersion.c_str(), GetAnonyString(uuid).c_str(), dhType);
469 UpdateVersionCache(uuid, versionInfo);
470 sinkVersion = iter->second.sinkVersion;
471 return DH_FWK_SUCCESS;
472 }
473
GetSinkVersion(const std::string & networkId,const std::string & uuid,DHType dhType,std::string & sinkVersion)474 int32_t ComponentManager::GetSinkVersion(const std::string &networkId, const std::string &uuid,
475 DHType dhType, std::string &sinkVersion)
476 {
477 int32_t ret = GetSinkVersionFromVerMgr(uuid, dhType, sinkVersion);
478 if ((ret == DH_FWK_SUCCESS) && (!sinkVersion.empty())) {
479 return DH_FWK_SUCCESS;
480 }
481
482 ret = GetSinkVersionFromVerInfoMgr(uuid, dhType, sinkVersion);
483 if ((ret == DH_FWK_SUCCESS) && (!sinkVersion.empty())) {
484 return DH_FWK_SUCCESS;
485 }
486
487 return ret;
488 }
489
UpdateVersionCache(const std::string & uuid,const VersionInfo & versionInfo)490 void ComponentManager::UpdateVersionCache(const std::string &uuid, const VersionInfo &versionInfo)
491 {
492 DHVersion dhVersion;
493 dhVersion.uuid = uuid;
494 dhVersion.dhVersion = versionInfo.dhVersion;
495 dhVersion.compVersions = versionInfo.compVersions;
496 VersionManager::GetInstance().AddDHVersion(uuid, dhVersion);
497 }
498
DumpLoadedComps(std::set<DHType> & compSourceType,std::set<DHType> & compSinkType)499 void ComponentManager::DumpLoadedComps(std::set<DHType> &compSourceType, std::set<DHType> &compSinkType)
500 {
501 for (auto compSource : compSource_) {
502 compSourceType.emplace(compSource.first);
503 }
504 for (auto compSink : compSink_) {
505 compSinkType.emplace(compSink.first);
506 }
507 }
508
Recover(DHType dhType)509 void ComponentManager::Recover(DHType dhType)
510 {
511 std::thread(&ComponentManager::DoRecover, this, dhType).detach();
512 }
513
DoRecover(DHType dhType)514 void ComponentManager::DoRecover(DHType dhType)
515 {
516 // step1: restart sa process
517 ReStartSA(dhType);
518 // step2: recover distributed hardware virtual driver
519 RecoverDistributedHardware(dhType);
520 }
521
ReStartSA(DHType dhType)522 void ComponentManager::ReStartSA(DHType dhType)
523 {
524 DHLOGI("Restart SA for DHType %" PRIu32, (uint32_t)dhType);
525 auto sourceResult = StartSource(dhType);
526 auto sinkResult = StartSink(dhType);
527
528 if (!WaitForResult(Action::START_SOURCE, sourceResult)) {
529 DHLOGE("ReStartSource failed, DHType: %" PRIu32, (uint32_t)dhType);
530 }
531
532 if (!WaitForResult(Action::START_SINK, sinkResult)) {
533 DHLOGE("ReStartSink failed, DHType: %" PRIu32, (uint32_t)dhType);
534 }
535 DHLOGI("Finish Restart");
536 }
537
RecoverDistributedHardware(DHType dhType)538 void ComponentManager::RecoverDistributedHardware(DHType dhType)
539 {
540 CapabilityInfoMap capabilityMap;
541 CapabilityInfoManager::GetInstance()->GetDataByDHType(dhType, capabilityMap);
542 for (const auto &capInfo : capabilityMap) {
543 std::string uuid = DHContext::GetInstance().GetUUIDByDeviceId(capInfo.second->GetDeviceId());
544 if (uuid.empty()) {
545 DHLOGE("Can not find uuid by capability deviceId: %s",
546 GetAnonyString(capInfo.second->GetDeviceId()).c_str());
547 continue;
548 }
549
550 std::string networkId = DHContext::GetInstance().GetNetworkIdByUUID(uuid);
551 if (networkId.empty()) {
552 DHLOGI("Can not find network id by uuid: %s", GetAnonyString(uuid).c_str());
553 continue;
554 }
555
556 TaskParam taskParam = {
557 .networkId = networkId,
558 .uuid = uuid,
559 .dhId = capInfo.second->GetDHId(),
560 .dhType = capInfo.second->GetDHType()
561 };
562 auto task = TaskFactory::GetInstance().CreateTask(TaskType::ENABLE, taskParam, nullptr);
563 TaskExecutor::GetInstance().PushTask(task);
564 }
565 }
566 } // namespace DistributedHardware
567 } // namespace OHOS
568