diff --git a/services/core/include/deviceprofilemanager/device_profile_manager.h b/services/core/include/deviceprofilemanager/device_profile_manager.h index e629e204d84d035d7a585cc6fb4601561408c81a..887e85da8aa574e1b3bd9b397842bf9ff18a3e2c 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 5ca3dbe27b7ee330f562011d6049715e397953e2..bb8d149d1ec3568c700be7513cbac5175cbf908f 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 582906650093ba0ec4a9c57d2be8b9525d1037cd..287d3abc98ae6fa197216f379e7a01ced2c8a8dc 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(peerNetworkId).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 fddc0c65ed24c775a0b8da4c12b0993a3aacc14e..c317f65f6cd617b10f9334b38deefb37a497857b 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,8 @@ bool ProfileCache::FilterAndGroupOnlineDevices(const std::vector& d if (item.GetOsType() == OHOS_TYPE) { ohBasedDevices.push_back(item.GetNetworkId()); } else { - notOHBasedDevices.push_back(item.GetNetworkId()); + notOHBasedDevicess.push_back({item.GetUdid(), item.GetNetworkId(), + ProfileUtils::IsP2p(item.GetAuthForm())}); } } return true;