summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorJimmy Chen <jimmycmchen@google.com>2020-09-14 02:10:50 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-09-14 02:10:50 +0000
commit90b8c690138228ae755a68dd11b6c6d102eeb824 (patch)
tree03c66ed0f278d12ed4c1a3ed6a5818afb6c0a17e /service
parent1416c9d16d9188cc0e647ca0a533a55dbb2df487 (diff)
parent27238dba7590ea489f8cc487452dc7d82d687e3d (diff)
Merge "p2p: select proper GO intent value according to STA states" into rvc-qpr-dev
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceHal.java13
-rw-r--r--service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java40
2 files changed, 44 insertions, 9 deletions
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<String> 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;
+ }
+
}
/**