From 7ca6cc47964f2d4595eef18c130dac634088684c Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Tue, 24 Jun 2025 11:44:10 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhaohao --- .../device_profile_manager.h | 9 ++++-- services/core/include/utils/profile_cache.h | 4 ++- .../device_profile_manager.cpp | 31 +++++++++++-------- services/core/src/utils/profile_cache.cpp | 5 +-- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/services/core/include/deviceprofilemanager/device_profile_manager.h b/services/core/include/deviceprofilemanager/device_profile_manager.h index e629e204..887e85da 100644 --- a/services/core/include/deviceprofilemanager/device_profile_manager.h +++ b/services/core/include/deviceprofilemanager/device_profile_manager.h @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "dm_device_info.h" @@ -77,10 +78,12 @@ public: private: bool LoadDpSyncAdapter(); void UnloadDpSyncAdapter(); - int32_t RunloadedFunction(const std::string& deviceId, sptr syncCompletedCallback); - int32_t SyncWithNotOHBasedDevice(const std::vector& notOHBasedDevices, + int32_t RunloadedFunction(const std::string& peerUdid, const std::string& peerNetId, + sptr syncCompletedCallback, bool isP2p); + int32_t SyncWithNotOHBasedDevice(const std::vector>& notOHBasedDevices, const std::string& callerDescriptor, sptr syncCompletedCallback); - void SyncWithNotOHBasedDeviceFailed(const std::vector& notOHBasedDevices, + void SyncWithNotOHBasedDeviceFailed( + const std::vector>& notOHBasedDevices, sptr syncCompletedCallback); void AddToPutTempCache(const std::map& values); void FixDataOnDeviceOnline(const TrustedDeviceInfo& deviceInfo); diff --git a/services/core/include/utils/profile_cache.h b/services/core/include/utils/profile_cache.h index 5ca3dbe2..bb8d149d 100644 --- a/services/core/include/utils/profile_cache.h +++ b/services/core/include/utils/profile_cache.h @@ -17,6 +17,7 @@ #define OHOS_DP_PROFILE_CACHE_H #include +#include #include #include #include @@ -92,7 +93,8 @@ public: std::string GetLocalAccountId(); int32_t AddAllTrustedDevices(const std::vector& deviceInfos); bool FilterAndGroupOnlineDevices(const std::vector& deviceList, - std::vector& ohBasedDevices, std::vector& notOHBasedDevices); + std::vector& ohBasedDevices, + std::vector>& notOHBasedDevicess); bool IsDeviceOnline(); private: diff --git a/services/core/src/deviceprofilemanager/device_profile_manager.cpp b/services/core/src/deviceprofilemanager/device_profile_manager.cpp index 58290665..36b4297e 100644 --- a/services/core/src/deviceprofilemanager/device_profile_manager.cpp +++ b/services/core/src/deviceprofilemanager/device_profile_manager.cpp @@ -494,7 +494,7 @@ int32_t DeviceProfileManager::SyncDeviceProfile(const DistributedDeviceProfile:: return DP_INVALID_PARAMS; } std::vector ohBasedDevices; - std::vector notOHBasedDevices; + std::vector> notOHBasedDevices; ProfileCache::GetInstance().FilterAndGroupOnlineDevices(syncOptions.GetDeviceList(), ohBasedDevices, notOHBasedDevices); if (ohBasedDevices.empty() && notOHBasedDevices.empty()) { @@ -596,7 +596,8 @@ void DeviceProfileManager::UnloadDpSyncAdapter() } } -int32_t DeviceProfileManager::SyncWithNotOHBasedDevice(const std::vector& notOHBasedDevices, +int32_t DeviceProfileManager::SyncWithNotOHBasedDevice( + const std::vector>& notOHBasedDevices, const std::string& callerDescriptor, sptr syncCompletedCallback) { if (!LoadDpSyncAdapter()) { @@ -604,22 +605,26 @@ int32_t DeviceProfileManager::SyncWithNotOHBasedDevice(const std::vector(item); + std::string peerNetworkId = std::get<1>(item); + bool isP2p = std::get<2>(item); + if (RunloadedFunction(peerUdid, peerNetworkId, syncCompletedCallback, isP2p) != DP_SUCCESS) { HILOGE("Sync With NotOHBasedDevice Failed. deviceId:%{public}s", - ProfileUtils::GetAnonyString(deviceId).c_str()); - SyncWithNotOHBasedDeviceFailed({deviceId}, syncCompletedCallback); + ProfileUtils::GetAnonyString(item[1]).c_str()); + SyncWithNotOHBasedDeviceFailed({item}, syncCompletedCallback); } } return DP_SUCCESS; } -void DeviceProfileManager::SyncWithNotOHBasedDeviceFailed(const std::vector& notOHBasedDevices, +void DeviceProfileManager::SyncWithNotOHBasedDeviceFailed( + const std::vector>& notOHBasedDevices, sptr syncCompletedCallback) { std::map syncResults; - for (const auto& deviceId : notOHBasedDevices) { - syncResults[deviceId] = SyncStatus::FAILED; + for (const auto& item : notOHBasedDevices) { + syncResults[std::get<1>(item)] = SyncStatus::FAILED; } sptr syncListenerProxy = iface_cast(syncCompletedCallback); if (syncListenerProxy == nullptr) { @@ -629,19 +634,19 @@ void DeviceProfileManager::SyncWithNotOHBasedDeviceFailed(const std::vectorOnSyncCompleted(syncResults); } -int32_t DeviceProfileManager::RunloadedFunction(const std::string& deviceId, sptr syncCompletedCallback) +int32_t DeviceProfileManager::RunloadedFunction(const std::string& peerUdid, const std::string& peerNetId, + sptr syncCompletedCallback, bool isP2p) { std::lock_guard lock(isAdapterLoadLock_); if (dpSyncAdapter_ == nullptr) { HILOGE("dpSyncAdapter is nullptr."); return DP_LOAD_SYNC_ADAPTER_FAILED; } - if (dpSyncAdapter_->DetectRemoteDPVersion(deviceId) != DP_SUCCESS) { + if (dpSyncAdapter_->DetectRemoteDPVersion(peerNetId) != DP_SUCCESS) { HILOGE("dp service adapter detect remote version failed."); return DP_LOAD_SYNC_ADAPTER_FAILED; } - const std::list deviceIdList = { deviceId }; - if (dpSyncAdapter_->SyncProfile(deviceIdList, syncCompletedCallback) != DP_SUCCESS) { + if (dpSyncAdapter_->SyncProfile(peerUdid, peerNetId, syncCompletedCallback, isP2p) != DP_SUCCESS) { HILOGE("dp service adapter sync profile failed."); return DP_LOAD_SYNC_ADAPTER_FAILED; } diff --git a/services/core/src/utils/profile_cache.cpp b/services/core/src/utils/profile_cache.cpp index fddc0c65..04fe9859 100644 --- a/services/core/src/utils/profile_cache.cpp +++ b/services/core/src/utils/profile_cache.cpp @@ -847,7 +847,8 @@ int32_t ProfileCache::AddAllTrustedDevices(const std::vector& } bool ProfileCache::FilterAndGroupOnlineDevices(const std::vector& deviceList, - std::vector& ohBasedDevices, std::vector& notOHBasedDevices) + std::vector& ohBasedDevices, + std::vector>& notOHBasedDevicess) { HILOGI("deviceList.size: %{public}zu!", deviceList.size()); if (deviceList.size() == 0 || deviceList.size() > MAX_DEVICE_SIZE) { @@ -862,7 +863,7 @@ bool ProfileCache::FilterAndGroupOnlineDevices(const std::vector& d if (item.GetOsType() == OHOS_TYPE) { ohBasedDevices.push_back(item.GetNetworkId()); } else { - notOHBasedDevices.push_back(item.GetNetworkId()); + notOHBasedDevices.push_back({item.GetUdid(), item.GetNetworkId(), ProfileUtils::IsP2p(item.GetAuthForm())}); } } return true; -- Gitee From 8820dc500b59fa93f699864f8130d3edc6861e41 Mon Sep 17 00:00:00 2001 From: wzhhhh Date: Tue, 24 Jun 2025 07:13:24 +0000 Subject: [PATCH 2/5] update services/core/src/deviceprofilemanager/device_profile_manager.cpp. Signed-off-by: wzhhhh --- .../core/src/deviceprofilemanager/device_profile_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/core/src/deviceprofilemanager/device_profile_manager.cpp b/services/core/src/deviceprofilemanager/device_profile_manager.cpp index 36b4297e..1d82412c 100644 --- a/services/core/src/deviceprofilemanager/device_profile_manager.cpp +++ b/services/core/src/deviceprofilemanager/device_profile_manager.cpp @@ -611,7 +611,7 @@ int32_t DeviceProfileManager::SyncWithNotOHBasedDevice( bool isP2p = std::get<2>(item); if (RunloadedFunction(peerUdid, peerNetworkId, syncCompletedCallback, isP2p) != DP_SUCCESS) { HILOGE("Sync With NotOHBasedDevice Failed. deviceId:%{public}s", - ProfileUtils::GetAnonyString(item[1]).c_str()); + ProfileUtils::GetAnonyString(std::get<1>(item)).c_str()); SyncWithNotOHBasedDeviceFailed({item}, syncCompletedCallback); } } -- Gitee From c260f4ff1ebc73ac87a4026a5111a6a373a4da19 Mon Sep 17 00:00:00 2001 From: wzhhhh Date: Tue, 24 Jun 2025 07:14:42 +0000 Subject: [PATCH 3/5] update services/core/src/utils/profile_cache.cpp. Signed-off-by: wzhhhh --- services/core/src/utils/profile_cache.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/core/src/utils/profile_cache.cpp b/services/core/src/utils/profile_cache.cpp index 04fe9859..c317f65f 100644 --- a/services/core/src/utils/profile_cache.cpp +++ b/services/core/src/utils/profile_cache.cpp @@ -863,7 +863,8 @@ bool ProfileCache::FilterAndGroupOnlineDevices(const std::vector& d if (item.GetOsType() == OHOS_TYPE) { ohBasedDevices.push_back(item.GetNetworkId()); } else { - notOHBasedDevices.push_back({item.GetUdid(), item.GetNetworkId(), ProfileUtils::IsP2p(item.GetAuthForm())}); + notOHBasedDevicess.push_back({item.GetUdid(), item.GetNetworkId(), + ProfileUtils::IsP2p(item.GetAuthForm())}); } } return true; -- Gitee From 1f491b72d22a7fe466f459f39d1d6036114e1277 Mon Sep 17 00:00:00 2001 From: wzhhhh Date: Tue, 24 Jun 2025 08:34:10 +0000 Subject: [PATCH 4/5] update services/core/src/deviceprofilemanager/device_profile_manager.cpp. Signed-off-by: wzhhhh --- .../core/src/deviceprofilemanager/device_profile_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/core/src/deviceprofilemanager/device_profile_manager.cpp b/services/core/src/deviceprofilemanager/device_profile_manager.cpp index 1d82412c..cfd575ce 100644 --- a/services/core/src/deviceprofilemanager/device_profile_manager.cpp +++ b/services/core/src/deviceprofilemanager/device_profile_manager.cpp @@ -611,7 +611,7 @@ int32_t DeviceProfileManager::SyncWithNotOHBasedDevice( bool isP2p = std::get<2>(item); if (RunloadedFunction(peerUdid, peerNetworkId, syncCompletedCallback, isP2p) != DP_SUCCESS) { HILOGE("Sync With NotOHBasedDevice Failed. deviceId:%{public}s", - ProfileUtils::GetAnonyString(std::get<1>(item)).c_str()); + ProfileUtils::GetAnonyString(std::get(item)).c_str()); SyncWithNotOHBasedDeviceFailed({item}, syncCompletedCallback); } } -- Gitee From 63a528a765c77548d52cf324838b2ee46f6b9f05 Mon Sep 17 00:00:00 2001 From: wzhhhh Date: Tue, 24 Jun 2025 09:17:10 +0000 Subject: [PATCH 5/5] update services/core/src/deviceprofilemanager/device_profile_manager.cpp. Signed-off-by: wzhhhh --- .../core/src/deviceprofilemanager/device_profile_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/core/src/deviceprofilemanager/device_profile_manager.cpp b/services/core/src/deviceprofilemanager/device_profile_manager.cpp index cfd575ce..287d3abc 100644 --- a/services/core/src/deviceprofilemanager/device_profile_manager.cpp +++ b/services/core/src/deviceprofilemanager/device_profile_manager.cpp @@ -611,7 +611,7 @@ int32_t DeviceProfileManager::SyncWithNotOHBasedDevice( bool isP2p = std::get<2>(item); if (RunloadedFunction(peerUdid, peerNetworkId, syncCompletedCallback, isP2p) != DP_SUCCESS) { HILOGE("Sync With NotOHBasedDevice Failed. deviceId:%{public}s", - ProfileUtils::GetAnonyString(std::get(item)).c_str()); + ProfileUtils::GetAnonyString(peerNetworkId).c_str()); SyncWithNotOHBasedDeviceFailed({item}, syncCompletedCallback); } } -- Gitee