diff options
author | Ahmed ElArabawy <arabawy@google.com> | 2019-11-22 23:36:19 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-11-22 23:36:19 +0000 |
commit | 890b3372d493c5f19101c163faaa54ef73282857 (patch) | |
tree | f1e322f0396a17375a43a6405df7ccfeb47183a2 | |
parent | 5061866142919467d1119c6c5e2cd4e64cb9f25e (diff) | |
parent | 38d561fdd3a4df125e285312d38de5b0b26e189a (diff) |
Merge "Parametrize periodic single scanning schedule"
-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 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java | 167 |
4 files changed, 241 insertions, 47 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 --> diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java index be78461ee..96e5b5d22 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java @@ -162,7 +162,14 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { private static final String INVALID_SCAN_RESULT_BSSID = "6c:f3:7f:ae:8c:f4"; private static final long CURRENT_SYSTEM_TIME_MS = 1000; private static final int MAX_BSSID_BLACKLIST_SIZE = 16; - + private static final int[] VALID_CONNECTED_SINGLE_SCAN_SCHEDULE = {10, 30, 50}; + private static final int[] VALID_DISCONNECTED_SINGLE_SCAN_SCHEDULE = {25, 40, 60}; + private static final int[] INVALID_SCHEDULE_EMPTY = {}; + private static final int[] INVALID_SCHEDULE_NEGATIVE_VALUES = {10, -10, 20}; + private static final int[] INVALID_SCHEDULE_ZERO_VALUES = {10, 0, 20}; + private static final int MAX_SCAN_INTERVAL_IN_SCHEDULE = 60; + private static final int[] DEFAULT_SINGLE_SCAN_SCHEDULE = {20, 40, 80, 160}; + private static final int MAX_SCAN_INTERVAL_IN_DEFAULT_SCHEDULE = 160; Resources mockResource() { Resources resource = mock(Resources.class); @@ -180,6 +187,13 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { R.integer.config_wifi_framework_max_tx_rate_for_full_scan)).thenReturn(8); when(resource.getInteger( R.integer.config_wifi_framework_max_rx_rate_for_full_scan)).thenReturn(16); + when(resource.getIntArray( + R.array.config_wifiConnectedScanIntervalScheduleSec)) + .thenReturn(VALID_CONNECTED_SINGLE_SCAN_SCHEDULE); + when(resource.getIntArray( + R.array.config_wifiDisconnectedScanIntervalScheduleSec)) + .thenReturn(VALID_DISCONNECTED_SINGLE_SCAN_SCHEDULE); + return resource; } @@ -761,6 +775,102 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { } /** + * Verify that if configuration for single scan schedule is empty, default + * schedule is being used. + */ + @Test + public void checkPeriodicScanIntervalWhenDisconnectedWithEmptySchedule() throws Exception { + when(mResource.getIntArray(R.array.config_wifiDisconnectedScanIntervalScheduleSec)) + .thenReturn(INVALID_SCHEDULE_EMPTY); + + checkWorkingWithDefaultSchedule(); + } + + /** + * Verify that if configuration for single scan schedule has zero values, default + * schedule is being used. + */ + @Test + public void checkPeriodicScanIntervalWhenDisconnectedWithZeroValuesSchedule() { + when(mResource.getIntArray(R.array.config_wifiDisconnectedScanIntervalScheduleSec)) + .thenReturn(INVALID_SCHEDULE_ZERO_VALUES); + + checkWorkingWithDefaultSchedule(); + } + + /** + * Verify that if configuration for single scan schedule has negative values, default + * schedule is being used. + */ + @Test + public void checkPeriodicScanIntervalWhenDisconnectedWithNegativeValuesSchedule() { + when(mResource.getIntArray(R.array.config_wifiDisconnectedScanIntervalScheduleSec)) + .thenReturn(INVALID_SCHEDULE_NEGATIVE_VALUES); + + checkWorkingWithDefaultSchedule(); + } + + private void checkWorkingWithDefaultSchedule() { + long currentTimeStamp = CURRENT_SYSTEM_TIME_MS; + when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); + + mWifiConnectivityManager = createConnectivityManager(); + mWifiConnectivityManager.setTrustedConnectionAllowed(true); + mWifiConnectivityManager.setWifiEnabled(true); + + // Set screen to ON + mWifiConnectivityManager.handleScreenStateChanged(true); + + // Wait for max periodic scan interval so that any impact triggered + // by screen state change can settle + currentTimeStamp += MAX_SCAN_INTERVAL_IN_DEFAULT_SCHEDULE * 1000; + when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); + + // Set WiFi to disconnected state to trigger periodic scan + mWifiConnectivityManager.handleConnectionStateChanged( + WifiConnectivityManager.WIFI_STATE_DISCONNECTED); + + // Get the first periodic scan interval + long firstIntervalMs = mAlarmManager + .getTriggerTimeMillis(WifiConnectivityManager.PERIODIC_SCAN_TIMER_TAG) + - currentTimeStamp; + assertEquals(DEFAULT_SINGLE_SCAN_SCHEDULE[0] * 1000, firstIntervalMs); + + currentTimeStamp += firstIntervalMs; + when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); + + // Now fire the first periodic scan alarm timer + mAlarmManager.dispatch(WifiConnectivityManager.PERIODIC_SCAN_TIMER_TAG); + mLooper.dispatchAll(); + + // Get the second periodic scan interval + long secondIntervalMs = mAlarmManager + .getTriggerTimeMillis(WifiConnectivityManager.PERIODIC_SCAN_TIMER_TAG) + - currentTimeStamp; + + // Verify the intervals are exponential back off + assertEquals(DEFAULT_SINGLE_SCAN_SCHEDULE[1] * 1000, secondIntervalMs); + + currentTimeStamp += secondIntervalMs; + when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); + + // Make sure we eventually stay at the maximum scan interval. + long intervalMs = 0; + for (int i = 0; i < 5; i++) { + mAlarmManager.dispatch(WifiConnectivityManager.PERIODIC_SCAN_TIMER_TAG); + mLooper.dispatchAll(); + intervalMs = mAlarmManager + .getTriggerTimeMillis(WifiConnectivityManager.PERIODIC_SCAN_TIMER_TAG) + - currentTimeStamp; + currentTimeStamp += intervalMs; + when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); + } + + assertEquals(DEFAULT_SINGLE_SCAN_SCHEDULE[DEFAULT_SINGLE_SCAN_SCHEDULE.length - 1] * 1000, + intervalMs); + } + + /** * Verify that scan interval for screen on and wifi disconnected scenario * is in the exponential backoff fashion. * @@ -775,9 +885,9 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { // Set screen to ON mWifiConnectivityManager.handleScreenStateChanged(true); - // Wait for MAX_PERIODIC_SCAN_INTERVAL_MS so that any impact triggered + // Wait for max periodic scan interval so that any impact triggered // by screen state change can settle - currentTimeStamp += WifiConnectivityManager.MAX_PERIODIC_SCAN_INTERVAL_MS; + currentTimeStamp += MAX_SCAN_INTERVAL_IN_SCHEDULE * 1000; when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); // Set WiFi to disconnected state to trigger periodic scan @@ -788,7 +898,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { long firstIntervalMs = mAlarmManager .getTriggerTimeMillis(WifiConnectivityManager.PERIODIC_SCAN_TIMER_TAG) - currentTimeStamp; - assertEquals(firstIntervalMs, WifiConnectivityManager.PERIODIC_SCAN_INTERVAL_MS); + assertEquals(VALID_DISCONNECTED_SINGLE_SCAN_SCHEDULE[0] * 1000, firstIntervalMs); currentTimeStamp += firstIntervalMs; when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); @@ -803,7 +913,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { - currentTimeStamp; // Verify the intervals are exponential back off - assertEquals(firstIntervalMs * 2, secondIntervalMs); + assertEquals(VALID_DISCONNECTED_SINGLE_SCAN_SCHEDULE[1] * 1000, secondIntervalMs); currentTimeStamp += secondIntervalMs; when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); @@ -820,7 +930,8 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); } - assertEquals(intervalMs, WifiConnectivityManager.MAX_PERIODIC_SCAN_INTERVAL_MS); + assertEquals(VALID_DISCONNECTED_SINGLE_SCAN_SCHEDULE[ + VALID_DISCONNECTED_SINGLE_SCAN_SCHEDULE.length - 1] * 1000, intervalMs); } /** @@ -838,9 +949,9 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { // Set screen to ON mWifiConnectivityManager.handleScreenStateChanged(true); - // Wait for MAX_PERIODIC_SCAN_INTERVAL_MS so that any impact triggered + // Wait for max scanning interval so that any impact triggered // by screen state change can settle - currentTimeStamp += WifiConnectivityManager.MAX_PERIODIC_SCAN_INTERVAL_MS; + currentTimeStamp += MAX_SCAN_INTERVAL_IN_SCHEDULE * 1000; when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); // Set WiFi to connected state to trigger periodic scan @@ -851,7 +962,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { long firstIntervalMs = mAlarmManager .getTriggerTimeMillis(WifiConnectivityManager.PERIODIC_SCAN_TIMER_TAG) - currentTimeStamp; - assertEquals(firstIntervalMs, WifiConnectivityManager.PERIODIC_SCAN_INTERVAL_MS); + assertEquals(VALID_CONNECTED_SINGLE_SCAN_SCHEDULE[0] * 1000, firstIntervalMs); currentTimeStamp += firstIntervalMs; when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); @@ -866,7 +977,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { - currentTimeStamp; // Verify the intervals are exponential back off - assertEquals(firstIntervalMs * 2, secondIntervalMs); + assertEquals(VALID_CONNECTED_SINGLE_SCAN_SCHEDULE[1] * 1000, secondIntervalMs); currentTimeStamp += secondIntervalMs; when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); @@ -883,7 +994,8 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); } - assertEquals(intervalMs, WifiConnectivityManager.MAX_PERIODIC_SCAN_INTERVAL_MS); + assertEquals(VALID_CONNECTED_SINGLE_SCAN_SCHEDULE[ + VALID_CONNECTED_SINGLE_SCAN_SCHEDULE.length - 1] * 1000, intervalMs); } /** @@ -891,7 +1003,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { * change event back to back to verify that the minium scan interval is enforced. * * Expected behavior: WifiConnectivityManager start the second periodic single - * scan PERIODIC_SCAN_INTERVAL_MS after the first one. + * scan after the first one by first interval in connected scanning schedule. */ @Test public void checkMinimumPeriodicScanIntervalWhenScreenOnAndConnected() { @@ -901,9 +1013,9 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { // Set screen to ON mWifiConnectivityManager.handleScreenStateChanged(true); - // Wait for MAX_PERIODIC_SCAN_INTERVAL_MS so that any impact triggered + // Wait for max scanning interval in schedule so that any impact triggered // by screen state change can settle - currentTimeStamp += WifiConnectivityManager.MAX_PERIODIC_SCAN_INTERVAL_MS; + currentTimeStamp += MAX_SCAN_INTERVAL_IN_SCHEDULE * 1000; long scanForDisconnectedTimeStamp = currentTimeStamp; when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); @@ -925,10 +1037,10 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { long firstScanForConnectedTimeStamp = mAlarmManager .getTriggerTimeMillis(WifiConnectivityManager.PERIODIC_SCAN_TIMER_TAG); - // Verify that the first scan for connected state is scheduled PERIODIC_SCAN_INTERVAL_MS - // after the scan for disconnected state - assertEquals(firstScanForConnectedTimeStamp, scanForDisconnectedTimeStamp - + WifiConnectivityManager.PERIODIC_SCAN_INTERVAL_MS); + // Verify that the first scan for connected state is scheduled after the scan for + // disconnected state by first interval in connected scanning schedule. + assertEquals(scanForDisconnectedTimeStamp + VALID_CONNECTED_SINGLE_SCAN_SCHEDULE[0] * 1000, + firstScanForConnectedTimeStamp); } /** @@ -948,9 +1060,9 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { // Set screen to ON mWifiConnectivityManager.handleScreenStateChanged(true); - // Wait for MAX_PERIODIC_SCAN_INTERVAL_MS so that any impact triggered + // Wait for maximum scanning interval in schedule so that any impact triggered // by screen state change can settle - currentTimeStamp += WifiConnectivityManager.MAX_PERIODIC_SCAN_INTERVAL_MS; + currentTimeStamp += MAX_SCAN_INTERVAL_IN_SCHEDULE * 1000; long scanForConnectedTimeStamp = currentTimeStamp; when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); @@ -973,10 +1085,11 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { long secondScanForDisconnectedTimeStamp = mAlarmManager .getTriggerTimeMillis(WifiConnectivityManager.PERIODIC_SCAN_TIMER_TAG); - // Verify that the second scan is scheduled PERIODIC_SCAN_INTERVAL_MS after - // entering DISCONNECTED state. - assertEquals(secondScanForDisconnectedTimeStamp, enteringDisconnectedStateTimeStamp - + WifiConnectivityManager.PERIODIC_SCAN_INTERVAL_MS); + // Verify that the second scan is scheduled after entering DISCONNECTED state by first + // interval in disconnected scanning schedule. + assertEquals(enteringDisconnectedStateTimeStamp + + VALID_DISCONNECTED_SINGLE_SCAN_SCHEDULE[0] * 1000, + secondScanForDisconnectedTimeStamp); } /** @@ -995,9 +1108,9 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { // Set screen to ON mWifiConnectivityManager.handleScreenStateChanged(true); - // Wait for MAX_PERIODIC_SCAN_INTERVAL_MS so that any impact triggered + // Wait for maximum interval in scanning schedule so that any impact triggered // by screen state change can settle - currentTimeStamp += WifiConnectivityManager.MAX_PERIODIC_SCAN_INTERVAL_MS; + currentTimeStamp += MAX_SCAN_INTERVAL_IN_SCHEDULE * 1000; long firstScanTimeStamp = currentTimeStamp; when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); @@ -1146,7 +1259,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { long firstIntervalMs = mAlarmManager .getTriggerTimeMillis(WifiConnectivityManager.PERIODIC_SCAN_TIMER_TAG) - currentTimeStamp; - assertEquals(firstIntervalMs, WifiConnectivityManager.PERIODIC_SCAN_INTERVAL_MS); + assertEquals(VALID_CONNECTED_SINGLE_SCAN_SCHEDULE[0] * 1000, firstIntervalMs); } /** |