Update logging util to not crash on null
The logging for the wifi access points could cause a crash if a bad scan result is passed in for any reason. This CL updates it to be resilient to that by doing a best effort logging of the scan results. Bug: 74507895 Test: robotests Change-Id: I4eaf948d7279374b1f4d009ef6f4fd0119f22ab7
This commit is contained in:
@@ -76,7 +76,8 @@ public class WifiUtils {
|
||||
* ["rssi 5Ghz", "num results on 5GHz" / "rssi 5Ghz", "num results on 5GHz"]
|
||||
* For instance [-40,5/-30,2]
|
||||
*/
|
||||
private static String getVisibilityStatus(AccessPoint accessPoint) {
|
||||
@VisibleForTesting
|
||||
static String getVisibilityStatus(AccessPoint accessPoint) {
|
||||
final WifiInfo info = accessPoint.getInfo();
|
||||
StringBuilder visibility = new StringBuilder();
|
||||
StringBuilder scans24GHz = new StringBuilder();
|
||||
@@ -110,6 +111,9 @@ public class WifiUtils {
|
||||
// TODO: sort list by RSSI or age
|
||||
long nowMs = SystemClock.elapsedRealtime();
|
||||
for (ScanResult result : accessPoint.getScanResults()) {
|
||||
if (result == null) {
|
||||
continue;
|
||||
}
|
||||
if (result.frequency >= AccessPoint.LOWER_FREQ_5GHZ
|
||||
&& result.frequency <= AccessPoint.HIGHER_FREQ_5GHZ) {
|
||||
// Strictly speaking: [4915, 5825]
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.android.settingslib.wifi;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -31,6 +32,7 @@ import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.os.SystemClock;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.ArraySet;
|
||||
|
||||
import com.android.settingslib.R;
|
||||
import com.android.settingslib.SettingsLibRobolectricTestRunner;
|
||||
@@ -43,6 +45,7 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
@RunWith(SettingsLibRobolectricTestRunner.class)
|
||||
public class WifiUtilsTest {
|
||||
@@ -56,6 +59,8 @@ public class WifiUtilsTest {
|
||||
private RssiCurve mockBadgeCurve;
|
||||
@Mock
|
||||
private WifiNetworkScoreCache mockWifiNetworkScoreCache;
|
||||
@Mock
|
||||
private AccessPoint mAccessPoint;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -84,6 +89,15 @@ public class WifiUtilsTest {
|
||||
assertThat(summary.contains(mContext.getString(R.string.speed_label_very_fast))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetVisibilityStatus_nullResultDoesNotCrash() {
|
||||
doReturn(null).when(mAccessPoint).getInfo();
|
||||
Set<ScanResult> set = new ArraySet<>();
|
||||
set.add(null);
|
||||
doReturn(set).when(mAccessPoint).getScanResults();
|
||||
WifiUtils.getVisibilityStatus(mAccessPoint);
|
||||
}
|
||||
|
||||
private static ArrayList<ScanResult> buildScanResultCache() {
|
||||
ArrayList<ScanResult> scanResults = new ArrayList<>();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
|
||||
Reference in New Issue
Block a user