From 6df16377e799fb10348f870d2d9aea34d8bd1cac Mon Sep 17 00:00:00 2001 From: q30043944 Date: Tue, 12 Aug 2025 09:21:19 +0800 Subject: [PATCH] =?UTF-8?q?init=E6=97=B6=E5=BA=8F=E5=92=8Cstatus=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: q30043944 --- .../include/deviceprofile_connector.h | 1 + .../src/deviceprofile_connector.cpp | 9 +++- .../auth_stages/auth_confirm.cpp | 5 +++ .../auth_stages/auth_negotiate.cpp | 5 +++ .../src/authentication_v2/dm_auth_state.cpp | 6 ++- .../src/discovery/discovery_manager.cpp | 41 ++++++++----------- .../src/ipc/standard/ipc_server_stub.cpp | 2 +- 7 files changed, 41 insertions(+), 28 deletions(-) diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 3923a314d..d472c7350 100644 --- a/commondependency/include/deviceprofile_connector.h +++ b/commondependency/include/deviceprofile_connector.h @@ -165,6 +165,7 @@ public: DM_EXPORT int32_t PutAccessControlList(DmAclInfo aclInfo, DmAccesser dmAccesser, DmAccessee dmAccessee); int32_t UpdateAccessControlList(int32_t userId, std::string &oldAccountId, std::string &newAccountId); + void UpdateAccessControlList(const DistributedDeviceProfile::AccessControlProfile &profile); DM_EXPORT std::unordered_map GetAppTrustDeviceList( const std::string &pkgName, const std::string &deviceId); DM_EXPORT std::vector GetBindTypeByPkgName(std::string pkgName, diff --git a/commondependency/src/deviceprofile_connector.cpp b/commondependency/src/deviceprofile_connector.cpp index b43bd68c1..3e9fbffe5 100644 --- a/commondependency/src/deviceprofile_connector.cpp +++ b/commondependency/src/deviceprofile_connector.cpp @@ -1593,6 +1593,11 @@ void DeviceProfileConnector::DeleteServiceBindLevel(DmOfflineParam &offlineParam offlineParam.leftAclNumber = bindNums - deleteNums; } +void DeviceProfileConnector::UpdateAccessControlList(const DistributedDeviceProfile::AccessControlProfile &profile) +{ + DistributedDeviceProfileClient::GetInstance().UpdateAccessControlProfile(profile); +} + int32_t DeviceProfileConnector::UpdateAccessControlList(int32_t userId, std::string &oldAccountId, std::string &newAccountId) { @@ -3118,7 +3123,7 @@ DM_EXPORT bool DeviceProfileConnector::CheckSrcAccessControl(const DmAccessCalle std::string trustUdid = (localUdid == srcUdid ? sinkUdid : srcUdid); for (const auto &item : profiles) { PrintProfile(item); - if (item.GetTrustDeviceId() != trustUdid || item.GetStatus() != ACTIVE) { + if (item.GetTrustDeviceId() != trustUdid) { continue; } switch (item.GetBindType()) { @@ -3243,7 +3248,7 @@ DM_EXPORT bool DeviceProfileConnector::CheckSinkAccessControl(const DmAccessCall std::string trustUdid = (localUdid == srcUdid ? sinkUdid : srcUdid); for (const auto &item : profiles) { PrintProfile(item); - if (item.GetTrustDeviceId() != trustUdid || item.GetStatus() != ACTIVE) { + if (item.GetTrustDeviceId() != trustUdid) { continue; } switch (item.GetBindType()) { diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp index 28ed7e71f..bb02ed6b9 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_confirm.cpp @@ -330,6 +330,11 @@ void AuthSrcConfirmState::GetSrcAclInfo(std::shared_ptr context, bindLevel = item.GetBindLevel(); switch (item.GetBindType()) { case DM_IDENTICAL_ACCOUNT: + if (context->accessee.accountIdHash != context->accesser.accountIdHash || + context->accesser.accountId != item.GetAccesser().GetAccesserAccountId()) { + DeviceProfileConnector::GetInstance().DeleteAccessControlById(item.GetAccessControlId()); + break; + } if (IdenticalAccountAclCompare(context, item.GetAccesser(), item.GetAccessee())) { aclInfo["identicalAcl"] = DM_IDENTICAL_ACCOUNT; context->accesser.aclProfiles[DM_IDENTICAL_ACCOUNT] = item; diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_negotiate.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_negotiate.cpp index 853d616dc..9c42db371 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_negotiate.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_negotiate.cpp @@ -435,6 +435,11 @@ void AuthSinkNegotiateStateMachine::GetSinkAclInfo(std::shared_ptraccessee.accountIdHash != context->accesser.accountIdHash || + context->accessee.accountId != item.GetAccesser().GetAccesserAccountId()) { + DeviceProfileConnector::GetInstance().DeleteAccessControlById(item.GetAccessControlId()); + break; + } if (IdenticalAccountAclCompare(context, item.GetAccesser(), item.GetAccessee())) { aclInfo["identicalAcl"] = DM_IDENTICAL_ACCOUNT; context->accessee.aclProfiles[DM_IDENTICAL_ACCOUNT] = item; diff --git a/services/implementation/src/authentication_v2/dm_auth_state.cpp b/services/implementation/src/authentication_v2/dm_auth_state.cpp index c51087201..b3de1341c 100644 --- a/services/implementation/src/authentication_v2/dm_auth_state.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_state.cpp @@ -607,7 +607,7 @@ void DmAuthState::FilterProfilesByContext( { CHECK_NULL_VOID(context); std::vector aclProfilesVec; - for (const auto &item : profiles) { + for (auto &item : profiles) { std::string accesserDeviceIdHash = Crypto::GetUdidHash(item.GetAccesser().GetAccesserDeviceId()); std::string accesseeDeviceIdHash = Crypto::GetUdidHash(item.GetAccessee().GetAccesseeDeviceId()); if ((context->accesser.deviceIdHash == accesserDeviceIdHash && @@ -618,6 +618,10 @@ void DmAuthState::FilterProfilesByContext( context->accesser.deviceIdHash == accesseeDeviceIdHash && context->accessee.userId == item.GetAccesser().GetAccesserUserId() && context->accesser.userId == item.GetAccessee().GetAccesseeUserId())) { + if (item.GetStatus() == INACTIVE) { + item.SetStatus(ACTIVE); + DeviceProfileConnector::GetInstance().UpdateAccessControlList(item); + } aclProfilesVec.push_back(item); } } diff --git a/services/service/src/discovery/discovery_manager.cpp b/services/service/src/discovery/discovery_manager.cpp index c83110f90..dff269a69 100644 --- a/services/service/src/discovery/discovery_manager.cpp +++ b/services/service/src/discovery/discovery_manager.cpp @@ -368,6 +368,23 @@ int32_t DiscoveryManager::StopDiscoveringByInnerSubId(const std::string &pkgName void DiscoveryManager::OnDeviceFound(const std::string &pkgName, const DmDeviceInfo &info, bool isOnline) { + JsonObject jsonObject(info.extraData); + if (jsonObject.IsDiscarded()) { + LOGE("OnDeviceFound jsonStr error"); + return; + } + if (!IsUint32(jsonObject, PARAM_KEY_DISC_CAPABILITY)) { + LOGE("err json string: %{public}s", PARAM_KEY_DISC_CAPABILITY); + return; + } + uint32_t capabilityType = jsonObject[PARAM_KEY_DISC_CAPABILITY].Get(); + { + std::lock_guard capLock(capabilityMapLocks_); + if (capabilityMap_.find(pkgName) == capabilityMap_.end() || + !CompareCapability(capabilityType, capabilityMap_[pkgName])) { + return; + } + } int32_t userId = -1; std::string callerPkgName = ""; GetPkgNameAndUserId(pkgName, callerPkgName, userId); @@ -380,16 +397,6 @@ void DiscoveryManager::OnDeviceFound(const std::string &pkgName, const DmDeviceI filterPara.authForm) != DM_OK) { LOGE("The found device get online param failed."); } - JsonObject jsonObject(info.extraData); - if (jsonObject.IsDiscarded()) { - LOGE("OnDeviceFound jsonStr error"); - return; - } - if (!IsUint32(jsonObject, PARAM_KEY_DISC_CAPABILITY)) { - LOGE("err json string: %{public}s", PARAM_KEY_DISC_CAPABILITY); - return; - } - uint32_t capabilityType = jsonObject[PARAM_KEY_DISC_CAPABILITY].Get(); OnDeviceFound(pkgName, capabilityType, info, filterPara); } @@ -421,26 +428,12 @@ void DiscoveryManager::OnDeviceFound(const std::string &pkgName, const uint32_t } } if (!isIndiscoveryContextMap) { - { - std::lock_guard capLock(capabilityMapLocks_); - if (capabilityMap_.find(pkgName) == capabilityMap_.end() || - !CompareCapability(capabilityType, capabilityMap_[pkgName])) { - return; - } - } LOGD("OnDeviceFound, pkgName = %{public}s, cabability = %{public}d", pkgName.c_str(), capabilityType); listener_->OnDeviceFound(processInfo, externalSubId, info); return; } DiscoveryFilter filter; if (filter.IsValidDevice(discoveryContext.filterOp, discoveryContext.filters, filterPara)) { - { - std::lock_guard capLock(capabilityMapLocks_); - if (capabilityMap_.find(pkgName) == capabilityMap_.end() || - !CompareCapability(capabilityType, capabilityMap_[pkgName])) { - return; - } - } LOGD("OnDeviceFound, pkgName = %{public}s, cabability = %{public}d", pkgName.c_str(), capabilityType); listener_->OnDeviceFound(processInfo, externalSubId, info); } diff --git a/services/service/src/ipc/standard/ipc_server_stub.cpp b/services/service/src/ipc/standard/ipc_server_stub.cpp index acc8499e7..6f0fc375c 100644 --- a/services/service/src/ipc/standard/ipc_server_stub.cpp +++ b/services/service/src/ipc/standard/ipc_server_stub.cpp @@ -228,6 +228,7 @@ void IpcServerStub::OnRemoveSystemAbility(int32_t systemAbilityId, const std::st bool IpcServerStub::Init() { LOGI("IpcServerStub::Init ready to init."); + KVAdapterManager::GetInstance().Init(); DeviceManagerService::GetInstance().InitDMServiceListener(); if (!registerToService_) { bool ret = Publish(this); @@ -237,7 +238,6 @@ bool IpcServerStub::Init() return false; } registerToService_ = true; - KVAdapterManager::GetInstance().Init(); } return true; } -- Gitee