diff options
author | Paul Stewart <pstew@google.com> | 2016-06-06 21:53:15 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-06-06 21:53:16 +0000 |
commit | 2d7797eae8364c2c42d7368090b25adc74de3ff1 (patch) | |
tree | 1cb8b51e1b297d724fca0f2f9d8f1f6209d88e89 /service | |
parent | 5f4074fa7f8e61d27cd24c317a0a1b8a5ece4724 (diff) | |
parent | 016ca1ae5e33eb9529ae10c2510a56fa5c7fec4d (diff) |
Merge "WCM: Periodic scan interval policy adjustment" into nyc-dev
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/WifiConnectivityManager.java | 58 |
1 files changed, 35 insertions, 23 deletions
diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java index eb9427c8b..e6d285e96 100644 --- a/service/java/com/android/server/wifi/WifiConnectivityManager.java +++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java @@ -65,7 +65,11 @@ public class WifiConnectivityManager { "WifiConnectivityManager Restart Scan"; private static final String TAG = "WifiConnectivityManager"; - private static final long INVALID_TIME_STAMP = Long.MIN_VALUE; + private static final long RESET_TIME_STAMP = Long.MIN_VALUE; + // Constants to indicate whether a scan should start immediately or + // it should comply to the minimum scan interval rule. + private static final boolean SCAN_IMMEDIATELY = true; + private static final boolean SCAN_ON_SCHEDULE = false; // Periodic scan interval in milli-seconds. This is the scan // performed when screen is on. @VisibleForTesting @@ -134,7 +138,6 @@ public class WifiConnectivityManager { private boolean mDbg = false; private boolean mWifiEnabled = false; private boolean mWifiConnectivityManagerEnabled = true; - private boolean mForceSelectNetwork = false; private boolean mScreenOn = false; private int mWifiState = WIFI_STATE_UNKNOWN; private boolean mUntrustedConnectionAllowed = false; @@ -143,7 +146,7 @@ public class WifiConnectivityManager { private int mTotalConnectivityAttemptsRateLimited = 0; private String mLastConnectionAttemptBssid = null; private int mPeriodicSingleScanInterval = PERIODIC_SCAN_INTERVAL_MS; - private long mLastPeriodicSingleScanTimeStamp = INVALID_TIME_STAMP; + private long mLastPeriodicSingleScanTimeStamp = RESET_TIME_STAMP; // PNO settings private int mMin5GHzRssi; @@ -165,7 +168,7 @@ public class WifiConnectivityManager { private final AlarmManager.OnAlarmListener mRestartScanListener = new AlarmManager.OnAlarmListener() { public void onAlarm() { - startConnectivityScan(mForceSelectNetwork); + startConnectivityScan(SCAN_IMMEDIATELY); } }; @@ -215,7 +218,7 @@ public class WifiConnectivityManager { private boolean handleScanResults(List<ScanDetail> scanDetails, String listenerName) { localLog(listenerName + " onResults: start QNS"); WifiConfiguration candidate = - mQualifiedNetworkSelector.selectQualifiedNetwork(mForceSelectNetwork, + mQualifiedNetworkSelector.selectQualifiedNetwork(false, mUntrustedConnectionAllowed, scanDetails, mStateMachine.isLinkDebouncing(), mStateMachine.isConnected(), mStateMachine.isDisconnected(), @@ -666,7 +669,7 @@ public class WifiConnectivityManager { private void startPeriodicSingleScan() { long currentTimeStamp = mClock.elapsedRealtime(); - if (mLastPeriodicSingleScanTimeStamp != INVALID_TIME_STAMP) { + if (mLastPeriodicSingleScanTimeStamp != RESET_TIME_STAMP) { long msSinceLastScan = currentTimeStamp - mLastPeriodicSingleScanTimeStamp; if (msSinceLastScan < PERIODIC_SCAN_INTERVAL_MS) { localLog("Last periodic single scan started " + msSinceLastScan @@ -701,6 +704,12 @@ public class WifiConnectivityManager { } } + // Reset the last periodic single scan time stamp so that the next periodic single + // scan can start immediately. + private void resetLastPeriodicSingleScanTimeStamp() { + mLastPeriodicSingleScanTimeStamp = RESET_TIME_STAMP; + } + // Periodic scan timer handler private void periodicScanTimerHandler() { localLog("periodicScanTimerHandler"); @@ -749,12 +758,15 @@ public class WifiConnectivityManager { } // Start a periodic scan when screen is on - private void startPeriodicScan() { + private void startPeriodicScan(boolean scanImmediately) { mPnoScanListener.resetLowRssiNetworkRetryDelay(); // Due to b/28020168, timer based single scan will be scheduled // to provide periodic scan in an exponential backoff fashion. if (!ENABLE_BACKGROUND_SCAN) { + if (scanImmediately) { + resetLastPeriodicSingleScanTimeStamp(); + } mPeriodicSingleScanInterval = PERIODIC_SCAN_INTERVAL_MS; startPeriodicSingleScan(); } else { @@ -894,10 +906,10 @@ public class WifiConnectivityManager { // Start a connectivity scan. The scan method is chosen according to // the current screen state and WiFi state. - private void startConnectivityScan(boolean forceSelectNetwork) { + private void startConnectivityScan(boolean scanImmediately) { localLog("startConnectivityScan: screenOn=" + mScreenOn + " wifiState=" + mWifiState - + " forceSelectNetwork=" + forceSelectNetwork + + " scanImmediately=" + scanImmediately + " wifiEnabled=" + mWifiEnabled + " wifiConnectivityManagerEnabled=" + mWifiConnectivityManagerEnabled); @@ -915,10 +927,8 @@ public class WifiConnectivityManager { return; } - mForceSelectNetwork = forceSelectNetwork; - if (mScreenOn) { - startPeriodicScan(); + startPeriodicScan(scanImmediately); } else { // screenOff if (mWifiState == WIFI_STATE_CONNECTED) { startConnectedPnoScan(); @@ -949,7 +959,7 @@ public class WifiConnectivityManager { mScreenOn = screenOn; - startConnectivityScan(false); + startConnectivityScan(SCAN_ON_SCHEDULE); } /** @@ -965,7 +975,7 @@ public class WifiConnectivityManager { scheduleWatchdogTimer(); } - startConnectivityScan(false); + startConnectivityScan(SCAN_ON_SCHEDULE); } /** @@ -976,7 +986,7 @@ public class WifiConnectivityManager { if (mUntrustedConnectionAllowed != allowed) { mUntrustedConnectionAllowed = allowed; - startConnectivityScan(false); + startConnectivityScan(SCAN_IMMEDIATELY); } } @@ -990,10 +1000,6 @@ public class WifiConnectivityManager { mQualifiedNetworkSelector.userSelectNetwork(netId, persistent); clearConnectionAttemptTimeStamps(); - - // Initiate a scan which will trigger the connection to the user selected - // network when scan result is available. - startConnectivityScan(true); } /** @@ -1002,7 +1008,7 @@ public class WifiConnectivityManager { public void forceConnectivityScan() { Log.i(TAG, "forceConnectivityScan"); - startConnectivityScan(false); + startConnectivityScan(SCAN_IMMEDIATELY); } /** @@ -1018,7 +1024,7 @@ public class WifiConnectivityManager { // Disabling a BSSID can happen when the AP candidate to connect to has // no capacity for new stations. We start another scan immediately so that QNS // can give us another candidate to connect to. - startConnectivityScan(false); + startConnectivityScan(SCAN_IMMEDIATELY); } return ret; @@ -1031,7 +1037,7 @@ public class WifiConnectivityManager { Log.i(TAG, "User band preference: " + band); mQualifiedNetworkSelector.setUserPreferredBand(band); - startConnectivityScan(false); + startConnectivityScan(SCAN_IMMEDIATELY); } /** @@ -1044,7 +1050,7 @@ public class WifiConnectivityManager { if (!mWifiEnabled) { stopConnectivityScan(); - mLastPeriodicSingleScanTimeStamp = INVALID_TIME_STAMP; + resetLastPeriodicSingleScanTimeStamp(); } } @@ -1058,6 +1064,7 @@ public class WifiConnectivityManager { if (!mWifiConnectivityManagerEnabled) { stopConnectivityScan(); + resetLastPeriodicSingleScanTimeStamp(); } } @@ -1084,4 +1091,9 @@ public class WifiConnectivityManager { int getLowRssiNetworkRetryDelay() { return mPnoScanListener.getLowRssiNetworkRetryDelay(); } + + @VisibleForTesting + long getLastPeriodicSingleScanTimeStamp() { + return mLastPeriodicSingleScanTimeStamp; + } } |