From 990435711bb3917cfe92ada2f6a09224aed5356a Mon Sep 17 00:00:00 2001 From: Kai Shi Date: Wed, 12 Feb 2020 13:43:19 -0800 Subject: Add one more boundary check of maxNumSpatialStream Due to the missing NL80211 PHY attribute parsing and incorrect initialization of BandInfo in wificond, throughputPredictor's maxNumSpatialStream is set to 0 which results in 0 Mbps throughput To avoid similar issue due to incorrect implementation of wificond or WifiHAL, add a safety check in throughputPredictor to ensure maxNumSpatialStream >= 1. Bug: 149415717 Test: atest com.android.server.wifi Change-Id: Ib19a897d3fadfe4f43bbfa2522b2f971ea90f588 --- .../com/android/server/wifi/ThroughputPredictor.java | 4 ++++ .../android/server/wifi/ThroughputPredictorTest.java | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/service/java/com/android/server/wifi/ThroughputPredictor.java b/service/java/com/android/server/wifi/ThroughputPredictor.java index 8cda4c288..80df9aa43 100644 --- a/service/java/com/android/server/wifi/ThroughputPredictor.java +++ b/service/java/com/android/server/wifi/ThroughputPredictor.java @@ -228,6 +228,10 @@ public class ThroughputPredictor { int numTonePerSym; int symDurationNs; int maxBitsPerTone; + if (maxNumSpatialStream < 1) { + Log.e(TAG, "maxNumSpatialStream < 1 due to wrong implementation. Overridden to 1"); + maxNumSpatialStream = 1; + } if (wifiStandard == ScanResult.WIFI_STANDARD_UNKNOWN) { return WifiInfo.LINK_SPEED_UNKNOWN; } else if (wifiStandard == ScanResult.WIFI_STANDARD_LEGACY) { diff --git a/tests/wifitests/src/com/android/server/wifi/ThroughputPredictorTest.java b/tests/wifitests/src/com/android/server/wifi/ThroughputPredictorTest.java index 2043bf1c8..3844687a3 100644 --- a/tests/wifitests/src/com/android/server/wifi/ThroughputPredictorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ThroughputPredictorTest.java @@ -200,6 +200,17 @@ public class ThroughputPredictorTest extends WifiBaseTest { assertEquals(144, predictedThroughputMbps); } + @Test + public void verifyHighRssiMinChannelUtilizationHt2g20MhzIncorrectNss() { + when(mDeviceCapabilities.getMaxNumberTxSpatialStreams()).thenReturn(0); + when(mDeviceCapabilities.getMaxNumberRxSpatialStreams()).thenReturn(0); + int predictedThroughputMbps = mThroughputPredictor.predictThroughput(mDeviceCapabilities, + ScanResult.WIFI_STANDARD_11N, ScanResult.CHANNEL_WIDTH_20MHZ, -50, 2437, 2, + MIN_CHANNEL_UTILIZATION, INVALID, false); + // Expect to 1SS peak rate because maxNumberSpatialStream is overridden to 1. + assertEquals(72, predictedThroughputMbps); + } + @Test public void verifyLowRssiDefaultChannelUtilizationHt2g20Mhz1ss() { int predictedThroughputMbps = mThroughputPredictor.predictThroughput(mDeviceCapabilities, @@ -252,6 +263,15 @@ public class ThroughputPredictorTest extends WifiBaseTest { assertEquals(866, mThroughputPredictor.predictMaxRxThroughput(mConnectionCap)); } + @Test + public void verifyMaxThroughputAc80MhzIncorrectNss() { + mConnectionCap.wifiStandard = ScanResult.WIFI_STANDARD_11AC; + mConnectionCap.channelBandwidth = ScanResult.CHANNEL_WIDTH_80MHZ; + mConnectionCap.maxNumberRxSpatialStreams = -5; + // Expect to 1SS peak rate because maxNumberSpatialStream is overridden to 1. + assertEquals(433, mThroughputPredictor.predictMaxRxThroughput(mConnectionCap)); + } + @Test public void verifyMaxThroughputN20Mhz1ss() { mConnectionCap.wifiStandard = ScanResult.WIFI_STANDARD_11N; -- cgit v1.2.3