From b4cbe338b520a41bbb09b6b8f0b6a56aa77cf684 Mon Sep 17 00:00:00 2001 From: libuyan Date: Wed, 25 Dec 2024 22:48:05 +0800 Subject: [PATCH 1/4] =?UTF-8?q?DM=E6=94=AF=E6=8C=81=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E7=BA=A7=E7=BB=91=E5=AE=9A=E8=AE=A4=E8=AF=81,=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=8D=95=E7=94=A8=E6=88=B7=E5=89=8D=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: libuyan --- common/include/dm_constants.h | 1 + .../include/ipc/model/ipc_unbind_device_req.h | 11 + .../include/deviceprofile_connector.h | 17 +- .../src/deviceprofile_connector.cpp | 168 ++++++++++++--- .../native_cpp/include/device_manager.h | 2 + .../native_cpp/include/device_manager_impl.h | 2 + .../native_cpp/src/device_manager_impl.cpp | 30 +++ .../src/ipc/standard/ipc_cmd_parser.cpp | 4 + interfaces/kits/js4.0/src/dm_native_util.cpp | 3 + .../authentication/auth_message_processor.h | 1 + .../include/authentication/dm_auth_manager.h | 8 +- .../include/device_manager_service_impl.h | 5 + .../device_manager_service_impl_lite.h | 3 + .../authentication/auth_message_processor.cpp | 6 + .../src/authentication/dm_auth_manager.cpp | 53 +++-- .../src/device_manager_service_impl.cpp | 33 ++- .../src/device_manager_service_impl_lite.cpp | 10 + .../service/include/device_manager_service.h | 6 + .../include/idevice_manager_service_impl.h | 5 + .../relationship_sync_mgr.h | 1 + .../service/src/device_manager_service.cpp | 93 +++++++- .../src/ipc/standard/ipc_cmd_parser.cpp | 8 +- .../relationship_sync_mgr.cpp | 20 +- .../dm_auth_manager_fuzzer.cpp | 2 +- .../UTTest_dm_auth_manager_first.cpp | 11 +- .../UTTest_dm_auth_manager_third.cpp | 119 ++++++++-- .../UTTest_dm_deviceprofile_connector.cpp | 204 +++++------------- .../device_profile_connector_fuzzer.cpp | 4 +- 28 files changed, 597 insertions(+), 233 deletions(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 5053b0512..2615f88a7 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -230,6 +230,7 @@ constexpr const char* PARAM_KEY_CONN_ADDR_TYPE = "CONN_ADDR_TYPE"; constexpr const char* PARAM_KEY_PUBLISH_ID = "PUBLISH_ID"; constexpr const char* PARAM_KEY_SUBSCRIBE_ID = "SUBSCRIBE_ID"; constexpr const char* PARAM_KEY_TARGET_PKG_NAME = "TARGET_PKG_NAME"; +constexpr const char* PARAM_KEY_PEER_BUNDLE_NAME = "PEER_BUNDLE_NAME"; constexpr const char* PARAM_KEY_DISC_FREQ = "DISC_FREQ"; constexpr const char* PARAM_KEY_DISC_MEDIUM = "DISC_MEDIUM"; constexpr const char* PARAM_KEY_DISC_CAPABILITY = "DISC_CAPABILITY"; diff --git a/common/include/ipc/model/ipc_unbind_device_req.h b/common/include/ipc/model/ipc_unbind_device_req.h index 0777c871e..7700d47e1 100644 --- a/common/include/ipc/model/ipc_unbind_device_req.h +++ b/common/include/ipc/model/ipc_unbind_device_req.h @@ -44,8 +44,19 @@ public: deviceId_ = deviceId; } + const std::string &GetExtraInfo() const + { + return extra_; + } + + void SetExtraInfo(const std::string &extra) + { + extra_ = extra; + } + private: std::string deviceId_; + std::string extra_ = ""; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 7b746adc9..793d0e7cb 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -107,6 +107,7 @@ public: const std::string &deviceId); std::vector GetBindTypeByPkgName(std::string pkgName, std::string requestDeviceId, std::string trustUdid); + uint64_t GetTokenIdByNameAndDeviceId(std::string pkgName, std::string requestDeviceId); std::vector SyncAclByBindType(std::string pkgName, std::vector bindTypeVec, std::string localDeviceId, std::string targetDeviceId); int32_t GetDeviceAclParam(DmDiscoveryInfo discoveryInfo, bool &isOnline, int32_t &authForm); @@ -114,7 +115,7 @@ public: const std::string &peerUdid, int32_t peerUserId); void DeleteAclForUserRemoved(std::string localUdid, int32_t userId); DmOfflineParam DeleteAccessControlList(const std::string &pkgName, const std::string &localDeviceId, - const std::string &remoteDeviceId, int32_t bindLevel); + const std::string &remoteDeviceId, int32_t bindLevel, const std::string &extra); std::vector GetProcessInfoFromAclByUserId(const std::string &localDeviceId, const std::string &targetDeviceId, int32_t userId); bool CheckIdenticalAccount(int32_t userId, const std::string &accountId); @@ -141,6 +142,8 @@ public: int32_t HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, const std::string &localUdid); OHOS::DistributedHardware::ProcessInfo HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, const std::string &localUdid); + OHOS::DistributedHardware::ProcessInfo HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, + int32_t tokenId, const std::string &localUdid, int32_t peerTokenId); std::vector GetAllAccessControlProfile(); void DeleteAccessControlById(int64_t accessControlId); int32_t HandleUserSwitched(const std::string &localUdid, const std::vector &deviceVec, @@ -166,10 +169,11 @@ public: private: int32_t HandleDmAuthForm(DistributedDeviceProfile::AccessControlProfile profiles, DmDiscoveryInfo discoveryInfo); - void GetParamBindTypeVec(DistributedDeviceProfile::AccessControlProfile profiles, std::string pkgName, - std::string requestDeviceId, std::vector &bindTypeVec); - void ProcessBindType(DistributedDeviceProfile::AccessControlProfile profiles, DmDiscoveryInfo paramInfo, - std::vector &sinkBindType, std::vector &bindTypeIndex, uint32_t index); + void GetParamBindTypeVec(DistributedDeviceProfile::AccessControlProfile profiles, std::string requestDeviceId, + std::vector &bindTypeVec, std::string trustUdid); + void ProcessBindType(DistributedDeviceProfile::AccessControlProfile profiles, std::string localDeviceId, + std::vector &sinkBindType, std::vector &bindTypeIndex, + uint32_t index, std::string targetDeviceId); int32_t GetAuthForm(DistributedDeviceProfile::AccessControlProfile profiles, const std::string &trustDev, const std::string &reqDev); int32_t CheckAuthForm(DmAuthForm form, DistributedDeviceProfile::AccessControlProfile profiles, @@ -179,6 +183,9 @@ private: void DeleteAppBindLevel(DmOfflineParam &offlineParam, const std::string &pkgName, const std::vector &profiles, const std::string &localUdid, const std::string &remoteUdid); + void DeleteAppBindLevel(DmOfflineParam &offlineParam, const std::string &pkgName, + const std::vector &profiles, const std::string &localUdid, + const std::string &remoteUdid, const std::string &extra); void DeleteDeviceBindLevel(DmOfflineParam &offlineParam, const std::vector &profiles, const std::string &localUdid, const std::string &remoteUdid); diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index e5cb7d3e1..806d77066 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -258,13 +258,32 @@ std::vector DeviceProfileConnector::GetBindTypeByPkgName(std::string pk if (trustUdid != item.GetTrustDeviceId() || item.GetStatus() != ACTIVE) { continue; } - GetParamBindTypeVec(item, pkgName, requestDeviceId, bindTypeVec); + GetParamBindTypeVec(item, requestDeviceId, bindTypeVec, trustUdid); } return bindTypeVec; } -void DeviceProfileConnector::GetParamBindTypeVec(AccessControlProfile profiles, std::string pkgName, - std::string requestDeviceId, std::vector &bindTypeVec) +uint64_t DeviceProfileConnector::GetTokenIdByNameAndDeviceId(std::string pkgName, std::string requestDeviceId) +{ + std::vector profiles = GetAccessControlProfile(); + uint64_t peerTokenId = 0; + for (auto &item : profiles) { + if (item.GetAccesser().GetAccesserBundleName() == pkgName && + item.GetAccesser().GetAccesserDeviceId() == requestDeviceId) { + peerTokenId = static_cast(item.GetAccesser().GetAccesserTokenId()); + break; + } + if (item.GetAccessee().GetAccesseeBundleName() == pkgName && + item.GetAccessee().GetAccesseeDeviceId() == requestDeviceId) { + peerTokenId = static_cast(item.GetAccessee().GetAccesseeTokenId()); + break; + } + } + return peerTokenId; +} + +void DeviceProfileConnector::GetParamBindTypeVec(AccessControlProfile profiles, std::string requestDeviceId, + std::vector &bindTypeVec, std::string trustUdid) { if (profiles.GetBindType() == DM_IDENTICAL_ACCOUNT) { bindTypeVec.push_back(IDENTICAL_ACCOUNT_TYPE); @@ -274,12 +293,12 @@ void DeviceProfileConnector::GetParamBindTypeVec(AccessControlProfile profiles, bindTypeVec.push_back(DEVICE_PEER_TO_PEER_TYPE); } if (profiles.GetBindLevel() == APP) { - if (profiles.GetAccesser().GetAccesserBundleName() == pkgName && - profiles.GetAccesser().GetAccesserDeviceId() == requestDeviceId) { + if (profiles.GetAccesser().GetAccesserDeviceId() == trustUdid && + profiles.GetAccessee().GetAccesseeDeviceId() == requestDeviceId) { bindTypeVec.push_back(APP_PEER_TO_PEER_TYPE); } - if ((profiles.GetAccessee().GetAccesseeBundleName() == pkgName && - profiles.GetAccessee().GetAccesseeDeviceId() == requestDeviceId)) { + if (profiles.GetAccessee().GetAccesseeDeviceId() == trustUdid && + profiles.GetAccesser().GetAccesserDeviceId() == requestDeviceId) { bindTypeVec.push_back(APP_PEER_TO_PEER_TYPE); } } @@ -289,12 +308,12 @@ void DeviceProfileConnector::GetParamBindTypeVec(AccessControlProfile profiles, bindTypeVec.push_back(DEVICE_ACROSS_ACCOUNT_TYPE); } if (profiles.GetBindLevel() == APP) { - if (profiles.GetAccesser().GetAccesserBundleName() == pkgName && - profiles.GetAccesser().GetAccesserDeviceId() == requestDeviceId) { + if (profiles.GetAccesser().GetAccesserDeviceId() == trustUdid && + profiles.GetAccessee().GetAccesseeDeviceId() == requestDeviceId) { bindTypeVec.push_back(APP_ACROSS_ACCOUNT_TYPE); } - if ((profiles.GetAccessee().GetAccesseeBundleName() == pkgName && - profiles.GetAccessee().GetAccesseeDeviceId() == requestDeviceId)) { + if (profiles.GetAccessee().GetAccesseeDeviceId() == trustUdid && + profiles.GetAccesser().GetAccesserDeviceId() == requestDeviceId) { bindTypeVec.push_back(APP_ACROSS_ACCOUNT_TYPE); } } @@ -313,13 +332,13 @@ std::vector DeviceProfileConnector::CompareBindType(std::vector &sinkBindType, std::vector &bindTypeIndex, uint32_t index) +void DeviceProfileConnector::ProcessBindType(AccessControlProfile profiles, std::string localDeviceId, + std::vector &sinkBindType, std::vector &bindTypeIndex, uint32_t index, std::string targetDeviceId) { if (profiles.GetBindType() == DM_IDENTICAL_ACCOUNT) { sinkBindType.push_back(IDENTICAL_ACCOUNT_TYPE); @@ -331,13 +350,13 @@ void DeviceProfileConnector::ProcessBindType(AccessControlProfile profiles, DmDi bindTypeIndex.push_back(index); } if (profiles.GetBindLevel() == APP) { - if (profiles.GetAccesser().GetAccesserBundleName() == paramInfo.pkgname && - profiles.GetAccesser().GetAccesserDeviceId() == paramInfo.localDeviceId) { + if (profiles.GetAccesser().GetAccesserDeviceId() == targetDeviceId && + profiles.GetAccessee().GetAccesseeDeviceId() == localDeviceId) { sinkBindType.push_back(APP_PEER_TO_PEER_TYPE); bindTypeIndex.push_back(index); } - if (profiles.GetAccessee().GetAccesseeBundleName() == paramInfo.pkgname && - profiles.GetAccessee().GetAccesseeDeviceId() == paramInfo.localDeviceId) { + if (profiles.GetAccessee().GetAccesseeDeviceId() == targetDeviceId && + profiles.GetAccesser().GetAccesserDeviceId() == localDeviceId) { sinkBindType.push_back(APP_PEER_TO_PEER_TYPE); bindTypeIndex.push_back(index); } @@ -349,13 +368,13 @@ void DeviceProfileConnector::ProcessBindType(AccessControlProfile profiles, DmDi bindTypeIndex.push_back(index); } if (profiles.GetBindLevel() == APP) { - if (profiles.GetAccesser().GetAccesserBundleName() == paramInfo.pkgname && - profiles.GetAccesser().GetAccesserDeviceId() == paramInfo.localDeviceId) { + if (profiles.GetAccesser().GetAccesserDeviceId() == targetDeviceId && + profiles.GetAccessee().GetAccesseeDeviceId() == localDeviceId) { sinkBindType.push_back(APP_ACROSS_ACCOUNT_TYPE); bindTypeIndex.push_back(index); } - if (profiles.GetAccessee().GetAccesseeBundleName() == paramInfo.pkgname && - profiles.GetAccessee().GetAccesseeDeviceId() == paramInfo.localDeviceId) { + if (profiles.GetAccessee().GetAccesseeDeviceId() == targetDeviceId && + profiles.GetAccesser().GetAccesserDeviceId() == localDeviceId) { sinkBindType.push_back(APP_ACROSS_ACCOUNT_TYPE); bindTypeIndex.push_back(index); } @@ -373,6 +392,7 @@ std::vector DeviceProfileConnector::SyncAclByBindType(std::string pkgNa std::vector bindType; std::vector bindTypeIndex = CompareBindType(profiles, pkgName, sinkBindType, localDeviceId, targetDeviceId); + LOGI("SyncAclByBindType sinkBindType size is %{public}zu", sinkBindType.size()); for (uint32_t sinkIndex = 0; sinkIndex < sinkBindType.size(); sinkIndex++) { bool deleteAclFlag = true; for (uint32_t srcIndex = 0; srcIndex < bindTypeVec.size(); srcIndex++) { @@ -384,6 +404,7 @@ std::vector DeviceProfileConnector::SyncAclByBindType(std::string pkgNa if (deleteAclFlag) { int32_t deleteIndex = profiles[bindTypeIndex[sinkIndex]].GetAccessControlId(); DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(deleteIndex); + LOGI("SyncAclByBindType deleteAcl index is %{public}d", deleteIndex); } } return bindType; @@ -529,7 +550,8 @@ void DeviceProfileConnector::DeleteAccessControlList(const std::string &udid) } DmOfflineParam DeviceProfileConnector::DeleteAccessControlList(const std::string &pkgName, - const std::string &localDeviceId, const std::string &remoteDeviceId, int32_t bindLevel) + const std::string &localDeviceId, const std::string &remoteDeviceId, + int32_t bindLevel, const std::string &extra) { LOGI("pkgName %{public}s, localDeviceId %{public}s, remoteDeviceId %{public}s, bindLevel %{public}d.", pkgName.c_str(), GetAnonyString(localDeviceId).c_str(), GetAnonyString(remoteDeviceId).c_str(), bindLevel); @@ -546,7 +568,11 @@ DmOfflineParam DeviceProfileConnector::DeleteAccessControlList(const std::string } switch (bindLevel) { case APP: - DeleteAppBindLevel(offlineParam, pkgName, profiles, localDeviceId, remoteDeviceId); + if (extra == "") { + DeleteAppBindLevel(offlineParam, pkgName, profiles, localDeviceId, remoteDeviceId); + } else { + DeleteAppBindLevel(offlineParam, pkgName, profiles, localDeviceId, remoteDeviceId, extra); + } break; case SERVICE: DeleteServiceBindLevel(offlineParam, pkgName, profiles, localDeviceId, remoteDeviceId); @@ -605,6 +631,56 @@ void DeviceProfileConnector::DeleteAppBindLevel(DmOfflineParam &offlineParam, co offlineParam.leftAclNumber = bindNums - deleteNums; } +void DeviceProfileConnector::DeleteAppBindLevel(DmOfflineParam &offlineParam, const std::string &pkgName, + const std::vector &profiles, const std::string &localUdid, + const std::string &remoteUdid, const std::string &extra) +{ + LOGI("DeviceProfileConnector::DeleteAppBindLevel extra %{public}s", extra.c_str()); + int32_t bindNums = 0; + int32_t deleteNums = 0; + std::string peerBundleName = extra; + for (auto &item : profiles) { + if (item.GetTrustDeviceId() != remoteUdid || item.GetBindType() == DM_IDENTICAL_ACCOUNT || + item.GetBindLevel() != APP) { + continue; + } + bindNums++; + if (item.GetAccesser().GetAccesserBundleName() == pkgName && + item.GetAccessee().GetAccesseeBundleName() == peerBundleName && + item.GetAccesser().GetAccesserDeviceId() == localUdid && + item.GetAccessee().GetAccesseeDeviceId() == remoteUdid) { + DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId()); + deleteNums++; + offlineParam.bindType = APP; + ProcessInfo processInfo; + processInfo.pkgName = item.GetAccesser().GetAccesserBundleName(); + processInfo.userId = item.GetAccesser().GetAccesserUserId(); + offlineParam.processVec.push_back(processInfo); + LOGI("Src delete acl pkgName %{public}s, bindType %{public}d, localUdid %{public}s, remoteUdid %{public}s", + pkgName.c_str(), item.GetBindType(), GetAnonyString(localUdid).c_str(), + GetAnonyString(remoteUdid).c_str()); + continue; + } + if (item.GetAccessee().GetAccesseeBundleName() == pkgName && + item.GetAccesser().GetAccesserBundleName() == peerBundleName && + item.GetAccessee().GetAccesseeDeviceId() == localUdid && + item.GetAccesser().GetAccesserDeviceId() == remoteUdid) { + DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId()); + deleteNums++; + offlineParam.bindType = APP; + ProcessInfo processInfo; + processInfo.pkgName = item.GetAccessee().GetAccesseeBundleName(); + processInfo.userId = item.GetAccessee().GetAccesseeUserId(); + offlineParam.processVec.push_back(processInfo); + LOGI("Sink delete acl pkgName %{public}s, bindType %{public}d, localUdid %{public}s, remoteUdid %{public}s", + pkgName.c_str(), item.GetBindType(), GetAnonyString(localUdid).c_str(), + GetAnonyString(remoteUdid).c_str()); + continue; + } + } + offlineParam.leftAclNumber = bindNums - deleteNums; +} + void DeviceProfileConnector::DeleteDeviceBindLevel(DmOfflineParam &offlineParam, const std::vector &profiles, const std::string &localUdid, const std::string &remoteUdid) { @@ -869,7 +945,8 @@ bool DeviceProfileConnector::SingleUserProcess(const DistributedDeviceProfile::A if (profile.GetBindLevel() == DEVICE || profile.GetBindLevel() == SERVICE) { ret = true; } else if (profile.GetBindLevel() == APP && - profile.GetAccesser().GetAccesserBundleName() == caller.pkgName) { + (profile.GetAccesser().GetAccesserBundleName() == caller.pkgName || + profile.GetAccessee().GetAccesseeBundleName() == caller.pkgName)) { ret = true; } break; @@ -877,7 +954,8 @@ bool DeviceProfileConnector::SingleUserProcess(const DistributedDeviceProfile::A if (profile.GetBindLevel() == DEVICE || profile.GetBindLevel() == SERVICE) { ret = true; } else if (profile.GetBindLevel() == APP && - profile.GetAccesser().GetAccesserBundleName() == caller.pkgName) { + (profile.GetAccesser().GetAccesserBundleName() == caller.pkgName || + profile.GetAccessee().GetAccesseeBundleName() == caller.pkgName)) { ret = true; } break; @@ -1100,6 +1178,44 @@ OHOS::DistributedHardware::ProcessInfo DeviceProfileConnector::HandleAppUnBindEv return processInfo; } +OHOS::DistributedHardware::ProcessInfo DeviceProfileConnector::HandleAppUnBindEvent(int32_t remoteUserId, + const std::string &remoteUdid, int32_t tokenId, const std::string &localUdid, int32_t peerTokenId) +{ + LOGI("RemoteUserId %{public}d, remoteUdid %{public}s, tokenId %{public}d, localUdid %{public}s.", + remoteUserId, GetAnonyString(remoteUdid).c_str(), tokenId, GetAnonyString(localUdid).c_str()); + std::vector profiles = GetAccessControlProfile(); + ProcessInfo processInfo; + for (const auto &item : profiles) { + if (item.GetTrustDeviceId() != remoteUdid || item.GetBindType() == DM_IDENTICAL_ACCOUNT || + item.GetBindLevel() != APP) { + continue; + } + if (item.GetAccesser().GetAccesserUserId() == remoteUserId && + item.GetAccesser().GetAccesserDeviceId() == remoteUdid && + static_cast(item.GetAccesser().GetAccesserTokenId()) == tokenId && + static_cast(item.GetAccessee().GetAccesseeTokenId()) == peerTokenId && + item.GetAccessee().GetAccesseeDeviceId() == localUdid) { + LOGI("Src device unbind."); + DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId()); + processInfo.pkgName = item.GetAccessee().GetAccesseeBundleName(); + processInfo.userId = item.GetAccessee().GetAccesseeUserId(); + continue; + } + if (item.GetAccessee().GetAccesseeUserId() == remoteUserId && + item.GetAccessee().GetAccesseeDeviceId() == remoteUdid && + static_cast(item.GetAccessee().GetAccesseeTokenId()) == tokenId && + static_cast(item.GetAccesser().GetAccesserTokenId()) == peerTokenId && + item.GetAccesser().GetAccesserDeviceId() == localUdid) { + LOGI("Sink device unbind."); + DistributedDeviceProfileClient::GetInstance().DeleteAccessControlProfile(item.GetAccessControlId()); + processInfo.pkgName = item.GetAccesser().GetAccesserBundleName(); + processInfo.userId = item.GetAccesser().GetAccesserUserId(); + continue; + } + } + return processInfo; +} + std::vector DeviceProfileConnector::GetAllAccessControlProfile() { std::vector profiles; diff --git a/interfaces/inner_kits/native_cpp/include/device_manager.h b/interfaces/inner_kits/native_cpp/include/device_manager.h index d9abc7351..bcb32dad3 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager.h @@ -393,6 +393,8 @@ public: */ virtual int32_t UnBindDevice(const std::string &pkgName, const std::string &deviceId) = 0; + virtual int32_t UnBindDevice(const std::string &pkgName, const std::string &deviceId, const std::string &extra) = 0; + virtual int32_t CheckNewAPIAccessPermission() = 0; /** diff --git a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h index cf0951513..26886b6d1 100644 --- a/interfaces/inner_kits/native_cpp/include/device_manager_impl.h +++ b/interfaces/inner_kits/native_cpp/include/device_manager_impl.h @@ -336,6 +336,8 @@ public: virtual int32_t BindDevice(const std::string &pkgName, int32_t bindType, const std::string &deviceId, const std::string &extra, std::shared_ptr callback) override; virtual int32_t UnBindDevice(const std::string &pkgName, const std::string &deviceId) override; + virtual int32_t UnBindDevice(const std::string &pkgName, const std::string &deviceId, + const std::string &extra) override; virtual int32_t GetNetworkTypeByNetworkId(const std::string &pkgName, const std::string &netWorkId, int32_t &netWorkType) override; virtual int32_t ImportAuthCode(const std::string &pkgName, const std::string &authCode) override; diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index a799d988f..2432a0d47 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -1539,6 +1539,36 @@ int32_t DeviceManagerImpl::UnBindDevice(const std::string &pkgName, const std::s return DM_OK; } +int32_t DeviceManagerImpl::UnBindDevice(const std::string &pkgName, const std::string &deviceId, + const std::string &extra) +{ + if (pkgName.empty() || deviceId.empty()) { + LOGE("UnBindDevice error: Invalid para. pkgName %{public}s", pkgName.c_str()); + return ERR_DM_INPUT_PARA_INVALID; + } + LOGI("Start, pkgName: %{public}s, deviceId: %{public}s", pkgName.c_str(), + GetAnonyString(std::string(deviceId)).c_str()); + std::shared_ptr req = std::make_shared(); + std::shared_ptr rsp = std::make_shared(); + req->SetPkgName(pkgName); + req->SetDeviceId(deviceId); + req->SetExtraInfo(extra); + LOGI("DeviceManagerImpl::UnBindDevice extra: %{public}s.", extra.c_str()); + int32_t ret = ipcClientProxy_->SendRequest(UNBIND_DEVICE, req, rsp); + if (ret != DM_OK) { + LOGE("UnBindDevice error: Send Request failed ret: %{public}d", ret); + return ERR_DM_IPC_SEND_REQUEST_FAILED; + } + ret = rsp->GetErrCode(); + if (ret != DM_OK) { + LOGE("UnBindDevice error: Failed with ret %{public}d", ret); + return ret; + } + + LOGI("End"); + return DM_OK; +} + int32_t DeviceManagerImpl::GetNetworkTypeByNetworkId(const std::string &pkgName, const std::string &netWorkId, int32_t &netWorkType) { diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp index e6b1082fe..159883adb 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp @@ -1028,6 +1028,7 @@ ON_IPC_SET_REQUEST(UNBIND_DEVICE, std::shared_ptr pBaseReq, MessageParce std::shared_ptr pReq = std::static_pointer_cast(pBaseReq); std::string pkgName = pReq->GetPkgName(); std::string deviceId = pReq->GetDeviceId(); + std::string extra = pReq->GetExtraInfo(); if (!data.WriteString(pkgName)) { LOGE("write pkgName failed"); @@ -1037,6 +1038,9 @@ ON_IPC_SET_REQUEST(UNBIND_DEVICE, std::shared_ptr pBaseReq, MessageParce LOGE("write deviceId failed"); return ERR_DM_IPC_WRITE_FAILED; } + if (!data.WriteString(extra)) { + LOGE("write extra failed"); + } return DM_OK; } diff --git a/interfaces/kits/js4.0/src/dm_native_util.cpp b/interfaces/kits/js4.0/src/dm_native_util.cpp index a3b0eb5c8..a7af920e7 100644 --- a/interfaces/kits/js4.0/src/dm_native_util.cpp +++ b/interfaces/kits/js4.0/src/dm_native_util.cpp @@ -299,6 +299,8 @@ void JsToBindParam(const napi_env &env, const napi_value &object, std::string &b JsObjectToString(env, object, "targetPkgName", targetPkgName, sizeof(targetPkgName)); char metaType[DM_NAPI_BUF_LENGTH] = ""; JsObjectToString(env, object, "metaType", metaType, sizeof(metaType)); + char peerBundleName[DM_NAPI_BUF_LENGTH] = ""; + JsObjectToString(env, object, "peerBundleName", peerBundleName, sizeof(peerBundleName)); std::string metaTypeStr = metaType; isMetaType = !metaTypeStr.empty(); @@ -324,6 +326,7 @@ void JsToBindParam(const napi_env &env, const napi_value &object, std::string &b jsonObj[CUSTOM_DESCRIPTION] = std::string(customDescription); jsonObj[PARAM_KEY_TARGET_PKG_NAME] = std::string(targetPkgName); jsonObj[PARAM_KEY_META_TYPE] = metaTypeStr; + jsonObj[PARAM_KEY_PEER_BUNDLE_NAME] = std::string(peerBundleName); jsonObj[PARAM_KEY_PIN_CODE] = std::string(pinCode); jsonObj[PARAM_KEY_AUTH_TOKEN] = std::string(authToken); jsonObj[PARAM_KEY_BR_MAC] = std::string(brMac); diff --git a/services/implementation/include/authentication/auth_message_processor.h b/services/implementation/include/authentication/auth_message_processor.h index a987e0dc9..b23468ec5 100644 --- a/services/implementation/include/authentication/auth_message_processor.h +++ b/services/implementation/include/authentication/auth_message_processor.h @@ -76,6 +76,7 @@ constexpr const char* TAG_HOST_PKGLABEL = "hostPkgLabel"; constexpr const char* TAG_EDITION = "edition"; constexpr const char* TAG_BUNDLE_NAME = "bundleName"; constexpr const char* TAG_CRYPTIC_MSG = "encryptMsg"; +constexpr const char* TAG_PEER_BUNDLE_NAME = "PEER_BUNDLE_NAME"; class DmAuthManager; struct DmAuthRequestContext; diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index 4a4fafbaa..3d0a43172 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -111,6 +111,7 @@ typedef struct DmAuthRequestContext { std::string hostPkgName; std::string targetPkgName; std::string bundleName; + std::string peerBundleName; std::string appOperation; std::string appDesc; std::string appName; @@ -155,6 +156,7 @@ typedef struct DmAuthResponseContext { std::string hostPkgName; std::string targetPkgName; std::string bundleName; + std::string peerBundleName; std::string appOperation; std::string appDesc; std::string customDesc; @@ -223,7 +225,8 @@ public: * @param deviceId device id. * @return Return 0 if success. */ - int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel); + int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, + int32_t bindLevel, const std::string &extra); /** * @tc.name: DmAuthManager::OnSessionOpened @@ -517,8 +520,9 @@ private: int32_t ImportCredential(std::string &deviceId, std::string &publicKey); void GetAuthParam(const std::string &pkgName, int32_t authType, const std::string &deviceId, const std::string &extra); + void parseJsonObject(nlohmann::json jsonObject); int32_t DeleteAcl(const std::string &pkgName, const std::string &localUdid, const std::string &remoteUdid, - int32_t bindLevel); + int32_t bindLevel, const std::string &extra); void ProcessAuthRequestExt(const int32_t &sessionId); bool IsAuthFinish(); void ProcessAuthRequest(const int32_t &sessionId); diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index 4414b5bd9..c2c1f5a2a 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -47,6 +47,9 @@ public: int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel); + int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, + int32_t bindLevel, const std::string &extra); + int32_t SetUserOperation(std::string &pkgName, int32_t action, const std::string ¶ms); void HandleDeviceStatusChange(DmDeviceState devState, DmDeviceInfo &devInfo); @@ -141,6 +144,8 @@ private: const std::string &remoteUdid); void HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid); void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId); + void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, + int32_t tokenId, int32_t peerTokenId); void HandleUserRemoved(int32_t preUserId); void HandleRemoteUserRemoved(int32_t preUserId, const std::string &remoteUdid); DmAuthForm ConvertBindTypeToAuthForm(int32_t bindType); diff --git a/services/implementation/include/device_manager_service_impl_lite.h b/services/implementation/include/device_manager_service_impl_lite.h index 46bcc11ac..2f6c1e298 100644 --- a/services/implementation/include/device_manager_service_impl_lite.h +++ b/services/implementation/include/device_manager_service_impl_lite.h @@ -54,6 +54,9 @@ public: int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel); + int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, + int32_t bindLevel, const std::string &extra); + int32_t SetUserOperation(std::string &pkgName, int32_t action, const std::string ¶ms); void HandleDeviceStatusChange(DmDeviceState devState, DmDeviceInfo &devInfo); diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index b463cdf39..e847a7939 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -207,6 +207,7 @@ void AuthMessageProcessor::CreateNegotiateMessage(nlohmann::json &json) json[TAG_DMVERSION] = authResponseContext_->dmVersion; json[TAG_HOST] = authResponseContext_->hostPkgName; json[TAG_BUNDLE_NAME] = authResponseContext_->bundleName; + json[TAG_PEER_BUNDLE_NAME] = authResponseContext_->peerBundleName; json[TAG_TOKENID] = authResponseContext_->tokenId; json[TAG_IDENTICAL_ACCOUNT] = authResponseContext_->isIdenticalAccount; json[TAG_HAVE_CREDENTIAL] = authResponseContext_->haveCredential; @@ -589,6 +590,11 @@ void AuthMessageProcessor::ParseNegotiateMessage(const nlohmann::json &json) if (IsString(json, TAG_BUNDLE_NAME)) { authResponseContext_->bundleName = json[TAG_BUNDLE_NAME].get(); } + if (IsString(json, TAG_PEER_BUNDLE_NAME)) { + authResponseContext_->peerBundleName = json[TAG_PEER_BUNDLE_NAME].get(); + } else { + authResponseContext_->peerBundleName = authResponseContext_->hostPkgName; + } ParsePkgNegotiateMessage(json); } diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index a721ec725..069c253d7 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -216,6 +216,12 @@ void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, authRequestContext_->authed = !authRequestContext_->bindType.empty(); authRequestContext_->bindLevel = INVALIED_TYPE; nlohmann::json jsonObject = nlohmann::json::parse(extra, nullptr, false); + parseJsonObject(jsonObject); + authRequestContext_->token = std::to_string(GenRandInt(MIN_PIN_TOKEN, MAX_PIN_TOKEN)); +} + +void DmAuthManager::parseJsonObject(nlohmann::json jsonObject) +{ if (!jsonObject.is_discarded()) { if (IsString(jsonObject, TARGET_PKG_NAME_KEY)) { authRequestContext_->targetPkgName = jsonObject[TARGET_PKG_NAME_KEY].get(); @@ -238,9 +244,13 @@ void DmAuthManager::GetAuthParam(const std::string &pkgName, int32_t authType, authRequestContext_->closeSessionDelaySeconds = GetCloseSessionDelaySeconds(delaySecondsStr); } authRequestContext_->bindLevel = GetBindLevel(authRequestContext_->bindLevel); + if (IsString(jsonObject, TAG_PEER_BUNDLE_NAME)) { + authRequestContext_->peerBundleName = jsonObject[TAG_PEER_BUNDLE_NAME].get(); + } else { + authRequestContext_->peerBundleName = authRequestContext_->hostPkgName; + } } authRequestContext_->bundleName = GetBundleName(jsonObject); - authRequestContext_->token = std::to_string(GenRandInt(MIN_PIN_TOKEN, MAX_PIN_TOKEN)); } int32_t DmAuthManager::GetCloseSessionDelaySeconds(std::string &delaySecondsStr) @@ -339,7 +349,8 @@ int32_t DmAuthManager::UnAuthenticateDevice(const std::string &pkgName, const st if (bindLevel == DEVICE) { DeleteGroup(pkgName, udid); } - return DeleteAcl(pkgName, std::string(localDeviceId), udid, bindLevel); + std::string extra = ""; + return DeleteAcl(pkgName, std::string(localDeviceId), udid, bindLevel, extra); } int32_t DmAuthManager::StopAuthenticateDevice(const std::string &pkgName) @@ -361,12 +372,12 @@ int32_t DmAuthManager::StopAuthenticateDevice(const std::string &pkgName) } int32_t DmAuthManager::DeleteAcl(const std::string &pkgName, const std::string &localUdid, - const std::string &remoteUdid, int32_t bindLevel) + const std::string &remoteUdid, int32_t bindLevel, const std::string &extra) { LOGI("DeleteAcl pkgName %{public}s, localUdid %{public}s, remoteUdid %{public}s, bindLevel %{public}d.", pkgName.c_str(), GetAnonyString(localUdid).c_str(), GetAnonyString(remoteUdid).c_str(), bindLevel); DmOfflineParam offlineParam = - DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localUdid, remoteUdid, bindLevel); + DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localUdid, remoteUdid, bindLevel, extra); if (offlineParam.bindType == INVALIED_TYPE) { LOGE("Acl not contain the pkgname bind data."); return ERR_DM_FAILED; @@ -400,7 +411,8 @@ int32_t DmAuthManager::DeleteAcl(const std::string &pkgName, const std::string & return ERR_DM_FAILED; } -int32_t DmAuthManager::UnBindDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel) +int32_t DmAuthManager::UnBindDevice(const std::string &pkgName, const std::string &udid, + int32_t bindLevel, const std::string &extra) { if (pkgName.empty()) { LOGE("Invalid parameter, pkgName is empty."); @@ -411,7 +423,7 @@ int32_t DmAuthManager::UnBindDevice(const std::string &pkgName, const std::strin if (bindLevel == DEVICE) { DeleteGroup(pkgName, udid); } - return DeleteAcl(pkgName, std::string(localDeviceId), udid, bindLevel); + return DeleteAcl(pkgName, std::string(localDeviceId), udid, bindLevel, extra); } void DmAuthManager::GetPeerUdidHash(int32_t sessionId, std::string &peerUdidHash) @@ -794,6 +806,7 @@ void DmAuthManager::StartNegotiate(const int32_t &sessionId) authResponseContext_->accountGroupIdHash = GetAccountGroupIdHash(); authResponseContext_->hostPkgName = authRequestContext_->hostPkgName; authResponseContext_->bundleName = authRequestContext_->bundleName; + authResponseContext_->peerBundleName = authRequestContext_->peerBundleName; authResponseContext_->hostPkgLabel = authRequestContext_->hostPkgLabel; authResponseContext_->tokenId = authRequestContext_->tokenId; authResponseContext_->bindLevel = authRequestContext_->bindLevel; @@ -1037,14 +1050,6 @@ bool DmAuthManager::IsAuthFinish() return true; } - if (authResponseContext_->isOnline && authResponseContext_->authed) { - authRequestContext_->reason = DM_OK; - authResponseContext_->reply = DM_OK; - authResponseContext_->state = AuthState::AUTH_REQUEST_FINISH; - authRequestState_->TransitionTo(std::make_shared()); - return true; - } - if ((authResponseContext_->isIdenticalAccount && !authResponseContext_->authed) || (authResponseContext_->authed && !authResponseContext_->isOnline)) { softbusConnector_->JoinLnn(authRequestContext_->addr); @@ -1274,7 +1279,7 @@ int32_t DmAuthManager::JoinNetwork() void DmAuthManager::SinkAuthenticateFinish() { LOGI("DmAuthManager::SinkAuthenticateFinish, isFinishOfLocal: %{public}d", isFinishOfLocal_); - processInfo_.pkgName = authResponseContext_->hostPkgName; + processInfo_.pkgName = authResponseContext_->peerBundleName; listener_->OnSinkBindResult(processInfo_, peerTargetId_, authResponseContext_->reply, authResponseContext_->state, GenerateBindResultContent()); if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_FINISH && authPtr_ != nullptr) { @@ -1487,7 +1492,7 @@ void DmAuthManager::ShowConfigDialog() char localDeviceId[DEVICE_UUID_LENGTH] = {0}; GetDevUdid(localDeviceId, DEVICE_UUID_LENGTH); std::string localUdid = static_cast(localDeviceId); - DeviceProfileConnector::GetInstance().SyncAclByBindType(authResponseContext_->hostPkgName, + DeviceProfileConnector::GetInstance().SyncAclByBindType(authResponseContext_->peerBundleName, authResponseContext_->bindType, localUdid, remoteDeviceId_); DmDialogManager::GetInstance().ShowConfirmDialog(params); struct RadarInfo info = { @@ -2407,7 +2412,7 @@ void DmAuthManager::PutAccessControlList() DmAccesser accesser; accesser.requestBundleName = authResponseContext_->hostPkgName; DmAccessee accessee; - accessee.trustBundleName = authResponseContext_->hostPkgName; + accessee.trustBundleName = authResponseContext_->peerBundleName; if (authRequestState_ != nullptr && authResponseState_ == nullptr) { accesser.requestTokenId = static_cast(authResponseContext_->tokenId); accesser.requestUserId = authRequestContext_->localUserId; @@ -2683,7 +2688,8 @@ int32_t DmAuthManager::GetBinderInfo() return DM_OK; } ret = AppManager::GetInstance().GetHapTokenIdByName(authResponseContext_->localUserId, - authResponseContext_->bundleName, 0, authResponseContext_->tokenId); + authResponseContext_->peerBundleName, 0, authResponseContext_->tokenId); + LOGI("GetBinderInfo sink tokenId = %{public}llu", authResponseContext_->tokenId); if (ret != DM_OK) { LOGI("get tokenId by bundleName failed %{public}s", GetAnonyString(authResponseContext_->bundleName).c_str()); authResponseContext_->tokenId = authResponseContext_->remoteTokenId; @@ -2696,8 +2702,15 @@ void DmAuthManager::SetProcessInfo() CHECK_NULL_VOID(authResponseContext_); ProcessInfo processInfo; if (authResponseContext_->bindLevel == APP) { - processInfo.pkgName = authResponseContext_->hostPkgName; - processInfo.userId = authResponseContext_->localUserId; + if ((authRequestState_ != nullptr) && (authResponseState_ == nullptr)) { + processInfo.pkgName = authResponseContext_->hostPkgName; + processInfo.userId = authResponseContext_->localUserId; + } else if ((authRequestState_ == nullptr) && (authResponseState_ != nullptr)) { + processInfo.pkgName = authResponseContext_->peerBundleName; + processInfo.userId = authResponseContext_->localUserId; + } else { + LOGE("DMAuthManager::SetProcessInfo failed, state is invalid."); + } } else if (authResponseContext_->bindLevel == DEVICE || authResponseContext_->bindLevel == INVALIED_TYPE) { processInfo.pkgName = std::string(DM_PKG_NAME); processInfo.userId = authResponseContext_->localUserId; diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 46fc34742..83aae729b 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -129,7 +129,19 @@ int32_t DeviceManagerServiceImpl::UnBindDevice(const std::string &pkgName, const pkgName.c_str(), GetAnonyString(udid).c_str()); return ERR_DM_INPUT_PARA_INVALID; } - return authMgr_->UnBindDevice(pkgName, udid, bindLevel); + std::string extra = ""; + return authMgr_->UnBindDevice(pkgName, udid, bindLevel, extra); +} + +int32_t DeviceManagerServiceImpl::UnBindDevice(const std::string &pkgName, const std::string &udid, + int32_t bindLevel, const std::string &extra) +{ + if (pkgName.empty() || udid.empty()) { + LOGE("DeviceManagerServiceImpl::UnBindDevice failed, pkgName is %{public}s, udid is %{public}s", + pkgName.c_str(), GetAnonyString(udid).c_str()); + return ERR_DM_INPUT_PARA_INVALID; + } + return authMgr_->UnBindDevice(pkgName, udid, bindLevel, extra); } int32_t DeviceManagerServiceImpl::SetUserOperation(std::string &pkgName, int32_t action, @@ -821,6 +833,25 @@ void DeviceManagerServiceImpl::HandleAppUnBindEvent(int32_t remoteUserId, const softbusConnector_->HandleDeviceOffline(remoteUdid); } +void DeviceManagerServiceImpl::HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, + int32_t tokenId, int32_t peerTokenId) +{ + LOGI("HandleAppUnBindEvent peerTokenId = %{public}d.", peerTokenId); + char localUdidTemp[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localUdidTemp, DEVICE_UUID_LENGTH); + std::string localUdid = std::string(localUdidTemp); + ProcessInfo processInfo = + DeviceProfileConnector::GetInstance().HandleAppUnBindEvent(remoteUserId, remoteUdid, + tokenId, localUdid, peerTokenId); + if (processInfo.pkgName.empty()) { + LOGE("Pkgname is empty."); + return; + } + CHECK_NULL_VOID(softbusConnector_); + softbusConnector_->SetProcessInfo(processInfo); + softbusConnector_->HandleDeviceOffline(remoteUdid); +} + void DeviceManagerServiceImpl::HandleSyncUserIdEvent(const std::vector &foregroundUserIds, const std::vector &backgroundUserIds, const std::string &remoteUdid) { diff --git a/services/implementation/src/device_manager_service_impl_lite.cpp b/services/implementation/src/device_manager_service_impl_lite.cpp index cd7d6f40e..095fb3a4a 100644 --- a/services/implementation/src/device_manager_service_impl_lite.cpp +++ b/services/implementation/src/device_manager_service_impl_lite.cpp @@ -89,6 +89,16 @@ int32_t DeviceManagerServiceImpl::UnBindDevice(const std::string &pkgName, const return DM_OK; } +int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, + int32_t bindLevel, const std::string &extra) +{ + (void)pkgName; + (void)udid; + (void)bindLevel; + (void)extra; + return DM_OK; +} + int32_t DeviceManagerServiceImpl::SetUserOperation(std::string &pkgName, int32_t action, const std::string ¶ms) { diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 4cf68d0fa..513197c21 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -98,6 +98,8 @@ public: int32_t UnBindDevice(const std::string &pkgName, const std::string &udidHash); + int32_t UnBindDevice(const std::string &pkgName, const std::string &udidHash, const std::string &extra); + int32_t SetUserOperation(std::string &pkgName, int32_t action, const std::string ¶ms); void HandleDeviceStatusChange(DmDeviceState devState, DmDeviceInfo &devInfo); @@ -220,8 +222,12 @@ private: void UnloadDMServiceAdapterResident(); void SendUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId, int32_t bindLevel); + void SendUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId, + int32_t bindLevel, uint64_t peerTokenId); void SendDeviceUnBindBroadCast(const std::vector &peerUdids, int32_t userId); void SendAppUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId); + void SendAppUnBindBroadCast(const std::vector &peerUdids, int32_t userId, + uint64_t tokenId, uint64_t peerTokenId); void SendServiceUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId); void SendAccountLogoutBroadCast(const std::vector &peerUdids, const std::string &accountId, const std::string &accountName, int32_t userId); diff --git a/services/service/include/idevice_manager_service_impl.h b/services/service/include/idevice_manager_service_impl.h index 0e5f16bb2..73fcba70d 100644 --- a/services/service/include/idevice_manager_service_impl.h +++ b/services/service/include/idevice_manager_service_impl.h @@ -59,6 +59,9 @@ public: */ virtual int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel) = 0; + virtual int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, + int32_t bindLevel, const std::string &extra) = 0; + /** * @tc.name: IDeviceManagerServiceImpl::SetUserOperation * @tc.desc: Se tUser Operation of device manager service impl @@ -230,6 +233,8 @@ public: const std::string &remoteUdid) = 0; virtual void HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid) = 0; virtual void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId) = 0; + virtual void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, + int32_t tokenId, int32_t peerTokenId) = 0; virtual int32_t GetBindLevel(const std::string &pkgName, const std::string &localUdid, const std::string &udid, uint64_t &tokenId) = 0; virtual void HandleIdentAccountLogout(const std::string &localUdid, int32_t localUserId, diff --git a/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h b/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h index f64c1af30..22d74af97 100644 --- a/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h +++ b/services/service/include/relationshipsyncmgr/relationship_sync_mgr.h @@ -49,6 +49,7 @@ struct RelationShipChangeMsg { uint32_t userId; std::string accountId; uint64_t tokenId; + uint64_t peerTokenId = 0; // The broadcast need send to these devices with the udids std::vector peerUdids; // The broadcast from which device with the udid. diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 0868ce035..6edbe031c 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -664,6 +664,57 @@ int32_t DeviceManagerService::UnBindDevice(const std::string &pkgName, const std return DM_OK; } +int32_t DeviceManagerService::UnBindDevice(const std::string &pkgName, const std::string &udidHash, + const std::string &extra) +{ + if (!PermissionManager::GetInstance().CheckNewPermission()) { + LOGE("The caller does not have permission to call UnBindDevice."); + return ERR_DM_NO_PERMISSION; + } + LOGI("Begin for pkgName = %{public}s, udidHash = %{public}s", pkgName.c_str(), GetAnonyString(udidHash).c_str()); + if (pkgName.empty() || udidHash.empty()) { + LOGE("DeviceManagerService::UnBindDevice error: Invalid parameter, pkgName: %{public}s", pkgName.c_str()); + return ERR_DM_INPUT_PARA_INVALID; + } + if (!IsDMServiceImplReady()) { + LOGE("UnBindDevice failed, instance not init or init failed."); + return ERR_DM_NOT_INIT; + } + std::string realDeviceId = udidHash; +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::string udidHashTemp = ""; + if (GetUdidHashByAnoyDeviceId(udidHash, udidHashTemp) == DM_OK) { + realDeviceId = udidHashTemp; + } +#endif + std::string udid = ""; + if (SoftbusCache::GetInstance().GetUdidByUdidHash(realDeviceId, udid) != DM_OK) { + LOGE("Get udid by udidhash failed."); + return ERR_DM_FAILED; + } + char localUdid[DEVICE_UUID_LENGTH] = {0}; + GetDevUdid(localUdid, DEVICE_UUID_LENGTH); + uint64_t tokenId = 0; + int32_t bindLevel = dmServiceImpl_->GetBindLevel(pkgName, std::string(localUdid), udid, tokenId); + LOGI("UnAuthenticateDevice get bindlevel %{public}d.", bindLevel); + if (bindLevel == INVALIED_BIND_LEVEL) { + LOGE("UnAuthenticateDevice failed, Acl not contain the bindLevel %{public}d.", bindLevel); + return ERR_DM_FAILED; + } + uint64_t peerTokenId = DeviceProfileConnector::GetInstance().GetTokenIdByNameAndDeviceId(extra, udid); + if (dmServiceImpl_->UnBindDevice(pkgName, udid, bindLevel, extra) != DM_OK) { + LOGE("dmServiceImpl_ UnBindDevice failed."); + return ERR_DM_FAILED; + } +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + std::vector peerUdids; + peerUdids.emplace_back(udid); + SendUnBindBroadCast(peerUdids, MultipleUserConnector::GetCurrentAccountUserID(), tokenId, + bindLevel, peerTokenId); +#endif + return DM_OK; +} + int32_t DeviceManagerService::SetUserOperation(std::string &pkgName, int32_t action, const std::string ¶ms) { if (!PermissionManager::GetInstance().CheckPermission()) { @@ -2062,6 +2113,23 @@ void DeviceManagerService::SendUnBindBroadCast(const std::vector &p } } +void DeviceManagerService::SendUnBindBroadCast(const std::vector &peerUdids, int32_t userId, + uint64_t tokenId, int32_t bindLevel, uint64_t peerTokenId) +{ + if (bindLevel == DEVICE) { + SendDeviceUnBindBroadCast(peerUdids, userId); + return; + } + if (bindLevel == APP) { + SendAppUnBindBroadCast(peerUdids, userId, tokenId, peerTokenId); + return; + } + if (bindLevel == SERVICE) { + SendServiceUnBindBroadCast(peerUdids, userId, tokenId); + return; + } +} + void DeviceManagerService::SendDeviceUnBindBroadCast(const std::vector &peerUdids, int32_t userId) { RelationShipChangeMsg msg; @@ -2086,6 +2154,21 @@ void DeviceManagerService::SendAppUnBindBroadCast(const std::vector softbusListener_->SendAclChangedBroadcast(broadCastMsg); } +void DeviceManagerService::SendAppUnBindBroadCast(const std::vector &peerUdids, int32_t userId, + uint64_t tokenId, uint64_t peerTokenId) +{ + RelationShipChangeMsg msg; + msg.type = RelationShipChangeType::APP_UNBIND; + msg.userId = static_cast(userId); + msg.peerUdids = peerUdids; + msg.tokenId = tokenId; + msg.peerTokenId = peerTokenId; + LOGI("SendAppUnBindBroadCast msg.peerTokenId = %{public}llu.", msg.peerTokenId); + std::string broadCastMsg = ReleationShipSyncMgr::GetInstance().SyncTrustRelationShip(msg); + CHECK_NULL_VOID(softbusListener_); + softbusListener_->SendAclChangedBroadcast(broadCastMsg); +} + void DeviceManagerService::SendServiceUnBindBroadCast(const std::vector &peerUdids, int32_t userId, uint64_t tokenId) { @@ -2121,8 +2204,14 @@ void DeviceManagerService::HandleDeviceTrustedChange(const std::string &msg) dmServiceImpl_->HandleDevUnBindEvent(relationShipMsg.userId, relationShipMsg.peerUdid); break; case RelationShipChangeType::APP_UNBIND: - dmServiceImpl_->HandleAppUnBindEvent(relationShipMsg.userId, relationShipMsg.peerUdid, - static_cast(relationShipMsg.tokenId)); + if (relationShipMsg.peerTokenId != 0) { + dmServiceImpl_->HandleAppUnBindEvent(relationShipMsg.userId, relationShipMsg.peerUdid, + static_cast(relationShipMsg.tokenId), + static_cast(relationShipMsg.peerTokenId)); + } else { + dmServiceImpl_->HandleAppUnBindEvent(relationShipMsg.userId, relationShipMsg.peerUdid, + static_cast(relationShipMsg.tokenId)); + } break; case RelationShipChangeType::SYNC_USERID: HandleUserIdsBroadCast(relationShipMsg.userIdInfos, diff --git a/services/service/src/ipc/standard/ipc_cmd_parser.cpp b/services/service/src/ipc/standard/ipc_cmd_parser.cpp index 4c40447b6..bc75ba3eb 100644 --- a/services/service/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/service/src/ipc/standard/ipc_cmd_parser.cpp @@ -829,7 +829,13 @@ ON_IPC_CMD(UNBIND_DEVICE, MessageParcel &data, MessageParcel &reply) { std::string pkgName = data.ReadString(); std::string deviceId = data.ReadString(); - int32_t result = DeviceManagerService::GetInstance().UnBindDevice(pkgName, deviceId); + std::string extra = data.ReadString(); + int32_t result = 0; + if (extra == "") { + result = DeviceManagerService::GetInstance().UnBindDevice(pkgName, deviceId); + } else { + result = DeviceManagerService::GetInstance().UnBindDevice(pkgName, deviceId, extra); + } if (!reply.WriteInt32(result)) { LOGE("write result failed"); return ERR_DM_IPC_WRITE_FAILED; diff --git a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp index 2a7ddb86f..47d1def3a 100644 --- a/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp +++ b/services/service/src/relationshipsyncmgr/relationship_sync_mgr.cpp @@ -43,7 +43,7 @@ namespace { * | 2 bytes | 4 bytes | * | userid lower 2 bytes | token id lower 4 bytes | */ - const int32_t APP_UNBIND_PAYLOAD_LEN = 6; + const int32_t APP_UNBIND_PAYLOAD_LEN = 10; /** * @brief delete user payload length 2 bytes * | 2 bytes | @@ -55,6 +55,7 @@ namespace { * */ const int32_t USERID_PAYLOAD_LEN = 2; + const int32_t TOKENID_PAYLOAD_LEN = 6; const int32_t ACCOUNTID_PAYLOAD_LEN = 6; const int32_t SYNC_FRONT_OR_BACK_USERID_PAYLOAD_MAX_LEN = 11; const int32_t SYNC_FRONT_OR_BACK_USERID_PAYLOAD_MIN_LEN = 3; @@ -66,6 +67,7 @@ namespace { const char * const MSG_VALUE = "VALUE"; const char * const MSG_PEER_UDID = "PEER_UDID"; const char * const MSG_ACCOUNTID = "ACCOUNTID"; + const char * const MSG_PEER_TOKENID = "PEER_TOKENID"; // The need response mask offset, the 8th bit. const int32_t NEED_RSP_MASK_OFFSET = 7; @@ -242,10 +244,14 @@ void RelationShipChangeMsg::ToAppUnbindPayLoad(uint8_t *&msg, uint32_t &len) con msg[i] |= (userId >> (i * BITS_PER_BYTE)) & 0xFF; } - for (int i = USERID_PAYLOAD_LEN; i < APP_UNBIND_PAYLOAD_LEN; i++) { + for (int i = USERID_PAYLOAD_LEN; i < TOKENID_PAYLOAD_LEN; i++) { msg[i] |= (tokenId >> ((i - USERID_PAYLOAD_LEN) * BITS_PER_BYTE)) & 0xFF; } + for (int i = TOKENID_PAYLOAD_LEN; i < APP_UNBIND_PAYLOAD_LEN; i++) { + msg[i] |= (peerTokenId >> ((i - TOKENID_PAYLOAD_LEN) * BITS_PER_BYTE)) & 0xFF; + } + len = APP_UNBIND_PAYLOAD_LEN; } @@ -365,13 +371,21 @@ bool RelationShipChangeMsg::FromAppUnbindPayLoad(const cJSON *payloadJson) } } tokenId = 0; - for (uint32_t j = USERID_PAYLOAD_LEN; j < APP_UNBIND_PAYLOAD_LEN; j++) { + for (uint32_t j = USERID_PAYLOAD_LEN; j < TOKENID_PAYLOAD_LEN; j++) { cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, j); CHECK_NULL_RETURN(payloadItem, false); if (cJSON_IsNumber(payloadItem)) { tokenId |= (static_cast(payloadItem->valueint)) << ((j - USERID_PAYLOAD_LEN) * BITS_PER_BYTE); } } + peerTokenId = 0; + for (uint32_t j = TOKENID_PAYLOAD_LEN; j < APP_UNBIND_PAYLOAD_LEN; j++) { + cJSON *payloadItem = cJSON_GetArrayItem(payloadJson, j); + if (cJSON_IsNumber(payloadItem)) { + peerTokenId |= (static_cast(payloadItem->valueint)) << + ((j - TOKENID_PAYLOAD_LEN) * BITS_PER_BYTE); + } + } return true; } diff --git a/test/commonfuzztest/dmauthmanager_fuzzer/dm_auth_manager_fuzzer.cpp b/test/commonfuzztest/dmauthmanager_fuzzer/dm_auth_manager_fuzzer.cpp index 881aeb081..403ca99f6 100644 --- a/test/commonfuzztest/dmauthmanager_fuzzer/dm_auth_manager_fuzzer.cpp +++ b/test/commonfuzztest/dmauthmanager_fuzzer/dm_auth_manager_fuzzer.cpp @@ -106,7 +106,7 @@ void DmAuthManagerFuzzTest(const uint8_t* data, size_t size) g_authManager->RegisterUiStateCallback(str); g_authManager->UnRegisterUiStateCallback(str); g_authManager->UnAuthenticateDevice(str, str, bindLevel); - g_authManager->UnBindDevice(str, str, bindLevel); + g_authManager->UnBindDevice(str, str, bindLevel, str); } } } diff --git a/test/commonunittest/UTTest_dm_auth_manager_first.cpp b/test/commonunittest/UTTest_dm_auth_manager_first.cpp index 2306830dc..f5633e787 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_first.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_first.cpp @@ -561,23 +561,24 @@ HWTEST_F(DmAuthManagerTest, UnAuthenticateDevice_001, testing::ext::TestSize.Lev HWTEST_F(DmAuthManagerTest, UnBindDevice_001, testing::ext::TestSize.Level0) { std::string pkgName; - std::string udid = "UnAuthenticateDevice_001"; + std::string udid = "UnBindDevice_001"; int32_t bindLevel = DEVICE; - int32_t ret = authManager_->UnBindDevice(pkgName, udid, bindLevel); + std::string extra = "extraTest"; + int32_t ret = authManager_->UnBindDevice(pkgName, udid, bindLevel, extra); EXPECT_NE(ret, DM_OK); pkgName = "com.ohos.test"; authManager_->isAuthenticateDevice_ = false; - ret = authManager_->UnBindDevice(pkgName, udid, bindLevel); + ret = authManager_->UnBindDevice(pkgName, udid, bindLevel, extra); EXPECT_NE(ret, DM_OK); authManager_->authRequestState_ = nullptr; authManager_->authResponseContext_ = nullptr; - ret = authManager_->UnBindDevice(pkgName, udid, bindLevel); + ret = authManager_->UnBindDevice(pkgName, udid, bindLevel, extra); EXPECT_NE(ret, DM_OK); bindLevel = 0; - ret = authManager_->UnBindDevice(pkgName, udid, bindLevel); + ret = authManager_->UnBindDevice(pkgName, udid, bindLevel, extra); EXPECT_NE(ret, DM_OK); } diff --git a/test/commonunittest/UTTest_dm_auth_manager_third.cpp b/test/commonunittest/UTTest_dm_auth_manager_third.cpp index d4c1150f5..5643f011c 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_third.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_third.cpp @@ -69,15 +69,6 @@ bool SoftbusConnector::CheckIsOnline(const std::string &targetDeviceId) return g_checkIsOnlineReturnBoolValue; } -DmOfflineParam DeviceProfileConnector::DeleteAccessControlList(const std::string &pkgName, - const std::string &localDeviceId, const std::string &remoteDeviceId, int32_t bindLevel) -{ - DmOfflineParam offlineParam; - offlineParam.bindType = g_bindType; - offlineParam.leftAclNumber = g_leftAclNumber; - return offlineParam; -} - bool DmRadarHelper::ReportAuthConfirmBox(struct RadarInfo &info) { return g_reportAuthConfirmBoxReturnBoolValue; @@ -225,37 +216,38 @@ HWTEST_F(DmAuthManagerTest, DeleteAcl001, testing::ext::TestSize.Level0) std::string pkgName = "pkgName"; std::string localUdid = "localUdid"; std::string remoteUdid = "remoteUdid"; + std::string extra = "extraTest"; int32_t sessionId = 0; int32_t bindLevel = APP; g_bindType = INVALIED_TYPE; - int32_t ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel); + int32_t ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); EXPECT_EQ(ret, ERR_DM_FAILED); bindLevel = APP; g_bindType = APP_PEER_TO_PEER_TYPE; g_leftAclNumber = 1; authManager_->softbusConnector_->deviceStateManagerCallback_ = std::make_shared(); - ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel); + ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); EXPECT_EQ(ret, DM_OK); g_leftAclNumber = 0; - ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel); + ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); EXPECT_EQ(ret, DM_OK); bindLevel = DEVICE; - ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel); + ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); EXPECT_EQ(ret, DM_OK); g_leftAclNumber = 1; g_peerUdidHash = "test"; authManager_->DeleteOffLineTimer(sessionId); - ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel); + ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); EXPECT_EQ(ret, DM_OK); authManager_->softbusConnector_ = nullptr; authManager_->DeleteOffLineTimer(sessionId); bindLevel = 0; - ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel); + ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); EXPECT_EQ(ret, ERR_DM_FAILED); } @@ -319,6 +311,103 @@ HWTEST_F(DmAuthManagerTest, ShowStartAuthDialog001, testing::ext::TestSize.Level ASSERT_EQ(authManager_->authResponseContext_->targetDeviceName, DmDialogManager::GetInstance().targetDeviceName_); } +HWTEST_F(DmAuthManagerTest, DeleteAccessControlList001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "pkgName"; + std::string localDeviceId = "localDeviceId"; + std::string remoteDeviceId = "remoteDeviceId"; + int32_t bindLevel = APP; + std::string extra = ""; + auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, + remoteDeviceId, bindLevel, extra); + EXPECT_EQ(APP, ret.bindType); +} + +HWTEST_F(DmAuthManagerTest, DeleteAccessControlList002, testing::ext::TestSize.Level0) +{ + DmOfflineParam offlineParam; + offlineParam.leftAclNumber = 1; + std::string pkgName = "pkgName"; + std::string localDeviceId = "localDeviceId"; + std::string remoteDeviceId = "remoteDeviceId"; + int32_t bindLevel = APP; + std::string extra = "extratest"; + auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, + remoteDeviceId, bindLevel, extra); + EXPECT_EQ(APP, ret.bindType); + EXPECT_EQ(0, ret.leftAclNumber); +} + +HWTEST_F(DmAuthManagerTest, DeleteAccessControlList003, testing::ext::TestSize.Level0) +{ + DmOfflineParam offlineParam; + offlineParam.leftAclNumber = 1; + std::string pkgName = "pkgName"; + std::string localDeviceId = "localDeviceId"; + std::string remoteDeviceId = "remoteDeviceId"; + int32_t bindLevel = SERVICE ; + std::string extra = "extratest"; + auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, + remoteDeviceId, bindLevel, extra); + EXPECT_EQ(SERVICE, ret.bindType); + EXPECT_EQ(0, ret.leftAclNumber); +} + +HWTEST_F(DmAuthManagerTest, DeleteAccessControlList004, testing::ext::TestSize.Level0) +{ + DmOfflineParam offlineParam; + offlineParam.leftAclNumber = 1; + std::string pkgName = "pkgName"; + std::string localDeviceId = "localDeviceId"; + std::string remoteDeviceId = "remoteDeviceId"; + int32_t bindLevel = DEVICE ; + std::string extra = ""; + auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, + remoteDeviceId, bindLevel, extra); + EXPECT_EQ(DEVICE , ret.bindType); + EXPECT_EQ(0, ret.leftAclNumber); +} + +HWTEST_F(DmAuthManagerTest, DeleteAcl001, testing::ext::TestSize.Level0) +{ + std::string pkgName = "pkgName"; + std::string localUdid = "localUdid"; + std::string remoteUdid = "remoteUdid"; + std::string extra = "extraTest"; + int32_t sessionId = 0; + int32_t bindLevel = APP; + g_bindType = INVALIED_TYPE; + int32_t ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); + EXPECT_EQ(ret, ERR_DM_FAILED); + + bindLevel = APP; + g_bindType = APP_PEER_TO_PEER_TYPE; + g_leftAclNumber = 1; + authManager_->softbusConnector_->deviceStateManagerCallback_ = std::make_shared(); + ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); + EXPECT_EQ(ret, DM_OK); + + g_leftAclNumber = 0; + ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); + EXPECT_EQ(ret, DM_OK); + + bindLevel = DEVICE; + ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); + EXPECT_EQ(ret, DM_OK); + + g_leftAclNumber = 1; + g_peerUdidHash = "test"; + authManager_->DeleteOffLineTimer(sessionId); + ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); + EXPECT_EQ(ret, DM_OK); + + authManager_->softbusConnector_ = nullptr; + authManager_->DeleteOffLineTimer(sessionId); + bindLevel = 0; + ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); + EXPECT_EQ(ret, ERR_DM_FAILED); +} + HWTEST_F(DmAuthManagerTest, OnUserOperation001, testing::ext::TestSize.Level0) { int32_t action = USER_OPERATION_TYPE_AUTH_CONFIRM_TIMEOUT; diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp index 5e8c831ac..0b9764c47 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp @@ -709,11 +709,11 @@ HWTEST_F(DeviceProfileConnectorTest, GetParamBindTypeVec_001, testing::ext::Test { DistributedDeviceProfile::AccessControlProfile profiles; profiles.SetBindType(DM_IDENTICAL_ACCOUNT); - std::string pkgName; - std::string requestDeviceId; + std::string requestDeviceId = "requestDeviceId"; + std::string trustUdid = "trustUdid"; std::vector bindTypeVec; - DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, pkgName, requestDeviceId, bindTypeVec); - EXPECT_EQ(bindTypeVec.empty(), false); + DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, requestDeviceId, bindTypeVec, trustUdid); + EXPECT_EQ(bindTypeVec, std::vector({IDENTICAL_ACCOUNT_TYPE})); } HWTEST_F(DeviceProfileConnectorTest, GetParamBindTypeVec_002, testing::ext::TestSize.Level0) @@ -721,11 +721,11 @@ HWTEST_F(DeviceProfileConnectorTest, GetParamBindTypeVec_002, testing::ext::Test DistributedDeviceProfile::AccessControlProfile profiles; profiles.SetBindType(DM_POINT_TO_POINT); profiles.SetBindLevel(DEVICE); - std::string pkgName; - std::string requestDeviceId; + std::string requestDeviceId = "requestDeviceId"; + std::string trustUdid = "trustUdid"; std::vector bindTypeVec; - DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, pkgName, requestDeviceId, bindTypeVec); - EXPECT_EQ(bindTypeVec.empty(), false); + DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, requestDeviceId, bindTypeVec, trustUdid); + EXPECT_EQ(bindTypeVec, std::vector({DEVICE_PEER_TO_PEER_TYPE})); } HWTEST_F(DeviceProfileConnectorTest, GetParamBindTypeVec_003, testing::ext::TestSize.Level0) @@ -733,67 +733,39 @@ HWTEST_F(DeviceProfileConnectorTest, GetParamBindTypeVec_003, testing::ext::Test DistributedDeviceProfile::AccessControlProfile profiles; profiles.SetBindType(DM_POINT_TO_POINT); profiles.SetBindLevel(APP); - profiles.accesser_.SetAccesserBundleName("pkgName"); - profiles.accesser_.SetAccesserDeviceId("localDeviceId"); - std::string pkgName = "pkgName"; - std::string requestDeviceId = "localDeviceId"; + std::string requestDeviceId = "requestDeviceId"; + std::string trustUdid = "trustUdid"; + profiles.GetAccesser().SetAccesserDeviceId(trustUdid); + profiles.GetAccessee().SetAccesseeDeviceId(requestDeviceId); std::vector bindTypeVec; - DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, pkgName, requestDeviceId, bindTypeVec); - EXPECT_EQ(bindTypeVec.empty(), false); + DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, requestDeviceId, bindTypeVec, trustUdid); + EXPECT_EQ(bindTypeVec, std::vector({APP_PEER_TO_PEER_TYPE})); } HWTEST_F(DeviceProfileConnectorTest, GetParamBindTypeVec_004, testing::ext::TestSize.Level0) -{ - DistributedDeviceProfile::AccessControlProfile profiles; - profiles.SetBindType(DM_POINT_TO_POINT); - profiles.SetBindLevel(APP); - profiles.accessee_.SetAccesseeBundleName("pkgName"); - profiles.accessee_.SetAccesseeDeviceId("localDeviceId"); - std::string pkgName = "pkgName"; - std::string requestDeviceId = "localDeviceId"; - std::vector bindTypeVec; - DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, pkgName, requestDeviceId, bindTypeVec); - EXPECT_EQ(bindTypeVec.empty(), false); -} - -HWTEST_F(DeviceProfileConnectorTest, GetParamBindTypeVec_005, testing::ext::TestSize.Level0) { DistributedDeviceProfile::AccessControlProfile profiles; profiles.SetBindType(DM_ACROSS_ACCOUNT); profiles.SetBindLevel(DEVICE); - std::string pkgName; - std::string requestDeviceId; - std::vector bindTypeVec; - DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, pkgName, requestDeviceId, bindTypeVec); - EXPECT_EQ(bindTypeVec.empty(), false); -} - -HWTEST_F(DeviceProfileConnectorTest, GetParamBindTypeVec_006, testing::ext::TestSize.Level0) -{ - DistributedDeviceProfile::AccessControlProfile profiles; - profiles.SetBindType(DM_ACROSS_ACCOUNT); - profiles.SetBindLevel(APP); - profiles.accesser_.SetAccesserBundleName("pkgName"); - profiles.accesser_.SetAccesserDeviceId("localDeviceId"); - std::string pkgName = "pkgName"; - std::string requestDeviceId = "localDeviceId"; + std::string requestDeviceId = "requestDeviceId"; + std::string trustUdid = "trustUdid"; std::vector bindTypeVec; - DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, pkgName, requestDeviceId, bindTypeVec); - EXPECT_EQ(bindTypeVec.empty(), false); + DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, requestDeviceId, bindTypeVec, trustUdid); + EXPECT_EQ(bindTypeVec, std::vector({DEVICE_ACROSS_ACCOUNT_TYPE})); } -HWTEST_F(DeviceProfileConnectorTest, GetParamBindTypeVec_007, testing::ext::TestSize.Level0) +HWTEST_F(DeviceProfileConnectorTest, GetParamBindTypeVec_005, testing::ext::TestSize.Level0) { DistributedDeviceProfile::AccessControlProfile profiles; profiles.SetBindType(DM_ACROSS_ACCOUNT); profiles.SetBindLevel(APP); - profiles.accessee_.SetAccesseeBundleName("pkgName"); - profiles.accessee_.SetAccesseeDeviceId("localDeviceId"); - std::string pkgName = "pkgName"; - std::string requestDeviceId = "localDeviceId"; + std::string requestDeviceId = "requestDeviceId"; + std::string trustUdid = "trustUdid"; + profiles.GetAccesser().SetAccesserDeviceId(trustUdid); + profiles.GetAccessee().SetAccesseeDeviceId(requestDeviceId); std::vector bindTypeVec; - DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, pkgName, requestDeviceId, bindTypeVec); - EXPECT_EQ(bindTypeVec.empty(), false); + DeviceProfileConnector::GetInstance().GetParamBindTypeVec(profiles, requestDeviceId, bindTypeVec, trustUdid); + EXPECT_EQ(bindTypeVec, std::vector({APP_ACROSS_ACCOUNT_TYPE})); } HWTEST_F(DeviceProfileConnectorTest, CompareBindType_001, testing::ext::TestSize.Level0) @@ -848,106 +820,42 @@ HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_001, testing::ext::TestSize { DistributedDeviceProfile::AccessControlProfile profiles; profiles.SetBindType(DM_IDENTICAL_ACCOUNT); - DmDiscoveryInfo paramInfo; - std::vector sinkBindType; - std::vector bindTypeIndex; + vector sinkBindType; + vector bindTypeIndex; + string localDeviceId = "localDeviceId"; + string targetDeviceId = "targetDeviceId"; uint32_t index = 0; - DeviceProfileConnector::GetInstance().ProcessBindType(profiles, paramInfo, sinkBindType, bindTypeIndex, index); - EXPECT_EQ(sinkBindType.empty(), false); + DeviceProfileConnector::GetInstance().ProcessBindType(profiles, localDeviceId, sinkBindType, bindTypeIndex, index, targetDeviceId); + EXPECT_EQ(sinkBindType, vector({IDENTICAL_ACCOUNT_TYPE})); + EXPECT_EQ(bindTypeIndex, vector({0})); } HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_002, testing::ext::TestSize.Level0) { DistributedDeviceProfile::AccessControlProfile profiles; profiles.SetBindType(DM_POINT_TO_POINT); - profiles.SetBindLevel(DEVICE); - DmDiscoveryInfo paramInfo; - std::vector sinkBindType; - std::vector bindTypeIndex; + vector sinkBindType; + vector bindTypeIndex; + string localDeviceId = "localDeviceId"; + string targetDeviceId = "targetDeviceId"; uint32_t index = 0; - DeviceProfileConnector::GetInstance().ProcessBindType(profiles, paramInfo, sinkBindType, bindTypeIndex, index); - EXPECT_EQ(sinkBindType.empty(), false); + DeviceProfileConnector::GetInstance().ProcessBindType(profiles, localDeviceId, sinkBindType, bindTypeIndex, index, targetDeviceId); + EXPECT_EQ(sinkBindType, vector({DEVICE_PEER_TO_PEER_TYPE})); + EXPECT_EQ(bindTypeIndex, vector({0})); } HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_003, testing::ext::TestSize.Level0) -{ - DistributedDeviceProfile::AccessControlProfile profiles; - profiles.SetBindType(DM_POINT_TO_POINT); - profiles.SetBindLevel(APP); - profiles.accesser_.SetAccesserBundleName("pkgName"); - profiles.accesser_.SetAccesserDeviceId("localDeviceId"); - DmDiscoveryInfo paramInfo; - paramInfo.pkgname = "pkgName"; - paramInfo.localDeviceId = "localDeviceId"; - std::vector sinkBindType; - std::vector bindTypeIndex; - uint32_t index = 0; - DeviceProfileConnector::GetInstance().ProcessBindType(profiles, paramInfo, sinkBindType, bindTypeIndex, index); - EXPECT_EQ(sinkBindType.empty(), false); -} - -HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_004, testing::ext::TestSize.Level0) -{ - DistributedDeviceProfile::AccessControlProfile profiles; - profiles.SetBindType(DM_POINT_TO_POINT); - profiles.SetBindLevel(APP); - profiles.accessee_.SetAccesseeBundleName("pkgName"); - profiles.accessee_.SetAccesseeDeviceId("localDeviceId"); - DmDiscoveryInfo paramInfo; - paramInfo.pkgname = "pkgName"; - paramInfo.localDeviceId = "localDeviceId"; - std::vector sinkBindType; - std::vector bindTypeIndex; - uint32_t index = 0; - DeviceProfileConnector::GetInstance().ProcessBindType(profiles, paramInfo, sinkBindType, bindTypeIndex, index); - EXPECT_EQ(sinkBindType.empty(), false); -} - -HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_005, testing::ext::TestSize.Level0) -{ - DistributedDeviceProfile::AccessControlProfile profiles; - profiles.SetBindType(DM_ACROSS_ACCOUNT); - profiles.SetBindLevel(DEVICE); - DmDiscoveryInfo paramInfo; - std::vector sinkBindType; - std::vector bindTypeIndex; - uint32_t index = 0; - DeviceProfileConnector::GetInstance().ProcessBindType(profiles, paramInfo, sinkBindType, bindTypeIndex, index); - EXPECT_EQ(sinkBindType.empty(), false); -} - -HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_006, testing::ext::TestSize.Level0) { DistributedDeviceProfile::AccessControlProfile profiles; profiles.SetBindType(DM_ACROSS_ACCOUNT); - profiles.SetBindLevel(APP); - profiles.accesser_.SetAccesserBundleName("pkgName"); - profiles.accesser_.SetAccesserDeviceId("localDeviceId"); - DmDiscoveryInfo paramInfo; - paramInfo.pkgname = "pkgName"; - paramInfo.localDeviceId = "localDeviceId"; - std::vector sinkBindType; - std::vector bindTypeIndex; - uint32_t index = 0; - DeviceProfileConnector::GetInstance().ProcessBindType(profiles, paramInfo, sinkBindType, bindTypeIndex, index); - EXPECT_EQ(sinkBindType.empty(), false); -} - -HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_007, testing::ext::TestSize.Level0) -{ - DistributedDeviceProfile::AccessControlProfile profiles; - profiles.SetBindType(DM_ACROSS_ACCOUNT); - profiles.SetBindLevel(APP); - profiles.accessee_.SetAccesseeBundleName("pkgName"); - profiles.accessee_.SetAccesseeDeviceId("localDeviceId"); - DmDiscoveryInfo paramInfo; - paramInfo.pkgname = "pkgName"; - paramInfo.localDeviceId = "localDeviceId"; - std::vector sinkBindType; - std::vector bindTypeIndex; + vector sinkBindType; + vector bindTypeIndex; + string localDeviceId = "localDeviceId"; + string targetDeviceId = "targetDeviceId"; uint32_t index = 0; - DeviceProfileConnector::GetInstance().ProcessBindType(profiles, paramInfo, sinkBindType, bindTypeIndex, index); - EXPECT_EQ(sinkBindType.empty(), false); + DeviceProfileConnector::GetInstance().ProcessBindType(profiles, localDeviceId, sinkBindType, bindTypeIndex, index, targetDeviceId); + EXPECT_EQ(sinkBindType, vector({DEVICE_ACROSS_ACCOUNT_TYPE})); + EXPECT_EQ(bindTypeIndex, vector({0})); } HWTEST_F(DeviceProfileConnectorTest, SyncAclByBindType_001, testing::ext::TestSize.Level0) @@ -1200,11 +1108,10 @@ HWTEST_F(DeviceProfileConnectorTest, DeleteAccessControlList_001, testing::ext:: std::string pkgName = "bundleName"; std::string localDeviceId = "localDeviceId"; std::string remoteDeviceId = "remoteDeviceId"; + std::string extra = "extraTest"; int32_t bindLevel = INVALIED_TYPE; - DmOfflineParam offlineParam = DeviceProfileConnector::GetInstance() - .DeleteAccessControlList(pkgName, localDeviceId, remoteDeviceId, bindLevel); - + .DeleteAccessControlList(pkgName, localDeviceId, remoteDeviceId, bindLevel, extra); EXPECT_EQ(offlineParam.bindType, INVALIED_TYPE); } @@ -1213,11 +1120,10 @@ HWTEST_F(DeviceProfileConnectorTest, DeleteAccessControlList_002, testing::ext:: std::string pkgName = "bundleName"; std::string localDeviceId = "localDeviceId"; std::string remoteDeviceId = "remoteDeviceId"; + std::string extra = "extraTest"; int32_t bindLevel = APP; - DmOfflineParam offlineParam = DeviceProfileConnector::GetInstance() - .DeleteAccessControlList(pkgName, localDeviceId, remoteDeviceId, bindLevel); - + .DeleteAccessControlList(pkgName, localDeviceId, remoteDeviceId, bindLevel, extra); EXPECT_EQ(offlineParam.bindType, APP); } @@ -1226,11 +1132,10 @@ HWTEST_F(DeviceProfileConnectorTest, DeleteAccessControlList_003, testing::ext:: std::string pkgName = "bundleName"; std::string localDeviceId = "localDeviceId"; std::string remoteDeviceId = "remoteDeviceId"; + std::string extra = "extraTest"; int32_t bindLevel = SERVICE; - DmOfflineParam offlineParam = DeviceProfileConnector::GetInstance() - .DeleteAccessControlList(pkgName, localDeviceId, remoteDeviceId, bindLevel); - + .DeleteAccessControlList(pkgName, localDeviceId, remoteDeviceId, bindLevel, extra); EXPECT_EQ(offlineParam.bindType, SERVICE); } @@ -1239,11 +1144,10 @@ HWTEST_F(DeviceProfileConnectorTest, DeleteAccessControlList_004, testing::ext:: std::string pkgName = "bundleName"; std::string localDeviceId = "localDeviceId"; std::string remoteDeviceId = "remoteDeviceId"; + std::string extra = "extraTest"; int32_t bindLevel = DEVICE; - DmOfflineParam offlineParam = DeviceProfileConnector::GetInstance() - .DeleteAccessControlList(pkgName, localDeviceId, remoteDeviceId, bindLevel); - + .DeleteAccessControlList(pkgName, localDeviceId, remoteDeviceId, bindLevel, extra); EXPECT_EQ(offlineParam.bindType, DEVICE); } diff --git a/test/servicesfuzztest/deviceprofileconnector_fuzzer/device_profile_connector_fuzzer.cpp b/test/servicesfuzztest/deviceprofileconnector_fuzzer/device_profile_connector_fuzzer.cpp index 112f21058..f638d20a3 100644 --- a/test/servicesfuzztest/deviceprofileconnector_fuzzer/device_profile_connector_fuzzer.cpp +++ b/test/servicesfuzztest/deviceprofileconnector_fuzzer/device_profile_connector_fuzzer.cpp @@ -35,6 +35,7 @@ void DeviceProfileConnectorFuzzTest(const uint8_t* data, size_t size) std::string requestDeviceId(reinterpret_cast(data), size); std::string pkgName(reinterpret_cast(data), size); std::string trustUdid(reinterpret_cast(data), size); + std::string extra(reinterpret_cast(data), size); std::string localDeviceId(reinterpret_cast(data), size); std::string targetDeviceId(reinterpret_cast(data), size); std::string requestAccountId(reinterpret_cast(data), size); @@ -56,12 +57,11 @@ void DeviceProfileConnectorFuzzTest(const uint8_t* data, size_t size) dmAccessee.trustBundleName = trustBundleName; int32_t userId = fdp.ConsumeIntegral(); std::string accountId(reinterpret_cast(data), size); - int32_t bindLevel = fdp.ConsumeIntegral(); DeviceProfileConnector::GetInstance().CheckBindType(trustDeviceId, requestDeviceId); DeviceProfileConnector::GetInstance().GetBindTypeByPkgName(pkgName, requestDeviceId, trustUdid); DeviceProfileConnector::GetInstance().GetProcessInfoFromAclByUserId(localDeviceId, targetDeviceId, userId); DeviceProfileConnector::GetInstance().PutAccessControlList(aclInfo, dmAccesser, dmAccessee); - DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, requestDeviceId, bindLevel); + DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, requestDeviceId, bindLevel, extra); DeviceProfileConnector::GetInstance().UpdateAccessControlList(userId, accountId, accountId); DeviceProfileConnector::GetInstance().CheckIdenticalAccount(userId, accountId); DeviceProfileConnector::GetInstance().CheckDevIdInAclForDevBind(pkgName, localDeviceId); -- Gitee From 6737633bb68a30f3a68df002694a907bc37417ad Mon Sep 17 00:00:00 2001 From: libuyan Date: Thu, 26 Dec 2024 09:50:36 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=B8=85=E9=99=A4codecheck=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: libuyan --- .../device_manager_service_impl_lite.h | 2 ++ .../src/device_manager_service_impl_lite.cpp | 23 ++++++++++++++++++- .../UTTest_dm_auth_manager_third.cpp | 18 +++++++-------- .../UTTest_dm_deviceprofile_connector.cpp | 9 +++++--- .../device_profile_connector_fuzzer.cpp | 4 +++- 5 files changed, 42 insertions(+), 14 deletions(-) diff --git a/services/implementation/include/device_manager_service_impl_lite.h b/services/implementation/include/device_manager_service_impl_lite.h index 2f6c1e298..2773a6fea 100644 --- a/services/implementation/include/device_manager_service_impl_lite.h +++ b/services/implementation/include/device_manager_service_impl_lite.h @@ -135,6 +135,8 @@ public: const std::string &remoteUdid); void HandleDevUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid); void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId); + void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, + int32_t tokenId, int32_t peerTokenId); void HandleIdentAccountLogout(const std::string &localUdid, int32_t localUserId, const std::string &peerUdid, int32_t peerUserId); void HandleUserRemoved(int32_t preUserId); diff --git a/services/implementation/src/device_manager_service_impl_lite.cpp b/services/implementation/src/device_manager_service_impl_lite.cpp index 095fb3a4a..881befbf4 100644 --- a/services/implementation/src/device_manager_service_impl_lite.cpp +++ b/services/implementation/src/device_manager_service_impl_lite.cpp @@ -69,6 +69,7 @@ void DeviceManagerServiceImpl::Release() softbusConnector_ = nullptr; hiChainConnector_ = nullptr; mineHiChainConnector_ = nullptr; + return; } int32_t DeviceManagerServiceImpl::UnAuthenticateDevice(const std::string &pkgName, const std::string &udid, @@ -119,6 +120,7 @@ void DeviceManagerServiceImpl::HandleDeviceStatusChange(DmDeviceState devState, LOGE("get deviceId: %{public}s failed", GetAnonyString(deviceId).c_str()); } deviceStateMgr_->HandleDeviceStatusChange(devState, devInfo); + return; } std::string DeviceManagerServiceImpl::GetUdidHashByNetworkId(const std::string &networkId) @@ -146,6 +148,7 @@ int DeviceManagerServiceImpl::OnSessionOpened(int sessionId, int result) void DeviceManagerServiceImpl::OnSessionClosed(int sessionId) { (void)sessionId; + return; } void DeviceManagerServiceImpl::OnBytesReceived(int sessionId, const void *data, unsigned int dataLen) @@ -153,6 +156,7 @@ void DeviceManagerServiceImpl::OnBytesReceived(int sessionId, const void *data, (void)sessionId; (void)data; (void)dataLen; + return; } int DeviceManagerServiceImpl::OnPinHolderSessionOpened(int sessionId, int result) @@ -165,6 +169,7 @@ int DeviceManagerServiceImpl::OnPinHolderSessionOpened(int sessionId, int result void DeviceManagerServiceImpl::OnPinHolderSessionClosed(int sessionId) { (void)sessionId; + return; } void DeviceManagerServiceImpl::OnPinHolderBytesReceived(int sessionId, const void *data, unsigned int dataLen) @@ -172,6 +177,7 @@ void DeviceManagerServiceImpl::OnPinHolderBytesReceived(int sessionId, const voi (void)sessionId; (void)data; (void)dataLen; + return; } int32_t DeviceManagerServiceImpl::RequestCredential(const std::string &reqJsonStr, std::string &returnJsonStr) @@ -374,6 +380,7 @@ std::unordered_map DeviceManagerServiceImpl::GetAppTrus void DeviceManagerServiceImpl::LoadHardwareFwkService() { + return; } int32_t DeviceManagerServiceImpl::DpAclAdd(const std::string &udid) @@ -391,6 +398,7 @@ int32_t DeviceManagerServiceImpl::IsSameAccount(const std::string &udid) void DeviceManagerServiceImpl::ScreenCommonEventCallback(std::string commonEventType) { (void)commonEventType; + return; } int32_t DeviceManagerServiceImpl::CheckIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, @@ -462,6 +470,16 @@ void DeviceManagerServiceImpl::HandleAppUnBindEvent(int32_t remoteUserId, const return; } +void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, + int32_t tokenId, int32_t peerTokenId) +{ + (void)remoteUserId; + (void)remoteUdid; + (void)tokenId; + (void)peerTokenId; + return; +} + void DeviceManagerServiceImpl::HandleIdentAccountLogout(const std::string &localUdid, int32_t localUserId, const std::string &peerUdid, int32_t peerUserId) { @@ -521,23 +539,26 @@ void DeviceManagerServiceImpl::HandleSyncUserIdEvent(const std::vector (void)foregroundUserIds; (void)backgroundUserIds; (void)remoteUdid; + return; } void HandleRemoteUserRemoved(int32_t preUserId, const std::string &remoteUdid) { (void)preUserId; (void)remoteUdid; + return; } std::map DeviceManagerServiceImpl::GetDeviceIdAndBindLevel(int32_t userId) { (void)userId; + return std::map {}; } std::multimap DeviceManagerServiceImpl::GetDeviceIdAndUserId(int32_t localUserId) { (void)localUserId; - return {}; + return std::multimap {}; } int32_t DeviceManagerServiceImpl::SaveOnlineDeviceInfo(const std::vector &deviceList) diff --git a/test/commonunittest/UTTest_dm_auth_manager_third.cpp b/test/commonunittest/UTTest_dm_auth_manager_third.cpp index 5643f011c..b7836625d 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_third.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_third.cpp @@ -316,9 +316,9 @@ HWTEST_F(DmAuthManagerTest, DeleteAccessControlList001, testing::ext::TestSize.L std::string pkgName = "pkgName"; std::string localDeviceId = "localDeviceId"; std::string remoteDeviceId = "remoteDeviceId"; - int32_t bindLevel = APP; + int32_t bindLevel = APP; std::string extra = ""; - auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, + auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, remoteDeviceId, bindLevel, extra); EXPECT_EQ(APP, ret.bindType); } @@ -330,9 +330,9 @@ HWTEST_F(DmAuthManagerTest, DeleteAccessControlList002, testing::ext::TestSize.L std::string pkgName = "pkgName"; std::string localDeviceId = "localDeviceId"; std::string remoteDeviceId = "remoteDeviceId"; - int32_t bindLevel = APP; + int32_t bindLevel = APP; std::string extra = "extratest"; - auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, + auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, remoteDeviceId, bindLevel, extra); EXPECT_EQ(APP, ret.bindType); EXPECT_EQ(0, ret.leftAclNumber); @@ -345,9 +345,9 @@ HWTEST_F(DmAuthManagerTest, DeleteAccessControlList003, testing::ext::TestSize.L std::string pkgName = "pkgName"; std::string localDeviceId = "localDeviceId"; std::string remoteDeviceId = "remoteDeviceId"; - int32_t bindLevel = SERVICE ; + int32_t bindLevel = SERVICE; std::string extra = "extratest"; - auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, + auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, remoteDeviceId, bindLevel, extra); EXPECT_EQ(SERVICE, ret.bindType); EXPECT_EQ(0, ret.leftAclNumber); @@ -360,11 +360,11 @@ HWTEST_F(DmAuthManagerTest, DeleteAccessControlList004, testing::ext::TestSize.L std::string pkgName = "pkgName"; std::string localDeviceId = "localDeviceId"; std::string remoteDeviceId = "remoteDeviceId"; - int32_t bindLevel = DEVICE ; + int32_t bindLevel = DEVICE; std::string extra = ""; - auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, + auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, remoteDeviceId, bindLevel, extra); - EXPECT_EQ(DEVICE , ret.bindType); + EXPECT_EQ(DEVICE, ret.bindType); EXPECT_EQ(0, ret.leftAclNumber); } diff --git a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp index 0b9764c47..cfe3f14a6 100644 --- a/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp +++ b/test/commonunittest/UTTest_dm_deviceprofile_connector.cpp @@ -825,7 +825,8 @@ HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_001, testing::ext::TestSize string localDeviceId = "localDeviceId"; string targetDeviceId = "targetDeviceId"; uint32_t index = 0; - DeviceProfileConnector::GetInstance().ProcessBindType(profiles, localDeviceId, sinkBindType, bindTypeIndex, index, targetDeviceId); + DeviceProfileConnector::GetInstance().ProcessBindType(profiles, localDeviceId, + sinkBindType, bindTypeIndex, index, targetDeviceId); EXPECT_EQ(sinkBindType, vector({IDENTICAL_ACCOUNT_TYPE})); EXPECT_EQ(bindTypeIndex, vector({0})); } @@ -839,7 +840,8 @@ HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_002, testing::ext::TestSize string localDeviceId = "localDeviceId"; string targetDeviceId = "targetDeviceId"; uint32_t index = 0; - DeviceProfileConnector::GetInstance().ProcessBindType(profiles, localDeviceId, sinkBindType, bindTypeIndex, index, targetDeviceId); + DeviceProfileConnector::GetInstance().ProcessBindType(profiles, localDeviceId, + sinkBindType, bindTypeIndex, index, targetDeviceId); EXPECT_EQ(sinkBindType, vector({DEVICE_PEER_TO_PEER_TYPE})); EXPECT_EQ(bindTypeIndex, vector({0})); } @@ -853,7 +855,8 @@ HWTEST_F(DeviceProfileConnectorTest, ProcessBindType_003, testing::ext::TestSize string localDeviceId = "localDeviceId"; string targetDeviceId = "targetDeviceId"; uint32_t index = 0; - DeviceProfileConnector::GetInstance().ProcessBindType(profiles, localDeviceId, sinkBindType, bindTypeIndex, index, targetDeviceId); + DeviceProfileConnector::GetInstance().ProcessBindType(profiles, localDeviceId, + sinkBindType, bindTypeIndex, index, targetDeviceId); EXPECT_EQ(sinkBindType, vector({DEVICE_ACROSS_ACCOUNT_TYPE})); EXPECT_EQ(bindTypeIndex, vector({0})); } diff --git a/test/servicesfuzztest/deviceprofileconnector_fuzzer/device_profile_connector_fuzzer.cpp b/test/servicesfuzztest/deviceprofileconnector_fuzzer/device_profile_connector_fuzzer.cpp index f638d20a3..f0ef6424f 100644 --- a/test/servicesfuzztest/deviceprofileconnector_fuzzer/device_profile_connector_fuzzer.cpp +++ b/test/servicesfuzztest/deviceprofileconnector_fuzzer/device_profile_connector_fuzzer.cpp @@ -41,6 +41,7 @@ void DeviceProfileConnectorFuzzTest(const uint8_t* data, size_t size) std::string requestAccountId(reinterpret_cast(data), size); std::string deviceIdHash(reinterpret_cast(data), size); std::string trustBundleName(reinterpret_cast(data), size); + int32_t bindLevel = 1; DmAclInfo aclInfo; aclInfo.bindType = fdp.ConsumeIntegral(); aclInfo.bindLevel = fdp.ConsumeIntegral(); @@ -61,7 +62,8 @@ void DeviceProfileConnectorFuzzTest(const uint8_t* data, size_t size) DeviceProfileConnector::GetInstance().GetBindTypeByPkgName(pkgName, requestDeviceId, trustUdid); DeviceProfileConnector::GetInstance().GetProcessInfoFromAclByUserId(localDeviceId, targetDeviceId, userId); DeviceProfileConnector::GetInstance().PutAccessControlList(aclInfo, dmAccesser, dmAccessee); - DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, requestDeviceId, bindLevel, extra); + DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId, + requestDeviceId, bindLevel, extra); DeviceProfileConnector::GetInstance().UpdateAccessControlList(userId, accountId, accountId); DeviceProfileConnector::GetInstance().CheckIdenticalAccount(userId, accountId); DeviceProfileConnector::GetInstance().CheckDevIdInAclForDevBind(pkgName, localDeviceId); -- Gitee From 7208423e1a727ef8ca779834a449d983b2f27b0e Mon Sep 17 00:00:00 2001 From: Huyuhao <610494558@qq.com> Date: Thu, 26 Dec 2024 11:19:36 +0800 Subject: [PATCH 3/4] fix lite problem Signed-off-by: Huyuhao <610494558@qq.com> --- .../include/device_manager_service_impl.h | 1 + .../device_manager_service_impl_lite.h | 1 + .../src/device_manager_service_impl.cpp | 16 ++++++++ .../src/device_manager_service_impl_lite.cpp | 12 +++++- .../include/idevice_manager_service_impl.h | 1 + .../service/src/device_manager_service.cpp | 3 +- .../UTTest_dm_auth_manager_third.cpp | 40 ------------------- 7 files changed, 31 insertions(+), 43 deletions(-) diff --git a/services/implementation/include/device_manager_service_impl.h b/services/implementation/include/device_manager_service_impl.h index c2c1f5a2a..42bf914d3 100644 --- a/services/implementation/include/device_manager_service_impl.h +++ b/services/implementation/include/device_manager_service_impl.h @@ -110,6 +110,7 @@ public: int32_t DpAclAdd(const std::string &udid); int32_t IsSameAccount(const std::string &udid); + uint64_t GetTokenIdByNameAndDeviceId(std::string pkgName, std::string requestDeviceId); void ScreenCommonEventCallback(std::string commonEventType); int32_t CheckIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid); diff --git a/services/implementation/include/device_manager_service_impl_lite.h b/services/implementation/include/device_manager_service_impl_lite.h index 2773a6fea..212146f8f 100644 --- a/services/implementation/include/device_manager_service_impl_lite.h +++ b/services/implementation/include/device_manager_service_impl_lite.h @@ -122,6 +122,7 @@ public: int32_t DpAclAdd(const std::string &udid); int32_t IsSameAccount(const std::string &udid); + uint64_t GetTokenIdByNameAndDeviceId(std::string pkgName, std::string requestDeviceId); void ScreenCommonEventCallback(std::string commonEventType); int32_t CheckIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid); diff --git a/services/implementation/src/device_manager_service_impl.cpp b/services/implementation/src/device_manager_service_impl.cpp index 83aae729b..877306b23 100644 --- a/services/implementation/src/device_manager_service_impl.cpp +++ b/services/implementation/src/device_manager_service_impl.cpp @@ -638,6 +638,22 @@ int32_t DeviceManagerServiceImpl::IsSameAccount(const std::string &udid) return DeviceProfileConnector::GetInstance().IsSameAccount(udid); } +uint64_t DeviceManagerServiceImpl::GetTokenIdByNameAndDeviceId(std::string pkgName, + std::string requestDeviceId) +{ + if (pkgName.empty()) { + LOGE("DeviceManagerServiceImpl::GetTokenIdByNameAndDeviceId error: pkgName."); + return ERR_DM_INPUT_PARA_INVALID; + } + + if (requestDeviceId.empty()) { + LOGE("DeviceManagerServiceImpl::GetTokenIdByNameAndDeviceId error: requestDeviceId."); + return ERR_DM_INPUT_PARA_INVALID; + } + + return DeviceProfileConnector::GetInstance().GetTokenIdByNameAndDeviceId(pkgName, requestDeviceId); +} + std::unordered_map DeviceManagerServiceImpl::GetAppTrustDeviceIdList( std::string pkgname) { diff --git a/services/implementation/src/device_manager_service_impl_lite.cpp b/services/implementation/src/device_manager_service_impl_lite.cpp index 881befbf4..e14fde93b 100644 --- a/services/implementation/src/device_manager_service_impl_lite.cpp +++ b/services/implementation/src/device_manager_service_impl_lite.cpp @@ -90,7 +90,7 @@ int32_t DeviceManagerServiceImpl::UnBindDevice(const std::string &pkgName, const return DM_OK; } -int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, +int32_t DeviceManagerServiceImpl::UnBindDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel, const std::string &extra) { (void)pkgName; @@ -395,6 +395,14 @@ int32_t DeviceManagerServiceImpl::IsSameAccount(const std::string &udid) return DM_OK; } +uint64_t DeviceManagerServiceImpl::GetTokenIdByNameAndDeviceId(std::string pkgName, + std::string requestDeviceId) +{ + (void)pkgName; + (void)requestDeviceId; + return 0; +} + void DeviceManagerServiceImpl::ScreenCommonEventCallback(std::string commonEventType) { (void)commonEventType; @@ -470,7 +478,7 @@ void DeviceManagerServiceImpl::HandleAppUnBindEvent(int32_t remoteUserId, const return; } -void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, +void DeviceManagerServiceImpl::HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId, int32_t peerTokenId) { (void)remoteUserId; diff --git a/services/service/include/idevice_manager_service_impl.h b/services/service/include/idevice_manager_service_impl.h index 73fcba70d..8335e13fe 100644 --- a/services/service/include/idevice_manager_service_impl.h +++ b/services/service/include/idevice_manager_service_impl.h @@ -221,6 +221,7 @@ public: virtual std::unordered_map GetAppTrustDeviceIdList(std::string pkgname) = 0; virtual int32_t DpAclAdd(const std::string &udid) = 0; virtual int32_t IsSameAccount(const std::string &udid) = 0; + virtual uint64_t GetTokenIdByNameAndDeviceId(std::string pkgName, std::string requestDeviceId) = 0; virtual void ScreenCommonEventCallback(std::string commonEventType) = 0; virtual int32_t CheckIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, const DmAccessCallee &callee, const std::string &sinkUdid) = 0; diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 6edbe031c..5df8839aa 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -270,6 +270,7 @@ int32_t DeviceManagerService::GetTrustedDeviceList(const std::string &pkgName, c std::vector &deviceList) { LOGI("Begin for pkgName = %{public}s.", pkgName.c_str()); + (void)extra; if (pkgName.empty()) { LOGE("Invalid parameter, pkgName is empty."); return ERR_DM_INPUT_PARA_INVALID; @@ -701,7 +702,7 @@ int32_t DeviceManagerService::UnBindDevice(const std::string &pkgName, const std LOGE("UnAuthenticateDevice failed, Acl not contain the bindLevel %{public}d.", bindLevel); return ERR_DM_FAILED; } - uint64_t peerTokenId = DeviceProfileConnector::GetInstance().GetTokenIdByNameAndDeviceId(extra, udid); + uint64_t peerTokenId = dmServiceImpl_->GetTokenIdByNameAndDeviceId(extra, udid); if (dmServiceImpl_->UnBindDevice(pkgName, udid, bindLevel, extra) != DM_OK) { LOGE("dmServiceImpl_ UnBindDevice failed."); return ERR_DM_FAILED; diff --git a/test/commonunittest/UTTest_dm_auth_manager_third.cpp b/test/commonunittest/UTTest_dm_auth_manager_third.cpp index b7836625d..29c5f1b0b 100644 --- a/test/commonunittest/UTTest_dm_auth_manager_third.cpp +++ b/test/commonunittest/UTTest_dm_auth_manager_third.cpp @@ -368,46 +368,6 @@ HWTEST_F(DmAuthManagerTest, DeleteAccessControlList004, testing::ext::TestSize.L EXPECT_EQ(0, ret.leftAclNumber); } -HWTEST_F(DmAuthManagerTest, DeleteAcl001, testing::ext::TestSize.Level0) -{ - std::string pkgName = "pkgName"; - std::string localUdid = "localUdid"; - std::string remoteUdid = "remoteUdid"; - std::string extra = "extraTest"; - int32_t sessionId = 0; - int32_t bindLevel = APP; - g_bindType = INVALIED_TYPE; - int32_t ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); - EXPECT_EQ(ret, ERR_DM_FAILED); - - bindLevel = APP; - g_bindType = APP_PEER_TO_PEER_TYPE; - g_leftAclNumber = 1; - authManager_->softbusConnector_->deviceStateManagerCallback_ = std::make_shared(); - ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); - EXPECT_EQ(ret, DM_OK); - - g_leftAclNumber = 0; - ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); - EXPECT_EQ(ret, DM_OK); - - bindLevel = DEVICE; - ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); - EXPECT_EQ(ret, DM_OK); - - g_leftAclNumber = 1; - g_peerUdidHash = "test"; - authManager_->DeleteOffLineTimer(sessionId); - ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); - EXPECT_EQ(ret, DM_OK); - - authManager_->softbusConnector_ = nullptr; - authManager_->DeleteOffLineTimer(sessionId); - bindLevel = 0; - ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra); - EXPECT_EQ(ret, ERR_DM_FAILED); -} - HWTEST_F(DmAuthManagerTest, OnUserOperation001, testing::ext::TestSize.Level0) { int32_t action = USER_OPERATION_TYPE_AUTH_CONFIRM_TIMEOUT; -- Gitee From bfae9c633cbb2948a023e3696c87a650e02e6eb6 Mon Sep 17 00:00:00 2001 From: Huyuhao <610494558@qq.com> Date: Thu, 26 Dec 2024 12:41:17 +0800 Subject: [PATCH 4/4] fix problem Signed-off-by: Huyuhao <610494558@qq.com> --- services/service/src/device_manager_service.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 5df8839aa..49ed6a713 100755 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -270,7 +270,6 @@ int32_t DeviceManagerService::GetTrustedDeviceList(const std::string &pkgName, c std::vector &deviceList) { LOGI("Begin for pkgName = %{public}s.", pkgName.c_str()); - (void)extra; if (pkgName.empty()) { LOGE("Invalid parameter, pkgName is empty."); return ERR_DM_INPUT_PARA_INVALID; -- Gitee