From 3d896dcda63181f8a2a92fb3d26b0d74dc766b10 Mon Sep 17 00:00:00 2001 From: Mingguang Xu Date: Wed, 12 Aug 2020 00:17:54 -0700 Subject: Wifi usability: Add minimum confirmation duration for sending network score to connectivity service when score breaches 1. Add a flag in config overlay to control whether adding minimum confirmation duration is enabled or not. By default it is not enabled. 2. The minimum confirmation duration is configurable via DeviceConfigFacade. 3. The minimum confirmation duration only applies to sending network score to ConnectivityService. No confirmation duration is needed for triggering NUD check and WiFi metric collection. Bug: 163348782 Test: atest com.android.server.wifi Signed-off-by: Mingguang Xu Change-Id: I0abe68f72c64c26fc75e8bc5edc7d341eae54133 Merged-In: I0abe68f72c64c26fc75e8bc5edc7d341eae54133 --- .../com/android/server/wifi/ClientModeImpl.java | 3 +- .../android/server/wifi/DeviceConfigFacade.java | 35 +++++++++++- .../com/android/server/wifi/WifiScoreReport.java | 63 +++++++++++++++++----- service/res/values/config.xml | 3 ++ service/res/values/overlayable.xml | 1 + 5 files changed, 90 insertions(+), 15 deletions(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java index 6c31185da..e90064679 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -811,7 +811,8 @@ public class ClientModeImpl extends StateMachine { mWifiScoreReport = new WifiScoreReport(mWifiInjector.getScoringParams(), mClock, mWifiMetrics, mWifiInfo, mWifiNative, mBssidBlocklistMonitor, - mWifiInjector.getWifiThreadRunner()); + mWifiInjector.getWifiThreadRunner(), mWifiInjector.getDeviceConfigFacade(), + mContext); mNetworkCapabilitiesFilter = new NetworkCapabilities.Builder() .addTransportType(NetworkCapabilities.TRANSPORT_WIFI) diff --git a/service/java/com/android/server/wifi/DeviceConfigFacade.java b/service/java/com/android/server/wifi/DeviceConfigFacade.java index 0b707701f..3856ff1fd 100644 --- a/service/java/com/android/server/wifi/DeviceConfigFacade.java +++ b/service/java/com/android/server/wifi/DeviceConfigFacade.java @@ -129,6 +129,16 @@ public class DeviceConfigFacade { // Default health monitor firmware alert valid time. // -1 disables firmware alert time check static final int DEFAULT_HEALTH_MONITOR_FW_ALERT_VALID_TIME_MS = -1; + // Default minimum confirmation duration for sending network score to connectivity service + // when score breaches low. The actual confirmation duration is longer in general and it + // depends on the score evaluation period normally controlled by + // 'com.android.wifi.resources.R' config_wifiPollRssiIntervalMilliseconds. + static final int DEFAULT_MIN_CONFIRMATION_DURATION_SEND_LOW_SCORE_MS = 5000; + // Default minimum confirmation duration for sending network score to connectivity service + // when score breaches high. The actual confirmation duration is longer in general and it + // depends on the score evaluation period normally controlled by + // 'com.android.wifi.resources.R' config_wifiPollRssiIntervalMilliseconds. + static final int DEFAULT_MIN_CONFIRMATION_DURATION_SEND_HIGH_SCORE_MS = 0; // Cached values of fields updated via updateDeviceConfigFlags() private boolean mIsAbnormalConnectionBugreportEnabled; private int mAbnormalConnectionDurationMs; @@ -177,6 +187,8 @@ public class DeviceConfigFacade { private int mNonstationaryScanRssiValidTimeMs; private int mStationaryScanRssiValidTimeMs; private int mHealthMonitorFwAlertValidTimeMs; + private int mMinConfirmationDurationSendLowScoreMs; + private int mMinConfirmationDurationSendHighScoreMs; public DeviceConfigFacade(Context context, Handler handler, WifiMetrics wifiMetrics) { mContext = context; @@ -324,7 +336,12 @@ public class DeviceConfigFacade { "health_monitor_fw_alert_valid_time_ms", DEFAULT_HEALTH_MONITOR_FW_ALERT_VALID_TIME_MS); mWifiMetrics.setHealthMonitorRssiPollValidTimeMs(mHealthMonitorRssiPollValidTimeMs); - + mMinConfirmationDurationSendLowScoreMs = DeviceConfig.getInt(NAMESPACE, + "min_confirmation_duration_send_low_score_ms", + DEFAULT_MIN_CONFIRMATION_DURATION_SEND_LOW_SCORE_MS); + mMinConfirmationDurationSendHighScoreMs = DeviceConfig.getInt(NAMESPACE, + "min_confirmation_duration_send_high_score_ms", + DEFAULT_MIN_CONFIRMATION_DURATION_SEND_HIGH_SCORE_MS); } private Set getUnmodifiableSetQuoted(String key) { @@ -673,4 +690,20 @@ public class DeviceConfigFacade { public int getHealthMonitorFwAlertValidTimeMs() { return mHealthMonitorFwAlertValidTimeMs; } + + /** + * Gets the minimum confirmation duration for sending network score to connectivity service + * when score breaches low. + */ + public int getMinConfirmationDurationSendLowScoreMs() { + return mMinConfirmationDurationSendLowScoreMs; + } + + /** + * Gets the minimum confirmation duration for sending network score to connectivity service + * when score breaches high. + */ + public int getMinConfirmationDurationSendHighScoreMs() { + return mMinConfirmationDurationSendHighScoreMs; + } } diff --git a/service/java/com/android/server/wifi/WifiScoreReport.java b/service/java/com/android/server/wifi/WifiScoreReport.java index fa0ba6a3c..a2c3e6c62 100644 --- a/service/java/com/android/server/wifi/WifiScoreReport.java +++ b/service/java/com/android/server/wifi/WifiScoreReport.java @@ -16,6 +16,7 @@ package com.android.server.wifi; +import android.content.Context; import android.net.Network; import android.net.NetworkAgent; import android.net.wifi.IScoreUpdateObserver; @@ -26,6 +27,8 @@ import android.os.IBinder; import android.os.RemoteException; import android.util.Log; +import com.android.wifi.resources.R; + import java.io.FileDescriptor; import java.io.PrintWriter; import java.text.SimpleDateFormat; @@ -62,7 +65,9 @@ public class WifiScoreReport { private int mSessionNumber = 0; // not to be confused with sessionid, this just counts resets private String mInterfaceName; private final BssidBlocklistMonitor mBssidBlocklistMonitor; - private long mLastScoreBreachLowTimeMillis = -1; + private final Context mContext; + private long mLastScoreBreachLowTimeMillis = INVALID_WALL_CLOCK_MILLIS; + private long mLastScoreBreachHighTimeMillis = INVALID_WALL_CLOCK_MILLIS; ConnectedScore mAggressiveConnectedScore; VelocityBasedConnectedScore mVelocityBasedConnectedScore; @@ -72,6 +77,7 @@ public class WifiScoreReport { WifiInfo mWifiInfo; WifiNative mWifiNative; WifiThreadRunner mWifiThreadRunner; + DeviceConfigFacade mDeviceConfigFacade; /** * Callback proxy. See {@link android.net.wifi.WifiManager.ScoreUpdateObserver}. @@ -89,10 +95,6 @@ public class WifiScoreReport { + " score=" + score); return; } - if (mNetworkAgent != null) { - mNetworkAgent.sendNetworkScore(score); - } - long millis = mClock.getWallClockMillis(); if (score < ConnectedScore.WIFI_TRANSITION_SCORE) { if (mScore >= ConnectedScore.WIFI_TRANSITION_SCORE) { @@ -101,7 +103,14 @@ public class WifiScoreReport { } else { mLastScoreBreachLowTimeMillis = INVALID_WALL_CLOCK_MILLIS; } - + if (score > ConnectedScore.WIFI_TRANSITION_SCORE) { + if (mScore <= ConnectedScore.WIFI_TRANSITION_SCORE) { + mLastScoreBreachHighTimeMillis = millis; + } + } else { + mLastScoreBreachHighTimeMillis = INVALID_WALL_CLOCK_MILLIS; + } + reportNetworkScoreToConnectivityServiceIfNecessary(score); mScore = score; updateWifiMetrics(millis, -1, mScore); }); @@ -166,6 +175,34 @@ public class WifiScoreReport { } } + /** + * Report network score to connectivity service. + */ + private void reportNetworkScoreToConnectivityServiceIfNecessary(int score) { + if (mNetworkAgent == null) { + return; + } + if (mWifiConnectedNetworkScorerHolder == null && score == mWifiInfo.getScore()) { + return; + } + if (mWifiConnectedNetworkScorerHolder != null + && mContext.getResources().getBoolean( + R.bool.config_wifiMinConfirmationDurationSendNetworkScoreEnabled)) { + long millis = mClock.getWallClockMillis(); + if (mLastScoreBreachLowTimeMillis != INVALID_WALL_CLOCK_MILLIS + && (millis - mLastScoreBreachLowTimeMillis) + < mDeviceConfigFacade.getMinConfirmationDurationSendLowScoreMs()) { + return; + } + if (mLastScoreBreachHighTimeMillis != INVALID_WALL_CLOCK_MILLIS + && (millis - mLastScoreBreachHighTimeMillis) + < mDeviceConfigFacade.getMinConfirmationDurationSendHighScoreMs()) { + return; + } + } + mNetworkAgent.sendNetworkScore(score); + } + /** * Container for storing info about external scorer and tracking its death. */ @@ -251,7 +288,8 @@ public class WifiScoreReport { WifiScoreReport(ScoringParams scoringParams, Clock clock, WifiMetrics wifiMetrics, WifiInfo wifiInfo, WifiNative wifiNative, BssidBlocklistMonitor bssidBlocklistMonitor, - WifiThreadRunner wifiThreadRunner) { + WifiThreadRunner wifiThreadRunner, DeviceConfigFacade deviceConfigFacade, + Context context) { mScoringParams = scoringParams; mClock = clock; mAggressiveConnectedScore = new AggressiveConnectedScore(scoringParams, clock); @@ -261,6 +299,8 @@ public class WifiScoreReport { mWifiNative = wifiNative; mBssidBlocklistMonitor = bssidBlocklistMonitor; mWifiThreadRunner = wifiThreadRunner; + mDeviceConfigFacade = deviceConfigFacade; + mContext = context; } /** @@ -276,6 +316,7 @@ public class WifiScoreReport { } mLastDownwardBreachTimeMillis = 0; mLastScoreBreachLowTimeMillis = INVALID_WALL_CLOCK_MILLIS; + mLastScoreBreachHighTimeMillis = INVALID_WALL_CLOCK_MILLIS; if (mVerboseLoggingEnabled) Log.d(TAG, "reset"); } @@ -357,12 +398,7 @@ public class WifiScoreReport { } //report score - if (score != mWifiInfo.getScore()) { - if (mNetworkAgent != null) { - mNetworkAgent.sendNetworkScore(score); - } - } - + reportNetworkScoreToConnectivityServiceIfNecessary(score); updateWifiMetrics(millis, s2, score); mScore = score; } @@ -611,6 +647,7 @@ public class WifiScoreReport { } mWifiConnectedNetworkScorerHolder.startSession(sessionId); mLastScoreBreachLowTimeMillis = INVALID_WALL_CLOCK_MILLIS; + mLastScoreBreachHighTimeMillis = INVALID_WALL_CLOCK_MILLIS; } /** diff --git a/service/res/values/config.xml b/service/res/values/config.xml index cc80f608c..a0c73cc3b 100644 --- a/service/res/values/config.xml +++ b/service/res/values/config.xml @@ -462,4 +462,7 @@ 0 + + + false diff --git a/service/res/values/overlayable.xml b/service/res/values/overlayable.xml index a4b7011b0..882890f17 100644 --- a/service/res/values/overlayable.xml +++ b/service/res/values/overlayable.xml @@ -144,6 +144,7 @@ + -- cgit v1.2.3