From 41769d6bebe1cda033204823aee61c8f205fdeff Mon Sep 17 00:00:00 2001 From: David Su Date: Tue, 26 May 2020 22:26:05 -0700 Subject: Add overlays for stationary/moving PNO scan interval Allow customization of the stationary/moving PNO scan interval using overlays. Bug: 157172802 Test: atest WifiConnectivityManagerTest Change-Id: I31a976ae38fa3e5ba25210bcf608afc14f61e672 Merged-In: I31a976ae38fa3e5ba25210bcf608afc14f61e672 --- .../server/wifi/WifiConnectivityManager.java | 33 ++++++++-------------- service/res/values/config.xml | 13 +++++++++ service/res/values/overlayable.xml | 2 ++ 3 files changed, 27 insertions(+), 21 deletions(-) (limited to 'service') 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 @@ false + + + 20000 + + + 60000 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 @@ + + -- cgit v1.2.3