diff --git a/wifi/base/BUILD.gn b/wifi/base/BUILD.gn index 11394351255f7e30fb7ef51e85ed2b29d142d6e1..7b3387d9cec38b96ddcd39cc2d282a45e71aa1d4 100644 --- a/wifi/base/BUILD.gn +++ b/wifi/base/BUILD.gn @@ -136,6 +136,9 @@ if (defined(ohos_lite)) { defined(global_parts_info.powermgr_battery_manager)) { external_deps += [ "battery_manager:batterysrv_client" ] defines += [ "HAS_BATTERY_MANAGER_PART" ] + } + if (wifi_feature_with_p2p_untrust_invitation) { + defines += [ "SUPPORT_P2P_UNTRUST_INVITATION" ] } cflags = memory_optimization_cflags cflags_cc = memory_optimization_cflags_cc diff --git a/wifi/base/shared_util/wifi_notification_util.cpp b/wifi/base/shared_util/wifi_notification_util.cpp index 318d828ac62f9f3731e7b75112377c999160bc3c..8c5c9a4fb053d2fbd9cfd31bae0b74d4421b470b 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 2a04619124131338dcb76ffda3cbb8d0e5022b45..76691bf3e3e1973b95215aee927af86b8350dc7d 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 26c1d70adbbfb9bd31505df904c9d53ae6a17d1f..5ee56798c15c1841262b829362d3e533b8bdead5 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/BUILD.gn b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/BUILD.gn index 4999f195c4571f28303acb9e15446e57e4055b1e..825db60898d368b11c688564f3be8a2116ff545a 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/BUILD.gn +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/BUILD.gn @@ -121,6 +121,10 @@ ohos_shared_library("wifi_p2p_service") { defines += [ "SUPPORT_LOCAL_RANDOM_MAC" ] } + if (wifi_feature_with_p2p_untrust_invitation) { + defines += [ "SUPPORT_P2P_UNTRUST_INVITATION" ] + } + external_deps = [ "ability_base:base", "ability_base:want", 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 0ad3262875d4f88cf1e0a748d57f4ce4d059c17f..8bab97b9421d56817b1f77d010c6fa3a2a242acf 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 d449cc6337adfbfcaa5ad34bfddd7ae76154c5dd..4d087e8b02fabd551c282ef7bb9b18ff3463db05 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 7b2484fd5b4d6204d8e45f4d66e262ce2f1ee51e..980bedf18a85b1d2fe44bbc0c23e08979ce61db2 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 0620c6f4427a9d65d96fb31594f5841e0fd30d44..197605067b3f12ff04575f116b274b31f31c82ff 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 2bfb84836632adb97ec204ccbc51290b67284c95..1a601457dcb61a9a05ad03f9ed2d4decdb560e75 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 0b83deb9da0cb5e08b5c50d2bae042aa497e8372..c8a19bc02556172aedaeffba27e89671b1eb15df 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 53606b0ce80f7ab498443ec2f4bca03c3952553a..61f10d0f2d49f3daa0a26a2588f2db9b91d2002d 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 e8845c6c8a531db84f70228d354325f3faa2551d..bea271d4ca73b917e6dc33f051d92f550029412f 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 7f932e09b04822ac9e26f945f7d006ff18aae8f9..e223795e0e72df35003603c5d95f17611ea852c7 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 d3bb0ca9d57247e9fe9c35a64a9665697acaf147..5656b841205d340ee1daef54f61e2cee1e81531e 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 063237b77e8f6ffd856481ce03c801d79bdda4c1..0e42db765e0cc99b30395721b005226c49839c8f 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 82a1daccadf5841fd84ec6e93c99f1cc3d230310..372d43f2ebdd989784674e3c2532b5579d213cb9 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 62a5fe07801e3b05c59a8581ffdb6d3122f38f6b..cb3e24774a1fdefc926bb4e185dbb289f7d9637e 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 6142a8b8602636f12dc74a17358dd1a97cf6c725..13012fcdf024f7b2ac63b1ab32a6c7b08ab65ab0 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 @@ -885,12 +885,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 @@ -918,11 +918,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 c9d71250b97e39b156b30281adfa397151e6a416..52ba7c29f2ac79cbbee28da2baa2e56bb3e91d74 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 f03716b897ebdee90ecfffbd1d5d76bff1e80554..7075d8352b8c4499484145579d640a45b79598f5 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/BUILD.gn b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/test/BUILD.gn index eb0f914e278b113cb984f38e88c108ab2acee1e2..c7112c9f45cfe0e394df53820eaeeeefd93bf42a 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/test/BUILD.gn +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/test/BUILD.gn @@ -138,6 +138,9 @@ ohos_unittest("wifi_p2p_test") { "-fPIC", "--coverage", ] + if (wifi_feature_with_p2p_untrust_invitation) { + defines += [ "SUPPORT_P2P_UNTRUST_INVITATION" ] + } deps = [ "$WIFI_ROOT_DIR/base:wifi_base", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_manager_service", 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 4d35247e7c4f6612b540870336aa96ce3430d2a4..ba76431a4d8e521b6004d67c93e68007a8648062 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 ec19c6b1a5c9050f53721deb027e803612d31fc4..8393b6b5ed8f9308d14c59ecf678df7d337d14f0 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 18738cd827903b332234d9e1ff00252da54c7047..11b911a96b43e6f7e45067685abfb0f0464e7a92 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,19 @@ HWTEST_F(P2pStateMachineTest, WakeUpScreenSaverTest, TestSize.Level1) WarpWakeUpScreenSaver(); EXPECT_FALSE(g_errLog.find("P2pStateMachine") != std::string::npos); } + +#ifdef SUPPORT_P2P_UNTRUST_INVITATION +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); +} +#endif } // namespace Wifi } // namespace OHOS \ No newline at end of file diff --git a/wifi/wifi.gni b/wifi/wifi.gni index f7c0c55280a60ca518484c5867304c373e9eee6f..ddb41e4623680fc5050b5aca00c842e426e04129 100644 --- a/wifi/wifi.gni +++ b/wifi/wifi.gni @@ -62,6 +62,7 @@ declare_args() { wifi_feature_mdm_restricted_enable = true wifi_feature_with_scan_control_action_listen = true wifi_feature_autoopen_specified_location = true + wifi_feature_with_p2p_untrust_invitation = false } memory_optimization_cflags = [