From dc25400569b3a38efe3244dc25a2d1c11aaa3cb3 Mon Sep 17 00:00:00 2001 From: wuliangdong Date: Thu, 14 Aug 2025 17:03:01 +0800 Subject: [PATCH 1/2] Fix CheckSameAccount For Adapting To New Inteface Supported By DM. Signed-off-by: wuliangdong Change-Id: Idef70fcb1b9a2945801fe0e1c893084109cde750 --- demo.diff | 1 + intention/adapters/ddm_adapter/src/ddm_adapter_impl.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 demo.diff diff --git a/demo.diff b/demo.diff new file mode 100644 index 000000000..086a03532 --- /dev/null +++ b/demo.diff @@ -0,0 +1 @@ +sss \ No newline at end of file diff --git a/intention/adapters/ddm_adapter/src/ddm_adapter_impl.cpp b/intention/adapters/ddm_adapter/src/ddm_adapter_impl.cpp index 51d4e068d..cc6f71aac 100644 --- a/intention/adapters/ddm_adapter/src/ddm_adapter_impl.cpp +++ b/intention/adapters/ddm_adapter/src/ddm_adapter_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at -- Gitee From 52358f6eace78747226334d746885a74312f6823 Mon Sep 17 00:00:00 2001 From: wuliangdong Date: Thu, 14 Aug 2025 09:08:46 +0000 Subject: [PATCH 2/2] Fix CheckSameAccount For Adapting To New Inteface Supported By DM. Signed-off-by: wuliangdong Change-Id: I6d069bda0a60475e0821603caeae4684ae1cf49c --- demo.diff | 1 - .../ddm_adapter/include/ddm_adapter.h | 5 + .../ddm_adapter/include/ddm_adapter_impl.h | 10 ++ .../adapters/ddm_adapter/src/ddm_adapter.cpp | 25 ++++ .../ddm_adapter/src/ddm_adapter_impl.cpp | 85 +++++++++++- .../plugin/include/cooperate_context.h | 5 + .../plugin/include/cooperate_events.h | 15 ++ .../cooperate/plugin/src/cooperate_free.cpp | 11 ++ .../cooperate/plugin/src/cooperate_in.cpp | 8 ++ .../cooperate/plugin/src/dsoftbus_handler.cpp | 58 +++++++- .../cooperate/plugin/src/state_machine.cpp | 131 +++++++++++------- intention/prototype/include/i_ddm_adapter.h | 5 + 12 files changed, 300 insertions(+), 59 deletions(-) delete mode 100644 demo.diff diff --git a/demo.diff b/demo.diff deleted file mode 100644 index 086a03532..000000000 --- a/demo.diff +++ /dev/null @@ -1 +0,0 @@ -sss \ No newline at end of file diff --git a/intention/adapters/ddm_adapter/include/ddm_adapter.h b/intention/adapters/ddm_adapter/include/ddm_adapter.h index 53e7cbdb8..5b2b1dc65 100644 --- a/intention/adapters/ddm_adapter/include/ddm_adapter.h +++ b/intention/adapters/ddm_adapter/include/ddm_adapter.h @@ -41,6 +41,11 @@ public: bool CheckSameAccountToLocal(const std::string &networkId) override; bool CheckSameAccountToLocalWithUid(const std::string &networkId, const int32_t uid = 0) override; + bool CheckSrcIsSameAccount(const std::string &networkId) override; + bool CheckSinkIsSameAccount(const std::string &networkId, + int32_t userId, const std::string &accountId) override; + int32_t GetUserId() override; + std::string GetAccountId() override; private: std::shared_ptr ddm_; diff --git a/intention/adapters/ddm_adapter/include/ddm_adapter_impl.h b/intention/adapters/ddm_adapter/include/ddm_adapter_impl.h index 49b00087d..e2277c524 100644 --- a/intention/adapters/ddm_adapter/include/ddm_adapter_impl.h +++ b/intention/adapters/ddm_adapter/include/ddm_adapter_impl.h @@ -41,6 +41,14 @@ public: bool CheckSameAccountToLocal(const std::string &networkId) override; bool CheckSameAccountToLocalWithUid(const std::string &networkId, const int32_t uid = 0) override; + bool CheckSrcIsSameAccount(const std::string &networkId) override; + bool CheckSinkIsSameAccount(const std::string &networkId, + int32_t userId, const std::string &accountId) override; + int32_t GetUserId() override; + std::string GetAccountId() override; + bool GetDmAccessCallerAndCallee(DistributedHardware::DmAccessCaller &caller, + DistributedHardware::DmAccessCallee &callee, + const std::string &networkId, const bool isSrc); private: int32_t GetTrustedDeviceList(std::vector &deviceList); @@ -113,6 +121,8 @@ private: std::shared_ptr initCb_; std::shared_ptr boardStateCb_; std::set observers_; + int32_t userId_ { -1 }; + std::string accountId_; }; } // namespace DeviceStatus } // namespace Msdp diff --git a/intention/adapters/ddm_adapter/src/ddm_adapter.cpp b/intention/adapters/ddm_adapter/src/ddm_adapter.cpp index a5136bd2c..5af8e7460 100644 --- a/intention/adapters/ddm_adapter/src/ddm_adapter.cpp +++ b/intention/adapters/ddm_adapter/src/ddm_adapter.cpp @@ -65,6 +65,31 @@ bool DDMAdapter::CheckSameAccountToLocalWithUid(const std::string &networkId, co CALL_DEBUG_ENTER; return ddm_->CheckSameAccountToLocalWithUid(networkId, uid); } + +bool DDMAdapter::CheckSrcIsSameAccount(const std::string &networkId) +{ + CALL_DEBUG_ENTER; + return ddm_->CheckSrcIsSameAccount(networkId); +} + +bool DDMAdapter::CheckSinkIsSameAccount(const std::string &networkId, + int32_t userId, const std::string &accountId) +{ + CALL_DEBUG_ENTER; + return ddm_->CheckSinkIsSameAccount(networkId, userId, accountId); +} + +int32_t DDMAdapter::GetUserId() +{ + CALL_DEBUG_ENTER; + return ddm_->GetUserId(); +} + +std::string DDMAdapter::GetAccountId() +{ + CALL_DEBUG_ENTER; + return ddm_->GetAccountId(); +} } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS diff --git a/intention/adapters/ddm_adapter/src/ddm_adapter_impl.cpp b/intention/adapters/ddm_adapter/src/ddm_adapter_impl.cpp index cc6f71aac..b1aae2d8d 100644 --- a/intention/adapters/ddm_adapter/src/ddm_adapter_impl.cpp +++ b/intention/adapters/ddm_adapter/src/ddm_adapter_impl.cpp @@ -124,9 +124,21 @@ int32_t DDMAdapterImpl::GetTrustedDeviceList(std::vector ids; ErrCode ret = OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids); if (ret != ERR_OK || ids.empty()) { @@ -139,23 +151,84 @@ bool DDMAdapterImpl::CheckSameAccountToLocal(const std::string &networkId) FI_HILOGE("Get accountId from Ohos account info fail, ret: %{public}d.", ret); return false; } - DistributedHardware::DmAccessCaller Caller = { + caller = { .accountId = osAccountInfo.uid_, .networkId = IDSoftbusAdapter::GetLocalNetworkId(), .userId = ids[0], .tokenId = IPCSkeleton::GetCallingTokenID(), }; - DistributedHardware::DmAccessCallee Callee = { + callee = { .networkId = networkId, .peerId = "", }; - if (D_DEV_MGR.CheckIsSameAccount(Caller, Callee)) { + if (isSink) { + callee.accountId = osAccountInfo.uid_; + callee.userId = ids[0]; + } + return true; +} + +bool DDMAdapterImpl::CheckSrcIsSameAccount(const std::string &networkId) +{ + CALL_INFO_TRACE; + DistributedHardware::DmAccessCaller caller; + DistributedHardware::DmAccessCallee callee; + bool isSink = false; + bool ret = GetDmAccessCallerAndCallee(caller, callee, networkId, isSink); + if (!ret) { + FI_HILOGI("check same account fail, will try check access Group by hichain"); + return false; + } + userId_ = caller.userId; + accountId_ = caller.accountId; + if (D_DEV_MGR.CheckSrcIsSameAccount(caller, callee)) { return true; } FI_HILOGI("check same account fail, will try check access Group by hichain"); return false; } +bool DDMAdapterImpl::CheckSinkIsSameAccount(const std::string &networkId, + int32_t userId, const std::string &accountId) +{ + CALL_INFO_TRACE; + DistributedHardware::DmAccessCaller caller; + DistributedHardware::DmAccessCallee callee; + bool isSink = true; + bool ret = GetDmAccessCallerAndCallee(caller, callee, networkId, isSink); + if (!ret) { + FI_HILOGI("check same account fail, will try check access Group by hichain"); + return false; + } + caller.networkId = networkId; + caller.accountId = accountId; + caller.userId = userId; + callee.networkId = IDSoftbusAdapter::GetLocalNetworkId(); + if (D_DEV_MGR.CheckSinkIsSameAccount(caller, callee)) { + return true; + } + FI_HILOGI("check same account fail, will try check access Group by hichain"); + return false; +} + +bool DDMAdapterImpl::CheckSameAccountToLocal(const std::string &networkId) +{ + CALL_INFO_TRACE; + DistributedHardware::DmAccessCaller caller; + DistributedHardware::DmAccessCallee callee; + bool isSink = false; + bool ret = GetDmAccessCallerAndCallee(caller, callee, networkId, isSink); + if (!ret) { + FI_HILOGI("check same account fail, will try check access Group by hichain"); + return false; + } + if (D_DEV_MGR.CheckIsSameAccount(caller, callee)) { + return true; + } + FI_HILOGI("check same account fail, will try check access Group by hichain"); + return false; +} + bool DDMAdapterImpl::CheckSameAccountToLocalWithUid(const std::string &networkId, const int32_t uid) { CALL_INFO_TRACE; @@ -189,7 +262,7 @@ bool DDMAdapterImpl::CheckSameAccountToLocalWithUid(const std::string &networkId FI_HILOGI("app userId is not Foreground"); return false; } - return CheckSameAccountToLocal(networkId); + return CheckSrcIsSameAccount(networkId); } void DDMAdapterImpl::OnBoardOnline(const std::string &networkId) diff --git a/intention/cooperate/plugin/include/cooperate_context.h b/intention/cooperate/plugin/include/cooperate_context.h index 2da3592b3..87b38c52f 100644 --- a/intention/cooperate/plugin/include/cooperate_context.h +++ b/intention/cooperate/plugin/include/cooperate_context.h @@ -110,6 +110,8 @@ public: void StorePeerTouchPadSpeed(int32_t speed); void ClearPeerTouchPadSpeed(); void StoreOriginTouchPadSpeed(); + void SetUserId(int32_t userId); + void SetAccountId(const std::string &accountId); #ifdef ENABLE_PERFORMANCE_CHECK void StartTrace(const std::string &name); @@ -124,6 +126,7 @@ public: InputEventBuilder inputEventBuilder_; InputEventInterceptor inputEventInterceptor_; CommonEventAdapter commonEvent_; + private: int32_t StartEventHandler(); @@ -153,6 +156,8 @@ private: int32_t peerTouchPadSpeed_ { -1 }; int32_t originTouchPadSpeed_ { -1 }; int32_t VirtualTrackpadDeviceId_ { -1 }; + int32_t userId_ { -1 }; + std::string accountId_; std::shared_ptr eventHandler_; std::shared_ptr boardObserver_; std::shared_ptr hotplugObserver_; diff --git a/intention/cooperate/plugin/include/cooperate_events.h b/intention/cooperate/plugin/include/cooperate_events.h index e1118dfa1..73f1ca828 100644 --- a/intention/cooperate/plugin/include/cooperate_events.h +++ b/intention/cooperate/plugin/include/cooperate_events.h @@ -112,6 +112,9 @@ struct StartCooperateEvent { int32_t startDeviceId; std::shared_ptr> errCode; int32_t uid { 0 }; + int32_t userId { -1 }; + std::string accountId; + bool needCheckSameAccount; }; struct EnableCooperateEvent { @@ -193,6 +196,9 @@ struct DSoftbusStartCooperate { int32_t pointerSpeed { -1 }; int32_t touchPadSpeed { -1 }; int32_t uid { 0 }; + int32_t userId { -1 }; + std::string accountId; + bool needCheckSameAccount; }; struct DSoftbusCooperateOptions { @@ -204,6 +210,9 @@ struct DSoftbusCooperateOptions { int32_t errCode { static_cast(CoordinationErrCode::COORDINATION_OK) }; int32_t pointerSpeed { -1 }; int32_t touchPadSpeed { -1 }; + int32_t userId { -1 }; + std::string accountId; + bool needCheckSameAccount; }; using DSoftbusStartCooperateFinished = DSoftbusStartCooperate; @@ -220,6 +229,9 @@ struct DSoftbusRelayCooperate { int32_t pointerSpeed { -1 }; int32_t touchPadSpeed { -1 }; int32_t uid { 0 }; + int32_t userId { -1 }; + std::string accountId; + bool needCheckSameAccount; }; struct DSoftbusSubscribeMouseLocation { @@ -292,6 +304,9 @@ struct StartWithOptionsEvent { int32_t displayY { -1 }; int32_t displayId { -1 }; std::shared_ptr> errCode; + int32_t userId { -1 }; + std::string accountId; + bool needCheckSameAccount; }; struct CooperateEvent { diff --git a/intention/cooperate/plugin/src/cooperate_free.cpp b/intention/cooperate/plugin/src/cooperate_free.cpp index 9005e493a..5c0408ebb 100644 --- a/intention/cooperate/plugin/src/cooperate_free.cpp +++ b/intention/cooperate/plugin/src/cooperate_free.cpp @@ -169,6 +169,7 @@ void CooperateFree::Initial::OnStart(Context &context, const CooperateEvent &eve context.eventMgr_.ErrorNotAollowCooperateWhenMotionDragging(result); return; } + bool needCheckSameAccount = !(parent_.env_->GetDSoftbus().HasSessionExisted(context.Peer())); int32_t ret = context.dsoftbus_.OpenSession(context.Peer()); if (ret != RET_OK) { CooperateFail(context, ret); @@ -188,6 +189,9 @@ void CooperateFree::Initial::OnStart(Context &context, const CooperateEvent &eve .pointerSpeed = context.GetPointerSpeed(), .touchPadSpeed = context.GetTouchPadSpeed(), .uid = notice.uid, + .userId = parent_.env_->GetDDM().GetUserId(), + .accountId = parent_.env_->GetDDM().GetAccountId(), + .needCheckSameAccount = needCheckSameAccount, }; context.OnStartCooperate(startNotice.extra); ret = context.dsoftbus_.StartCooperate(context.Peer(), startNotice); @@ -280,6 +284,7 @@ void CooperateFree::Initial::OnStartWithOptions(Context &context, const Cooperat context.eventMgr_.ErrorNotAollowCooperateWhenMotionDragging(result); return; } + bool needCheckSameAccount = !(parent_.env_->GetDSoftbus().HasSessionExisted(context.Peer())); int32_t ret = context.dsoftbus_.OpenSession(context.Peer()); if (ret != RET_OK) { FI_HILOGE("[start cooperation] Failed to connect\'%{public}s\'", Utility::Anonymize(context.Peer()).c_str()); @@ -297,7 +302,13 @@ void CooperateFree::Initial::OnStartWithOptions(Context &context, const Cooperat .cooperateOptions = {notice.displayX, notice.displayY, notice.displayId}, .pointerSpeed = context.GetPointerSpeed(), .touchPadSpeed = context.GetTouchPadSpeed(), + .userId = parent_.env_->GetDDM().GetUserId(), + .accountId = parent_.env_->GetDDM().GetAccountId(), + .needCheckSameAccount = needCheckSameAccount, }; + FI_HILOGI("sgd OnStartWithOptions userId:%{public}d", startNotice.userId); + FI_HILOGI("sgd OnStartWithOptions account:%{public}s", startNotice.accountId.c_str()); + FI_HILOGI("sgd OnStartWithOptions startEvent.needCheckSameAccount:%{public}s", (startNotice.needCheckSameAccount ? "true" : "false")); context.OnStartCooperate(startNotice.extra); context.dsoftbus_.StartCooperateWithOptions(context.Peer(), startNotice); context.inputEventInterceptor_.Enable(context); diff --git a/intention/cooperate/plugin/src/cooperate_in.cpp b/intention/cooperate/plugin/src/cooperate_in.cpp index a5a062946..b634c5382 100644 --- a/intention/cooperate/plugin/src/cooperate_in.cpp +++ b/intention/cooperate/plugin/src/cooperate_in.cpp @@ -775,6 +775,7 @@ void CooperateIn::RelayConfirmation::OnProgress(Context &context, const Cooperat { std::string remoteNetworkId = parent_.process_.Peer(); FI_HILOGI("[relay cooperate] Connect \'%{public}s\'", Utility::Anonymize(remoteNetworkId).c_str()); + bool needCheckSameAccount = !(parent_.env_->GetDSoftbus().HasSessionExisted(context.Peer())); int32_t ret = context.dsoftbus_.OpenSession(remoteNetworkId); if (ret != RET_OK) { FI_HILOGE("[relay cooperate] Failed to connect to \'%{public}s\'", Utility::Anonymize(remoteNetworkId).c_str()); @@ -788,6 +789,9 @@ void CooperateIn::RelayConfirmation::OnProgress(Context &context, const Cooperat .pointerSpeed = context.GetPointerSpeed(), .touchPadSpeed = context.GetTouchPadSpeed(), .uid = startEvent.uid, + .userId = parent_.env_->GetDDM().GetUserId(), + .accountId = parent_.env_->GetDDM().GetAccountId(), + .needCheckSameAccount = needCheckSameAccount, }; context.dsoftbus_.RelayCooperate(context.Peer(), notice); timerId_ = parent_.env_->GetTimerManager().AddTimer(DEFAULT_TIMEOUT, REPEAT_ONCE, @@ -808,6 +812,7 @@ void CooperateIn::RelayConfirmation::OnProgressWithOptions(Context &context, con { std::string remoteNetworkId = parent_.process_.Peer(); FI_HILOGI("[relay cooperate] Connect \'%{public}s\'", Utility::Anonymize(remoteNetworkId).c_str()); + bool needCheckSameAccount = !(parent_.env_->GetDSoftbus().HasSessionExisted(context.Peer())); int32_t ret = context.dsoftbus_.OpenSession(remoteNetworkId); if (ret != RET_OK) { FI_HILOGE("[relay cooperate] Failed to connect to \'%{public}s\'", Utility::Anonymize(remoteNetworkId).c_str()); @@ -820,6 +825,9 @@ void CooperateIn::RelayConfirmation::OnProgressWithOptions(Context &context, con .targetNetworkId = parent_.process_.Peer(), .pointerSpeed = context.GetPointerSpeed(), .touchPadSpeed = context.GetTouchPadSpeed(), + .userId = parent_.env_->GetDDM().GetUserId(), + .accountId = parent_.env_->GetDDM().GetAccountId(), + .needCheckSameAccount = needCheckSameAccount, }; context.dsoftbus_.RelayCooperateWithOptions(context.Peer(), notice); startWithOptionsEvent_ = std::get(event.event); diff --git a/intention/cooperate/plugin/src/dsoftbus_handler.cpp b/intention/cooperate/plugin/src/dsoftbus_handler.cpp index 04ddb83f0..876de3105 100644 --- a/intention/cooperate/plugin/src/dsoftbus_handler.cpp +++ b/intention/cooperate/plugin/src/dsoftbus_handler.cpp @@ -148,7 +148,7 @@ int32_t DSoftbusHandler::StartCooperate(const std::string &networkId, const DSof NetPacket packet(MessageId::DSOFTBUS_START_COOPERATE); packet << event.originNetworkId << event.cursorPos.x << event.cursorPos.y << event.success << event.extra.priv << event.pointerSpeed - << event.touchPadSpeed << event.uid; + << event.touchPadSpeed << event.uid << event.userId << event.accountId << event.needCheckSameAccount; if (packet.ChkRWError()) { FI_HILOGE("Failed to write data packet"); CooperateRadarInfo radarInfo { @@ -191,7 +191,7 @@ int32_t DSoftbusHandler::StartCooperateWithOptions(const std::string &networkId, NetPacket packet(MessageId::DSOFTBUS_COOPERATE_WITH_OPTIONS); packet << event.originNetworkId << event.cooperateOptions.displayX << event.cooperateOptions.displayY << event.cooperateOptions.displayId << event.success << event.extra.priv << event.pointerSpeed - << event.touchPadSpeed; + << event.touchPadSpeed << event.userId << event.accountId << event.needCheckSameAccount; if (packet.ChkRWError()) { FI_HILOGE("Failed to write data packet"); CooperateRadarInfo radarInfo { @@ -279,7 +279,8 @@ int32_t DSoftbusHandler::RelayCooperate(const std::string &networkId, const DSof CALL_INFO_TRACE; CHKPR(env_, RET_ERR); NetPacket packet(MessageId::DSOFTBUS_RELAY_COOPERATE); - packet << event.targetNetworkId << event.pointerSpeed << event.touchPadSpeed << event.uid; + packet << event.targetNetworkId << event.pointerSpeed << event.touchPadSpeed << event.uid << + event.userId << event.accountId << event.needCheckSameAccount; if (packet.ChkRWError()) { FI_HILOGE("Failed to write data packet"); return RET_ERR; @@ -313,7 +314,8 @@ int32_t DSoftbusHandler::RelayCooperateWithOptions(const std::string &networkId, CALL_INFO_TRACE; CHKPR(env_, RET_ERR); NetPacket packet(MessageId::DSOFTBUS_RELAY_COOPERATE_WITHOPTIONS); - packet << event.targetNetworkId << event.pointerSpeed << event.touchPadSpeed; + packet << event.targetNetworkId << event.pointerSpeed << event.touchPadSpeed << + event.userId << event.accountId << event.needCheckSameAccount; if (packet.ChkRWError()) { FI_HILOGE("Failed to write data packet"); return RET_ERR; @@ -452,6 +454,18 @@ void DSoftbusHandler::OnStartCooperate(const std::string &networkId, NetPacket & if (packet.ChkRWError()) { event.uid = 0; } + packet >> event.userId; + if (packet.ChkRWError()) { + event.userId = -1; + } + packet >> event.accountId; + if (packet.ChkRWError()) { + event.accountId = ""; + } + packet >> event.needCheckSameAccount; + if (packet.ChkRWError()) { + event.needCheckSameAccount = true; + } FI_HILOGI("Cur pointerSpeed:%{public}d, touchPadSpeed:%{public}d, uid:%{public}d", event.pointerSpeed, event.touchPadSpeed, event.uid); SendEvent(CooperateEvent( @@ -524,6 +538,18 @@ void DSoftbusHandler::OnStartCooperateWithOptions(const std::string &networkId, if (packet.ChkRWError()) { event.touchPadSpeed = -1; } + packet >> event.userId; + if (packet.ChkRWError()) { + event.userId = -1; + } + packet >> event.accountId; + if (packet.ChkRWError()) { + event.accountId = ""; + } + packet >> event.needCheckSameAccount; + if (packet.ChkRWError()) { + event.needCheckSameAccount = true; + } SendEvent(CooperateEvent( CooperateEventType::DSOFTBUS_COOPERATE_WITH_OPTIONS, event)); @@ -607,6 +633,18 @@ void DSoftbusHandler::OnRelayCooperate(const std::string &networkId, NetPacket & if (packet.ChkRWError()) { event.uid = 0; } + packet >> event.userId; + if (packet.ChkRWError()) { + event.userId = -1; + } + packet >> event.accountId; + if (packet.ChkRWError()) { + event.accountId = ""; + } + packet >> event.needCheckSameAccount; + if (packet.ChkRWError()) { + event.needCheckSameAccount = true; + } FI_HILOGI("Cur uid:%{public}d", event.uid); SendEvent(CooperateEvent( CooperateEventType::DSOFTBUS_RELAY_COOPERATE, @@ -655,6 +693,18 @@ void DSoftbusHandler::OnRelayCooperateWithOptions(const std::string &networkId, if (packet.ChkRWError()) { event.touchPadSpeed = -1; } + packet >> event.userId; + if (packet.ChkRWError()) { + event.userId = -1; + } + packet >> event.accountId; + if (packet.ChkRWError()) { + event.accountId = ""; + } + packet >> event.needCheckSameAccount; + if (packet.ChkRWError()) { + event.needCheckSameAccount = true; + } FI_HILOGI("Cur touchPadSpeed:%{public}d", event.touchPadSpeed); SendEvent(CooperateEvent( CooperateEventType::DSOFTBUS_RELAY_COOPERATE_WITHOPTIONS, diff --git a/intention/cooperate/plugin/src/state_machine.cpp b/intention/cooperate/plugin/src/state_machine.cpp index 41a29180e..ef8646e8c 100644 --- a/intention/cooperate/plugin/src/state_machine.cpp +++ b/intention/cooperate/plugin/src/state_machine.cpp @@ -329,27 +329,31 @@ void StateMachine::StartCooperate(Context &context, const CooperateEvent &event) CHKPV(env_); StartCooperateEvent startEvent = std::get(event.event); bool checkSameAccount = false; - if (startEvent.uid > 0) { - checkSameAccount = env_->GetDDM().CheckSameAccountToLocalWithUid(startEvent.remoteNetworkId, startEvent.uid); + if (!env_->GetDSoftbus().HasSessionExisted(startEvent.remoteNetworkId)) { + if (startEvent.uid > 0) { + checkSameAccount = env_->GetDDM().CheckSameAccountToLocalWithUid(startEvent.remoteNetworkId, startEvent.uid); + } else { + checkSameAccount = env_->GetDDM().CheckSrcIsSameAccount(startEvent.remoteNetworkId); + } + if (!checkSameAccount) { + FI_HILOGE("CheckSameAccountToLocal failed"); + startEvent.errCode->set_value(COMMON_PERMISSION_CHECK_ERROR); + CooperateRadarInfo radarInfo { + .funcName = __FUNCTION__, + .bizState = static_cast (BizState::STATE_END), + .bizStage = static_cast (BizCooperateStage::STAGE_CHECK_SAME_ACCOUNT), + .stageRes = static_cast (BizCooperateStageRes::RES_FAIL), + .bizScene = static_cast (BizCooperateScene::SCENE_ACTIVE), + .errCode = static_cast (CooperateRadarErrCode::CHECK_SAME_ACCOUNT_FAILED), + .hostName = "", + .localNetId = Utility::DFXRadarAnonymize(context.Local().c_str()), + .peerNetId = Utility::DFXRadarAnonymize(startEvent.remoteNetworkId.c_str()) + }; + CooperateRadar::ReportCooperateRadarInfo(radarInfo); + return; + } } else { - checkSameAccount = env_->GetDDM().CheckSameAccountToLocal(startEvent.remoteNetworkId); - } - if (!checkSameAccount) { - FI_HILOGE("CheckSameAccountToLocal failed"); - startEvent.errCode->set_value(COMMON_PERMISSION_CHECK_ERROR); - CooperateRadarInfo radarInfo { - .funcName = __FUNCTION__, - .bizState = static_cast (BizState::STATE_END), - .bizStage = static_cast (BizCooperateStage::STAGE_CHECK_SAME_ACCOUNT), - .stageRes = static_cast (BizCooperateStageRes::RES_FAIL), - .bizScene = static_cast (BizCooperateScene::SCENE_ACTIVE), - .errCode = static_cast (CooperateRadarErrCode::CHECK_SAME_ACCOUNT_FAILED), - .hostName = "", - .localNetId = Utility::DFXRadarAnonymize(context.Local().c_str()), - .peerNetId = Utility::DFXRadarAnonymize(startEvent.remoteNetworkId.c_str()) - }; - CooperateRadar::ReportCooperateRadarInfo(radarInfo); - return; + startEvent.needCheckSameAccount = false; } UpdateApplicationStateObserver(startEvent.pid); if (!context.IsAllowCooperate()) { @@ -387,22 +391,26 @@ void StateMachine::StartCooperateWithOptions(Context &context, const CooperateEv CALL_INFO_TRACE; CHKPV(env_); StartWithOptionsEvent withOptionsEvent = std::get(event.event); - if (!env_->GetDDM().CheckSameAccountToLocal(withOptionsEvent.remoteNetworkId)) { - FI_HILOGE("CheckSameAccountToLocal failed"); - withOptionsEvent.errCode->set_value(COMMON_PERMISSION_CHECK_ERROR); - CooperateRadarInfo radarInfo { - .funcName = __FUNCTION__, - .bizState = static_cast (BizState::STATE_END), - .bizStage = static_cast (BizCooperateStage::STAGE_CHECK_SAME_ACCOUNT), - .stageRes = static_cast (BizCooperateStageRes::RES_FAIL), - .bizScene = static_cast (BizCooperateScene::SCENE_ACTIVE), - .errCode = static_cast (CooperateRadarErrCode::CHECK_SAME_ACCOUNT_FAILED), - .hostName = "", - .localNetId = Utility::DFXRadarAnonymize(context.Local().c_str()), - .peerNetId = Utility::DFXRadarAnonymize(withOptionsEvent.remoteNetworkId.c_str()) - }; - CooperateRadar::ReportCooperateRadarInfo(radarInfo); - return; + FI_HILOGI("sgd StartCooperateWithOptions test"); + if (!env_->GetDSoftbus().HasSessionExisted(withOptionsEvent.remoteNetworkId)) { + FI_HILOGI("sgd StartCooperateWithOptions has session"); + if (!env_->GetDDM().CheckSrcIsSameAccount(withOptionsEvent.remoteNetworkId)) { + FI_HILOGE("CheckSrcIsSameAccount failed"); + withOptionsEvent.errCode->set_value(COMMON_PERMISSION_CHECK_ERROR); + CooperateRadarInfo radarInfo { + .funcName = __FUNCTION__, + .bizState = static_cast (BizState::STATE_END), + .bizStage = static_cast (BizCooperateStage::STAGE_CHECK_SAME_ACCOUNT), + .stageRes = static_cast (BizCooperateStageRes::RES_FAIL), + .bizScene = static_cast (BizCooperateScene::SCENE_ACTIVE), + .errCode = static_cast (CooperateRadarErrCode::CHECK_SAME_ACCOUNT_FAILED), + .hostName = "", + .localNetId = Utility::DFXRadarAnonymize(context.Local().c_str()), + .peerNetId = Utility::DFXRadarAnonymize(withOptionsEvent.remoteNetworkId.c_str()) + }; + CooperateRadar::ReportCooperateRadarInfo(radarInfo); + return; + } } UpdateApplicationStateObserver(withOptionsEvent.pid); if (!context.IsAllowCooperate()) { @@ -598,12 +606,23 @@ void StateMachine::OnRemoteStart(Context &context, const CooperateEvent &event) .localNetId = Utility::DFXRadarAnonymize(context.Local().c_str()), .peerNetId = Utility::DFXRadarAnonymize(startEvent.originNetworkId.c_str()) }; - bool checkSameAccount = env_->GetDDM().CheckSameAccountToLocal(startEvent.originNetworkId); - if (!checkSameAccount) { - radarInfo.bizStage = static_cast (BizCooperateStage::STAGE_PASSIVE_CHECK_SAME_ACCOUNT); - radarInfo.stageRes = static_cast (BizCooperateStageRes::RES_FAIL); - radarInfo.errCode = static_cast (CooperateRadarErrCode::PASSIVE_CHECK_SAME_ACCOUNT_FAILED); - CooperateRadar::ReportCooperateRadarInfo(radarInfo); + bool checkSameAccount = true; + if (startEvent.needCheckSameAccount) { + if (startEvent.userId == -1 || startEvent.accountId == "") { + FI_HILOGI("sgd OnRemoteStart old"); + checkSameAccount = env_->GetDDM().CheckSameAccountToLocal(startEvent.originNetworkId); + } else { + FI_HILOGI("sgd OnRemoteStart new, origin userid:%{public}d, origin accountId:%{public}s", + startEvent.userId, startEvent.accountId.c_str()); + checkSameAccount = env_->GetDDM().CheckSinkIsSameAccount(startEvent.originNetworkId, + startEvent.userId, startEvent.accountId); + } + if (!checkSameAccount) { + radarInfo.bizStage = static_cast (BizCooperateStage::STAGE_PASSIVE_CHECK_SAME_ACCOUNT); + radarInfo.stageRes = static_cast (BizCooperateStageRes::RES_FAIL); + radarInfo.errCode = static_cast (CooperateRadarErrCode::PASSIVE_CHECK_SAME_ACCOUNT_FAILED); + CooperateRadar::ReportCooperateRadarInfo(radarInfo); + } } if (!isCooperateEnable_) { radarInfo.bizStage = static_cast (BizCooperateStage::STAGE_CHECK_PEER_SWITCH); @@ -637,12 +656,28 @@ void StateMachine::OnRemoteStartWithOptions(Context &context, const CooperateEve .localNetId = Utility::DFXRadarAnonymize(context.Local().c_str()), .peerNetId = Utility::DFXRadarAnonymize(startEvent.originNetworkId.c_str()) }; - bool checkSameAccount = env_->GetDDM().CheckSameAccountToLocal(startEvent.originNetworkId); - if (!checkSameAccount) { - radarInfo.bizStage = static_cast (BizCooperateStage::STAGE_PASSIVE_CHECK_SAME_ACCOUNT); - radarInfo.stageRes = static_cast (BizCooperateStageRes::RES_FAIL); - radarInfo.errCode = static_cast (CooperateRadarErrCode::PASSIVE_CHECK_SAME_ACCOUNT_FAILED); - CooperateRadar::ReportCooperateRadarInfo(radarInfo); + bool checkSameAccount = true; + FI_HILOGI("sgd OnRemoteStartWithOptions test"); + FI_HILOGI("sgd OnRemoteStartWithOptions startEvent.needCheckSameAccount:%{public}s", (startEvent.needCheckSameAccount ? "true" : "false")); + FI_HILOGI("sgd OnRemoteStartWithOptions userId:%{public}d", startEvent.userId); + FI_HILOGI("sgd OnRemoteStartWithOptions accountId:%{public}s", startEvent.accountId.c_str()); + if (startEvent.needCheckSameAccount) { + if (startEvent.userId == -1 || startEvent.accountId == "") { + FI_HILOGI("sgd OnRemoteStartWithOptions old"); + checkSameAccount = env_->GetDDM().CheckSameAccountToLocal(startEvent.originNetworkId); + } else { + FI_HILOGI("sgd OnRemoteStartWithOptions new"); + FI_HILOGI("sgd OnRemoteStartWithOptions new, origin userid:%{public}d, origin accountId:%{public}s", + startEvent.userId, startEvent.accountId.c_str()); + checkSameAccount = env_->GetDDM().CheckSinkIsSameAccount(startEvent.originNetworkId, + startEvent.userId, startEvent.accountId); + } + if (!checkSameAccount) { + radarInfo.bizStage = static_cast (BizCooperateStage::STAGE_PASSIVE_CHECK_SAME_ACCOUNT); + radarInfo.stageRes = static_cast (BizCooperateStageRes::RES_FAIL); + radarInfo.errCode = static_cast (CooperateRadarErrCode::PASSIVE_CHECK_SAME_ACCOUNT_FAILED); + CooperateRadar::ReportCooperateRadarInfo(radarInfo); + } } if (!isCooperateEnable_) { radarInfo.bizStage = static_cast (BizCooperateStage::STAGE_CHECK_PEER_SWITCH); diff --git a/intention/prototype/include/i_ddm_adapter.h b/intention/prototype/include/i_ddm_adapter.h index ca2886142..2a2d8d483 100644 --- a/intention/prototype/include/i_ddm_adapter.h +++ b/intention/prototype/include/i_ddm_adapter.h @@ -43,6 +43,11 @@ public: virtual bool CheckSameAccountToLocal(const std::string &networkId) = 0; virtual bool CheckSameAccountToLocalWithUid(const std::string &networkId, const int32_t uid = 0) = 0; + virtual bool CheckSrcIsSameAccount(const std::string &networkId) = 0; + virtual bool CheckSinkIsSameAccount(const std::string &networkId, + int32_t userId, const std::string &accountId) = 0; + virtual int32_t GetUserId() = 0; + virtual std::string GetAccountId() = 0; }; } // namespace DeviceStatus } // namespace Msdp -- Gitee