summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2017-07-14 12:00:30 -0700
committerRoshan Pius <rpius@google.com>2017-07-21 08:31:22 -0700
commited3eb18b3896a107e2356b90713425fe3e2a2924 (patch)
tree07d953e519180192ef06dbdf79345af275dc5e05 /tests
parent43d042f5fe899676f02b609975575efad7796fac (diff)
WifiStateMachine: Dont repeatedly call sendExplicitlySelected
Use the last selected network timestamp (WifiConfigManager.getLastSelectedTimestamp) to limit the invocation of NetworkAgent.sendExplicitlySelected. The current expiration is set at 30 seconds to prevent the user from receiving notifications about lack of internet connectivity repeatedly on the same network. Bug: 62503737 Test: Added a unit test for the helper function. Ideally would have wanted to use a mock WifiNetworkAgent and capture the interaction on it, but because of the way WSM is designed currently, it's impossible to use a WifiInjector to mock it out. Change-Id: I342b617769141c3e8071e5aba89efebe42c97390 (cherry-picked from 674c12b8a66d2961cf9a5930b1e0fab4dda86152)
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java69
1 files changed, 68 insertions, 1 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index eb1bae018..8d578b3d9 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -346,6 +346,7 @@ public class WifiStateMachineTest {
@Mock IpManager mIpManager;
@Mock TelephonyManager mTelephonyManager;
@Mock WrongPasswordNotifier mWrongPasswordNotifier;
+ @Mock Clock mClock;
public WifiStateMachineTest() throws Exception {
}
@@ -387,6 +388,7 @@ public class WifiStateMachineTest {
when(mWifiInjector.getWifiNative()).thenReturn(mWifiNative);
when(mWifiInjector.getSelfRecovery()).thenReturn(mSelfRecovery);
when(mWifiInjector.makeTelephonyManager()).thenReturn(mTelephonyManager);
+ when(mWifiInjector.getClock()).thenReturn(mClock);
when(mWifiNative.setupForClientMode())
.thenReturn(Pair.create(WifiNative.SETUP_SUCCESS, mClientInterface));
@@ -2028,7 +2030,7 @@ public class WifiStateMachineTest {
verify(mWifiNative, never()).resetTxPowerLimit();
}
- /*
+ /**
* Verifies that a network disconnection event will result in WifiStateMachine invoking
* {@link WifiConfigManager#removeAllEphemeralOrPasspointConfiguredNetworks()} to remove
* any ephemeral or passpoint networks from it's internal database.
@@ -2075,4 +2077,69 @@ public class WifiStateMachineTest {
verify(mWifiConfigManager).clearRecentFailureReason(eq(0));
verify(mWifiConfigManager, never()).setRecentFailureAssociationStatus(anyInt(), anyInt());
}
+
+ /**
+ * Test that the helper method
+ * {@link WifiStateMachine#shouldEvaluateWhetherToSendExplicitlySelected(WifiConfiguration)}
+ * returns true when we connect to the last selected network before expiration of
+ * {@link WifiStateMachine#LAST_SELECTED_NETWORK_EXPIRATION_AGE_MILLIS}.
+ */
+ @Test
+ public void testShouldEvaluateWhetherToSendExplicitlySelected_SameNetworkNotExpired() {
+ long lastSelectedTimestamp = 45666743454L;
+ int lastSelectedNetworkId = 5;
+
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(
+ lastSelectedTimestamp
+ + WifiStateMachine.LAST_SELECTED_NETWORK_EXPIRATION_AGE_MILLIS - 1);
+ when(mWifiConfigManager.getLastSelectedTimeStamp()).thenReturn(lastSelectedTimestamp);
+ when(mWifiConfigManager.getLastSelectedNetwork()).thenReturn(lastSelectedNetworkId);
+
+ WifiConfiguration currentConfig = new WifiConfiguration();
+ currentConfig.networkId = lastSelectedNetworkId;
+ assertTrue(mWsm.shouldEvaluateWhetherToSendExplicitlySelected(currentConfig));
+ }
+
+ /**
+ * Test that the helper method
+ * {@link WifiStateMachine#shouldEvaluateWhetherToSendExplicitlySelected(WifiConfiguration)}
+ * returns false when we connect to the last selected network after expiration of
+ * {@link WifiStateMachine#LAST_SELECTED_NETWORK_EXPIRATION_AGE_MILLIS}.
+ */
+ @Test
+ public void testShouldEvaluateWhetherToSendExplicitlySelected_SameNetworkExpired() {
+ long lastSelectedTimestamp = 45666743454L;
+ int lastSelectedNetworkId = 5;
+
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(
+ lastSelectedTimestamp
+ + WifiStateMachine.LAST_SELECTED_NETWORK_EXPIRATION_AGE_MILLIS + 1);
+ when(mWifiConfigManager.getLastSelectedTimeStamp()).thenReturn(lastSelectedTimestamp);
+ when(mWifiConfigManager.getLastSelectedNetwork()).thenReturn(lastSelectedNetworkId);
+
+ WifiConfiguration currentConfig = new WifiConfiguration();
+ currentConfig.networkId = lastSelectedNetworkId;
+ assertFalse(mWsm.shouldEvaluateWhetherToSendExplicitlySelected(currentConfig));
+ }
+
+ /**
+ * Test that the helper method
+ * {@link WifiStateMachine#shouldEvaluateWhetherToSendExplicitlySelected(WifiConfiguration)}
+ * returns false when we connect to a different network to the last selected network.
+ */
+ @Test
+ public void testShouldEvaluateWhetherToSendExplicitlySelected_DifferentNetwork() {
+ long lastSelectedTimestamp = 45666743454L;
+ int lastSelectedNetworkId = 5;
+
+ when(mClock.getElapsedSinceBootMillis()).thenReturn(
+ lastSelectedTimestamp
+ + WifiStateMachine.LAST_SELECTED_NETWORK_EXPIRATION_AGE_MILLIS - 1);
+ when(mWifiConfigManager.getLastSelectedTimeStamp()).thenReturn(lastSelectedTimestamp);
+ when(mWifiConfigManager.getLastSelectedNetwork()).thenReturn(lastSelectedNetworkId);
+
+ WifiConfiguration currentConfig = new WifiConfiguration();
+ currentConfig.networkId = lastSelectedNetworkId - 1;
+ assertFalse(mWsm.shouldEvaluateWhetherToSendExplicitlySelected(currentConfig));
+ }
}