From c7bf002ad9f18b6f27dfaf76246baf02f001e0df Mon Sep 17 00:00:00 2001 From: WangYusen Date: Thu, 29 May 2025 20:04:49 +0800 Subject: [PATCH] p2p untrust invitation dialog Signed-off-by: WangYusen --- .../shared_util/wifi_notification_util.cpp | 5 ++ .../base/shared_util/wifi_notification_util.h | 3 +- wifi/bundle.json | 3 +- .../authorizing_negotiation_request_state.cpp | 3 + .../wifi_p2p/invitation_received_state.cpp | 3 + .../wifi_manage/wifi_p2p/ip2p_service.h | 5 +- .../wifi_manage/wifi_p2p/p2p_define.h | 1 + .../wifi_p2p/p2p_enabled_state.cpp | 20 +++++ .../wifi_manage/wifi_p2p/p2p_enabled_state.h | 12 ++- .../wifi_p2p/p2p_group_join_state.cpp | 3 + .../wifi_manage/wifi_p2p/p2p_interface.cpp | 4 +- .../wifi_manage/wifi_p2p/p2p_interface.h | 3 +- .../wifi_p2p/p2p_state_machine.cpp | 74 +++++++++++++++++++ .../wifi_manage/wifi_p2p/p2p_state_machine.h | 18 +++++ .../wifi_manage/wifi_p2p/wifi_p2p_service.cpp | 19 +++-- .../wifi_manage/wifi_p2p/wifi_p2p_service.h | 3 +- .../wifi_event_subscriber_manager.cpp | 15 ++-- .../unittest/wifi_mock_p2p_service.cpp | 2 +- .../unittest/wifi_mock_p2p_service.h | 2 +- .../wifi_p2p/test/Mock/mock_p2p_interface.cpp | 2 +- .../wifi_p2p/test/Mock/mock_p2p_interface.h | 2 +- .../wifi_p2p/test/p2p_state_machine_test.cpp | 28 +++++++ wifi/wifi.gni | 1 + 23 files changed, 205 insertions(+), 26 deletions(-) diff --git a/wifi/base/shared_util/wifi_notification_util.cpp b/wifi/base/shared_util/wifi_notification_util.cpp index 318d828ac..8c5c9a4fb 100644 --- a/wifi/base/shared_util/wifi_notification_util.cpp +++ b/wifi/base/shared_util/wifi_notification_util.cpp @@ -169,6 +169,11 @@ void WifiNotificationUtil::ShowDialog(WifiDialogType type, std::string comInfo) case CANDIDATE_CONNECT: param["targetSsid"] = comInfo; break; +#ifdef SUPPORT_P2P_UNTRUST_INVITATION + case P2P_UNTRUST_INVITE_DIALOG: + param["untrustDuration"] = comInfo; + break; +#endif default: { break; } diff --git a/wifi/base/shared_util/wifi_notification_util.h b/wifi/base/shared_util/wifi_notification_util.h index 2a0461912..76691bf3e 100644 --- a/wifi/base/shared_util/wifi_notification_util.h +++ b/wifi/base/shared_util/wifi_notification_util.h @@ -54,7 +54,8 @@ enum WifiDialogType { CANDIDATE_CONNECT = 2, AUTO_IDENTIFY_CONN = 3, P2P_WSC_PBC_DIALOG = 4, - SETTINGS_AUTO_IDENTIFY_CONN = 5 + SETTINGS_AUTO_IDENTIFY_CONN = 5, + P2P_UNTRUST_INVITE_DIALOG = 6, }; class WifiNotificationUtil { diff --git a/wifi/bundle.json b/wifi/bundle.json index 4dd441682..e0ac3dcd6 100644 --- a/wifi/bundle.json +++ b/wifi/bundle.json @@ -72,7 +72,8 @@ "wifi_feature_with_wifi_oeminfo_mac", "wifi_feature_voicewifi_enable", "wifi_feature_mdm_restricted_enable", - "wifi_feature_with_scan_control_action_listen" + "wifi_feature_with_scan_control_action_listen", + "wifi_feature_with_p2p_untrust_invitation" ], "adapted_system_type": [ "small", diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/authorizing_negotiation_request_state.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/authorizing_negotiation_request_state.cpp index 0ad326287..8bab97b94 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/authorizing_negotiation_request_state.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/authorizing_negotiation_request_state.cpp @@ -54,6 +54,9 @@ bool AuthorizingNegotiationRequestState::ExecuteStateMsg(InternalMessagePtr msg) } case P2P_STATE_MACHINE_CMD::INTERNAL_CONN_USER_TIME_OUT: case P2P_STATE_MACHINE_CMD::PEER_CONNECTION_USER_REJECT: { +#ifdef SUPPORT_P2P_UNTRUST_INVITATION + p2pStateMachine.DealP2pPeerConnectUserReject(); +#endif HandleUserRejectOrTimeOut(); break; } diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/invitation_received_state.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/invitation_received_state.cpp index d449cc633..4d087e8b0 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/invitation_received_state.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/invitation_received_state.cpp @@ -76,6 +76,9 @@ bool InvitationReceivedState::ExecuteStateMsg(InternalMessagePtr msg) case P2P_STATE_MACHINE_CMD::INTERNAL_CONN_USER_TIME_OUT: case P2P_STATE_MACHINE_CMD::PEER_CONNECTION_USER_REJECT: { WIFI_LOGI("User rejected invitation"); +#ifdef SUPPORT_P2P_UNTRUST_INVITATION + p2pStateMachine.DealP2pPeerConnectUserReject(); +#endif p2pStateMachine.SwitchState(&p2pStateMachine.p2pIdleState); break; } diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/ip2p_service.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/ip2p_service.h index 7b2484fd5..980bedf18 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/ip2p_service.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/ip2p_service.h @@ -353,10 +353,11 @@ public: /** * @Description Notify user accept result to p2p service * - * @param isAccept if user accept to projection screen + * @param isAccept if user accept the dialog + * @param dialogType dialog type * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED */ - virtual void NotifyWscDialogConfirmResult(bool isAccept) = 0; + virtual void NotifyP2pDialogConfirmResult(bool isAccept, int dialogType) = 0; /** * @Description Set miracast sink config diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_define.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_define.h index 0620c6f44..197605067 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_define.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_define.h @@ -163,6 +163,7 @@ enum class P2P_STATE_MACHINE_CMD { DISABLE_P2P_TIMED_OUT, REMOVE_SERVICE_REQUEST_RECORD, P2P_CONNECT_FAILED, + UNTRUST_INVITATION_RESULT, }; enum class DHCPTYPE { diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_enabled_state.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_enabled_state.cpp index 2bfb84836..1a601457d 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_enabled_state.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_enabled_state.cpp @@ -66,6 +66,9 @@ void P2pEnabledState::GoInState() void P2pEnabledState::GoOutState() { WIFI_LOGI(" GoOutState"); +#ifdef SUPPORT_P2P_UNTRUST_INVITATION + p2pStateMachine.AllowUntrustInvitation(); +#endif } void P2pEnabledState::Init() @@ -129,6 +132,10 @@ void P2pEnabledState::InitProcessMsg() [this](InternalMessagePtr msg) { return this->ProcessChrReport(msg); })); mProcessFunMap.insert(std::make_pair(P2P_STATE_MACHINE_CMD::CMD_SET_MIRACAST_SINK_CONFIG, [this](InternalMessagePtr msg) { return this->ProcessSetMiracastSinkConfig(msg); })); +#ifdef SUPPORT_P2P_UNTRUST_INVITATION + mProcessFunMap.insert(std::make_pair(P2P_STATE_MACHINE_CMD::UNTRUST_INVITATION_RESULT, + [this](InternalMessagePtr msg) { return this->ProcessUntrustInvitationDialogResult(msg); })); +#endif } bool P2pEnabledState::ProcessCmdDisable(InternalMessagePtr msg) const @@ -712,5 +719,18 @@ bool P2pEnabledState::ProcessSetMiracastSinkConfig(InternalMessagePtr msg) const WifiP2PHalInterface::GetInstance().SetMiracastSinkConfig(config); return EXECUTED; } + +#ifdef SUPPORT_P2P_UNTRUST_INVITATION +bool P2pEnabledState::ProcessUntrustInvitationDialogResult(InternalMessagePtr msg) const +{ + int accept = msg->GetParam1(); + if (accept) { + p2pStateMachine.DisallowUntrustInvitation(); + } else { + p2pStateMachine.AllowUntrustInvitation(); + } + return EXECUTED; +} +#endif } // namespace Wifi } // namespace OHOS diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_enabled_state.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_enabled_state.h index 0b83deb9d..c8a19bc02 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_enabled_state.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_enabled_state.h @@ -281,10 +281,20 @@ private: /** * @Description Set miracast sink config * - * @param config - miracast config + * @param msg - Message body sent by the state machine * @return - bool true:handle false:not handle */ virtual bool ProcessSetMiracastSinkConfig(InternalMessagePtr msg) const; + +#ifdef SUPPORT_P2P_UNTRUST_INVITATION + /** + * @Description Process user select result of untrust invitation dialog result + * + * @param msg - Message body sent by the state machine + * @return - bool true:handle false:not handle + */ + virtual bool ProcessUntrustInvitationDialogResult(InternalMessagePtr msg) const; +#endif private: void P2pConfigInitExt(bool &result); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_group_join_state.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_group_join_state.cpp index 53606b0ce..61f10d0f2 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_group_join_state.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_group_join_state.cpp @@ -65,6 +65,9 @@ bool P2pGroupJoinState::ExecuteStateMsg(InternalMessagePtr msg) } case P2P_STATE_MACHINE_CMD::PEER_CONNECTION_USER_REJECT: { WIFI_LOGI("User(GO) rejected to join the group."); +#ifdef SUPPORT_P2P_UNTRUST_INVITATION + p2pStateMachine.DealP2pPeerConnectUserReject(); +#endif p2pStateMachine.SwitchState(&p2pStateMachine.p2pGroupFormedState); break; } diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_interface.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_interface.cpp index e8845c6c8..bea271d4c 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_interface.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_interface.cpp @@ -283,9 +283,9 @@ ErrCode P2pInterface::SetEnhanceService(IEnhanceService* enhanceService) return p2pService.SetEnhanceService(enhanceService); } -void P2pInterface::NotifyWscDialogConfirmResult(bool isAccept) +void P2pInterface::NotifyP2pDialogConfirmResult(bool isAccept, int dialogType) { - return p2pService.NotifyWscDialogConfirmResult(isAccept); + return p2pService.NotifyP2pDialogConfirmResult(isAccept, dialogType); } ErrCode P2pInterface::SetMiracastSinkConfig(const std::string& config) diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_interface.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_interface.h index 7f932e09b..e223795e0 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_interface.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_interface.h @@ -366,9 +366,10 @@ public: * @Description Notify user accept result to p2p service * * @param isAccept if user accept to projection screen + * @param dialogType dialog type * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED */ - void NotifyWscDialogConfirmResult(bool isAccept) override; + void NotifyP2pDialogConfirmResult(bool isAccept, int dialogType) override; /** * @Description Set miracast sink config diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_state_machine.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_state_machine.cpp index d3bb0ca9d..5656b8412 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_state_machine.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_state_machine.cpp @@ -55,6 +55,12 @@ const int ARP_TIMEOUT = 100; const int DEFAULT_TEMP_ID = -100; const std::string CARRY_DATA_MIRACAST = "1"; const std::vector FILTERED_FREQS = {2412, 2437, 2462}; +#ifdef SUPPORT_P2P_UNTRUST_INVITATION +const int P2P_REJECT_MAX_COUNT = 3; +const int P2P_REJECT_MAX_COUNT_LIMITED_TIME = 3 * 60 * 1000; +const int P2P_REJECT_FIRST_TIME = 1; +const int ONE_MINITE_UNIT = 60 * 1000; +#endif std::mutex P2pStateMachine::m_gcJoinmutex; DHCPTYPE P2pStateMachine::m_isNeedDhcp = DHCPTYPE::DHCP_P2P; @@ -750,7 +756,24 @@ void P2pStateMachine::NotifyUserProvDiscShowPinRequestMessage(const std::string void P2pStateMachine::NotifyUserInvitationReceivedMessage() { +#ifdef SUPPORT_P2P_UNTRUST_INVITATION + int64_t intervalTime = GetCurrentTimeMilliSeconds() - disallowUntrustInvitationTime_; + WIFI_LOGI("%{public}s, userDisallowUntrustInvitation:%{public}d, intervalTime:%{public}" PRId64"", + __func__, userDisallowUntrustInvitation_, intervalTime); + if (userDisallowUntrustInvitation_ && (intervalTime >= DISALLOW_UNTRUST_INVITE_DURATION || + intervalTime < 0)) { + p2pRejectCount_ = 0; + userDisallowUntrustInvitation_ = false; + disallowUntrustInvitationTime_ = 0; + } + if (p2pRejectCount_ >= P2P_REJECT_MAX_COUNT) { + WIFI_LOGI("p2pRejectCount=%{public}d, don't show dialog", p2pRejectCount_); + SendMessage(static_cast(P2P_STATE_MACHINE_CMD::CMD_CANCEL_CONNECT)); + return; + } +#else WIFI_LOGI("P2pStateMachine::NotifyUserInvitationReceivedMessage enter"); +#endif if (GetDeviceType() == ProductDeviceType::TV) { #ifndef OHOS_ARCH_LITE WakeUpScreenSaver(); @@ -1412,5 +1435,56 @@ void P2pStateMachine::WakeUpScreenSaver() WIFI_LOGI("Wake up screen saver success"); } #endif + +#ifdef SUPPORT_P2P_UNTRUST_INVITATION +void P2pStateMachine::DealP2pPeerConnectUserReject() +{ + p2pRejectCount_++; + WIFI_LOGI("p2pRejectCount=%{public}d", p2pRejectCount_); + // record the first time of p2p rejection + if (p2pRejectCount_ == P2P_REJECT_FIRST_TIME) { + p2pRejectFirstTime_ = GetCurrentTimeMilliSeconds(); + WIFI_LOGI("p2pRejectFirstTime=%{public}" PRId64"", p2pRejectFirstTime_); + } else { + WIFI_LOGI("curTime-p2pRejectFirstTime=%{public}" PRId64"", + (GetCurrentTimeMilliSeconds() - p2pRejectFirstTime_)); + } + + // continuously reject 3 times in 3 minutes, pop up the p2p up the untrust invitation dialog + if (p2pRejectCount_ >= P2P_REJECT_MAX_COUNT) { + if ((GetCurrentTimeMilliSeconds() - p2pRejectFirstTime_) < P2P_REJECT_MAX_COUNT_LIMITED_TIME) { + PopupP2pUntrustInvitationDialog(); + } else { + p2pRejectFirstTime_ = GetCurrentTimeMilliSeconds(); + p2pRejectCount_ = P2P_REJECT_FIRST_TIME; + WIFI_LOGI("set p2pRejectCount as first time and reset p2pRejectFirstTime=%{public}" PRId64"", + p2pRejectFirstTime_); + } + } +} + +void P2pStateMachine::AllowUntrustInvitation() +{ + WIFI_LOGI("Enter AllowUntrustInvitation"); + p2pRejectCount_ = 0; +} + +void P2pStateMachine::DisallowUntrustInvitation() +{ + WIFI_LOGI("Enter DisallowUntrustInvitation"); + userDisallowUntrustInvitation_ = true; + disallowUntrustInvitationTime_ = GetCurrentTimeMilliSeconds(); +} + +void P2pStateMachine::PopupP2pUntrustInvitationDialog() +{ + WIFI_LOGI("Enter PopupP2pUntrustInvitationDialog"); +#ifndef OHOS_ARCH_LITE + WakeUpScreenSaver(); +#endif + WifiNotificationUtil::GetInstance().ShowDialog(WifiDialogType::P2P_UNTRUST_INVITE_DIALOG, + std::to_string(DISALLOW_UNTRUST_INVITE_DURATION / ONE_MINITE_UNIT)); +} +#endif } // namespace Wifi } // namespace OHOS diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_state_machine.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_state_machine.h index 063237b77..0e42db765 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_state_machine.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_state_machine.h @@ -50,6 +50,9 @@ inline const int MAX_GROUP_NAME_LENGTH = 32; inline const int MAX_CLIENT_SIZE = 16; inline const int DISC_TIMEOUT_S = 120; inline const int WSC_DIALOG_SELECT_TIMEOUT = 30000; +#ifdef SUPPORT_P2P_UNTRUST_INVITATION +inline const int DISALLOW_UNTRUST_INVITE_DURATION = 10 * 60 * 1000; +#endif enum { P2P_GC, P2P_GO, @@ -139,7 +142,13 @@ public: bool GetConnectedStationInfo(std::map &result); void SetEnhanceService(IEnhanceService* enhanceService); +#ifdef SUPPORT_P2P_UNTRUST_INVITATION + void DealP2pPeerConnectUserReject(); + + void AllowUntrustInvitation(); + void DisallowUntrustInvitation(); +#endif private: /** * @Description Handle event of CMD_DEVICE_DISCOVERS @@ -440,6 +449,9 @@ private: void DoP2pArp(std::string serverIp, std::string clientIp); bool ReinvokeGroup(WifiP2pConfigInternal &config, int networkId, const WifiP2pDevice &device) const; void SetClientInfo(HalP2pGroupConfig &wpaConfig, WifiP2pGroupInfo &grpBuf) const; +#ifdef SUPPORT_P2P_UNTRUST_INVITATION + void PopupP2pUntrustInvitationDialog(); +#endif private: mutable std::mutex cbMapMutex; @@ -474,6 +486,12 @@ private: static DHCPTYPE m_isNeedDhcp; std::string p2pDevIface; static std::mutex m_gcJoinmutex; +#ifdef SUPPORT_P2P_UNTRUST_INVITATION + int64_t p2pRejectFirstTime_ = 0; + int p2pRejectCount_ = 0; + int64_t disallowUntrustInvitationTime_ = 0; + bool userDisallowUntrustInvitation_ = false; +#endif public: std::vector curClientList; diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/wifi_p2p_service.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/wifi_p2p_service.cpp index 82a1dacca..372d43f2e 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/wifi_p2p_service.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/wifi_p2p_service.cpp @@ -24,6 +24,7 @@ #include "wifi_config_center.h" #include "wifi_country_code_manager.h" #include "wifi_p2p_hal_interface.h" +#include "wifi_notification_util.h" #include "ap_define.h" DEFINE_WIFILOG_P2P_LABEL("WifiP2pService"); @@ -513,13 +514,19 @@ ErrCode WifiP2pService::SetGcIpAddress(const IpAddrInfo& ipInfo) return WIFI_OPT_SUCCESS; } -void WifiP2pService::NotifyWscDialogConfirmResult(bool isAccept) +void WifiP2pService::NotifyP2pDialogConfirmResult(bool isAccept, int dialogType) { - WIFI_LOGI("Notify user auth response:%{public}d", isAccept); - if (isAccept) { - p2pStateMachine.SendMessage(static_cast(P2P_STATE_MACHINE_CMD::INTERNAL_CONN_USER_ACCEPT)); - } else { - p2pStateMachine.SendMessage(static_cast(P2P_STATE_MACHINE_CMD::PEER_CONNECTION_USER_REJECT)); + WIFI_LOGI("Notify p2p dialog confirm result:%{public}d, dialogType:%{public}d", isAccept, dialogType); + if (dialogType == static_cast(WifiDialogType::P2P_WSC_PBC_DIALOG)) { + if (isAccept) { + p2pStateMachine.SendMessage(static_cast(P2P_STATE_MACHINE_CMD::INTERNAL_CONN_USER_ACCEPT)); + } else { + p2pStateMachine.SendMessage(static_cast(P2P_STATE_MACHINE_CMD::PEER_CONNECTION_USER_REJECT)); + } +#ifdef SUPPORT_P2P_UNTRUST_INVITATION + } else if (dialogType == static_cast(WifiDialogType::P2P_UNTRUST_INVITE_DIALOG)) { + p2pStateMachine.SendMessage(static_cast(P2P_STATE_MACHINE_CMD::UNTRUST_INVITATION_RESULT), isAccept); +#endif } } diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/wifi_p2p_service.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/wifi_p2p_service.h index 62a5fe078..cb3e24774 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/wifi_p2p_service.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/wifi_p2p_service.h @@ -336,9 +336,10 @@ public: * @Description Notify user accept result to p2p service * * @param isAccept if user accept to projection screen + * @param dialogType dialog type * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED */ - void NotifyWscDialogConfirmResult(bool isAccept) override; + void NotifyP2pDialogConfirmResult(bool isAccept, int dialogType) override; /** * @Description Set miracast sink config diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp index 44cc84c12..da8299ba9 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage/wifi_event_subscriber_manager.cpp @@ -879,12 +879,12 @@ void NotificationEventSubscriber::OnReceiveDialogAcceptEvent(int dialogType) } } #ifdef FEATURE_P2P_SUPPORT - if (dialogType == static_cast(WifiDialogType::P2P_WSC_PBC_DIALOG)) { - WIFI_LOGI("OnReceiveNotification P2P_WSC_PBC_DIALOG Accept"); - + if (dialogType == static_cast(WifiDialogType::P2P_WSC_PBC_DIALOG) || + dialogType == static_cast(WifiDialogType::P2P_UNTRUST_INVITE_DIALOG)) { + WIFI_LOGI("OnReceiveNotification p2p dialog reject"); IP2pService *p2pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); if (p2pService != nullptr) { - p2pService->NotifyWscDialogConfirmResult(true); + p2pService->NotifyP2pDialogConfirmResult(true, dialogType); } } #endif @@ -912,11 +912,12 @@ void NotificationEventSubscriber::OnReceiveDialogRejectEvent(int dialogType, boo } #ifdef FEATURE_P2P_SUPPORT - if (dialogType == static_cast(WifiDialogType::P2P_WSC_PBC_DIALOG)) { - WIFI_LOGI("OnReceiveNotification P2P_WSC_PBC_DIALOG Reject"); + if (dialogType == static_cast(WifiDialogType::P2P_WSC_PBC_DIALOG) || + dialogType == static_cast(WifiDialogType::P2P_UNTRUST_INVITE_DIALOG)) { + WIFI_LOGI("OnReceiveNotification p2p dialog reject"); IP2pService *p2pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); if (p2pService != nullptr) { - p2pService->NotifyWscDialogConfirmResult(false); + p2pService->NotifyP2pDialogConfirmResult(false, dialogType); } } #endif diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/unittest/wifi_mock_p2p_service.cpp b/wifi/test/wifi_standard/wifi_framework/wifi_manage/unittest/wifi_mock_p2p_service.cpp index c9d71250b..52ba7c29f 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/unittest/wifi_mock_p2p_service.cpp +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/unittest/wifi_mock_p2p_service.cpp @@ -431,7 +431,7 @@ ErrCode WifiMockP2pService::GetRptStationsList(std::vector &result) return WIFI_OPT_SUCCESS; } -void WifiMockP2pService::NotifyWscDialogConfirmResult(bool isAccept) +void WifiMockP2pService::NotifyP2pDialogConfirmResult(bool isAccept, int dialogType) { return; } diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/unittest/wifi_mock_p2p_service.h b/wifi/test/wifi_standard/wifi_framework/wifi_manage/unittest/wifi_mock_p2p_service.h index f03716b89..7075d8352 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/unittest/wifi_mock_p2p_service.h +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/unittest/wifi_mock_p2p_service.h @@ -53,7 +53,7 @@ public: ErrCode RegisterP2pServiceCallbacks(const IP2pServiceCallbacks &callbacks); ErrCode CreateRptGroup(const WifiP2pConfig &config); ErrCode GetRptStationsList(std::vector &result); - void NotifyWscDialogConfirmResult(bool isAccept); + void NotifyP2pDialogConfirmResult(bool isAccept, int dialogType); ErrCode SetMiracastSinkConfig(const std::string& config); public: diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/test/Mock/mock_p2p_interface.cpp b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/test/Mock/mock_p2p_interface.cpp index 4d35247e7..ba76431a4 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/test/Mock/mock_p2p_interface.cpp +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/test/Mock/mock_p2p_interface.cpp @@ -233,7 +233,7 @@ ErrCode P2pInterface::GetRptStationsList(std::vector &result) return WIFI_OPT_SUCCESS; } -void P2pInterface::NotifyWscDialogConfirmResult(bool isAccept) +void P2pInterface::NotifyP2pDialogConfirmResult(bool isAccept, int dialogType) { return; } diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/test/Mock/mock_p2p_interface.h b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/test/Mock/mock_p2p_interface.h index ec19c6b1a..8393b6b5e 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/test/Mock/mock_p2p_interface.h +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/test/Mock/mock_p2p_interface.h @@ -67,7 +67,7 @@ public: virtual ErrCode DisableRandomMac(int setmode); virtual ErrCode CreateRptGroup(const WifiP2pConfig &config); virtual ErrCode GetRptStationsList(std::vector &result); - virtual void NotifyWscDialogConfirmResult(bool isAccept); + virtual void NotifyP2pDialogConfirmResult(bool isAccept, int dialogType); virtual ErrCode SetMiracastSinkConfig(const std::string& config); }; } // namespace Wifi diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/test/p2p_state_machine_test.cpp b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/test/p2p_state_machine_test.cpp index 18738cd82..7640c486c 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/test/p2p_state_machine_test.cpp +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/test/p2p_state_machine_test.cpp @@ -395,6 +395,22 @@ public: { pP2pStateMachine->WakeUpScreenSaver(); } +#ifdef SUPPORT_P2P_UNTRUST_INVITATION + void WarpDealP2pPeerConnectUserReject() + { + pP2pStateMachine->DisallowUntrustInvitation(); + pP2pStateMachine->AllowUntrustInvitation(); + pP2pStateMachine->DealP2pPeerConnectUserReject(); + pP2pStateMachine->DealP2pPeerConnectUserReject(); + pP2pStateMachine->DealP2pPeerConnectUserReject(); + pP2pStateMachine->p2pRejectFirstTime_ = 0; + pP2pStateMachine->DealP2pPeerConnectUserReject(); + } + void WarpP2pUntrustInvitationDialog() + { + pP2pStateMachine->PopupP2pUntrustInvitationDialog(); + } +#endif }; void ButtonTest(AlertDialog &dialog, std::any ctx) @@ -935,5 +951,17 @@ HWTEST_F(P2pStateMachineTest, WakeUpScreenSaverTest, TestSize.Level1) WarpWakeUpScreenSaver(); EXPECT_FALSE(g_errLog.find("P2pStateMachine") != std::string::npos); } + +HWTEST_F(P2pStateMachineTest, P2pPeerConnectUserRejectTest, TestSize.Level1) +{ + WarpDealP2pPeerConnectUserReject(); + EXPECT_FALSE(g_errLog.find("P2pStateMachine") != std::string::npos); +} + +HWTEST_F(P2pStateMachineTest, P2pUntrustInvitationDialogTest, TestSize.Level1) +{ + WarpP2pUntrustInvitationDialog(); + EXPECT_FALSE(g_errLog.find("P2pStateMachine") != std::string::npos); +} } // namespace Wifi } // namespace OHOS \ No newline at end of file diff --git a/wifi/wifi.gni b/wifi/wifi.gni index a65ed624c..f0a8e477a 100644 --- a/wifi/wifi.gni +++ b/wifi/wifi.gni @@ -60,6 +60,7 @@ declare_args() { wifi_feature_with_wifi_oeminfo_mac = false wifi_feature_mdm_restricted_enable = true wifi_feature_with_scan_control_action_listen = true + wifi_feature_with_p2p_untrust_invitation = false } memory_optimization_cflags = [ -- Gitee