diff options
4 files changed, 37 insertions, 29 deletions
diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java index 8470d0c7d..b6f4baff5 100644 --- a/service/java/com/android/server/wifi/WifiConnectivityManager.java +++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java @@ -85,16 +85,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; - // 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. - @VisibleForTesting - static final int MOVING_PNO_SCAN_INTERVAL_MS = 20 * 1000; // 20 seconds - // Initial PNO scan interval in milliseconds when the device is stationary. The scan interval - // backs off from this initial interval on subsequent scans. This scan is performed when screen - // is off and disconnected. - @VisibleForTesting - static final int STATIONARY_PNO_SCAN_INTERVAL_MS = 60 * 1000; // 1 minute // PNO scan interval in milli-seconds. This is the scan // performed when screen is off and connected. @@ -208,7 +198,6 @@ public class WifiConnectivityManager { private int[] mCurrentSingleScanScheduleSec; private int mCurrentSingleScanScheduleIndex; - private int mPnoScanIntervalMs; private WifiChannelUtilization mWifiChannelUtilization; // Cached WifiCandidates used in high mobility state to avoid connecting to APs that are // moving relative to the user. @@ -792,7 +781,6 @@ public class WifiConnectivityManager { mClock = clock; mScoringParams = scoringParams; mConnectionAttemptTimeStamps = new LinkedList<>(); - mPnoScanIntervalMs = MOVING_PNO_SCAN_INTERVAL_MS; // Listen to WifiConfigManager network update events mConfigManager.addOnNetworkUpdateListener(new OnNetworkUpdateListener()); @@ -1321,14 +1309,16 @@ public class WifiConnectivityManager { startPeriodicSingleScan(); } - private static int deviceMobilityStateToPnoScanIntervalMs(@DeviceMobilityState int state) { + private int deviceMobilityStateToPnoScanIntervalMs(@DeviceMobilityState int state) { switch (state) { case WifiManager.DEVICE_MOBILITY_STATE_UNKNOWN: case WifiManager.DEVICE_MOBILITY_STATE_LOW_MVMT: case WifiManager.DEVICE_MOBILITY_STATE_HIGH_MVMT: - return MOVING_PNO_SCAN_INTERVAL_MS; + return mContext.getResources() + .getInteger(R.integer.config_wifiMovingPnoScanIntervalMillis); case WifiManager.DEVICE_MOBILITY_STATE_STATIONARY: - return STATIONARY_PNO_SCAN_INTERVAL_MS; + return mContext.getResources() + .getInteger(R.integer.config_wifiStationaryPnoScanIntervalMillis); default: return -1; } @@ -1343,16 +1333,18 @@ public class WifiConnectivityManager { * @param newState the new device mobility state */ public void setDeviceMobilityState(@DeviceMobilityState int newState) { - mDeviceMobilityState = newState; + int oldDeviceMobilityState = mDeviceMobilityState; localLog("Device mobility state changed. state=" + newState); - mWifiChannelUtilization.setDeviceMobilityState(newState); int newPnoScanIntervalMs = deviceMobilityStateToPnoScanIntervalMs(newState); if (newPnoScanIntervalMs < 0) { Log.e(TAG, "Invalid device mobility state: " + newState); return; } + mDeviceMobilityState = newState; + mWifiChannelUtilization.setDeviceMobilityState(newState); - if (newPnoScanIntervalMs == mPnoScanIntervalMs) { + int oldPnoScanIntervalMs = deviceMobilityStateToPnoScanIntervalMs(oldDeviceMobilityState); + if (newPnoScanIntervalMs == oldPnoScanIntervalMs) { if (mPnoScanStarted) { mWifiMetrics.logPnoScanStop(); mWifiMetrics.enterDeviceMobilityState(newState); @@ -1361,8 +1353,7 @@ public class WifiConnectivityManager { mWifiMetrics.enterDeviceMobilityState(newState); } } else { - mPnoScanIntervalMs = newPnoScanIntervalMs; - Log.d(TAG, "PNO Scan Interval changed to " + mPnoScanIntervalMs + " ms."); + Log.d(TAG, "PNO Scan Interval changed to " + newPnoScanIntervalMs + " ms."); if (mPnoScanStarted) { Log.d(TAG, "Restarting PNO Scan with new scan interval"); @@ -1400,7 +1391,7 @@ public class WifiConnectivityManager { scanSettings.band = getScanBand(); scanSettings.reportEvents = WifiScanner.REPORT_EVENT_NO_BATCH; scanSettings.numBssidsPerScan = 0; - scanSettings.periodInMs = mPnoScanIntervalMs; + scanSettings.periodInMs = deviceMobilityStateToPnoScanIntervalMs(mDeviceMobilityState); mPnoScanListener.clearScanDetails(); diff --git a/service/res/values/config.xml b/service/res/values/config.xml index dc2538cbc..4451f7c12 100644 --- a/service/res/values/config.xml +++ b/service/res/values/config.xml @@ -417,4 +417,17 @@ <!-- Wifi driver Automatic channel selection (ACS) for softap to include DFS channels --> <bool translatable="false" name="config_wifiSoftapAcsIncludeDfs">false</bool> + + <!-- Initial PNO scan interval, in milliseconds, when the device is moving (i.e. + WifiManager.DEVICE_MOBILITY_STATE_UNKNOWN, WifiManager.DEVICE_MOBILITY_STATE_HIGH_MVMT, or + WifiManager.DEVICE_MOBILITY_STATE_LOW_MVMT). + The scan interval backs off from this initial interval on subsequent scans. + This scan is performed when screen is off and disconnected. --> + <integer translatable="false" name="config_wifiMovingPnoScanIntervalMillis">20000</integer> + + <!-- Initial PNO scan interval, in milliseconds, when the device is stationary (i.e. + WifiManager.DEVICE_MOBILITY_STATE_STATIONARY). + The scan interval backs off from this initial interval on subsequent scans. + This scan is performed when screen is off and disconnected. --> + <integer translatable="false" name="config_wifiStationaryPnoScanIntervalMillis">60000</integer> </resources> diff --git a/service/res/values/overlayable.xml b/service/res/values/overlayable.xml index 52ef09e4f..9e0a18d7d 100644 --- a/service/res/values/overlayable.xml +++ b/service/res/values/overlayable.xml @@ -131,6 +131,8 @@ <item type="integer" name="config_wifiMaxNativeFailureSelfRecoveryPerHour" /> <item type="bool" name="config_wifiIgnoreOpenSavedNetworkWhenSecureSuggestionAvailable" /> <item type="bool" name="config_wifiSoftapAcsIncludeDfs" /> + <item type="integer" name="config_wifiMovingPnoScanIntervalMillis" /> + <item type="integer" name="config_wifiStationaryPnoScanIntervalMillis" /> <!-- Params from config.xml that can be overlayed --> <!-- Params from strings.xml that can be overlayed --> diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java index b01f2beb1..f3ba436cc 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java @@ -160,6 +160,10 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { HIGH_MVMT_RSSI_DELTA); resources.setInteger(R.integer.config_wifiInitialPartialScanChannelCacheAgeMins, CHANNEL_CACHE_AGE_MINS); + resources.setInteger(R.integer.config_wifiMovingPnoScanIntervalMillis, + MOVING_PNO_SCAN_INTERVAL_MILLIS); + resources.setInteger(R.integer.config_wifiStationaryPnoScanIntervalMillis, + STATIONARY_PNO_SCAN_INTERVAL_MILLIS); } /** @@ -244,6 +248,8 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { private static final int TEMP_BSSID_BLOCK_DURATION_MS = 10 * 1000; // 10 seconds private static final int TEST_CONNECTED_NETWORK_ID = 55; private static final int CHANNEL_CACHE_AGE_MINS = 14400; + private static final int MOVING_PNO_SCAN_INTERVAL_MILLIS = 20_000; + private static final int STATIONARY_PNO_SCAN_INTERVAL_MILLIS = 60_000; Context mockContext() { Context context = mock(Context.class); @@ -2730,8 +2736,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { inOrder.verify(mWifiScanner).startDisconnectedPnoScan( scanSettingsCaptor.capture(), any(), any(), any()); - assertEquals(scanSettingsCaptor.getValue().periodInMs, - WifiConnectivityManager.MOVING_PNO_SCAN_INTERVAL_MS); + assertEquals(scanSettingsCaptor.getValue().periodInMs, MOVING_PNO_SCAN_INTERVAL_MILLIS); // initial connectivity state uses moving PNO scan interval, now set it to stationary mWifiConnectivityManager.setDeviceMobilityState( @@ -2740,8 +2745,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { inOrder.verify(mWifiScanner).stopPnoScan(any()); inOrder.verify(mWifiScanner).startDisconnectedPnoScan( scanSettingsCaptor.capture(), any(), any(), any()); - assertEquals(scanSettingsCaptor.getValue().periodInMs, - WifiConnectivityManager.STATIONARY_PNO_SCAN_INTERVAL_MS); + assertEquals(scanSettingsCaptor.getValue().periodInMs, STATIONARY_PNO_SCAN_INTERVAL_MILLIS); verify(mScoringParams, times(2)).getEntryRssi(ScanResult.BAND_6_GHZ_START_FREQ_MHZ); verify(mScoringParams, times(2)).getEntryRssi(ScanResult.BAND_5_GHZ_START_FREQ_MHZ); verify(mScoringParams, times(2)).getEntryRssi(ScanResult.BAND_24_GHZ_START_FREQ_MHZ); @@ -2766,8 +2770,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { inOrder.verify(mWifiScanner, never()).stopPnoScan(any()); inOrder.verify(mWifiScanner).startDisconnectedPnoScan( scanSettingsCaptor.capture(), any(), any(), any()); - assertEquals(scanSettingsCaptor.getValue().periodInMs, - WifiConnectivityManager.MOVING_PNO_SCAN_INTERVAL_MS); + assertEquals(scanSettingsCaptor.getValue().periodInMs, MOVING_PNO_SCAN_INTERVAL_MILLIS); mWifiConnectivityManager.setDeviceMobilityState( WifiManager.DEVICE_MOBILITY_STATE_LOW_MVMT); @@ -2805,8 +2808,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { scanSettingsCaptor.capture(), any(), any(), any()); // check that now the PNO scan uses the stationary interval, even though it was set before // the PNO scan started - assertEquals(scanSettingsCaptor.getValue().periodInMs, - WifiConnectivityManager.STATIONARY_PNO_SCAN_INTERVAL_MS); + assertEquals(scanSettingsCaptor.getValue().periodInMs, STATIONARY_PNO_SCAN_INTERVAL_MILLIS); } /** |