diff --git a/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h b/services/distributedhardwarefwkservice/include/componentmanager/component_manager.h index 730b6f7e1e197cfcf41046700cd2a7a85480e74c..43905e79d3f464803836b085c4615637dcd39021 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 2bba2b056d9ec98776d8b3c127363cb0169fe6e3..24e19646a02acd8d74b0ce7b0c7539b4e6955bfd 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 efb64395f87ba37567da0b54f0d82c9c8c85edc9..3574cc6d867eb938fed0e2f39280bab9335153fe 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 389c093e7b5f86cb0b7f3ae475ccacea15c7af71..e10a675f00cf696ddcf4b2f4302c994b28f74b32 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 = 12, + DISABLE_SINK = 13 }; enum class TaskState : int32_t { diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 86285c9e9223ab9f317039b4b0a39395f37a2228..1f6bf903dbd9beb1ac3b3828adc5609105e0b883 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 8fb417d54c8dd0e60d58df7fefc8dc7def2d77bc..992c2fdf8749ac7a347d6b90094da2749dd91cf8 100644 --- a/services/distributedhardwarefwkservice/src/task/disable_task.cpp +++ b/services/distributedhardwarefwkservice/src/task/disable_task.cpp @@ -148,31 +148,33 @@ 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("DisableSinkTask 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("DisableTask DhType = %{public}#X, failed!", GetDhType()); } } + return ret; + } + + DHDescriptor dhDescriptor { + .id = GetDhId(), + .dhType = GetDhType() + }; + 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!"); } return ret; } diff --git a/services/distributedhardwarefwkservice/src/task/enable_task.cpp b/services/distributedhardwarefwkservice/src/task/enable_task.cpp index ff9cbabbc11c9b4959088df22d19c5cd6c6370a4..06d705a3badbf261603293f4fa199bf1e17ec776 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 5b9c0c9058ad9cbe0ab126b211cc34d64460630f..a5cd375a9e1febab74bfa647f9bf5ca470d667c7 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 e044b8170981d08396db55cfe3386703876e594b..f8ea343a4d6fd13e26fa6b30c5813a7b4bd36401 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 99bcb6a8630a98ddcf318c5863c36065ece22f29..0f567915ddf604351c860aefa7abf3b3423cf0b2 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 ea7516b35074b17274297d8af6ee860b4a0b42a0..156aa6f36dce35180e34e38c7982b500f29f57de 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 7ebfdf7de80019758f2026d653223ecb09ae4bbb..15eb950a730d223b33f20ef603e4bdbac16b3aa8 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 333cceda11d1e3bde190ff57d2c142dce7a4bfdb..7c7f28523c40a284f5d9d556f3832e94899f9dac 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 df73591343cba56d63d67abeadce67b580433f41..31d456464b0c2e44cdb1d798c200af4a20eea075 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)) {