• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 "distributed_hardware_service.h"
17 
18 #include <cinttypes>
19 
20 #include "constants.h"
21 #include "if_system_ability_manager.h"
22 #include "ipc_skeleton.h"
23 #include "ipc_types.h"
24 #include "ipublisher_listener.h"
25 #include "iservice_registry.h"
26 #include "cJSON.h"
27 #include "string_ex.h"
28 #include "system_ability_definition.h"
29 
30 #include "access_manager.h"
31 #include "av_trans_control_center.h"
32 #include "capability_info_manager.h"
33 #include "meta_info_manager.h"
34 #include "component_manager.h"
35 #include "dh_context.h"
36 #include "dh_utils_tool.h"
37 #include "dh_utils_hisysevent.h"
38 #include "distributed_hardware_fwk_kit_paras.h"
39 #include "distributed_hardware_errno.h"
40 #include "distributed_hardware_log.h"
41 #include "distributed_hardware_manager_factory.h"
42 #include "publisher.h"
43 #include "task_executor.h"
44 #include "task_factory.h"
45 
46 namespace OHOS {
47 namespace DistributedHardware {
48 #undef DH_LOG_TAG
49 #define DH_LOG_TAG "DistributedHardwareService"
50 REGISTER_SYSTEM_ABILITY_BY_ID(DistributedHardwareService, DISTRIBUTED_HARDWARE_SA_ID, true);
51 namespace {
52     constexpr int32_t INIT_BUSINESS_DELAY_TIME_MS = 5 * 100;
53     const std::string INIT_TASK_ID = "CheckAndInitDH";
54     const std::string LOCAL_NETWORKID_ALIAS = "local";
55 }
56 
DistributedHardwareService(int32_t saId,bool runOnCreate)57 DistributedHardwareService::DistributedHardwareService(int32_t saId, bool runOnCreate)
58     : SystemAbility(saId, runOnCreate)
59 {
60 }
61 
OnStart()62 void DistributedHardwareService::OnStart()
63 {
64     DHLOGI("DistributedHardwareService::OnStart start");
65     HiSysEventWriteMsg(DHFWK_INIT_BEGIN, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
66         "dhfwk sa start on demand.");
67 
68     if (state_ == ServiceRunningState::STATE_RUNNING) {
69         DHLOGI("DistributedHardwareService has already started.");
70         return;
71     }
72     if (!Init()) {
73         DHLOGE("failed to init DistributedHardwareService");
74         return;
75     }
76     state_ = ServiceRunningState::STATE_RUNNING;
77     DHLOGI("DistributedHardwareService::OnStart start service success.");
78 }
79 
Init()80 bool DistributedHardwareService::Init()
81 {
82     DHLOGI("DistributedHardwareService::Init ready to init.");
83     if (!registerToService_) {
84         bool ret = Publish(this);
85         if (!ret) {
86             DHLOGE("DistributedHardwareService::Init Publish failed!");
87             HiSysEventWriteMsg(DHFWK_INIT_FAIL, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
88                 "dhfwk sa init publish failed.");
89             return false;
90         }
91         registerToService_ = true;
92     }
93     std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create(true);
94     eventHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
95     auto executeInnerFunc = [this] { DoBusinessInit(); };
96     eventHandler_->PostTask(executeInnerFunc, INIT_TASK_ID, 0);
97     DHLOGI("DistributedHardwareService::Init success.");
98     HiSysEventWriteMsg(DHFWK_INIT_END, OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
99         "dhfwk sa init success.");
100     return true;
101 }
102 
InitLocalDevInfo()103 void DistributedHardwareService::InitLocalDevInfo()
104 {
105     DHLOGI("Init Local device info in DB");
106     DistributedHardwareManagerFactory::GetInstance().InitLocalDevInfo();
107 }
108 
DoBusinessInit()109 bool DistributedHardwareService::DoBusinessInit()
110 {
111     if (!IsDepSAStart()) {
112         DHLOGW("Depend sa not start");
113         auto executeInnerFunc = [this] { DoBusinessInit(); };
114         eventHandler_->PostTask(executeInnerFunc, INIT_TASK_ID, INIT_BUSINESS_DELAY_TIME_MS);
115         return false;
116     }
117 
118     DHLOGI("Init AccessManager");
119     auto ret = AccessManager::GetInstance()->Init();
120     if (ret != DH_FWK_SUCCESS) {
121         DHLOGE("DistributedHardwareService::Init failed.");
122         HiSysEventWriteErrCodeMsg(DHFWK_INIT_FAIL, OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
123             ret, "dhfwk sa AccessManager init fail.");
124     }
125     InitLocalDevInfo();
126     AccessManager::GetInstance()->CheckTrustedDeviceOnline();
127     return true;
128 }
129 
IsDepSAStart()130 bool DistributedHardwareService::IsDepSAStart()
131 {
132     sptr<ISystemAbilityManager> saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
133     if (saMgr == nullptr) {
134         DHLOGE("Get System Ability Manager failed");
135         return false;
136     }
137     DHLOGI("Check DSoftbus sa");
138     sptr<IRemoteObject> remoteObject = saMgr->CheckSystemAbility(SOFTBUS_SERVER_SA_ID);
139     if (remoteObject == nullptr) {
140         DHLOGW("DSoftbus not start");
141         return false;
142     }
143     DHLOGI("Check KVDB sa");
144     remoteObject = saMgr->CheckSystemAbility(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID);
145     if (remoteObject == nullptr) {
146         DHLOGW("KVDB not start");
147         return false;
148     }
149     DHLOGI("Check DM sa");
150     remoteObject = saMgr->CheckSystemAbility(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID);
151     if (remoteObject == nullptr) {
152         DHLOGW("DM not start");
153         return false;
154     }
155     return true;
156 }
157 
OnStop()158 void DistributedHardwareService::OnStop()
159 {
160     DHLOGI("DistributedHardwareService::OnStop ready to stop service.");
161     state_ = ServiceRunningState::STATE_NOT_START;
162     registerToService_ = false;
163 }
164 
RegisterPublisherListener(const DHTopic topic,const sptr<IPublisherListener> listener)165 int32_t DistributedHardwareService::RegisterPublisherListener(const DHTopic topic,
166     const sptr<IPublisherListener> listener)
167 {
168     Publisher::GetInstance().RegisterListener(topic, listener);
169     return DH_FWK_SUCCESS;
170 }
171 
UnregisterPublisherListener(const DHTopic topic,const sptr<IPublisherListener> listener)172 int32_t DistributedHardwareService::UnregisterPublisherListener(const DHTopic topic,
173     const sptr<IPublisherListener> listener)
174 {
175     Publisher::GetInstance().UnregisterListener(topic, listener);
176     return DH_FWK_SUCCESS;
177 }
178 
PublishMessage(const DHTopic topic,const std::string & msg)179 int32_t DistributedHardwareService::PublishMessage(const DHTopic topic, const std::string &msg)
180 {
181     DHContext::GetInstance();
182     Publisher::GetInstance().PublishMessage(topic, msg);
183     return DH_FWK_SUCCESS;
184 }
185 
QueryLocalSysSpec(const QueryLocalSysSpecType spec)186 std::string DistributedHardwareService::QueryLocalSysSpec(const QueryLocalSysSpecType spec)
187 {
188     DeviceInfo localDevInfo = DHContext::GetInstance().GetDeviceInfo();
189     std::vector<std::shared_ptr<CapabilityInfo>> resInfos;
190     CapabilityInfoManager::GetInstance()->GetCapabilitiesByDeviceId(localDevInfo.deviceId, resInfos);
191     DHType targetDhType = DHType::UNKNOWN;
192     std::string targetKey = "";
193     switch (spec) {
194         case QueryLocalSysSpecType::HISTREAMER_AUDIO_ENCODER:
195             targetKey = KEY_HISTREAMER_AUDIO_ENCODER;
196             targetDhType = DHType::AUDIO;
197             break;
198         case QueryLocalSysSpecType::HISTREAMER_AUDIO_DECODER:
199             targetKey = KEY_HISTREAMER_AUDIO_DECODER;
200             targetDhType = DHType::AUDIO;
201             break;
202         case QueryLocalSysSpecType::HISTREAMER_VIDEO_ENCODER:
203             targetKey = KEY_HISTREAMER_VIDEO_ENCODER;
204             targetDhType = DHType::SCREEN;
205             break;
206         case QueryLocalSysSpecType::HISTREAMER_VIDEO_DECODER:
207             targetKey = KEY_HISTREAMER_VIDEO_DECODER;
208             targetDhType = DHType::SCREEN;
209             break;
210         default:
211             break;
212     }
213 
214     DHLOGE("QueryLocalSysSpec targetKey: %{public}s, targetDhType: %{public}" PRIu32, targetKey.c_str(),
215         (uint32_t)targetDhType);
216     if (targetDhType == DHType::UNKNOWN) {
217         DHLOGE("Can not find matched dhtype");
218         return "";
219     }
220 
221     std::string attrs = "";
222     for (const auto &cap : resInfos) {
223         if (cap->GetDHType() != targetDhType) {
224             continue;
225         }
226         attrs = cap->GetDHAttrs();
227         break;
228     }
229     if (attrs.empty()) {
230         DHLOGE("Can not find dh attrs");
231         return "";
232     }
233 
234     return QueryDhSysSpec(targetKey, attrs);
235 }
236 
QueryDhSysSpec(const std::string & targetKey,std::string & attrs)237 std::string DistributedHardwareService::QueryDhSysSpec(const std::string &targetKey, std::string &attrs)
238 {
239     cJSON *attrJson = cJSON_Parse(attrs.c_str());
240     if (attrJson == NULL) {
241         DHLOGE("attrs json is invalid, attrs: %{public}s", attrs.c_str());
242         return "";
243     }
244     cJSON *targetKeyJson = cJSON_GetObjectItem(attrJson, targetKey.c_str());
245     if (!IsString(targetKeyJson)) {
246         DHLOGE("Attrs Json not contains key: %{public}s", targetKey.c_str());
247         cJSON_Delete(attrJson);
248         return "";
249     }
250     std::string result = targetKeyJson->valuestring;
251     cJSON_Delete(attrJson);
252     return result;
253 }
254 
InitializeAVCenter(const TransRole & transRole,int32_t & engineId)255 int32_t DistributedHardwareService::InitializeAVCenter(const TransRole &transRole, int32_t &engineId)
256 {
257     return AVTransControlCenter::GetInstance().InitializeAVCenter(transRole, engineId);
258 }
259 
ReleaseAVCenter(int32_t engineId)260 int32_t DistributedHardwareService::ReleaseAVCenter(int32_t engineId)
261 {
262     return AVTransControlCenter::GetInstance().ReleaseAVCenter(engineId);
263 }
264 
CreateControlChannel(int32_t engineId,const std::string & peerDevId)265 int32_t DistributedHardwareService::CreateControlChannel(int32_t engineId, const std::string &peerDevId)
266 {
267     return AVTransControlCenter::GetInstance().CreateControlChannel(engineId, peerDevId);
268 }
269 
NotifyAVCenter(int32_t engineId,const AVTransEvent & event)270 int32_t DistributedHardwareService::NotifyAVCenter(int32_t engineId, const AVTransEvent &event)
271 {
272     return AVTransControlCenter::GetInstance().NotifyAVCenter(engineId, event);
273 }
274 
RegisterCtlCenterCallback(int32_t engineId,const sptr<IAVTransControlCenterCallback> callback)275 int32_t DistributedHardwareService::RegisterCtlCenterCallback(int32_t engineId,
276     const sptr<IAVTransControlCenterCallback> callback)
277 {
278     return AVTransControlCenter::GetInstance().RegisterCtlCenterCallback(engineId, callback);
279 }
280 
NotifySourceRemoteSinkStarted(std::string & deviceId)281 int32_t DistributedHardwareService::NotifySourceRemoteSinkStarted(std::string &deviceId)
282 {
283     DHLOGI("DistributedHardwareService NotifySourceRemoteSinkStarted Init DHMS Ready Start.");
284     Publisher::GetInstance().PublishMessage(DHTopic::TOPIC_INIT_DHMS_READY, deviceId);
285     DHLOGI("DistributedHardwareService NotifySourceRemoteSinkStarted Init DHMS Ready End.");
286     return DH_FWK_SUCCESS;
287 }
288 
Dump(int32_t fd,const std::vector<std::u16string> & args)289 int DistributedHardwareService::Dump(int32_t fd, const std::vector<std::u16string>& args)
290 {
291     DHLOGI("DistributedHardwareService  Dump.");
292 
293     std::vector<std::string> argsStr {};
294     for (auto item : args) {
295         argsStr.emplace_back(Str16ToStr8(item));
296     }
297 
298     std::string result("");
299     int ret = AccessManager::GetInstance()->Dump(argsStr, result);
300     if (ret != DH_FWK_SUCCESS) {
301         DHLOGE("Dump error, ret = %{public}d", ret);
302     }
303 
304     if (dprintf(fd, "%s\n", result.c_str()) < 0) {
305         DHLOGE("Hidump dprintf error");
306         ret = ERR_DH_FWK_HIDUMP_DPRINTF_ERROR;
307     }
308 
309     return ret;
310 }
311 
PauseDistributedHardware(DHType dhType,const std::string & networkId)312 int32_t DistributedHardwareService::PauseDistributedHardware(DHType dhType, const std::string &networkId)
313 {
314     if (!IsIdLengthValid(networkId)) {
315         return ERR_DH_FWK_PARA_INVALID;
316     }
317     std::map<DHType, IDistributedHardwareSink*> sinkMap = ComponentManager::GetInstance().GetDHSinkInstance();
318     if (sinkMap.find(dhType) == sinkMap.end()) {
319         DHLOGE("PauseDistributedHardware for DHType: %{public}u not init sink handler", (uint32_t)dhType);
320         return ERR_DH_FWK_PARA_INVALID;
321     }
322     int32_t ret = sinkMap[dhType]->PauseDistributedHardware(networkId);
323     if (ret != 0) {
324         DHLOGE("PauseDistributedHardware for DHType: %{public}u failed, ret: %{public}d", (uint32_t)dhType, ret);
325         return ret;
326     }
327     return DH_FWK_SUCCESS;
328 }
329 
ResumeDistributedHardware(DHType dhType,const std::string & networkId)330 int32_t DistributedHardwareService::ResumeDistributedHardware(DHType dhType, const std::string &networkId)
331 {
332     if (!IsIdLengthValid(networkId)) {
333         return ERR_DH_FWK_PARA_INVALID;
334     }
335     std::map<DHType, IDistributedHardwareSink*> sinkMap = ComponentManager::GetInstance().GetDHSinkInstance();
336     if (sinkMap.find(dhType) == sinkMap.end()) {
337         DHLOGE("ResumeDistributedHardware for DHType: %{public}u not init sink handler", (uint32_t)dhType);
338         return ERR_DH_FWK_PARA_INVALID;
339     }
340     int32_t ret = sinkMap[dhType]->ResumeDistributedHardware(networkId);
341     if (ret != 0) {
342         DHLOGE("ResumeDistributedHardware for DHType: %{public}u failed, ret: %{public}d", (uint32_t)dhType, ret);
343         return ret;
344     }
345     return DH_FWK_SUCCESS;
346 }
347 
StopDistributedHardware(DHType dhType,const std::string & networkId)348 int32_t DistributedHardwareService::StopDistributedHardware(DHType dhType, const std::string &networkId)
349 {
350     if (!IsIdLengthValid(networkId)) {
351         return ERR_DH_FWK_PARA_INVALID;
352     }
353     std::map<DHType, IDistributedHardwareSink*> sinkMap = ComponentManager::GetInstance().GetDHSinkInstance();
354     if (sinkMap.find(dhType) == sinkMap.end()) {
355         DHLOGE("StopDistributedHardware for DHType: %{public}u not init sink handler", (uint32_t)dhType);
356         return ERR_DH_FWK_PARA_INVALID;
357     }
358     int32_t ret = sinkMap[dhType]->StopDistributedHardware(networkId);
359     if (ret != 0) {
360         DHLOGE("StopDistributedHardware for DHType: %{public}u failed, ret: %{public}d", (uint32_t)dhType, ret);
361         return ret;
362     }
363     return DH_FWK_SUCCESS;
364 }
365 
GetDistributedHardware(const std::string & networkId,std::vector<DHDescriptor> & descriptors)366 int32_t DistributedHardwareService::GetDistributedHardware(
367     const std::string &networkId, std::vector<DHDescriptor> &descriptors)
368 {
369     if (!IsIdLengthValid(networkId)) {
370         return ERR_DH_FWK_PARA_INVALID;
371     }
372     std::string deviceId;
373     if (networkId == LOCAL_NETWORKID_ALIAS) {
374         deviceId = GetLocalDeviceInfo().deviceId;
375     } else {
376         deviceId = GetDeviceIdByUUID(DHContext::GetInstance().GetUUIDByNetworkId(networkId));
377     }
378     std::vector<std::shared_ptr<CapabilityInfo>> capabilities;
379     CapabilityInfoManager::GetInstance()->GetCapabilitiesByDeviceId(deviceId, capabilities);
380     if (capabilities.empty()) {
381         CapabilityInfoManager::GetInstance()->SyncDeviceInfoFromDB(deviceId);
382         std::string udid = DHContext::GetInstance().GetUDIDByNetworkId(networkId);
383         std::string udidHash = Sha256(udid);
384         std::vector<std::shared_ptr<MetaCapabilityInfo>> metaCapInfos;
385         MetaInfoManager::GetInstance()->GetMetaCapInfosByUdidHash(udidHash, metaCapInfos);
386         for (const auto &metaCapInfo : metaCapInfos) {
387             DHDescriptor descriptor;
388             descriptor.id = metaCapInfo->GetDHId();
389             descriptor.dhType = metaCapInfo->GetDHType();
390             descriptors.push_back(descriptor);
391         }
392     } else {
393         for (const auto &capabilitie : capabilities) {
394             DHDescriptor descriptor;
395             descriptor.id = capabilitie->GetDHId();
396             descriptor.dhType = capabilitie->GetDHType();
397             descriptors.push_back(descriptor);
398         }
399     }
400 
401     return DH_FWK_SUCCESS;
402 }
403 
RegisterDHStatusListener(sptr<IHDSinkStatusListener> listener)404 int32_t DistributedHardwareService::RegisterDHStatusListener(sptr<IHDSinkStatusListener> listener)
405 {
406     int32_t callingUid = IPCSkeleton::GetCallingUid();
407     int32_t callingPid = IPCSkeleton::GetCallingPid();
408     int32_t ret = ComponentManager::GetInstance().RegisterDHStatusListener(listener, callingUid, callingPid);
409     if (ret != 0) {
410         DHLOGE("RegisterDHStatusListener failed, ret: %{public}d.", ret);
411         return ret;
412     }
413     return DH_FWK_SUCCESS;
414 }
415 
UnregisterDHStatusListener(sptr<IHDSinkStatusListener> listener)416 int32_t DistributedHardwareService::UnregisterDHStatusListener(sptr<IHDSinkStatusListener> listener)
417 {
418     int32_t callingUid = IPCSkeleton::GetCallingUid();
419     int32_t callingPid = IPCSkeleton::GetCallingPid();
420     int32_t ret = ComponentManager::GetInstance().UnregisterDHStatusListener(listener, callingUid, callingPid);
421     if (ret != 0) {
422         DHLOGE("UnregisterDHStatusListener failed, ret: %{public}d.", ret);
423         return ret;
424     }
425     return DH_FWK_SUCCESS;
426 }
427 
RegisterDHStatusListener(const std::string & networkId,sptr<IHDSourceStatusListener> listener)428 int32_t DistributedHardwareService::RegisterDHStatusListener(
429     const std::string &networkId, sptr<IHDSourceStatusListener> listener)
430 {
431     if (!IsIdLengthValid(networkId)) {
432         return ERR_DH_FWK_PARA_INVALID;
433     }
434     int32_t callingUid = IPCSkeleton::GetCallingUid();
435     int32_t callingPid = IPCSkeleton::GetCallingPid();
436     int32_t ret = ComponentManager::GetInstance().RegisterDHStatusListener(
437         networkId, listener, callingUid, callingPid);
438     if (ret != 0) {
439         DHLOGE("RegisterDHStatusListener failed, ret: %{public}d.", ret);
440         return ret;
441     }
442     return DH_FWK_SUCCESS;
443 }
444 
UnregisterDHStatusListener(const std::string & networkId,sptr<IHDSourceStatusListener> listener)445 int32_t DistributedHardwareService::UnregisterDHStatusListener(
446     const std::string &networkId, sptr<IHDSourceStatusListener> listener)
447 {
448     if (!IsIdLengthValid(networkId)) {
449         return ERR_DH_FWK_PARA_INVALID;
450     }
451     int32_t callingUid = IPCSkeleton::GetCallingUid();
452     int32_t callingPid = IPCSkeleton::GetCallingPid();
453     int32_t ret = ComponentManager::GetInstance().UnregisterDHStatusListener(
454         networkId, listener, callingUid, callingPid);
455     if (ret != 0) {
456         DHLOGE("UnregisterDHStatusListener failed, ret: %{public}d.", ret);
457         return ret;
458     }
459     return DH_FWK_SUCCESS;
460 }
461 
EnableSink(const std::vector<DHDescriptor> & descriptors)462 int32_t DistributedHardwareService::EnableSink(const std::vector<DHDescriptor> &descriptors)
463 {
464     for (const auto &descriptor : descriptors) {
465         TaskParam taskParam = {
466             .dhId = descriptor.id,
467             .dhType = descriptor.dhType,
468             .effectSink = true,
469             .effectSource = false,
470             .callingUid = IPCSkeleton::GetCallingUid(),
471             .callingPid = IPCSkeleton::GetCallingPid()
472         };
473         auto task = TaskFactory::GetInstance().CreateTask(TaskType::ENABLE, taskParam, nullptr);
474         TaskExecutor::GetInstance().PushTask(task);
475     }
476     return DH_FWK_SUCCESS;
477 }
478 
DisableSink(const std::vector<DHDescriptor> & descriptors)479 int32_t DistributedHardwareService::DisableSink(const std::vector<DHDescriptor> &descriptors)
480 {
481     for (const auto &descriptor : descriptors) {
482         TaskParam taskParam = {
483             .dhId = descriptor.id,
484             .dhType = descriptor.dhType,
485             .effectSink = true,
486             .effectSource = false,
487             .callingUid = IPCSkeleton::GetCallingUid(),
488             .callingPid = IPCSkeleton::GetCallingPid()
489         };
490         auto task = TaskFactory::GetInstance().CreateTask(TaskType::DISABLE, taskParam, nullptr);
491         TaskExecutor::GetInstance().PushTask(task);
492     }
493     return DH_FWK_SUCCESS;
494 }
495 
EnableSource(const std::string & networkId,const std::vector<DHDescriptor> & descriptors)496 int32_t DistributedHardwareService::EnableSource(
497     const std::string &networkId, const std::vector<DHDescriptor> &descriptors)
498 {
499     if (!IsIdLengthValid(networkId)) {
500         return ERR_DH_FWK_PARA_INVALID;
501     }
502     for (const auto &descriptor : descriptors) {
503         TaskParam taskParam = {
504             .networkId = networkId,
505             .dhId = descriptor.id,
506             .dhType = descriptor.dhType,
507             .effectSink = false,
508             .effectSource = true,
509             .callingUid = IPCSkeleton::GetCallingUid(),
510             .callingPid = IPCSkeleton::GetCallingPid()
511         };
512         auto task = TaskFactory::GetInstance().CreateTask(TaskType::ENABLE, taskParam, nullptr);
513         TaskExecutor::GetInstance().PushTask(task);
514     }
515     return DH_FWK_SUCCESS;
516 }
517 
DisableSource(const std::string & networkId,const std::vector<DHDescriptor> & descriptors)518 int32_t DistributedHardwareService::DisableSource(
519     const std::string &networkId, const std::vector<DHDescriptor> &descriptors)
520 {
521     if (!IsIdLengthValid(networkId)) {
522         return ERR_DH_FWK_PARA_INVALID;
523     }
524     for (const auto &descriptor : descriptors) {
525         TaskParam taskParam = {
526             .networkId = networkId,
527             .dhId = descriptor.id,
528             .dhType = descriptor.dhType,
529             .effectSink = false,
530             .effectSource = true,
531             .callingUid = IPCSkeleton::GetCallingUid(),
532             .callingPid = IPCSkeleton::GetCallingPid()
533         };
534         auto task = TaskFactory::GetInstance().CreateTask(TaskType::DISABLE, taskParam, nullptr);
535         TaskExecutor::GetInstance().PushTask(task);
536     }
537     return DH_FWK_SUCCESS;
538 }
539 } // namespace DistributedHardware
540 } // namespace OHOS
541