From 1ee61b2af7ff4079416d863dd55b5383d3950f15 Mon Sep 17 00:00:00 2001 From: Michael Plass Date: Mon, 21 May 2018 11:49:44 -0700 Subject: [WifiScoreReport] Don't report score if RSSI is invalid Bug: 79338641 Test: Unit tests Change-Id: I392a1c021e34b9d30c53739a9d6a923a38ad00c2 --- service/java/com/android/server/wifi/WifiScoreReport.java | 4 ++++ .../src/com/android/server/wifi/WifiScoreReportTest.java | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/service/java/com/android/server/wifi/WifiScoreReport.java b/service/java/com/android/server/wifi/WifiScoreReport.java index c6a7105be..d4d443bb2 100644 --- a/service/java/com/android/server/wifi/WifiScoreReport.java +++ b/service/java/com/android/server/wifi/WifiScoreReport.java @@ -89,6 +89,10 @@ public class WifiScoreReport { */ public void calculateAndReportScore(WifiInfo wifiInfo, NetworkAgent networkAgent, WifiMetrics wifiMetrics) { + if (wifiInfo.getRssi() == WifiInfo.INVALID_RSSI) { + Log.d(TAG, "Not reporting score because RSSI is invalid"); + return; + } int score; long millis = mClock.getWallClockMillis(); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java b/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java index 38e45d306..3e9e9217c 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java @@ -25,6 +25,7 @@ import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.atMost; import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -159,6 +160,20 @@ public class WifiScoreReportTest { verify(mWifiMetrics).incrementWifiScoreCount(anyInt()); } + /** + * Test for no score report if rssi is invalid + * + * The score should be sent to neither the NetworkAgent nor the + * WifiMetrics + */ + @Test + public void calculateAndReportScoreDoesNotReportWhenRssiIsNotValid() throws Exception { + mWifiInfo.setRssi(WifiInfo.INVALID_RSSI); + mWifiScoreReport.calculateAndReportScore(mWifiInfo, mNetworkAgent, mWifiMetrics); + verify(mNetworkAgent, never()).sendNetworkScore(anyInt()); + verify(mWifiMetrics, never()).incrementWifiScoreCount(anyInt()); + } + /** * Test for operation with null NetworkAgent * -- cgit v1.2.3