diff --git a/commondependency/include/deviceprofile_connector.h b/commondependency/include/deviceprofile_connector.h index 3923a314d7a56f349674d0e3b69db2417a284201..d472c7350ec2714fdfb559da0051b598205a92b0 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 b43bd68c156e7ed2a60c59b7122a8066f3c343d6..14ae45173fc801d0e33768d8c9742e7a5039af05 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()) { @@ -3400,8 +3405,7 @@ DM_EXPORT bool DeviceProfileConnector::CheckSrcIsSameAccount(const DmAccessCalle std::string trustUdid = (localUdid == srcUdid ? sinkUdid : srcUdid); for (const auto &item : profiles) { PrintProfile(item); - if (item.GetTrustDeviceId() != trustUdid || item.GetStatus() != ACTIVE || - item.GetBindType() != DM_IDENTICAL_ACCOUNT) { + if (item.GetTrustDeviceId() != trustUdid || item.GetBindType() != DM_IDENTICAL_ACCOUNT) { continue; } if (CheckSrcAcuntAccessControl(item, caller, srcUdid, callee, sinkUdid)) { @@ -3425,8 +3429,7 @@ DM_EXPORT bool DeviceProfileConnector::CheckSinkIsSameAccount(const DmAccessCall std::string trustUdid = (localUdid == srcUdid ? sinkUdid : srcUdid); for (const auto &item : profiles) { PrintProfile(item); - if (item.GetTrustDeviceId() != trustUdid || item.GetStatus() != ACTIVE || - item.GetBindType() != DM_IDENTICAL_ACCOUNT) { + if (item.GetTrustDeviceId() != trustUdid || item.GetBindType() != DM_IDENTICAL_ACCOUNT) { continue; } if (CheckSinkAcuntAccessControl(item, caller, srcUdid, callee, sinkUdid)) { 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 c5fe661fd07e3a2911b82511e90ca0e0b9e0b6f8..84cfee2ba70df4b76d42734ad3c472fd63d6c273 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 853d616dc8d701543e683a78b91efb8a7c37764a..9c42db371bdc709009c9455d54892ed1c0221b98 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 200483586313cea6b5010e396a149f3d09c35f71..8b94f9c7e2dbeb6af0243d686772b6b3a367f04f 100644 --- a/services/implementation/src/authentication_v2/dm_auth_state.cpp +++ b/services/implementation/src/authentication_v2/dm_auth_state.cpp @@ -608,7 +608,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 && @@ -619,6 +619,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 c83110f9087e5e40848fbcb59353229749b04bd3..edd0ecda873228ea4535fb4a3fab9829d926a5af 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); } @@ -420,27 +427,9 @@ void DiscoveryManager::OnDeviceFound(const std::string &pkgName, const uint32_t break; } } - 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; - } - } + if (!isIndiscoveryContextMap || + filter.IsValidDevice(discoveryContext.filterOp, discoveryContext.filters, filterPara)) { 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 acc8499e74fc3f0e1a283b0c4a5e5c60f9b88311..6f0fc375ca1ebf29f85c71c3ca9c74357c1a5ff0 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; }