From c4347df5c58aee161cdc51e7f9a2e233e76589c6 Mon Sep 17 00:00:00 2001 From: li-tiangang4 Date: Mon, 31 Mar 2025 20:50:14 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=BB=84=E7=BD=91?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=8B=89=E8=B5=B7=E5=88=86=E5=B8=83=E5=BC=8F?= =?UTF-8?q?modem=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-tiangang4 --- .../componentmanager/component_manager.h | 2 +- .../include/task/offline_task.h | 3 +- .../include/task/online_task.h | 3 +- .../include/utils/impl_utils.h | 4 +- .../componentmanager/component_manager.cpp | 24 +---------- .../src/task/disable_task.cpp | 43 ++++++++++--------- .../src/task/enable_task.cpp | 35 ++++++++------- .../src/task/offline_task.cpp | 36 +++++++++++++++- .../src/task/online_task.cpp | 36 +++++++++++++++- .../componentmanager_fuzzer.cpp | 3 +- .../src/component_manager_test.cpp | 3 +- .../src/component_manager_test_ext.cpp | 12 ++---- utils/include/dh_utils_tool.h | 4 +- utils/src/dh_utils_tool.cpp | 13 +++++- 14 files changed, 139 insertions(+), 82 deletions(-) diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h index 730b6f7e..43905e79 100644 --- a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h +++ b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h @@ -79,7 +79,7 @@ public: */ bool FetchNeedRefreshTask(const std::pair &taskKey, TaskParam &taskParam); - int32_t CheckDemandStart(const std::string &uuid, const DHType dhType, bool &enableSink, bool &enableSource); + int32_t CheckDemandStart(const std::string &uuid, const DHType dhType, bool &enableSource); int32_t RegisterDHStatusListener(sptr listener, int32_t callingUid, int32_t callingPid); int32_t UnregisterDHStatusListener(sptr listener, int32_t callingUid, int32_t callingPid); int32_t RegisterDHStatusListener(const std::string &networkId, diff --git a/services/distributedhardwarefwkservice/include/task/offline_task.h b/services/distributedhardwarefwkservice/include/task/offline_task.h index 2bba2b05..24e19646 100644 --- a/services/distributedhardwarefwkservice/include/task/offline_task.h +++ b/services/distributedhardwarefwkservice/include/task/offline_task.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -44,6 +44,7 @@ private: void ClearOffLineInfo(); /* create meta disable tasks for off line device */ void CreateMetaDisableTask(); + void CreateDisableSinkTask(); private: /* condition for children task finish */ diff --git a/services/distributedhardwarefwkservice/include/task/online_task.h b/services/distributedhardwarefwkservice/include/task/online_task.h index efb64395..3574cc6d 100644 --- a/services/distributedhardwarefwkservice/include/task/online_task.h +++ b/services/distributedhardwarefwkservice/include/task/online_task.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -32,6 +32,7 @@ private: void DoSyncInfo(); void CreateEnableTask(); void CreateMetaEnableTask(); + void CreateEnableSinkTask(); }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/distributedhardwarefwkservice/include/utils/impl_utils.h b/services/distributedhardwarefwkservice/include/utils/impl_utils.h index 389c093e..b44e1f97 100644 --- a/services/distributedhardwarefwkservice/include/utils/impl_utils.h +++ b/services/distributedhardwarefwkservice/include/utils/impl_utils.h @@ -44,7 +44,9 @@ enum class TaskStep : int32_t { META_ENABLE_TASK = 8, META_DISABLE_TASK = 9, DO_MODEM_META_ENABLE = 10, - DO_MODEM_META_DISABLE = 11 + DO_MODEM_META_DISABLE = 11, + ENABLE_SINK, + DISABLE_SINK }; enum class TaskState : int32_t { diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 86285c9e..1f6bf903 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -821,11 +821,9 @@ std::shared_ptr ComponentManager return this->eventHandler_; } -int32_t ComponentManager::CheckDemandStart(const std::string &uuid, - const DHType dhType, bool &enableSink, bool &enableSource) +int32_t ComponentManager::CheckDemandStart(const std::string &uuid, const DHType dhType, bool &enableSource) { // Initialize output parameters - enableSink = false; enableSource = false; // Get remote config @@ -845,36 +843,16 @@ int32_t ComponentManager::CheckDemandStart(const std::string &uuid, } auto iterLocal = dhVersion.compVersions.find(dhType); - if (iterLocal == dhVersion.compVersions.end()) { - DHLOGE("Not find dhType in local: %{public}#X!", dhType); - return ERR_DH_FWK_TYPE_NOT_EXIST; - } - // Check local config if (!iterLocal->second.haveFeature) { - enableSink = true; enableSource = true; return DH_FWK_SUCCESS; } - if (iterLocal->second.sinkSupportedFeatures.size()) { - enableSink = true; - } - if (iterLocal->second.sourceFeatureFilters.size() == 0) { return DH_FWK_SUCCESS; } - // Check remote config - if (!compVersion.haveFeature) { // Remote config is null, need enable source - enableSource = true; - return DH_FWK_SUCCESS; - } - - if (compVersion.sinkSupportedFeatures.size() == 0) { // Remote sink config is empty, not enable source - return DH_FWK_SUCCESS; - } - // Check if the configurations on both ends match enableSource = IsFeatureMatched(iterLocal->second.sourceFeatureFilters, compVersion.sinkSupportedFeatures); diff --git a/services/distributedhardwarefwkservice/src/task/disable_task.cpp b/services/distributedhardwarefwkservice/src/task/disable_task.cpp index 8fb417d5..b8c6b60d 100644 --- a/services/distributedhardwarefwkservice/src/task/disable_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/disable_task.cpp @@ -148,31 +148,32 @@ int32_t DisableTask::GetCallingPid() int32_t DisableTask::DoAutoDisable() { - bool disableSink = false; - bool disableSource = false; - int32_t ret = ComponentManager::GetInstance().CheckDemandStart(GetUUID(), GetDhType(), disableSink, disableSource); - if (ret != DH_FWK_SUCCESS) { - DHLOGE("CheckDemandStart failed!"); - return ret; - } - if (DHContext::GetInstance().GetRealTimeOnlineDeviceCount() == 0 && - DHContext::GetInstance().GetIsomerismConnectCount() == 0) { - DHDescriptor dhDescriptor { - .id = GetDhId(), - .dhType = GetDhType() - }; - if (disableSink) { + std::string localUdid = GetLocalUdid(); + if (localUdid == GetUDID()) { + auto ret = DH_FWK_SUCCESS; + if (DHContext::GetInstance().GetRealTimeOnlineDeviceCount() == 0 && + DHContext::GetInstance().GetIsomerismConnectCount() == 0) { + DHDescriptor dhDescriptor { + .id = GetDhId(), + .dhType = GetDhType() + }; + DHLOGI("DisableTask DhType = %{public}#X, id= %{public}s", GetDhType(), GetAnonyString(GetDhId()).c_str()); ret = ComponentManager::GetInstance().ForceDisableSink(dhDescriptor); if (ret != DH_FWK_SUCCESS) { - DHLOGE("DisableSink failed!"); - } - } - if (disableSource) { - ret = ComponentManager::GetInstance().ForceDisableSource(GetNetworkId(), dhDescriptor); - if (ret != DH_FWK_SUCCESS) { - DHLOGE("DisableSource failed!"); + DHLOGE("EnableSink DhType = %{public}#X, failed!", GetDhType()); } } + return ret; + } + + DHDescriptor dhDescriptor { + .id = GetDhId(), + .dhType = GetDhType() + }; + DHLOGI("EnableSource DhType = %{public}#X, id= %{public}s", GetDhType(), GetAnonyString(GetDhId()).c_str()); + auto ret = ComponentManager::GetInstance().ForceDisableSource(GetNetworkId(), dhDescriptor); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("DisableSource failed!"); } return ret; } diff --git a/services/distributedhardwarefwkservice/src/task/enable_task.cpp b/services/distributedhardwarefwkservice/src/task/enable_task.cpp index ff9cbabb..06d705a3 100644 --- a/services/distributedhardwarefwkservice/src/task/enable_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/enable_task.cpp @@ -143,32 +143,37 @@ int32_t EnableTask::GetCallingPid() int32_t EnableTask::DoAutoEnable() { - bool enableSink = false; + std::string localUdid = GetLocalUdid(); + if (localUdid == GetUDID()) { + DHDescriptor dhDescriptor { + .id = GetDhId(), + .dhType = GetDhType() + }; + DHLOGI("EnableSink DhType = %{public}#X", GetDhType()); + auto ret = ComponentManager::GetInstance().EnableSink(dhDescriptor, GetCallingUid(), GetCallingPid()); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("EnableSink DhType = %{public}#X, failed!", GetDhType()); + } + return ret; + } + bool enableSource = false; - int32_t ret = ComponentManager::GetInstance().CheckDemandStart(GetUUID(), GetDhType(), enableSink, enableSource); + int32_t ret = ComponentManager::GetInstance().CheckDemandStart(GetUUID(), GetDhType(), enableSource); if (ret != DH_FWK_SUCCESS) { DHLOGE("CheckDemandStart failed!"); return ret; } - if (!enableSink && !enableSource) { + if (!enableSource) { + DHLOGE("No need Enablesource."); return ERR_DH_FWK_COMPONENT_LIMIT_DEMAND_START; } DHDescriptor dhDescriptor { .id = GetDhId(), .dhType = GetDhType() }; - if (enableSink) { - ret = ComponentManager::GetInstance().EnableSink(dhDescriptor, GetCallingUid(), GetCallingPid()); - if (ret != DH_FWK_SUCCESS) { - DHLOGE("EnableSink failed!"); - } - } - if (enableSource) { - ret = ComponentManager::GetInstance().EnableSource( - GetNetworkId(), dhDescriptor, GetCallingUid(), GetCallingPid()); - if (ret != DH_FWK_SUCCESS) { - DHLOGE("EnableSource failed!"); - } + ret = ComponentManager::GetInstance().EnableSource(GetNetworkId(), dhDescriptor, GetCallingUid(), GetCallingPid()); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("EnableSource DhType = %{public}#X, failed!", GetDhType()); } return ret; } diff --git a/services/distributedhardwarefwkservice/src/task/offline_task.cpp b/services/distributedhardwarefwkservice/src/task/offline_task.cpp index 5b9c0c90..a5cd375a 100644 --- a/services/distributedhardwarefwkservice/src/task/offline_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/offline_task.cpp @@ -44,7 +44,7 @@ OffLineTask::OffLineTask(const std::string &networkId, const std::string &uuid, { this->SetTaskType(TaskType::OFF_LINE); this->SetTaskSteps({TaskStep::META_DISABLE_TASK, TaskStep::UNREGISTER_OFFLINE_DISTRIBUTED_HARDWARE, - TaskStep::WAIT_UNREGISTGER_COMPLETE, TaskStep::CLEAR_OFFLINE_INFO}); + TaskStep::DISABLE_SINK, TaskStep::WAIT_UNREGISTGER_COMPLETE, TaskStep::CLEAR_OFFLINE_INFO}); DHLOGD("OffLineTask id: %{public}s, networkId: %{public}s, uuid: %{public}s, udid: %{public}s", GetId().c_str(), GetAnonyString(GetNetworkId()).c_str(), GetAnonyString(GetUUID()).c_str(), GetAnonyString(GetUDID()).c_str()); @@ -75,6 +75,10 @@ void OffLineTask::DoTaskInner() CreateDisableTask(); break; } + case TaskStep::DISABLE_SINK: { + CreateDisableSinkTask(); + break; + } case TaskStep::WAIT_UNREGISTGER_COMPLETE: { WaitDisableTaskFinish(); break; @@ -94,7 +98,7 @@ void OffLineTask::DoTaskInner() } this->SetTaskState(TaskState::SUCCESS); - DHLOGD("Finish OffLine task, remove it, id: %{public}s", GetId().c_str()); + DHLOGI("Finish OffLine task, remove it, id: %{public}s", GetId().c_str()); TaskBoard::GetInstance().RemoveTask(this->GetId()); if (DHContext::GetInstance().GetRealTimeOnlineDeviceCount() == 0 && DHContext::GetInstance().GetIsomerismConnectCount() == 0 && @@ -129,6 +133,7 @@ void OffLineTask::CreateDisableTask() if (devDhInfos.empty()) { DHLOGE("Can not get cap info, uuid = %{public}s, deviceId = %{public}s", GetAnonyString(GetUUID()).c_str(), GetAnonyString(deviceId).c_str()); + return; } for (const auto &info : devDhInfos) { @@ -143,6 +148,33 @@ void OffLineTask::CreateDisableTask() } } +void OffLineTask::CreateDisableSinkTask() +{ + DHLOGI("CreateDisableSinkTask start"); + DeviceInfo localDeviceInfo = GetLocalDeviceInfo(); + std::vector> localMetaInfos; + std::vector> metaCapInfos; + MetaInfoManager::GetInstance()->GetMetaCapInfosByUdidHash(localDeviceInfo.udidHash, metaCapInfos); + std::for_each(metaCapInfos.begin(), metaCapInfos.end(), [&](std::shared_ptr localMetaInfo) { + localMetaInfos.push_back({localMetaInfo->GetDHId(), localMetaInfo->GetDHType()}); + }); + if (localMetaInfos.empty()) { + DHLOGE("Can not get localMetainfo."); + return; + } + for (const auto &localInfo : localMetaInfos) { + TaskParam taskParam = { + .networkId = localDeviceInfo.networkId, + .uuid = localDeviceInfo.uuid, + .udid = localDeviceInfo.udid, + .dhId = localInfo.first, + .dhType = localInfo.second + }; + auto task = TaskFactory::GetInstance().CreateTask(TaskType::DISABLE, taskParam, shared_from_this()); + TaskExecutor::GetInstance().PushTask(task); + } +} + void OffLineTask::WaitDisableTaskFinish() { DHLOGI("start wait disable task finish"); diff --git a/services/distributedhardwarefwkservice/src/task/online_task.cpp b/services/distributedhardwarefwkservice/src/task/online_task.cpp index e044b817..f8ea343a 100644 --- a/services/distributedhardwarefwkservice/src/task/online_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/online_task.cpp @@ -38,7 +38,7 @@ OnLineTask::OnLineTask(const std::string &networkId, const std::string &uuid, co { SetTaskType(TaskType::ON_LINE); SetTaskSteps(std::vector { TaskStep::SYNC_ONLINE_INFO, TaskStep::REGISTER_ONLINE_DISTRIBUTED_HARDWARE, - TaskStep::META_ENABLE_TASK}); + TaskStep::ENABLE_SINK, TaskStep::META_ENABLE_TASK}); DHLOGD("OnLineTask id: %{public}s, networkId: %{public}s, uuid: %{public}s, udid: %{public}s", GetId().c_str(), GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str(), GetAnonyString(udid).c_str()); @@ -65,6 +65,10 @@ void OnLineTask::DoTask() CreateEnableTask(); break; } + case TaskStep::ENABLE_SINK: { + CreateEnableSinkTask(); + break; + } case TaskStep::META_ENABLE_TASK: { CreateMetaEnableTask(); break; @@ -75,7 +79,7 @@ void OnLineTask::DoTask() } } SetTaskState(TaskState::SUCCESS); - DHLOGD("finish online task, remove it, id = %{public}s.", GetId().c_str()); + DHLOGI("finish online task, remove it, id = %{public}s.", GetId().c_str()); TaskBoard::GetInstance().RemoveTask(this->GetId()); } @@ -134,6 +138,7 @@ void OnLineTask::CreateEnableTask() if (devDhInfos.empty()) { DHLOGE("Can not get cap info, uuid = %{public}s, deviceId = %{public}s", GetAnonyString(GetUUID()).c_str(), GetAnonyString(deviceId).c_str()); + return; } for (const auto &info : devDhInfos) { @@ -149,6 +154,33 @@ void OnLineTask::CreateEnableTask() } } +void OnLineTask::CreateEnableSinkTask() +{ + DHLOGI("CreateEnableSinkTask start"); + DeviceInfo localDeviceInfo = GetLocalDeviceInfo(); + std::vector> localMetaInfos; + std::vector> metaCapInfos; + MetaInfoManager::GetInstance()->GetMetaCapInfosByUdidHash(localDeviceInfo.udidHash, metaCapInfos); + std::for_each(metaCapInfos.begin(), metaCapInfos.end(), [&](std::shared_ptr localMetaInfo) { + localMetaInfos.push_back({localMetaInfo->GetDHId(), localMetaInfo->GetDHType()}); + }); + if (localMetaInfos.empty()) { + DHLOGE("Can not get localMetainfo."); + return; + } + for (const auto &localInfo : localMetaInfos) { + TaskParam taskParam = { + .networkId = localDeviceInfo.networkId, + .uuid = localDeviceInfo.uuid, + .udid = localDeviceInfo.udid, + .dhId = localInfo.first, + .dhType = localInfo.second + }; + auto task = TaskFactory::GetInstance().CreateTask(TaskType::ENABLE, taskParam, shared_from_this()); + TaskExecutor::GetInstance().PushTask(task); + } +} + void OnLineTask::CreateMetaEnableTask() { DHLOGI("CreateMetaEnableTask, networkId: %{public}s, uuid: %{public}s, udid: %{public}s", diff --git a/services/distributedhardwarefwkservice/test/fuzztest/componentmanager_fuzzer/componentmanager_fuzzer.cpp b/services/distributedhardwarefwkservice/test/fuzztest/componentmanager_fuzzer/componentmanager_fuzzer.cpp index 99bcb6a8..0f567915 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/componentmanager_fuzzer/componentmanager_fuzzer.cpp +++ b/services/distributedhardwarefwkservice/test/fuzztest/componentmanager_fuzzer/componentmanager_fuzzer.cpp @@ -47,7 +47,6 @@ void ComponentManagerFuzzTest(const uint8_t* data, size_t size) std::string uuid(reinterpret_cast(data), size); std::string dhId(reinterpret_cast(data), size); DHType dhType = dhTypeFuzz[data[0] % DH_TYPE_SIZE]; - bool enableSink = false; bool enableSource = false; sptr sinkListener = nullptr; sptr sourceListener = nullptr; @@ -61,7 +60,7 @@ void ComponentManagerFuzzTest(const uint8_t* data, size_t size) ComponentManager::GetInstance().Init(); ComponentManager::GetInstance().Enable(networkId, uuid, dhId, dhType); ComponentManager::GetInstance().Disable(networkId, uuid, dhId, dhType); - ComponentManager::GetInstance().CheckDemandStart(uuid, dhType, enableSink, enableSource); + ComponentManager::GetInstance().CheckDemandStart(uuid, dhType, enableSource); ComponentManager::GetInstance().RegisterDHStatusListener(sinkListener, callingUid, callingPid); ComponentManager::GetInstance().UnregisterDHStatusListener(sinkListener, callingUid, callingPid); ComponentManager::GetInstance().RegisterDHStatusListener(networkId, sourceListener, callingUid, callingPid); diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp index ea7516b3..156aa6f3 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp @@ -1103,9 +1103,8 @@ HWTEST_F(ComponentManagerTest, GetDHSourceInstance_002, TestSize.Level1) HWTEST_F(ComponentManagerTest, CheckDemandStart_001, TestSize.Level1) { - bool enableSink = false; bool enableSource = false; - auto ret = ComponentManager::GetInstance().CheckDemandStart(UUID_TEST, DHType::AUDIO, enableSink, enableSource); + auto ret = ComponentManager::GetInstance().CheckDemandStart(UUID_TEST, DHType::AUDIO, enableSource); EXPECT_EQ(ret, ERR_DH_FWK_COMPONENT_COMPVERSION_NOT_FOUND); } diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test_ext.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test_ext.cpp index 7ebfdf7d..15eb950a 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test_ext.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test_ext.cpp @@ -485,13 +485,9 @@ HWTEST_F(ComponentManagerTestExt, CheckDemandStart_001, testing::ext::TestSize.L EXPECT_CALL(*componentLoader_, GetLocalDHVersion(_)) .WillRepeatedly(DoAll(SetArgReferee<0>(dhVersion), Return(DH_FWK_SUCCESS))); - bool isEnableSink = false; bool isEnableSource = false; - auto ret = ComponentManager::GetInstance().CheckDemandStart( - VALUABLE_DEVICE_INFO.uuid, targetType, isEnableSink, isEnableSource); + auto ret = ComponentManager::GetInstance().CheckDemandStart(VALUABLE_DEVICE_INFO.uuid, targetType, isEnableSource); EXPECT_EQ(ret, DH_FWK_SUCCESS); - EXPECT_TRUE(isEnableSink); - EXPECT_TRUE(isEnableSource); } HWTEST_F(ComponentManagerTestExt, CheckDemandStart_002, testing::ext::TestSize.Level2) @@ -507,10 +503,9 @@ HWTEST_F(ComponentManagerTestExt, CheckDemandStart_002, testing::ext::TestSize.L })); for (size_t i = 0; i < 2; ++i) { - bool isEnableSink = false; bool isEnableSource = false; auto ret = ComponentManager::GetInstance().CheckDemandStart( - VALUABLE_DEVICE_INFO.uuid, DHType::CAMERA, isEnableSink, isEnableSource); + VALUABLE_DEVICE_INFO.uuid, DHType::CAMERA, isEnableSource); EXPECT_EQ(ret, ERR_DH_FWK_COMPONENT_COMPVERSION_NOT_FOUND); } } @@ -537,10 +532,9 @@ HWTEST_F(ComponentManagerTestExt, CheckDemandStart_003, testing::ext::TestSize.L })); for (size_t i = 0; i < 2; ++i) { - bool isEnableSink = false; bool isEnableSource = false; auto ret = ComponentManager::GetInstance().CheckDemandStart( - VALUABLE_DEVICE_INFO.uuid, DHType::CAMERA, isEnableSink, isEnableSource); + VALUABLE_DEVICE_INFO.uuid, DHType::CAMERA, isEnableSource); EXPECT_EQ(ret, ERR_DH_FWK_TYPE_NOT_EXIST); } } diff --git a/utils/include/dh_utils_tool.h b/utils/include/dh_utils_tool.h index 333cceda..7c7f2852 100644 --- a/utils/include/dh_utils_tool.h +++ b/utils/include/dh_utils_tool.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -42,6 +42,8 @@ DeviceInfo GetLocalDeviceInfo(); std::string GetLocalNetworkId(); +std::string GetLocalUdid(); + /* Convert uuid to deviceId by sha256 encode */ std::string GetDeviceIdByUUID(const std::string &uuid); diff --git a/utils/src/dh_utils_tool.cpp b/utils/src/dh_utils_tool.cpp index df735913..31d45646 100644 --- a/utils/src/dh_utils_tool.cpp +++ b/utils/src/dh_utils_tool.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2024 Huawei Device Co., Ltd. + * Copyright (c) 2021-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -163,6 +163,17 @@ std::string GetLocalNetworkId() return info.networkId; } +std::string GetLocalUdid() +{ + DmDeviceInfo info; + auto ret = DeviceManager::GetInstance().GetLocalDeviceInfo(DH_FWK_PKG_NAME, info); + if (ret != DH_FWK_SUCCESS) { + DHLOGE("GetLocalNodeDeviceInfo failed, errCode = %{public}d", ret); + return ""; + } + return GetUDIDByDm(info.networkId); +} + bool IsUInt8(const cJSON* jsonObj) { if (jsonObj == NULL || !cJSON_IsNumber(jsonObj)) { -- Gitee From 88f5045c08e5180511e8859a0ec9f528eef11a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A4=A9=E5=88=9A?= Date: Tue, 1 Apr 2025 13:10:46 +0000 Subject: [PATCH 2/4] update services/distributedhardwarefwkservice/src/task/disable_task.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李天刚 --- .../distributedhardwarefwkservice/src/task/disable_task.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/distributedhardwarefwkservice/src/task/disable_task.cpp b/services/distributedhardwarefwkservice/src/task/disable_task.cpp index b8c6b60d..8160ebb9 100644 --- a/services/distributedhardwarefwkservice/src/task/disable_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/disable_task.cpp @@ -157,10 +157,10 @@ int32_t DisableTask::DoAutoDisable() .id = GetDhId(), .dhType = GetDhType() }; - DHLOGI("DisableTask DhType = %{public}#X, id= %{public}s", GetDhType(), GetAnonyString(GetDhId()).c_str()); + DHLOGI("DisableSinkTask DhType = %{public}#X, id= %{public}s", GetDhType(), GetAnonyString(GetDhId()).c_str()); ret = ComponentManager::GetInstance().ForceDisableSink(dhDescriptor); if (ret != DH_FWK_SUCCESS) { - DHLOGE("EnableSink DhType = %{public}#X, failed!", GetDhType()); + DHLOGE("DisableTask DhType = %{public}#X, failed!", GetDhType()); } } return ret; @@ -170,7 +170,7 @@ int32_t DisableTask::DoAutoDisable() .id = GetDhId(), .dhType = GetDhType() }; - DHLOGI("EnableSource DhType = %{public}#X, id= %{public}s", GetDhType(), GetAnonyString(GetDhId()).c_str()); + DHLOGI("DisableSourceTask DhType = %{public}#X, id= %{public}s", GetDhType(), GetAnonyString(GetDhId()).c_str()); auto ret = ComponentManager::GetInstance().ForceDisableSource(GetNetworkId(), dhDescriptor); if (ret != DH_FWK_SUCCESS) { DHLOGE("DisableSource failed!"); -- Gitee From 1eb24e414b97a1ef1f3f0ab6039bd6b75bc6aeff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A4=A9=E5=88=9A?= Date: Tue, 1 Apr 2025 13:38:35 +0000 Subject: [PATCH 3/4] update services/distributedhardwarefwkservice/src/task/disable_task.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李天刚 --- .../distributedhardwarefwkservice/src/task/disable_task.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/distributedhardwarefwkservice/src/task/disable_task.cpp b/services/distributedhardwarefwkservice/src/task/disable_task.cpp index 8160ebb9..992c2fdf 100644 --- a/services/distributedhardwarefwkservice/src/task/disable_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/disable_task.cpp @@ -157,7 +157,8 @@ int32_t DisableTask::DoAutoDisable() .id = GetDhId(), .dhType = GetDhType() }; - DHLOGI("DisableSinkTask DhType = %{public}#X, id= %{public}s", GetDhType(), GetAnonyString(GetDhId()).c_str()); + DHLOGI("DisableSinkTask DhType = %{public}#X, id= %{public}s", GetDhType(), + GetAnonyString(GetDhId()).c_str()); ret = ComponentManager::GetInstance().ForceDisableSink(dhDescriptor); if (ret != DH_FWK_SUCCESS) { DHLOGE("DisableTask DhType = %{public}#X, failed!", GetDhType()); -- Gitee From 493db957170a63d9bc71c68e5842cc912bf99951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A4=A9=E5=88=9A?= Date: Wed, 2 Apr 2025 06:05:33 +0000 Subject: [PATCH 4/4] update services/distributedhardwarefwkservice/include/utils/impl_utils.h. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 李天刚 --- .../distributedhardwarefwkservice/include/utils/impl_utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributedhardwarefwkservice/include/utils/impl_utils.h b/services/distributedhardwarefwkservice/include/utils/impl_utils.h index b44e1f97..e10a675f 100644 --- a/services/distributedhardwarefwkservice/include/utils/impl_utils.h +++ b/services/distributedhardwarefwkservice/include/utils/impl_utils.h @@ -45,8 +45,8 @@ enum class TaskStep : int32_t { META_DISABLE_TASK = 9, DO_MODEM_META_ENABLE = 10, DO_MODEM_META_DISABLE = 11, - ENABLE_SINK, - DISABLE_SINK + ENABLE_SINK = 12, + DISABLE_SINK = 13 }; enum class TaskState : int32_t { -- Gitee