diff options
author | Mingguang Xu <mingguangxu@google.com> | 2020-02-26 21:41:03 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-02-26 21:41:03 +0000 |
commit | 8714ca9f17c7b4cc06bb601c094beb6417c77a74 (patch) | |
tree | ac74b38a070a96d01f173be4a72dca1c5e2784f3 | |
parent | 30bb825c32f030aee393b7604c46a227f290a481 (diff) | |
parent | 4c35610c475d562120c17a2dfa6e4122b3155bb1 (diff) |
Merge "Extension API: Replace NetworkScore object with integer in API surface" into rvc-dev
-rw-r--r-- | service/java/com/android/server/wifi/WifiScoreReport.java | 28 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java | 54 |
2 files changed, 35 insertions, 47 deletions
diff --git a/service/java/com/android/server/wifi/WifiScoreReport.java b/service/java/com/android/server/wifi/WifiScoreReport.java index 34ef25637..c61127d93 100644 --- a/service/java/com/android/server/wifi/WifiScoreReport.java +++ b/service/java/com/android/server/wifi/WifiScoreReport.java @@ -16,7 +16,6 @@ package com.android.server.wifi; -import android.annotation.NonNull; import android.net.Network; import android.net.NetworkAgent; import android.net.NetworkScore; @@ -65,7 +64,7 @@ public class WifiScoreReport { private int mSessionNumber = 0; private String mInterfaceName; private final BssidBlocklistMonitor mBssidBlocklistMonitor; - private long mLastExitingTimeMillis = -1; + private long mLastScoreBreachLowTimeMillis = -1; ConnectedScore mAggressiveConnectedScore; VelocityBasedConnectedScore mVelocityBasedConnectedScore; @@ -81,7 +80,7 @@ public class WifiScoreReport { */ private class ScoreChangeCallbackProxy extends IScoreChangeCallback.Stub { @Override - public void onScoreChange(int sessionId, @NonNull NetworkScore score) { + public void onScoreChange(int sessionId, int score) { mWifiThreadRunner.post(() -> { if (mWifiConnectedNetworkScorerHolder == null) { return; @@ -90,20 +89,19 @@ public class WifiScoreReport { return; } if (mNetworkAgent != null) { - mNetworkAgent.sendNetworkScore(score); + mNetworkAgent.sendNetworkScore(getNetworkScoreForLegacyInt(score)); } long millis = mClock.getWallClockMillis(); - if (score.isExiting()) { - if (mScore > ConnectedScore.WIFI_TRANSITION_SCORE) { - mLastExitingTimeMillis = millis; + if (score < ConnectedScore.WIFI_TRANSITION_SCORE) { + if (mScore >= ConnectedScore.WIFI_TRANSITION_SCORE) { + mLastScoreBreachLowTimeMillis = millis; } } else { - mLastExitingTimeMillis = INVALID_WALL_CLOCK_MILLIS; + mLastScoreBreachLowTimeMillis = INVALID_WALL_CLOCK_MILLIS; } - mScore = score.isExiting() ? ConnectedScore.WIFI_TRANSITION_SCORE - 1 : - ConnectedScore.WIFI_TRANSITION_SCORE + 1; + mScore = score; updateWifiMetrics(millis, -1, mScore); }); } @@ -262,7 +260,7 @@ public class WifiScoreReport { mAggressiveConnectedScore.reset(); mVelocityBasedConnectedScore.reset(); mLastDownwardBreachTimeMillis = 0; - mLastExitingTimeMillis = INVALID_WALL_CLOCK_MILLIS; + mLastScoreBreachLowTimeMillis = INVALID_WALL_CLOCK_MILLIS; if (mVerboseLoggingEnabled) Log.d(TAG, "reset"); } @@ -577,7 +575,7 @@ public class WifiScoreReport { + mWifiConnectedNetworkScorerHolder, e); revertAospConnectedScorer(); } - mLastExitingTimeMillis = INVALID_WALL_CLOCK_MILLIS; + mLastScoreBreachLowTimeMillis = INVALID_WALL_CLOCK_MILLIS; } /** @@ -598,13 +596,13 @@ public class WifiScoreReport { mSessionId = INVALID_SESSION_ID; long millis = mClock.getWallClockMillis(); // Blocklist the current BSS - if ((mLastExitingTimeMillis != INVALID_WALL_CLOCK_MILLIS) - && ((millis - mLastExitingTimeMillis) + if ((mLastScoreBreachLowTimeMillis != INVALID_WALL_CLOCK_MILLIS) + && ((millis - mLastScoreBreachLowTimeMillis) >= MIN_TIME_TO_WAIT_BEFORE_BLOCKLIST_BSSID_MILLIS)) { mBssidBlocklistMonitor.blockBssidForDurationMs(mWifiInfo.getBSSID(), mWifiInfo.getSSID(), DURATION_TO_BLOCKLIST_BSSID_AFTER_FIRST_EXITING_MILLIS); - mLastExitingTimeMillis = INVALID_WALL_CLOCK_MILLIS; + mLastScoreBreachLowTimeMillis = INVALID_WALL_CLOCK_MILLIS; } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java b/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java index adfdc0082..33dbcd1ca 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java @@ -660,26 +660,24 @@ public class WifiScoreReportTest extends WifiBaseTest { mWifiScoreReport.startConnectedNetworkScorer(anyInt()); // Invalid session ID - final NetworkScore ns1 = new NetworkScore.Builder().setExiting(true).build(); - scorerImpl.mScoreChangeCallback.onScoreChange(-1, ns1); + scorerImpl.mScoreChangeCallback.onScoreChange(-1, 49); assertEquals(mWifiScoreReport.getScore(), ConnectedScore.WIFI_MAX_SCORE); // Incorrect session ID - final NetworkScore ns2 = new NetworkScore.Builder().setExiting(true).build(); - scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId + 10, ns2); + scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId + 10, 49); assertEquals(mWifiScoreReport.getScore(), ConnectedScore.WIFI_MAX_SCORE); - final NetworkScore ns3 = new NetworkScore.Builder().setExiting(true).build(); - scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, ns3); + final NetworkScore ns3 = new NetworkScore.Builder().setLegacyScore(49).build(); + scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, 49); mLooper.dispatchAll(); verify(mNetworkAgent).sendNetworkScore(eq(ns3)); assertEquals(mWifiScoreReport.getScore(), 49); - final NetworkScore ns4 = new NetworkScore.Builder().setExiting(false).build(); - scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, ns4); + final NetworkScore ns4 = new NetworkScore.Builder().setLegacyScore(59).build(); + scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, 59); mLooper.dispatchAll(); verify(mNetworkAgent).sendNetworkScore(eq(ns4)); - assertEquals(mWifiScoreReport.getScore(), 51); + assertEquals(mWifiScoreReport.getScore(), 59); } /** @@ -711,27 +709,25 @@ public class WifiScoreReportTest extends WifiBaseTest { mClock.mStepMillis = 0; mClock.mWallClockMillis = 5001; - final NetworkScore ns1 = new NetworkScore.Builder().setExiting(true).build(); - scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, ns1); + scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, 49); mLooper.dispatchAll(); assertTrue(mWifiScoreReport.shouldCheckIpLayer()); mWifiScoreReport.noteIpCheck(); mClock.mWallClockMillis = 10000; - final NetworkScore ns2 = new NetworkScore.Builder().setExiting(true).build(); - scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, ns2); + scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, 49); mLooper.dispatchAll(); assertFalse(mWifiScoreReport.shouldCheckIpLayer()); mClock.mWallClockMillis = 10001; - final NetworkScore ns3 = new NetworkScore.Builder().setExiting(true).build(); - scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, ns3); + scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, 49); mLooper.dispatchAll(); assertTrue(mWifiScoreReport.shouldCheckIpLayer()); } /** - * Verify BSSID blocklist doesnot happen when exiting is set for less than the minimum duration + * Verify BSSID blocklist doesnot happen when score stays below threshold for less than the + * minimum duration */ @Test public void bssidBlockListDoesnotHappenWhenExitingIsLessThanMinDuration() throws Exception { @@ -742,12 +738,10 @@ public class WifiScoreReportTest extends WifiBaseTest { mClock.mStepMillis = 0; mClock.mWallClockMillis = 10; - final NetworkScore ns1 = new NetworkScore.Builder().setExiting(true).build(); - scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, ns1); + scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, 49); mLooper.dispatchAll(); mClock.mWallClockMillis = 29009; - final NetworkScore ns2 = new NetworkScore.Builder().setExiting(true).build(); - scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, ns2); + scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, 49); mLooper.dispatchAll(); mWifiScoreReport.stopConnectedNetworkScorer(); mLooper.dispatchAll(); @@ -755,7 +749,8 @@ public class WifiScoreReportTest extends WifiBaseTest { } /** - * Verify BSSID blocklist happens when exiting is set for longer than the minimum duration + * Verify BSSID blocklist happens when score stays below threshold for longer than the + * minimum duration */ @Test public void bssidBlockListHappensWhenExitingIsLongerThanMinDuration() throws Exception { @@ -766,12 +761,10 @@ public class WifiScoreReportTest extends WifiBaseTest { mClock.mStepMillis = 0; mClock.mWallClockMillis = 10; - final NetworkScore ns1 = new NetworkScore.Builder().setExiting(true).build(); - scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, ns1); + scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, 49); mLooper.dispatchAll(); mClock.mWallClockMillis = 29011; - final NetworkScore ns2 = new NetworkScore.Builder().setExiting(true).build(); - scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, ns2); + scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, 49); mLooper.dispatchAll(); mWifiScoreReport.stopConnectedNetworkScorer(); mLooper.dispatchAll(); @@ -779,7 +772,7 @@ public class WifiScoreReportTest extends WifiBaseTest { } /** - * Verify BSSID blocklist doesnot happen exiting is reset + * Verify BSSID blocklist doesnot happen when there is score flip flop */ @Test public void bssidBlockListDoesnotHappenWhenExitingIsReset() throws Exception { @@ -790,16 +783,13 @@ public class WifiScoreReportTest extends WifiBaseTest { mClock.mStepMillis = 0; mClock.mWallClockMillis = 10; - final NetworkScore ns1 = new NetworkScore.Builder().setExiting(true).build(); - scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, ns1); + scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, 49); mLooper.dispatchAll(); mClock.mWallClockMillis = 15000; - final NetworkScore ns2 = new NetworkScore.Builder().setExiting(false).build(); - scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, ns2); + scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, 51); mLooper.dispatchAll(); mClock.mWallClockMillis = 29011; - final NetworkScore ns3 = new NetworkScore.Builder().setExiting(true).build(); - scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, ns3); + scorerImpl.mScoreChangeCallback.onScoreChange(scorerImpl.mSessionId, 49); mLooper.dispatchAll(); mWifiScoreReport.stopConnectedNetworkScorer(); mLooper.dispatchAll(); |