summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-03-27 17:11:49 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-03-27 17:11:49 +0000
commit30ff292b4ab8c1802eee1d3471ad9e16e0aaaba6 (patch)
treef519f78d0c3ffb777403d2cbcb15e4aef154a8ef
parent27147d48a8c04d5999402c13f6219a50e1ee3d19 (diff)
parent28d919a38957ec4a127f9eb2a55298f3c69ccac7 (diff)
downloadandroid_frameworks_opt_net_wifi-30ff292b4ab8c1802eee1d3471ad9e16e0aaaba6.tar.gz
android_frameworks_opt_net_wifi-30ff292b4ab8c1802eee1d3471ad9e16e0aaaba6.tar.bz2
android_frameworks_opt_net_wifi-30ff292b4ab8c1802eee1d3471ad9e16e0aaaba6.zip
Merge "WifiNetworkFactory: Ignore connection events after success"
-rw-r--r--service/java/com/android/server/wifi/WifiNetworkFactory.java15
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java60
2 files changed, 73 insertions, 2 deletions
diff --git a/service/java/com/android/server/wifi/WifiNetworkFactory.java b/service/java/com/android/server/wifi/WifiNetworkFactory.java
index c1b7dc347..a890c3ad9 100644
--- a/service/java/com/android/server/wifi/WifiNetworkFactory.java
+++ b/service/java/com/android/server/wifi/WifiNetworkFactory.java
@@ -137,6 +137,8 @@ public class WifiNetworkFactory extends NetworkFactory {
private boolean mPeriodicScanTimerSet = false;
private boolean mConnectionTimeoutSet = false;
private boolean mIsPeriodicScanPaused = false;
+ // We sent a new connection request and are waiting for connection success.
+ private boolean mPendingConnectionSuccess = false;
private boolean mWifiEnabled = false;
/**
* Indicates that we have new data to serialize.
@@ -752,6 +754,8 @@ public class WifiNetworkFactory extends NetworkFactory {
// Trigger connection to the network.
connectToNetwork(networkToConnect);
+ // Triggered connection to network, now wait for the connection status.
+ mPendingConnectionSuccess = true;
}
private void handleConnectToNetworkUserSelection(WifiConfiguration network) {
@@ -800,7 +804,10 @@ public class WifiNetworkFactory extends NetworkFactory {
* Invoked by {@link ClientModeImpl} on successful connection to a network.
*/
private void handleNetworkConnectionSuccess(@NonNull WifiConfiguration connectedNetwork) {
- if (mUserSelectedNetwork == null || connectedNetwork == null) return;
+ if (mUserSelectedNetwork == null || connectedNetwork == null
+ || !mPendingConnectionSuccess) {
+ return;
+ }
if (!isUserSelectedNetwork(connectedNetwork)) {
Log.w(TAG, "Connected to unknown network " + connectedNetwork + ". Ignoring...");
return;
@@ -823,7 +830,9 @@ public class WifiNetworkFactory extends NetworkFactory {
* Invoked by {@link ClientModeImpl} on failure to connect to a network.
*/
private void handleNetworkConnectionFailure(@NonNull WifiConfiguration failedNetwork) {
- if (mUserSelectedNetwork == null || failedNetwork == null) return;
+ if (mUserSelectedNetwork == null || failedNetwork == null || !mPendingConnectionSuccess) {
+ return;
+ }
if (!isUserSelectedNetwork(failedNetwork)) {
Log.w(TAG, "Connection failed to unknown network " + failedNetwork + ". Ignoring...");
return;
@@ -908,6 +917,7 @@ public class WifiNetworkFactory extends NetworkFactory {
mUserSelectedNetworkConnectRetryCount = 0;
mIsPeriodicScanPaused = false;
mActiveMatchedScanResults = null;
+ mPendingConnectionSuccess = false;
// Cancel periodic scan, connection timeout alarm.
cancelPeriodicScans();
cancelConnectionTimeout();
@@ -937,6 +947,7 @@ public class WifiNetworkFactory extends NetworkFactory {
mConnectedSpecificNetworkRequestSpecifier = mActiveSpecificNetworkRequestSpecifier;
mActiveSpecificNetworkRequest = null;
mActiveSpecificNetworkRequestSpecifier = null;
+ mPendingConnectionSuccess = false;
// Cancel connection timeout alarm.
cancelConnectionTimeout();
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
index 1b4218e27..4aa94fe56 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java
@@ -1360,6 +1360,66 @@ public class WifiNetworkFactoryTest {
}
/**
+ * Verify that we ignore connection success events after the first one (may be triggered by a
+ * roam event)
+ */
+ @Test
+ public void testNetworkSpecifierDuplicateHandleConnectionSuccess() throws Exception {
+ sendNetworkRequestAndSetupForConnectionStatus();
+
+ // Send network connection success indication.
+ assertNotNull(mSelectedNetwork);
+ mWifiNetworkFactory.handleConnectionAttemptEnded(
+ WifiMetrics.ConnectionEvent.FAILURE_NONE, mSelectedNetwork);
+
+ // Verify that we sent the connection success callback.
+ verify(mNetworkRequestMatchCallback).onUserSelectionConnectSuccess(
+ argThat(new WifiConfigMatcher(mSelectedNetwork)));
+ // verify we canceled the timeout alarm.
+ verify(mAlarmManager).cancel(mConnectionTimeoutAlarmListenerArgumentCaptor.getValue());
+
+ verify(mWifiMetrics).incrementNetworkRequestApiNumConnectSuccess();
+
+ // Send second network connection success indication which should be ignored.
+ mWifiNetworkFactory.handleConnectionAttemptEnded(
+ WifiMetrics.ConnectionEvent.FAILURE_NONE, mSelectedNetwork);
+ verifyNoMoreInteractions(mNetworkRequestMatchCallback);
+ }
+
+ /**
+ * Verify that we ignore any connection failure events after the first connection success (may
+ * be triggered by a disconnect).
+ * Note: The disconnect handling will be done via the NetworkAgent.
+ */
+ @Test
+ public void testNetworkSpecifierHandleConnectionFailureAfterSuccess() throws Exception {
+ sendNetworkRequestAndSetupForConnectionStatus();
+
+ // Send network connection success indication.
+ assertNotNull(mSelectedNetwork);
+ mWifiNetworkFactory.handleConnectionAttemptEnded(
+ WifiMetrics.ConnectionEvent.FAILURE_NONE, mSelectedNetwork);
+
+ // Verify that we sent the connection success callback.
+ verify(mNetworkRequestMatchCallback).onUserSelectionConnectSuccess(
+ argThat(new WifiConfigMatcher(mSelectedNetwork)));
+ // verify we canceled the timeout alarm.
+ verify(mAlarmManager).cancel(mConnectionTimeoutAlarmListenerArgumentCaptor.getValue());
+
+ verify(mWifiMetrics).incrementNetworkRequestApiNumConnectSuccess();
+
+ // Send a network connection failure indication which should be ignored (beyond the retry
+ // limit to trigger the failure handling).
+ for (int i = 0; i <= WifiNetworkFactory.USER_SELECTED_NETWORK_CONNECT_RETRY_MAX; i++) {
+ mWifiNetworkFactory.handleConnectionAttemptEnded(
+ WifiMetrics.ConnectionEvent.FAILURE_DHCP, mSelectedNetwork);
+ mLooper.dispatchAll();
+ }
+ // Verify that we ignore the second connection failure callback.
+ verifyNoMoreInteractions(mNetworkRequestMatchCallback);
+ }
+
+ /**
* Verify handling of connection success to a different network.
*/
@Test