summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2017-07-14 12:00:30 -0700
committerRoshan Pius <rpius@google.com>2017-07-24 18:11:55 +0000
commit06dcab2ee1a5d1293c9142f40cb65b52ffa2a5d6 (patch)
treeb063fae83df2f994533696c722e960d400cdaecc /service
parent96e29a8bc2b03c301658ce3831e64113b060c427 (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 Merged-In: I342b617769141c3e8071e5aba89efebe42c97390
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java30
1 files changed, 27 insertions, 3 deletions
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index 7e625bbda..33d8a14e5 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -769,6 +769,14 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
private static final int SUSPEND_DUE_TO_HIGH_PERF = 1 << 1;
private static final int SUSPEND_DUE_TO_SCREEN = 1 << 2;
+ /**
+ * Time window in milliseconds for which we send
+ * {@link NetworkAgent#explicitlySelected(boolean)}
+ * after connecting to the network which the user last selected.
+ */
+ @VisibleForTesting
+ public static final int LAST_SELECTED_NETWORK_EXPIRATION_AGE_MILLIS = 30 * 1000;
+
/* Tracks if user has enabled suspend optimizations through settings */
private AtomicBoolean mUserWantsSuspendOpt = new AtomicBoolean(true);
@@ -6069,13 +6077,29 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss
}
}
+ /**
+ * Helper function to check if we need to invoke
+ * {@link NetworkAgent#explicitlySelected(boolean)} to indicate that we connected to a network
+ * which the user just chose
+ * (i.e less than {@link #LAST_SELECTED_NETWORK_EXPIRATION_AGE_MILLIS) before).
+ */
+ @VisibleForTesting
+ public boolean shouldEvaluateWhetherToSendExplicitlySelected(WifiConfiguration currentConfig) {
+ if (currentConfig == null) {
+ Log.wtf(TAG, "Current WifiConfiguration is null, but IP provisioning just succeeded");
+ return false;
+ }
+ long currentTimeMillis = mClock.getElapsedSinceBootMillis();
+ return (mWifiConfigManager.getLastSelectedNetwork() == currentConfig.networkId
+ && currentTimeMillis - mWifiConfigManager.getLastSelectedTimeStamp()
+ < LAST_SELECTED_NETWORK_EXPIRATION_AGE_MILLIS);
+ }
+
private void sendConnectedState() {
// If this network was explicitly selected by the user, evaluate whether to call
// explicitlySelected() so the system can treat it appropriately.
WifiConfiguration config = getCurrentWifiConfiguration();
- if (config == null) {
- Log.wtf(TAG, "Current WifiConfiguration is null, but IP provisioning just succeeded");
- } else if (mWifiConfigManager.getLastSelectedNetwork() == config.networkId) {
+ if (shouldEvaluateWhetherToSendExplicitlySelected(config)) {
boolean prompt =
mWifiPermissionsUtil.checkConfigOverridePermission(config.lastConnectUid);
if (mVerboseLoggingEnabled) {