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; diff --git a/services/core/test/unittest/device_profile_manager_test.cpp b/services/core/test/unittest/device_profile_manager_test.cpp index 7c73d6b20172ca8a67d1a2642aa2ad9a613fccec..8f7a3de23dbf4bc0bafce40a8cceed204020921f 100644 --- a/services/core/test/unittest/device_profile_manager_test.cpp +++ b/services/core/test/unittest/device_profile_manager_test.cpp @@ -1527,9 +1527,12 @@ HWTEST_F(DeviceProfileManagerTest, GetInKvDB001, TestSize.Level1) */ HWTEST_F(DeviceProfileManagerTest, RunloadedFunction001, TestSize.Level1) { + DeviceProfileManager::GetInstance().dpSyncAdapter_ = nullptr; OHOS::sptr syncCb = OHOS::sptr(new SyncCallback()); - string peerNetworkId = "peerNetworkId"; - int32_t ret = DeviceProfileManager::GetInstance().RunloadedFunction(peerNetworkId, syncCb); + const std::string& peerUdid = "peerUdid"; + const std::string& peerNetId = "peerNetId"; + bool isP2p = false; + int32_t ret = DeviceProfileManager::GetInstance().RunloadedFunction(peerUdid, peerNetId, syncCb, isP2p); EXPECT_EQ(ret, DP_LOAD_SYNC_ADAPTER_FAILED); } /** @@ -1541,8 +1544,10 @@ HWTEST_F(DeviceProfileManagerTest, RunloadedFunction001, TestSize.Level1) HWTEST_F(DeviceProfileManagerTest, RunloadedFunction002, TestSize.Level1) { OHOS::sptr syncCb = OHOS::sptr(new SyncCallback()); - string peerNetworkId = "peerNetworkId"; - int32_t ret = DeviceProfileManager::GetInstance().RunloadedFunction(peerNetworkId, syncCb); + const std::string& peerUdid = "peerUdid"; + const std::string& peerNetId = "peerNetId"; + bool isP2p = false; + int32_t ret = DeviceProfileManager::GetInstance().RunloadedFunction(peerUdid, peerNetId, syncCb, isP2p); EXPECT_EQ(ret, DP_LOAD_SYNC_ADAPTER_FAILED); } @@ -1858,9 +1863,9 @@ HWTEST_F(DeviceProfileManagerTest, DeleteRemovedUserData005, TestSize.Level1) */ HWTEST_F(DeviceProfileManagerTest, SyncWithNotOHBasedDevice001, TestSize.Level1) { - std::vector notOHBasedDevices; const std::string callerDescriptor; sptr syncCompletedCallback; + const std::vector> notOHBasedDevices; int32_t ret = DeviceProfileManager::GetInstance().SyncWithNotOHBasedDevice( notOHBasedDevices, callerDescriptor, syncCompletedCallback); EXPECT_EQ(ret, DP_LOAD_SYNC_ADAPTER_FAILED); diff --git a/services/core/test/unittest/profile_cache_test.cpp b/services/core/test/unittest/profile_cache_test.cpp index 9cb605a3d4975b36ac4f3f597cf6f518e9ac389e..98a3c5b0456242a36e59ff1aa07cd928a6eea5d2 100644 --- a/services/core/test/unittest/profile_cache_test.cpp +++ b/services/core/test/unittest/profile_cache_test.cpp @@ -611,8 +611,8 @@ HWTEST_F(ProfileCacheTest, FilterAndGroupOnlineDevices001, TestSize.Level1) { vector deviceList; std::vector ohBasedDevices; - std::vector notOHBasedDevices; - bool res = ProfileCache::GetInstance().FilterAndGroupOnlineDevices(deviceList, ohBasedDevices, notOHBasedDevices); + std::vector> notOHBasedDevicess; + bool res = ProfileCache::GetInstance().FilterAndGroupOnlineDevices(deviceList, ohBasedDevices, notOHBasedDevicess); EXPECT_FALSE(res); } @@ -629,8 +629,8 @@ HWTEST_F(ProfileCacheTest, FilterAndGroupOnlineDevices002, TestSize.Level1) deviceList.emplace_back("networkId"); } std::vector ohBasedDevices; - std::vector notOHBasedDevices; - bool res = ProfileCache::GetInstance().FilterAndGroupOnlineDevices(deviceList, ohBasedDevices, notOHBasedDevices); + std::vector> notOHBasedDevicess; + bool res = ProfileCache::GetInstance().FilterAndGroupOnlineDevices(deviceList, ohBasedDevices, notOHBasedDevicess); EXPECT_FALSE(res); } @@ -656,11 +656,11 @@ HWTEST_F(ProfileCacheTest, FilterAndGroupOnlineDevices003, TestSize.Level1) std::vector deviceList {deviceInfo1.GetNetworkId(), deviceInfo2.GetNetworkId()}; std::vector ohBasedDevices; - std::vector notOHBasedDevices; - bool res = ProfileCache::GetInstance().FilterAndGroupOnlineDevices(deviceList, ohBasedDevices, notOHBasedDevices); + std::vector> notOHBasedDevicess; + bool res = ProfileCache::GetInstance().FilterAndGroupOnlineDevices(deviceList, ohBasedDevices, notOHBasedDevicess); EXPECT_TRUE(res); EXPECT_FALSE(ohBasedDevices.empty()); - EXPECT_FALSE(notOHBasedDevices.empty()); + EXPECT_FALSE(notOHBasedDevicess.empty()); ProfileCache::GetInstance().onlineDevMap_.erase(deviceInfo1.GetUdid()); ProfileCache::GetInstance().onlineDevMap_.erase(deviceInfo2.GetUdid()); }