summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/ClientModeImpl.java3
-rw-r--r--service/java/com/android/server/wifi/DeviceConfigFacade.java35
-rw-r--r--service/java/com/android/server/wifi/WifiScoreReport.java63
-rw-r--r--service/res/values/config.xml3
-rw-r--r--service/res/values/overlayable.xml1
-rw-r--r--tests/wifitests/src/com/android/server/wifi/DeviceConfigFacadeTest.java10
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java154
7 files changed, 253 insertions, 16 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java
index 2a487e312..866782ad3 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<String> 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 5a1e9d378..89f0445cb 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);
});
@@ -167,6 +176,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.
*/
private final class WifiConnectedNetworkScorerHolder implements IBinder.DeathRecipient {
@@ -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;
}
@@ -612,6 +648,7 @@ public class WifiScoreReport {
mWifiInfo.setScore(ConnectedScore.WIFI_MAX_SCORE);
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 742cf681f..1220c260a 100644
--- a/service/res/values/config.xml
+++ b/service/res/values/config.xml
@@ -454,4 +454,7 @@
<!-- integer indicating additional disconnect delay (in ms) after IMS onLost() indication is received -->
<integer translatable="false" name="config_wifiDelayDisconnectOnImsLostMs">0</integer>
+
+ <!-- Enable adding minimum confirmation duration when sending network score to connectivity service. -->
+ <bool translatable="false" name="config_wifiMinConfirmationDurationSendNetworkScoreEnabled">false</bool>
</resources>
diff --git a/service/res/values/overlayable.xml b/service/res/values/overlayable.xml
index 8b592623f..56c94246d 100644
--- a/service/res/values/overlayable.xml
+++ b/service/res/values/overlayable.xml
@@ -143,6 +143,7 @@
<item type="integer" name="config_wifiMovingPnoScanIntervalMillis" />
<item type="integer" name="config_wifiStationaryPnoScanIntervalMillis" />
<item type="integer" name="config_wifiDelayDisconnectOnImsLostMs" />
+ <item type="bool" name="config_wifiMinConfirmationDurationSendNetworkScoreEnabled" />
<!-- 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/DeviceConfigFacadeTest.java b/tests/wifitests/src/com/android/server/wifi/DeviceConfigFacadeTest.java
index bb03d42d7..43a16fe4c 100644
--- a/tests/wifitests/src/com/android/server/wifi/DeviceConfigFacadeTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/DeviceConfigFacadeTest.java
@@ -205,6 +205,10 @@ public class DeviceConfigFacadeTest extends WifiBaseTest {
mDeviceConfigFacade.getStationaryScanRssiValidTimeMs());
assertEquals(DeviceConfigFacade.DEFAULT_HEALTH_MONITOR_FW_ALERT_VALID_TIME_MS,
mDeviceConfigFacade.getHealthMonitorFwAlertValidTimeMs());
+ assertEquals(DeviceConfigFacade.DEFAULT_MIN_CONFIRMATION_DURATION_SEND_LOW_SCORE_MS,
+ mDeviceConfigFacade.getMinConfirmationDurationSendLowScoreMs());
+ assertEquals(DeviceConfigFacade.DEFAULT_MIN_CONFIRMATION_DURATION_SEND_HIGH_SCORE_MS,
+ mDeviceConfigFacade.getMinConfirmationDurationSendHighScoreMs());
}
/**
@@ -307,6 +311,10 @@ public class DeviceConfigFacadeTest extends WifiBaseTest {
anyInt())).thenReturn(3000);
when(DeviceConfig.getInt(anyString(), eq("health_monitor_fw_alert_valid_time_ms"),
anyInt())).thenReturn(1000);
+ when(DeviceConfig.getInt(anyString(), eq("min_confirmation_duration_send_low_score_ms"),
+ anyInt())).thenReturn(4000);
+ when(DeviceConfig.getInt(anyString(), eq("min_confirmation_duration_send_high_score_ms"),
+ anyInt())).thenReturn(1000);
mOnPropertiesChangedListenerCaptor.getValue().onPropertiesChanged(null);
// Verifying fields are updated to the new values
@@ -363,5 +371,7 @@ public class DeviceConfigFacadeTest extends WifiBaseTest {
assertEquals(4000, mDeviceConfigFacade.getNonstationaryScanRssiValidTimeMs());
assertEquals(3000, mDeviceConfigFacade.getStationaryScanRssiValidTimeMs());
assertEquals(1000, mDeviceConfigFacade.getHealthMonitorFwAlertValidTimeMs());
+ assertEquals(4000, mDeviceConfigFacade.getMinConfirmationDurationSendLowScoreMs());
+ assertEquals(1000, mDeviceConfigFacade.getMinConfirmationDurationSendHighScoreMs());
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java b/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java
index 9402e9900..82dbbe941 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java
@@ -101,6 +101,7 @@ public class WifiScoreReportTest extends WifiBaseTest {
@Mock WifiNative mWifiNative;
@Mock BssidBlocklistMonitor mBssidBlocklistMonitor;
@Mock Network mNetwork;
+ @Mock DeviceConfigFacade mDeviceConfigFacade;
private TestLooper mLooper;
public class WifiConnectedNetworkScorerImpl extends IWifiConnectedNetworkScorer.Stub {
@@ -174,6 +175,9 @@ public class WifiScoreReportTest extends WifiBaseTest {
when(resources.getInteger(
R.integer.config_wifiFrameworkMinPacketPerSecondHighTraffic))
.thenReturn(100);
+ when(resources.getBoolean(
+ R.bool.config_wifiMinConfirmationDurationSendNetworkScoreEnabled))
+ .thenReturn(false);
}
/**
@@ -197,8 +201,13 @@ public class WifiScoreReportTest extends WifiBaseTest {
mScoringParams = new ScoringParams();
mWifiThreadRunner = new WifiThreadRunner(new Handler(mLooper.getLooper()));
mWifiScoreReport = new WifiScoreReport(mScoringParams, mClock, mWifiMetrics, mWifiInfo,
- mWifiNative, mBssidBlocklistMonitor, mWifiThreadRunner);
+ mWifiNative, mBssidBlocklistMonitor, mWifiThreadRunner,
+ mDeviceConfigFacade, mContext);
mWifiScoreReport.setNetworkAgent(mNetworkAgent);
+ when(mDeviceConfigFacade.getMinConfirmationDurationSendLowScoreMs()).thenReturn(
+ DeviceConfigFacade.DEFAULT_MIN_CONFIRMATION_DURATION_SEND_LOW_SCORE_MS);
+ when(mDeviceConfigFacade.getMinConfirmationDurationSendHighScoreMs()).thenReturn(
+ DeviceConfigFacade.DEFAULT_MIN_CONFIRMATION_DURATION_SEND_HIGH_SCORE_MS);
}
/**
@@ -847,4 +856,147 @@ public class WifiScoreReportTest extends WifiBaseTest {
mWifiScoreReport.setWifiConnectedNetworkScorer(mAppBinder, mWifiConnectedNetworkScorer);
assertEquals(ConnectedScore.WIFI_MAX_SCORE, mWifiInfo.getScore());
}
+
+ /**
+ * Verify confirmation duration is not added when it is not enabled in config overlay by default
+ */
+ @Test
+ public void confirmationDurationIsNotAddedWhenItIsNotEnabledInConfigOverlay() throws Exception {
+ WifiConnectedNetworkScorerImpl scorerImpl = new WifiConnectedNetworkScorerImpl();
+ // Register Client for verification.
+ mWifiScoreReport.setWifiConnectedNetworkScorer(mAppBinder, scorerImpl);
+ when(mNetwork.getNetId()).thenReturn(TEST_NETWORK_ID);
+ mWifiScoreReport.startConnectedNetworkScorer(TEST_NETWORK_ID);
+ mClock.mStepMillis = 0;
+
+ mClock.mWallClockMillis = 10;
+ scorerImpl.mScoreUpdateObserver.notifyScoreUpdate(scorerImpl.mSessionId, 49);
+ mLooper.dispatchAll();
+ verify(mNetworkAgent).sendNetworkScore(anyInt());
+ }
+
+ /**
+ * Verify confirmation duration is not added when there is no score breacht
+ */
+ @Test
+ public void confirmationDurationIsNotAddedWhenThereIsNoScoreBreach() throws Exception {
+ WifiConnectedNetworkScorerImpl scorerImpl = new WifiConnectedNetworkScorerImpl();
+ // Register Client for verification.
+ mWifiScoreReport.setWifiConnectedNetworkScorer(mAppBinder, scorerImpl);
+ when(mNetwork.getNetId()).thenReturn(TEST_NETWORK_ID);
+ mWifiScoreReport.startConnectedNetworkScorer(TEST_NETWORK_ID);
+ mClock.mStepMillis = 0;
+ when(mContext.getResources().getBoolean(
+ R.bool.config_wifiMinConfirmationDurationSendNetworkScoreEnabled)).thenReturn(true);
+
+ mClock.mWallClockMillis = 10;
+ scorerImpl.mScoreUpdateObserver.notifyScoreUpdate(scorerImpl.mSessionId, 60);
+ mLooper.dispatchAll();
+ verify(mNetworkAgent).sendNetworkScore(60);
+ mClock.mWallClockMillis = 3010;
+ scorerImpl.mScoreUpdateObserver.notifyScoreUpdate(scorerImpl.mSessionId, 59);
+ mLooper.dispatchAll();
+ verify(mNetworkAgent).sendNetworkScore(59);
+ mClock.mWallClockMillis = 6010;
+ scorerImpl.mScoreUpdateObserver.notifyScoreUpdate(scorerImpl.mSessionId, 58);
+ mLooper.dispatchAll();
+ verify(mNetworkAgent).sendNetworkScore(58);
+ }
+
+ /**
+ * Verify confirmation duration is added for reporting low score when it is enabled in
+ * config overlay
+ */
+ @Test
+ public void confirmationDurationIsAddedForSendingLowScore() throws Exception {
+ WifiConnectedNetworkScorerImpl scorerImpl = new WifiConnectedNetworkScorerImpl();
+ // Register Client for verification.
+ mWifiScoreReport.setWifiConnectedNetworkScorer(mAppBinder, scorerImpl);
+ when(mNetwork.getNetId()).thenReturn(TEST_NETWORK_ID);
+ mWifiScoreReport.startConnectedNetworkScorer(TEST_NETWORK_ID);
+ mClock.mStepMillis = 0;
+ when(mContext.getResources().getBoolean(
+ R.bool.config_wifiMinConfirmationDurationSendNetworkScoreEnabled)).thenReturn(true);
+
+ mClock.mWallClockMillis = 10;
+ scorerImpl.mScoreUpdateObserver.notifyScoreUpdate(scorerImpl.mSessionId, 49);
+ mLooper.dispatchAll();
+ verify(mNetworkAgent, never()).sendNetworkScore(anyInt());
+ mClock.mWallClockMillis = 10
+ + mDeviceConfigFacade.DEFAULT_MIN_CONFIRMATION_DURATION_SEND_LOW_SCORE_MS - 1;
+ scorerImpl.mScoreUpdateObserver.notifyScoreUpdate(scorerImpl.mSessionId, 48);
+ mLooper.dispatchAll();
+ verify(mNetworkAgent, never()).sendNetworkScore(anyInt());
+ mClock.mWallClockMillis = 10
+ + mDeviceConfigFacade.DEFAULT_MIN_CONFIRMATION_DURATION_SEND_LOW_SCORE_MS;
+ scorerImpl.mScoreUpdateObserver.notifyScoreUpdate(scorerImpl.mSessionId, 47);
+ mLooper.dispatchAll();
+ verify(mNetworkAgent).sendNetworkScore(47);
+ mClock.mWallClockMillis = 10
+ + mDeviceConfigFacade.DEFAULT_MIN_CONFIRMATION_DURATION_SEND_LOW_SCORE_MS + 3000;
+ scorerImpl.mScoreUpdateObserver.notifyScoreUpdate(scorerImpl.mSessionId, 46);
+ mLooper.dispatchAll();
+ verify(mNetworkAgent).sendNetworkScore(46);
+ }
+
+ /**
+ * Verify confirmation duration is not added for reporting high score with default zero value
+ */
+ @Test
+ public void confirmationDurationIsNotAddedForSendingHighScore() throws Exception {
+ WifiConnectedNetworkScorerImpl scorerImpl = new WifiConnectedNetworkScorerImpl();
+ // Register Client for verification.
+ mWifiScoreReport.setWifiConnectedNetworkScorer(mAppBinder, scorerImpl);
+ when(mNetwork.getNetId()).thenReturn(TEST_NETWORK_ID);
+ mWifiScoreReport.startConnectedNetworkScorer(TEST_NETWORK_ID);
+ mClock.mStepMillis = 0;
+ when(mContext.getResources().getBoolean(
+ R.bool.config_wifiMinConfirmationDurationSendNetworkScoreEnabled)).thenReturn(true);
+
+ mClock.mWallClockMillis = 10;
+ scorerImpl.mScoreUpdateObserver.notifyScoreUpdate(scorerImpl.mSessionId, 49);
+ mLooper.dispatchAll();
+ verify(mNetworkAgent, never()).sendNetworkScore(anyInt());
+ mClock.mWallClockMillis = 3000;
+ scorerImpl.mScoreUpdateObserver.notifyScoreUpdate(scorerImpl.mSessionId, 51);
+ mLooper.dispatchAll();
+ verify(mNetworkAgent).sendNetworkScore(51);
+ mClock.mWallClockMillis = 6000;
+ scorerImpl.mScoreUpdateObserver.notifyScoreUpdate(scorerImpl.mSessionId, 52);
+ mLooper.dispatchAll();
+ verify(mNetworkAgent).sendNetworkScore(52);
+ }
+
+ /**
+ * Verify confirmation duration is added for reporting high score with non-zero value
+ */
+ @Test
+ public void confirmationDurationIsAddedForSendingHighScore() throws Exception {
+ WifiConnectedNetworkScorerImpl scorerImpl = new WifiConnectedNetworkScorerImpl();
+ // Register Client for verification.
+ mWifiScoreReport.setWifiConnectedNetworkScorer(mAppBinder, scorerImpl);
+ when(mNetwork.getNetId()).thenReturn(TEST_NETWORK_ID);
+ mWifiScoreReport.startConnectedNetworkScorer(TEST_NETWORK_ID);
+ mClock.mStepMillis = 0;
+ when(mContext.getResources().getBoolean(
+ R.bool.config_wifiMinConfirmationDurationSendNetworkScoreEnabled)).thenReturn(true);
+ when(mDeviceConfigFacade.getMinConfirmationDurationSendHighScoreMs()).thenReturn(4000);
+
+ mClock.mWallClockMillis = 10;
+ scorerImpl.mScoreUpdateObserver.notifyScoreUpdate(scorerImpl.mSessionId, 49);
+ mLooper.dispatchAll();
+ verify(mNetworkAgent, never()).sendNetworkScore(anyInt());
+ mClock.mWallClockMillis = 3000;
+ scorerImpl.mScoreUpdateObserver.notifyScoreUpdate(scorerImpl.mSessionId, 51);
+ mLooper.dispatchAll();
+ verify(mNetworkAgent, never()).sendNetworkScore(anyInt());
+ mClock.mWallClockMillis = 6999;
+ scorerImpl.mScoreUpdateObserver.notifyScoreUpdate(scorerImpl.mSessionId, 52);
+ mLooper.dispatchAll();
+ verify(mNetworkAgent, never()).sendNetworkScore(anyInt());
+ mClock.mWallClockMillis = 7000;
+ scorerImpl.mScoreUpdateObserver.notifyScoreUpdate(scorerImpl.mSessionId, 53);
+ mLooper.dispatchAll();
+ verify(mNetworkAgent).sendNetworkScore(53);
+ }
}