From ee17f16df4b4246cc5cac5e405cd9a9f793ed3eb Mon Sep 17 00:00:00 2001 From: BrainL Date: Mon, 12 May 2025 10:13:05 +0800 Subject: [PATCH 1/4] add Signed-off-by: BrainL --- commondependency/src/deviceprofile_connector.cpp | 8 ++++---- interfaces/inner_kits/native_cpp/include/dm_device_info.h | 4 ++++ .../implementation/src/device_manager_service_impl.cpp | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index 111b38c12..67c2797a8 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -676,10 +676,10 @@ std::unordered_map DeviceProfileConnector::GetAuthFormM deviceIdMap[trustDeviceId] = DmAuthForm::IDENTICAL_ACCOUNT; continue; } else if (highestBindType == SHARE_TYPE) { - if (CheckSinkShareType(item, userId, deviceId, trustDeviceId, DmAuthForm::ACROSS_ACCOUNT)) { + if (CheckSinkShareType(item, userId, deviceId, trustDeviceId, DmAuthForm::SHARE)) { continue; } - deviceIdMap[trustDeviceId] = DmAuthForm::ACROSS_ACCOUNT; + deviceIdMap[trustDeviceId] = DmAuthForm::SHARE; continue; } else if (highestBindType == DEVICE_PEER_TO_PEER_TYPE || highestBindType == APP_PEER_TO_PEER_TYPE || highestBindType == SERVICE_PEER_TO_PEER_TYPE) { @@ -703,7 +703,7 @@ bool DeviceProfileConnector::CheckSinkShareType(const DistributedDeviceProfile:: if (profile.GetAccessee().GetAccesseeUserId() == userId && profile.GetAccessee().GetAccesseeDeviceId() == deviceId && profile.GetAccesser().GetAccesserDeviceId() == trustDeviceId && - bindType == DmAuthForm::ACROSS_ACCOUNT) { + bindType == DmAuthForm::SHARE) { return true; } return false; @@ -789,7 +789,7 @@ int32_t DeviceProfileConnector::HandleDmAuthForm(AccessControlProfile profiles, return CheckAuthForm(DmAuthForm::PEER_TO_PEER, profiles, discoveryInfo); } if (profiles.GetBindType() == DM_SHARE) { - return CheckAuthForm(DmAuthForm::ACROSS_ACCOUNT, profiles, discoveryInfo); + return CheckAuthForm(DmAuthForm::SHARE, profiles, discoveryInfo); } return DmAuthForm::INVALID_TYPE; } diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index f4d1ea3d6..a9d610c33 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -149,6 +149,10 @@ typedef enum DmAuthForm { * Across Account Device auth. */ ACROSS_ACCOUNT = 2, + /** + * Share + */ + SHARE = 3; } DmAuthForm; /** diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 844e3e3d1..11f5a8a69 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -640,7 +640,7 @@ void DeviceManagerServiceImpl::HandleOffline(DmDeviceState devState, DmDeviceInf softbusConnector_->SetProcessInfo(processInfo); } else if (static_cast(item.second) == USER && bindType == SHARE_TYPE) { LOGI("The offline device is device bind level and share bind type."); - devInfo.authForm = DmAuthForm::ACROSS_ACCOUNT; + devInfo.authForm = DmAuthForm::SHARE; processInfo.userId = item.first; softbusConnector_->SetProcessInfo(processInfo); } else if (static_cast(item.second) == USER && bindType != SHARE_TYPE) { @@ -713,7 +713,7 @@ void DeviceManagerServiceImpl::SetOnlineProcessInfo(const uint32_t &bindType, Pr LOGI("ProcessDeviceStateChange authForm is share, peer is src."); return; } - devInfo.authForm = DmAuthForm::ACROSS_ACCOUNT; + devInfo.authForm = DmAuthForm::SHARE; softbusConnector_->SetProcessInfo(processInfo); } LOGI("DeviceManagerServiceImpl::HandleOnline success devInfo authForm is %{public}d.", devInfo.authForm); -- Gitee From 23de79708672f6689f08b4492ad9c4106581ceeb Mon Sep 17 00:00:00 2001 From: BrainL Date: Mon, 12 May 2025 11:18:54 +0800 Subject: [PATCH 2/4] modify Signed-off-by: BrainL --- interfaces/inner_kits/native_cpp/include/dm_device_info.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index a9d610c33..8db197757 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -152,7 +152,7 @@ typedef enum DmAuthForm { /** * Share */ - SHARE = 3; + SHARE = 3, } DmAuthForm; /** -- Gitee From fd285038ba30608ddda0210d5fb516c0251cc700 Mon Sep 17 00:00:00 2001 From: BrainL Date: Mon, 12 May 2025 19:22:54 +0800 Subject: [PATCH 3/4] modify UT Signed-off-by: BrainL --- .../relationship_sync_mgr.cpp | 2 +- .../UTTest_dm_deviceprofile_connector.cpp | 6 +++--- .../UTTest_dm_deviceprofile_connector_second.cpp | 16 ++++++++-------- .../UTTest_device_manager_service_impl_first.cpp | 2 +- test/unittest/UTTest_relationship_sync_mgr.cpp | 11 +++++------ 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp index 723e43fc3..9276bf679 100644 --- a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp +++ b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp @@ -147,7 +147,7 @@ bool RelationShipChangeMsg::ToBroadcastPayLoad(uint8_t *&msg, uint32_t &len) con void RelationShipChangeMsg::ToShareUnbindPayLoad(uint8_t *&msg, uint32_t &len) const { - if (credId.length() != (CREDID_PAYLOAD_LEN - USERID_PAYLOAD_LEN)) { + if (credId.length() <= (CREDID_PAYLOAD_LEN - USERID_PAYLOAD_LEN)) { LOGE("ToShareUnbindPayLoad credId length is invalid."); len = 0; return; diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp index 3731b851f..ffcd92306 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp @@ -727,7 +727,7 @@ HWTEST_F(DeviceProfileConnectorTest, HandleDmAuthForm_005, testing::ext::TestSiz profiles.SetBindLevel(USER); DmDiscoveryInfo discoveryInfo; int32_t ret = DeviceProfileConnector::GetInstance().HandleDmAuthForm(profiles, discoveryInfo); - EXPECT_EQ(ret, ACROSS_ACCOUNT); + EXPECT_EQ(ret, PEER_TO_PEER); } HWTEST_F(DeviceProfileConnectorTest, HandleDmAuthForm_006, testing::ext::TestSize.Level1) @@ -741,7 +741,7 @@ HWTEST_F(DeviceProfileConnectorTest, HandleDmAuthForm_006, testing::ext::TestSiz discoveryInfo.pkgname = "pkgName"; discoveryInfo.localDeviceId = "localDeviceId"; int32_t ret = DeviceProfileConnector::GetInstance().HandleDmAuthForm(profiles, discoveryInfo); - EXPECT_EQ(ret, ACROSS_ACCOUNT); + EXPECT_EQ(ret, PEER_TO_PEER); } HWTEST_F(DeviceProfileConnectorTest, HandleDmAuthForm_007, testing::ext::TestSize.Level1) @@ -755,7 +755,7 @@ HWTEST_F(DeviceProfileConnectorTest, HandleDmAuthForm_007, testing::ext::TestSiz discoveryInfo.pkgname = "pkgName"; discoveryInfo.localDeviceId = "localDeviceId"; int32_t ret = DeviceProfileConnector::GetInstance().HandleDmAuthForm(profiles, discoveryInfo); - EXPECT_EQ(ret, ACROSS_ACCOUNT); + EXPECT_EQ(ret, PEER_TO_PEER); } HWTEST_F(DeviceProfileConnectorTest, HandleDmAuthForm_008, testing::ext::TestSize.Level1) diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp index a7afeaccc..b8d4deb1a 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector_second.cpp @@ -592,7 +592,7 @@ HWTEST_F(DeviceProfileConnectorSecondTest, HandleDmAuthForm_009, testing::ext::T profiles.SetBindLevel(USER); DmDiscoveryInfo discoveryInfo; int32_t ret = DeviceProfileConnector::GetInstance().HandleDmAuthForm(profiles, discoveryInfo); - EXPECT_EQ(ret, ACROSS_ACCOUNT); + EXPECT_EQ(ret, SHARE); } HWTEST_F(DeviceProfileConnectorSecondTest, HandleDmAuthForm_010, testing::ext::TestSize.Level1) @@ -606,7 +606,7 @@ HWTEST_F(DeviceProfileConnectorSecondTest, HandleDmAuthForm_010, testing::ext::T discoveryInfo.pkgname = "ohos_test"; discoveryInfo.localDeviceId = "localDeviceId"; int32_t ret = DeviceProfileConnector::GetInstance().HandleDmAuthForm(profiles, discoveryInfo); - EXPECT_EQ(ret, ACROSS_ACCOUNT); + EXPECT_EQ(ret, SHARE); } HWTEST_F(DeviceProfileConnectorSecondTest, HandleDmAuthForm_011, testing::ext::TestSize.Level1) @@ -620,7 +620,7 @@ HWTEST_F(DeviceProfileConnectorSecondTest, HandleDmAuthForm_011, testing::ext::T discoveryInfo.pkgname = "pkgName"; discoveryInfo.localDeviceId = "localDeviceId"; int32_t ret = DeviceProfileConnector::GetInstance().HandleDmAuthForm(profiles, discoveryInfo); - EXPECT_EQ(ret, ACROSS_ACCOUNT); + EXPECT_EQ(ret, SHARE); } HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_001, testing::ext::TestSize.Level1) @@ -629,7 +629,7 @@ HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_001, testing::ext: int32_t userId = 123456; std::string deviceId = "deviceId"; std::string trustDeviceId = "trustDeviceId"; - int32_t bindType = DmAuthForm::ACROSS_ACCOUNT; + int32_t bindType = DmAuthForm::SHARE; DistributedDeviceProfile::Accessee accessee; accessee.SetAccesseeUserId(userId); @@ -651,7 +651,7 @@ HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_002, testing::ext: int32_t userId = 123456; std::string deviceId = "deviceId"; std::string trustDeviceId = "trustDeviceId"; - int32_t bindType = DmAuthForm::ACROSS_ACCOUNT; + int32_t bindType = DmAuthForm::SHARE; DistributedDeviceProfile::Accessee accessee; accessee.SetAccesseeUserId(0); @@ -664,7 +664,7 @@ HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_002, testing::ext: bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType( profile, userId, deviceId, trustDeviceId, bindType); - EXPECT_TRUE(ret); + EXPECT_FALSE(ret); } HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_003, testing::ext::TestSize.Level1) @@ -673,7 +673,7 @@ HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_003, testing::ext: int32_t userId = 123456; std::string deviceId = "deviceId"; std::string trustDeviceId = "trustDeviceId"; - int32_t bindType = DmAuthForm::ACROSS_ACCOUNT; + int32_t bindType = DmAuthForm::SHARE; DistributedDeviceProfile::Accessee accessee; accessee.SetAccesseeUserId(-1); @@ -685,7 +685,7 @@ HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_003, testing::ext: profile.SetAccesser(accesser); bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType( profile, userId, deviceId, trustDeviceId, bindType); - EXPECT_TRUE(ret); + EXPECT_FALSE(ret); } HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_004, testing::ext::TestSize.Level1) diff --git a/test/unittest/UTTest_device_manager_service_impl_first.cpp b/test/unittest/UTTest_device_manager_service_impl_first.cpp index 13b4a1d10..0d7ef000b 100644 --- a/test/unittest/UTTest_device_manager_service_impl_first.cpp +++ b/test/unittest/UTTest_device_manager_service_impl_first.cpp @@ -526,7 +526,7 @@ HWTEST_F(DeviceManagerServiceImplFirstTest, SetOnlineProcessInfo_006, testing::e deviceManagerServiceImpl_->SetOnlineProcessInfo( bindType, processInfo, devInfo, requestDeviceId, trustDeviceId, devState); - EXPECT_EQ(devInfo.authForm, DmAuthForm::ACROSS_ACCOUNT); + EXPECT_EQ(devInfo.authForm, DmAuthForm::SHARE); } } // namespace } // namespace DistributedHardware diff --git a/test/unittest/UTTest_relationship_sync_mgr.cpp b/test/unittest/UTTest_relationship_sync_mgr.cpp index 0121fe018..fe46bd0d1 100644 --- a/test/unittest/UTTest_relationship_sync_mgr.cpp +++ b/test/unittest/UTTest_relationship_sync_mgr.cpp @@ -1214,8 +1214,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToBroadcastPayLoad_010, testing::ext::TestSiz bool result = msg.ToBroadcastPayLoad(msgPtr, len); ASSERT_TRUE(result); - ASSERT_NE(msgPtr, nullptr); - ASSERT_GT(len, 0); + ASSERT_EQ(msgPtr, nullptr); delete[] msgPtr; } @@ -1261,7 +1260,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToShareUnbindPayLoad_001, testing::ext::TestS { RelationShipChangeMsg msg; msg.userId = 12345; - msg.credId = "cred123"; + msg.credId = "123456"; uint8_t* msgPtr = nullptr; uint32_t len = 0; @@ -1285,7 +1284,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToShareUnbindPayLoad_002, testing::ext::TestS { RelationShipChangeMsg msg; msg.userId = 12345; - msg.credId = ""; + msg.credId = "123456"; uint8_t* msgPtr = nullptr; uint32_t len = 0; @@ -1299,7 +1298,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToShareUnbindPayLoad_002, testing::ext::TestS ASSERT_EQ(msgPtr[1], static_cast((msg.userId >> 8) & 0xFF)); for (int i = USERID_PAYLOAD_LEN; i < SHARE_UNBIND_PAYLOAD_LEN; i++) { - ASSERT_EQ(msgPtr[i], 0); + ASSERT_NE(msgPtr[i], 0); } delete[] msgPtr; @@ -1309,7 +1308,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToShareUnbindPayLoad_003, testing::ext::TestS { RelationShipChangeMsg msg; msg.userId = UINT16_MAX; - msg.credId = "cred123"; + msg.credId = "123456"; uint8_t* msgPtr = nullptr; uint32_t len = 0; -- Gitee From 0573bcf06cef9db4152f1e03025ec9aa81b65a2c Mon Sep 17 00:00:00 2001 From: BrainL Date: Tue, 13 May 2025 15:48:54 +0800 Subject: [PATCH 4/4] modify Signed-off-by: BrainL --- test/unittest/UTTest_relationship_sync_mgr.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unittest/UTTest_relationship_sync_mgr.cpp b/test/unittest/UTTest_relationship_sync_mgr.cpp index fe46bd0d1..a4cf989ba 100644 --- a/test/unittest/UTTest_relationship_sync_mgr.cpp +++ b/test/unittest/UTTest_relationship_sync_mgr.cpp @@ -1260,7 +1260,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToShareUnbindPayLoad_001, testing::ext::TestS { RelationShipChangeMsg msg; msg.userId = 12345; - msg.credId = "123456"; + msg.credId = "12345678"; uint8_t* msgPtr = nullptr; uint32_t len = 0; @@ -1284,7 +1284,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToShareUnbindPayLoad_002, testing::ext::TestS { RelationShipChangeMsg msg; msg.userId = 12345; - msg.credId = "123456"; + msg.credId = "12345678"; uint8_t* msgPtr = nullptr; uint32_t len = 0; @@ -1308,7 +1308,7 @@ HWTEST_F(ReleationShipSyncMgrTest, ToShareUnbindPayLoad_003, testing::ext::TestS { RelationShipChangeMsg msg; msg.userId = UINT16_MAX; - msg.credId = "123456"; + msg.credId = "12345678"; uint8_t* msgPtr = nullptr; uint32_t len = 0; -- Gitee