diff options
author | Ahmed ElArabawy <arabawy@google.com> | 2019-11-20 13:07:26 -0800 |
---|---|---|
committer | Ahmed ElArabawy <arabawy@google.com> | 2019-11-22 15:33:46 -0800 |
commit | 38d561fdd3a4df125e285312d38de5b0b26e189a (patch) | |
tree | 29de9378ec5c74eec0dd94259e70d071423088cc /service | |
parent | f197d8606ad319bee12871b47bf2121d014c9b1f (diff) |
Parametrize periodic single scanning schedule
In current implementation, the periodic single scanning schedule used
with screen-on is hardcoded to 20, 40, 80, 160.
In this commit the schedule for both connected and disconnected is
parametrized via the overlay file. This gives OEMs the option to apply
their preferred schedule.
Bug: 141844561
Bug: 140596420
Bug: 141160876
Test: atest com.android.wifi.server
Change-Id: I8c739e2ce22c484b80ab310a2e8b370c457d876e
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/WifiConnectivityManager.java | 103 | ||||
-rw-r--r-- | service/res/values/config.xml | 16 | ||||
-rw-r--r-- | service/res/values/overlayable.xml | 2 |
3 files changed, 101 insertions, 20 deletions
diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java index b51c2ff59..25d52bb97 100644 --- a/service/java/com/android/server/wifi/WifiConnectivityManager.java +++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java @@ -71,15 +71,6 @@ public class WifiConnectivityManager { // 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 - public static final int PERIODIC_SCAN_INTERVAL_MS = 20 * 1000; // 20 seconds - // When screen is on and WiFi traffic is heavy, exponential backoff - // connectivity scans are scheduled. This constant defines the maximum - // scan interval in this scenario. - @VisibleForTesting - public static final int MAX_PERIODIC_SCAN_INTERVAL_MS = 160 * 1000; // 160 seconds // Initial PNO scan interval in milliseconds when the device is moving. The scan interval backs // off from this initial interval on subsequent scans. This scan is performed when screen is // off and disconnected. @@ -160,7 +151,6 @@ public class WifiConnectivityManager { private int mSingleScanRestartCount = 0; private int mTotalConnectivityAttemptsRateLimited = 0; private String mLastConnectionAttemptBssid = null; - private int mPeriodicSingleScanInterval = PERIODIC_SCAN_INTERVAL_MS; private long mLastPeriodicSingleScanTimeStamp = RESET_TIME_STAMP; private boolean mPnoScanStarted = false; private boolean mPeriodicScanTimerSet = false; @@ -180,6 +170,14 @@ public class WifiConnectivityManager { private int mRssiScoreSlope; private int mPnoScanIntervalMs; + // Scanning Schedules + // Default schedule used in case of invalid configuration + private static final int[] DEFAULT_SCANNING_SCHEDULE = {20, 40, 80, 160}; + private final int[] mConnectedSingleScanSchedule; + private final int[] mDisconnectedSingleScanSchedule; + private int[] mCurrentSingleScanSchedule; + private int mCurrentSingleScanScheduleIndex; + private WifiChannelUtilization mWifiChannelUtilization; // A helper to log debugging information in the local log buffer, which can @@ -600,12 +598,15 @@ public class WifiConnectivityManager { mUseSingleRadioChainScanResults = context.getResources().getBoolean( R.bool.config_wifi_framework_use_single_radio_chain_scan_results_network_selection); - mFullScanMaxTxRate = context.getResources().getInteger( R.integer.config_wifi_framework_max_tx_rate_for_full_scan); mFullScanMaxRxRate = context.getResources().getInteger( R.integer.config_wifi_framework_max_rx_rate_for_full_scan); + mConnectedSingleScanSchedule = initializeScanningSchedule(context, WIFI_STATE_CONNECTED); + mDisconnectedSingleScanSchedule = initializeScanningSchedule(context, + WIFI_STATE_DISCONNECTED); + mPnoScanIntervalMs = MOVING_PNO_SCAN_INTERVAL_MS; localLog("PNO settings:" @@ -623,6 +624,40 @@ public class WifiConnectivityManager { mNetworkSelector.setWifiChannelUtilization(mWifiChannelUtilization); } + /** Initialize single scanning schedules, and validate them */ + private int[] initializeScanningSchedule(Context context, int state) { + int[] schedule; + + if (state == WIFI_STATE_CONNECTED) { + schedule = context.getResources().getIntArray( + R.array.config_wifiConnectedScanIntervalScheduleSec); + } else if (state == WIFI_STATE_DISCONNECTED) { + schedule = context.getResources().getIntArray( + R.array.config_wifiDisconnectedScanIntervalScheduleSec); + } else { + schedule = null; + } + + boolean invalidConfig = false; + if (schedule == null || schedule.length == 0) { + invalidConfig = true; + } else { + for (int val : schedule) { + if (val <= 0) { + invalidConfig = true; + break; + } + } + } + if (!invalidConfig) { + return schedule; + } + + Log.e(TAG, "Configuration for wifi scanning schedule is mis-configured," + + "using default schedule"); + return DEFAULT_SCANNING_SCHEDULE; + } + /** Returns maximum PNO score, before any awards/bonuses. */ private int initialScoreMax() { return mRssiScoreSlope * (Math.max(mScoringParams.getGoodRssi(ScoringParams.BAND2), @@ -811,10 +846,11 @@ public class WifiConnectivityManager { if (mLastPeriodicSingleScanTimeStamp != RESET_TIME_STAMP) { long msSinceLastScan = currentTimeStamp - mLastPeriodicSingleScanTimeStamp; - if (msSinceLastScan < PERIODIC_SCAN_INTERVAL_MS) { + if (msSinceLastScan < getScheduledSingleScanInterval(0)) { localLog("Last periodic single scan started " + msSinceLastScan + "ms ago, defer this new scan request."); - schedulePeriodicScanTimer(PERIODIC_SCAN_INTERVAL_MS - (int) msSinceLastScan); + schedulePeriodicScanTimer( + getScheduledSingleScanInterval(0) - (int) msSinceLastScan); return; } } @@ -841,16 +877,35 @@ public class WifiConnectivityManager { if (isScanNeeded) { mLastPeriodicSingleScanTimeStamp = currentTimeStamp; startSingleScan(isFullBandScan, WIFI_WORK_SOURCE); - schedulePeriodicScanTimer(mPeriodicSingleScanInterval); + schedulePeriodicScanTimer( + getScheduledSingleScanInterval(mCurrentSingleScanScheduleIndex)); // Set up the next scan interval in an exponential backoff fashion. - mPeriodicSingleScanInterval *= 2; - if (mPeriodicSingleScanInterval > MAX_PERIODIC_SCAN_INTERVAL_MS) { - mPeriodicSingleScanInterval = MAX_PERIODIC_SCAN_INTERVAL_MS; - } + incrementSingleScanningIndex(); } else { // Since we already skipped this scan, keep the same scan interval for next scan. - schedulePeriodicScanTimer(mPeriodicSingleScanInterval); + schedulePeriodicScanTimer( + getScheduledSingleScanInterval(mCurrentSingleScanScheduleIndex)); + } + } + + // Retrieve a value from single scanning schedule in ms + private int getScheduledSingleScanInterval(int index) { + if (mCurrentSingleScanSchedule != null && mCurrentSingleScanSchedule.length > index) { + return mCurrentSingleScanSchedule[index] * 1000; + } else { + Log.e(TAG, "Invalid attempt to get schedule interval value, " + + ((mCurrentSingleScanSchedule == null) ? "Schedule array is null" + : "invalid index")); + // Use a default value + return DEFAULT_SCANNING_SCHEDULE[0]; + } + } + + // Step up index for single scanning + private void incrementSingleScanningIndex() { + if (mCurrentSingleScanScheduleIndex < (mCurrentSingleScanSchedule.length - 1)) { + mCurrentSingleScanScheduleIndex++; } } @@ -918,7 +973,7 @@ public class WifiConnectivityManager { if (scanImmediately) { resetLastPeriodicSingleScanTimeStamp(); } - mPeriodicSingleScanInterval = PERIODIC_SCAN_INTERVAL_MS; + mCurrentSingleScanScheduleIndex = 0; startPeriodicSingleScan(); } @@ -1154,8 +1209,16 @@ public class WifiConnectivityManager { if (mWifiState == WIFI_STATE_DISCONNECTED) { mLastConnectionAttemptBssid = null; scheduleWatchdogTimer(); + // Switch to the disconnected scanning schedule + mCurrentSingleScanSchedule = mDisconnectedSingleScanSchedule; startConnectivityScan(SCAN_IMMEDIATELY); + } else if (mWifiState == WIFI_STATE_CONNECTED) { + // Switch to connected single scanning schedule + mCurrentSingleScanSchedule = mConnectedSingleScanSchedule; + startConnectivityScan(SCAN_ON_SCHEDULE); } else { + // Intermediate state, no applicable single scanning schedule + mCurrentSingleScanSchedule = null; startConnectivityScan(SCAN_ON_SCHEDULE); } } diff --git a/service/res/values/config.xml b/service/res/values/config.xml index ff0befd5b..eb9928b52 100644 --- a/service/res/values/config.xml +++ b/service/res/values/config.xml @@ -204,4 +204,20 @@ <item>-55</item> <!-- [-66, -55) 3 --> <!-- [-55, +infinity) 4 --> </integer-array> + + <!-- Array describing scanning schedule in seconds when device is disconnected and screen is on --> + <integer-array translatable="false" name="config_wifiDisconnectedScanIntervalScheduleSec"> + <item>20</item> + <item>40</item> + <item>80</item> + <item>160</item> + </integer-array> + + <!-- Array describing scanning schedule in seconds when device is connected and screen is on --> + <integer-array translatable="false" name="config_wifiConnectedScanIntervalScheduleSec"> + <item>20</item> + <item>40</item> + <item>80</item> + <item>160</item> + </integer-array> </resources> diff --git a/service/res/values/overlayable.xml b/service/res/values/overlayable.xml index b7bcad273..8fc141017 100644 --- a/service/res/values/overlayable.xml +++ b/service/res/values/overlayable.xml @@ -78,6 +78,8 @@ <item type="bool" name="config_wifi_diagnostics_bugreport_enabled" /> <item type="bool" name="config_wifi_watchdog_enabled" /> <item type="array" name="config_wifiRssiLevelThresholds" /> + <item type="array" name="config_wifiDisconnectedScanIntervalScheduleSec" /> + <item type="array" name="config_wifiConnectedScanIntervalScheduleSec" /> <!-- Params from config.xml that can be overlayed --> <!-- Params from strings.xml that can be overlayed --> |