summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2018-05-22 07:22:56 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2018-05-22 07:22:56 +0000
commit5b02ddfd3e5b260b9c5f767c2c14a7dfaaa2536b (patch)
tree6af2f8f02eddb8368e63ceff8bcb4a65391e67d6
parente9edb049f819b761c7e18d7bbe9dafd21602f3a1 (diff)
parent095121ada1c9ea6034e86606395de20cddcad9ba (diff)
downloadwifi-5b02ddfd3e5b260b9c5f767c2c14a7dfaaa2536b.tar.gz
Snap for 4796401 from 095121ada1c9ea6034e86606395de20cddcad9ba to pi-release
Change-Id: I8e0cfc13588c069bcc33db3fe5850427bd3bed63
-rw-r--r--service/java/com/android/server/wifi/WifiConfigManager.java18
-rw-r--r--service/java/com/android/server/wifi/WifiConnectivityManager.java8
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java16
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java34
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java24
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java108
6 files changed, 193 insertions, 15 deletions
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java
index 982c48a48..0b70dbf4e 100644
--- a/service/java/com/android/server/wifi/WifiConfigManager.java
+++ b/service/java/com/android/server/wifi/WifiConfigManager.java
@@ -119,10 +119,11 @@ public class WifiConfigManager {
5, // threshold for DISABLED_AUTHENTICATION_FAILURE
5, // threshold for DISABLED_DHCP_FAILURE
5, // threshold for DISABLED_DNS_FAILURE
+ 1, // threshold for DISABLED_NO_INTERNET_TEMPORARY
1, // threshold for DISABLED_WPS_START
6, // threshold for DISABLED_TLS_VERSION_MISMATCH
1, // threshold for DISABLED_AUTHENTICATION_NO_CREDENTIALS
- 1, // threshold for DISABLED_NO_INTERNET
+ 1, // threshold for DISABLED_NO_INTERNET_PERMANENT
1, // threshold for DISABLED_BY_WIFI_MANAGER
1, // threshold for DISABLED_BY_USER_SWITCH
1 // threshold for DISABLED_BY_WRONG_PASSWORD
@@ -141,10 +142,11 @@ public class WifiConfigManager {
5 * 60 * 1000, // threshold for DISABLED_AUTHENTICATION_FAILURE
5 * 60 * 1000, // threshold for DISABLED_DHCP_FAILURE
5 * 60 * 1000, // threshold for DISABLED_DNS_FAILURE
+ 10 * 60 * 1000, // threshold for DISABLED_NO_INTERNET_TEMPORARY
0 * 60 * 1000, // threshold for DISABLED_WPS_START
Integer.MAX_VALUE, // threshold for DISABLED_TLS_VERSION
Integer.MAX_VALUE, // threshold for DISABLED_AUTHENTICATION_NO_CREDENTIALS
- Integer.MAX_VALUE, // threshold for DISABLED_NO_INTERNET
+ Integer.MAX_VALUE, // threshold for DISABLED_NO_INTERNET_PERMANENT
Integer.MAX_VALUE, // threshold for DISABLED_BY_WIFI_MANAGER
Integer.MAX_VALUE, // threshold for DISABLED_BY_USER_SWITCH
Integer.MAX_VALUE // threshold for DISABLED_BY_WRONG_PASSWORD
@@ -165,7 +167,7 @@ public class WifiConfigManager {
/**
* Invoked on saved network being permanently disabled.
*/
- void onSavedNetworkPermanentlyDisabled(int networkId);
+ void onSavedNetworkPermanentlyDisabled(int networkId, int disableReason);
/**
* Invoked on saved network being removed.
*/
@@ -173,7 +175,7 @@ public class WifiConfigManager {
/**
* Invoked on saved network being temporarily disabled.
*/
- void onSavedNetworkTemporarilyDisabled(int networkId);
+ void onSavedNetworkTemporarilyDisabled(int networkId, int disableReason);
/**
* Invoked on saved network being updated.
*/
@@ -1301,7 +1303,9 @@ public class WifiConfigManager {
// Only need a valid time filled in for temporarily disabled networks.
status.setDisableTime(mClock.getElapsedSinceBootMillis());
status.setNetworkSelectionDisableReason(disableReason);
- if (mListener != null) mListener.onSavedNetworkTemporarilyDisabled(config.networkId);
+ if (mListener != null) {
+ mListener.onSavedNetworkTemporarilyDisabled(config.networkId, disableReason);
+ }
}
/**
@@ -1315,7 +1319,9 @@ public class WifiConfigManager {
status.setDisableTime(
NetworkSelectionStatus.INVALID_NETWORK_SELECTION_DISABLE_TIMESTAMP);
status.setNetworkSelectionDisableReason(disableReason);
- if (mListener != null) mListener.onSavedNetworkPermanentlyDisabled(config.networkId);
+ if (mListener != null) {
+ mListener.onSavedNetworkPermanentlyDisabled(config.networkId, disableReason);
+ }
}
/**
diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java
index aa4fd80df..d10d80013 100644
--- a/service/java/com/android/server/wifi/WifiConnectivityManager.java
+++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java
@@ -16,6 +16,8 @@
package com.android.server.wifi;
+import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.DISABLED_NO_INTERNET_TEMPORARY;
+
import static com.android.server.wifi.WifiStateMachine.WIFI_WORK_SOURCE;
import android.app.AlarmManager;
@@ -37,7 +39,6 @@ import android.util.Log;
import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.util.ArrayUtils;
import com.android.server.wifi.hotspot2.PasspointNetworkEvaluator;
import com.android.server.wifi.util.ScanResultUtil;
@@ -545,11 +546,12 @@ public class WifiConnectivityManager {
updatePnoScan();
}
@Override
- public void onSavedNetworkTemporarilyDisabled(int networkId) {
+ public void onSavedNetworkTemporarilyDisabled(int networkId, int disableReason) {
+ if (disableReason == DISABLED_NO_INTERNET_TEMPORARY) return;
mConnectivityHelper.removeNetworkIfCurrent(networkId);
}
@Override
- public void onSavedNetworkPermanentlyDisabled(int networkId) {
+ public void onSavedNetworkPermanentlyDisabled(int networkId, int disableReason) {
mConnectivityHelper.removeNetworkIfCurrent(networkId);
updatePnoScan();
}
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index 74a4dc7f0..fa22749bb 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -5292,10 +5292,20 @@ public class WifiStateMachine extends StateMachine {
config.networkId, false);
mWifiConfigManager.updateNetworkSelectionStatus(config.networkId,
WifiConfiguration.NetworkSelectionStatus
- .DISABLED_NO_INTERNET);
+ .DISABLED_NO_INTERNET_PERMANENT);
+ } else {
+ mWifiConfigManager.incrementNetworkNoInternetAccessReports(
+ config.networkId);
+ // If this was not the last selected network, update network
+ // selection status to temporarily disable the network.
+ if (mWifiConfigManager.getLastSelectedNetwork() != config.networkId
+ && !config.noInternetAccessExpected) {
+ mWifiConfigManager.updateNetworkSelectionStatus(
+ config.networkId,
+ WifiConfiguration.NetworkSelectionStatus
+ .DISABLED_NO_INTERNET_TEMPORARY);
+ }
}
- mWifiConfigManager.incrementNetworkNoInternetAccessReports(
- config.networkId);
}
}
return HANDLED;
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index 844a358d0..a4bc61aa1 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -628,12 +628,42 @@ public class WifiConfigManagerTest {
for (int i = 1; i <= assocRejectThreshold; i++) {
verifyUpdateNetworkSelectionStatus(result.getNetworkId(), assocRejectReason, i);
}
- verify(mWcmListener).onSavedNetworkTemporarilyDisabled(networkId);
+ verify(mWcmListener).onSavedNetworkTemporarilyDisabled(
+ networkId, NetworkSelectionStatus.DISABLED_ASSOCIATION_REJECTION);
// Now set it to permanently disabled.
verifyUpdateNetworkSelectionStatus(
result.getNetworkId(), NetworkSelectionStatus.DISABLED_BY_WIFI_MANAGER, 0);
- verify(mWcmListener).onSavedNetworkPermanentlyDisabled(networkId);
+ verify(mWcmListener).onSavedNetworkPermanentlyDisabled(
+ networkId, NetworkSelectionStatus.DISABLED_BY_WIFI_MANAGER);
+
+ // Now set it back to enabled.
+ verifyUpdateNetworkSelectionStatus(
+ result.getNetworkId(), NetworkSelectionStatus.NETWORK_SELECTION_ENABLE, 0);
+ verify(mWcmListener, times(2)).onSavedNetworkEnabled(networkId);
+ }
+
+ /**
+ * Verifies the update of network status using
+ * {@link WifiConfigManager#updateNetworkSelectionStatus(int, int)}.
+ */
+ @Test
+ public void testNetworkSelectionStatusTemporarilyDisabledDueToNoInternet() {
+ WifiConfiguration openNetwork = WifiConfigurationTestUtil.createOpenNetwork();
+
+ NetworkUpdateResult result = verifyAddNetworkToWifiConfigManager(openNetwork);
+
+ int networkId = result.getNetworkId();
+ // First set it to enabled.
+ verifyUpdateNetworkSelectionStatus(
+ networkId, NetworkSelectionStatus.NETWORK_SELECTION_ENABLE, 0);
+
+ // Now set it to temporarily disabled. The threshold for no internet is 1, so
+ // disable it once to actually mark it temporarily disabled.
+ verifyUpdateNetworkSelectionStatus(
+ result.getNetworkId(), NetworkSelectionStatus.DISABLED_NO_INTERNET_TEMPORARY, 1);
+ verify(mWcmListener).onSavedNetworkTemporarilyDisabled(
+ networkId, NetworkSelectionStatus.DISABLED_NO_INTERNET_TEMPORARY);
// Now set it back to enabled.
verifyUpdateNetworkSelectionStatus(
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
index 36530edb8..cb423617f 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
@@ -16,6 +16,9 @@
package com.android.server.wifi;
+import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.DISABLED_AUTHENTICATION_FAILURE;
+import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.DISABLED_NO_INTERNET_TEMPORARY;
+
import static com.android.server.wifi.WifiConfigurationTestUtil.generateWifiConfig;
import static com.android.server.wifi.WifiStateMachine.WIFI_WORK_SOURCE;
@@ -134,6 +137,8 @@ public class WifiConnectivityManagerTest {
@Captor ArgumentCaptor<ScanResult> mCandidateScanResultCaptor;
@Captor ArgumentCaptor<ArrayList<String>> mBssidBlacklistCaptor;
@Captor ArgumentCaptor<ArrayList<String>> mSsidWhitelistCaptor;
+ @Captor ArgumentCaptor<WifiConfigManager.OnSavedNetworkUpdateListener>
+ mSavedNetworkUpdateListenerCaptor;
private MockResources mResources;
private int mFullScanMaxTxPacketRate;
private int mFullScanMaxRxPacketRate;
@@ -299,6 +304,8 @@ public class WifiConnectivityManagerTest {
pnoNetworkList.add(pnoNetwork);
when(wifiConfigManager.retrievePnoNetworkList()).thenReturn(pnoNetworkList);
when(wifiConfigManager.retrievePnoNetworkList()).thenReturn(pnoNetworkList);
+ doNothing().when(wifiConfigManager).setOnSavedNetworkUpdateListener(
+ mSavedNetworkUpdateListenerCaptor.capture());
return wifiConfigManager;
}
@@ -2040,4 +2047,21 @@ public class WifiConnectivityManagerTest {
assertTrue(capturedScanResults.contains(mScanData.getResults()[2]));
assertTrue(capturedScanResults.contains(mScanData.getResults()[3]));
}
+
+ /**
+ * Disabling the network temporarily due to lack of internet is a special reason for which we
+ * don't want WCM to trigger a disconnect (by removing the network from supplicant).
+ */
+ @Test
+ public void dontDisconnectIfNetworkTemporarilyDisabledDueToNoInternet() {
+ assertNotNull(mSavedNetworkUpdateListenerCaptor.getValue());
+
+ mSavedNetworkUpdateListenerCaptor.getValue()
+ .onSavedNetworkPermanentlyDisabled(0, DISABLED_AUTHENTICATION_FAILURE);
+ verify(mWifiConnectivityHelper).removeNetworkIfCurrent(0);
+
+ mSavedNetworkUpdateListenerCaptor.getValue()
+ .onSavedNetworkPermanentlyDisabled(0, DISABLED_NO_INTERNET_TEMPORARY);
+ // Don't remove network.
+ }
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index b067d9dfa..8da8339b3 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -16,6 +16,8 @@
package com.android.server.wifi;
+import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.DISABLED_NO_INTERNET_TEMPORARY;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@@ -37,6 +39,7 @@ import android.net.ConnectivityManager;
import android.net.DhcpResults;
import android.net.LinkProperties;
import android.net.MacAddress;
+import android.net.NetworkAgent;
import android.net.NetworkCapabilities;
import android.net.NetworkFactory;
import android.net.NetworkInfo;
@@ -2123,7 +2126,7 @@ public class WifiStateMachineTest {
Bundle thresholds = new Bundle();
thresholds.putIntegerArrayList("thresholds", thresholdsArray);
Message message = new Message();
- message.what = android.net.NetworkAgent.CMD_SET_SIGNAL_STRENGTH_THRESHOLDS;
+ message.what = NetworkAgent.CMD_SET_SIGNAL_STRENGTH_THRESHOLDS;
message.obj = thresholds;
messengerCaptor.getValue().send(message);
mLooper.dispatchAll();
@@ -2433,4 +2436,107 @@ public class WifiStateMachineTest {
mLooper.dispatchAll();
assertEquals(TEST_GLOBAL_MAC_ADDRESS.toString(), mWsm.getWifiInfo().getMacAddress());
}
+
+ /**
+ * Verify that we temporarily disable the network when auto-connected to a network
+ * with no internet access.
+ */
+ @Test
+ public void verifyAutoConnectedNetworkWithInternetValidationFailure() throws Exception {
+ // Simulate the first connection.
+ connect();
+ ArgumentCaptor<Messenger> messengerCaptor = ArgumentCaptor.forClass(Messenger.class);
+ verify(mConnectivityManager).registerNetworkAgent(messengerCaptor.capture(),
+ any(NetworkInfo.class), any(LinkProperties.class), any(NetworkCapabilities.class),
+ anyInt(), any(NetworkMisc.class));
+
+ WifiConfiguration currentNetwork = new WifiConfiguration();
+ currentNetwork.networkId = FRAMEWORK_NETWORK_ID;
+ currentNetwork.noInternetAccessExpected = false;
+ currentNetwork.numNoInternetAccessReports = 1;
+ when(mWifiConfigManager.getConfiguredNetwork(FRAMEWORK_NETWORK_ID))
+ .thenReturn(currentNetwork);
+ when(mWifiConfigManager.getLastSelectedNetwork()).thenReturn(FRAMEWORK_NETWORK_ID + 1);
+
+ Message message = new Message();
+ message.what = NetworkAgent.CMD_REPORT_NETWORK_STATUS;
+ message.arg1 = NetworkAgent.INVALID_NETWORK;
+ message.obj = new Bundle();
+ messengerCaptor.getValue().send(message);
+ mLooper.dispatchAll();
+
+ verify(mWifiConfigManager)
+ .incrementNetworkNoInternetAccessReports(FRAMEWORK_NETWORK_ID);
+ verify(mWifiConfigManager).updateNetworkSelectionStatus(
+ FRAMEWORK_NETWORK_ID, DISABLED_NO_INTERNET_TEMPORARY);
+ }
+
+ /**
+ * Verify that we don't temporarily disable the network when user selected to connect to a
+ * network with no internet access.
+ */
+ @Test
+ public void verifyLastSelectedNetworkWithInternetValidationFailure() throws Exception {
+ // Simulate the first connection.
+ connect();
+ ArgumentCaptor<Messenger> messengerCaptor = ArgumentCaptor.forClass(Messenger.class);
+ verify(mConnectivityManager).registerNetworkAgent(messengerCaptor.capture(),
+ any(NetworkInfo.class), any(LinkProperties.class), any(NetworkCapabilities.class),
+ anyInt(), any(NetworkMisc.class));
+
+ WifiConfiguration currentNetwork = new WifiConfiguration();
+ currentNetwork.networkId = FRAMEWORK_NETWORK_ID;
+ currentNetwork.noInternetAccessExpected = false;
+ currentNetwork.numNoInternetAccessReports = 1;
+ when(mWifiConfigManager.getConfiguredNetwork(FRAMEWORK_NETWORK_ID))
+ .thenReturn(currentNetwork);
+ when(mWifiConfigManager.getLastSelectedNetwork()).thenReturn(FRAMEWORK_NETWORK_ID);
+
+ Message message = new Message();
+ message.what = NetworkAgent.CMD_REPORT_NETWORK_STATUS;
+ message.arg1 = NetworkAgent.INVALID_NETWORK;
+ message.obj = new Bundle();
+ messengerCaptor.getValue().send(message);
+ mLooper.dispatchAll();
+
+ verify(mWifiConfigManager)
+ .incrementNetworkNoInternetAccessReports(FRAMEWORK_NETWORK_ID);
+ verify(mWifiConfigManager, never()).updateNetworkSelectionStatus(
+ FRAMEWORK_NETWORK_ID, DISABLED_NO_INTERNET_TEMPORARY);
+ }
+
+ /**
+ * Verify that we temporarily disable the network when auto-connected to a network
+ * with no internet access.
+ */
+ @Test
+ public void verifyAutoConnectedNoInternetExpectedNetworkWithInternetValidationFailure()
+ throws Exception {
+ // Simulate the first connection.
+ connect();
+ ArgumentCaptor<Messenger> messengerCaptor = ArgumentCaptor.forClass(Messenger.class);
+ verify(mConnectivityManager).registerNetworkAgent(messengerCaptor.capture(),
+ any(NetworkInfo.class), any(LinkProperties.class), any(NetworkCapabilities.class),
+ anyInt(), any(NetworkMisc.class));
+
+ WifiConfiguration currentNetwork = new WifiConfiguration();
+ currentNetwork.networkId = FRAMEWORK_NETWORK_ID;
+ currentNetwork.noInternetAccessExpected = true;
+ currentNetwork.numNoInternetAccessReports = 1;
+ when(mWifiConfigManager.getConfiguredNetwork(FRAMEWORK_NETWORK_ID + 1))
+ .thenReturn(currentNetwork);
+ when(mWifiConfigManager.getLastSelectedNetwork()).thenReturn(FRAMEWORK_NETWORK_ID);
+
+ Message message = new Message();
+ message.what = NetworkAgent.CMD_REPORT_NETWORK_STATUS;
+ message.arg1 = NetworkAgent.INVALID_NETWORK;
+ message.obj = new Bundle();
+ messengerCaptor.getValue().send(message);
+ mLooper.dispatchAll();
+
+ verify(mWifiConfigManager)
+ .incrementNetworkNoInternetAccessReports(FRAMEWORK_NETWORK_ID);
+ verify(mWifiConfigManager, never()).updateNetworkSelectionStatus(
+ FRAMEWORK_NETWORK_ID, DISABLED_NO_INTERNET_TEMPORARY);
+ }
}