From 27238dba7590ea489f8cc487452dc7d82d687e3d Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Fri, 14 Aug 2020 13:34:54 +0800 Subject: p2p: select proper GO intent value according to STA states Bug: 165804195 Test: manually initiate p2p connection: 1. no STA connection 2. STA connected to 2.4G network 3. STA connected to 5G network Test: atest FrameworksWifiTests Tets: CtsVerifier - Wi-Fi Direct Change-Id: I24e1901be8e63be60a2f95aa7cd35fc7a35322e4 --- .../server/wifi/p2p/SupplicantP2pIfaceHal.java | 13 +++---- .../server/wifi/p2p/WifiP2pServiceImpl.java | 40 ++++++++++++++++++++++ 2 files changed, 44 insertions(+), 9 deletions(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceHal.java b/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceHal.java index 3d15ec647..dca3a6082 100644 --- a/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceHal.java +++ b/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceHal.java @@ -63,7 +63,6 @@ public class SupplicantP2pIfaceHal { private static final String TAG = "SupplicantP2pIfaceHal"; private static boolean sVerboseLoggingEnabled = true; private static final int RESULT_NOT_VALID = -1; - private static final int DEFAULT_GROUP_OWNER_INTENT = 6; private static final int DEFAULT_OPERATING_CLASS = 81; /** * Regex pattern for extracting the wps device type bytes. @@ -828,13 +827,9 @@ public class SupplicantP2pIfaceHal { String preSelectedPin = TextUtils.isEmpty(config.wps.pin) ? "" : config.wps.pin; boolean persistent = (config.netId == WifiP2pGroup.NETWORK_ID_PERSISTENT); - int goIntent = 0; - if (!joinExistingGroup) { - int groupOwnerIntent = config.groupOwnerIntent; - if (groupOwnerIntent < 0 || groupOwnerIntent > 15) { - groupOwnerIntent = DEFAULT_GROUP_OWNER_INTENT; - } - goIntent = groupOwnerIntent; + if (config.groupOwnerIntent < 0 || config.groupOwnerIntent > 15) { + Log.e(TAG, "Invalid group owner intent: " + config.groupOwnerIntent); + return null; } SupplicantResult result = new SupplicantResult( @@ -842,7 +837,7 @@ public class SupplicantP2pIfaceHal { try { mISupplicantP2pIface.connect( peerAddress, provisionMethod, preSelectedPin, joinExistingGroup, - persistent, goIntent, + persistent, config.groupOwnerIntent, (SupplicantStatus status, String generatedPin) -> { result.setResult(status, generatedPin); }); diff --git a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java index 219da3884..eb2a89c4e 100644 --- a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java +++ b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java @@ -44,6 +44,9 @@ import android.net.ip.IIpClient; import android.net.ip.IpClientCallbacks; import android.net.ip.IpClientUtil; import android.net.shared.ProvisioningConfiguration; +import android.net.wifi.ScanResult; +import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.net.wifi.WpsInfo; import android.net.wifi.p2p.IWifiP2pManager; @@ -130,6 +133,8 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { private static final String TAG = "WifiP2pService"; private boolean mVerboseLoggingEnabled = false; private static final String NETWORKTYPE = "WIFI_P2P"; + @VisibleForTesting + static final int DEFAULT_GROUP_OWNER_INTENT = 6; private Context mContext; @@ -2240,6 +2245,8 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { break; case PEER_CONNECTION_USER_CONFIRM: mSavedPeerConfig.wps.setup = WpsInfo.DISPLAY; + mSavedPeerConfig.groupOwnerIntent = + selectGroupOwnerIntentIfNecessary(mSavedPeerConfig); mWifiNative.p2pConnect(mSavedPeerConfig, FORM_GROUP); transitionTo(mGroupNegotiationState); break; @@ -3537,6 +3544,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { Log.e(TAG, "Invalid device"); return; } + config.groupOwnerIntent = selectGroupOwnerIntentIfNecessary(config); String pin = mWifiNative.p2pConnect(config, dev.isGroupOwner()); try { Integer.parseInt(pin); @@ -4313,6 +4321,38 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { clearServiceRequests(c.mMessenger); } } + + private int selectGroupOwnerIntentIfNecessary(WifiP2pConfig config) { + int intent = config.groupOwnerIntent; + // return the legacy default value for invalid values. + if (intent != WifiP2pConfig.GROUP_OWNER_INTENT_AUTO) { + if (intent < WifiP2pConfig.GROUP_OWNER_INTENT_MIN + || intent > WifiP2pConfig.GROUP_OWNER_INTENT_MAX) { + intent = DEFAULT_GROUP_OWNER_INTENT; + } + return intent; + } + + WifiManager wifiManager = mContext.getSystemService(WifiManager.class); + + WifiInfo wifiInfo = wifiManager.getConnectionInfo(); + Log.d(TAG, "WifiInfo: " + wifiInfo); + int freq = wifiInfo.getFrequency(); + if (wifiInfo.getNetworkId() == WifiConfiguration.INVALID_NETWORK_ID) { + intent = DEFAULT_GROUP_OWNER_INTENT + 1; + } else if (ScanResult.is24GHz(freq)) { + intent = WifiP2pConfig.GROUP_OWNER_INTENT_MIN; + } else if (ScanResult.is5GHz(freq)) { + // If both sides use the maximum, the negotiation would fail. + intent = WifiP2pConfig.GROUP_OWNER_INTENT_MAX - 1; + } else { + intent = DEFAULT_GROUP_OWNER_INTENT; + } + Log.i(TAG, "change GO intent value from " + + config.groupOwnerIntent + " to " + intent); + return intent; + } + } /** -- cgit v1.2.3