Loading packages/SettingsLib/src/com/android/settingslib/wifi/WifiUtils.java +11 −4 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.net.wifi.WifiConfiguration.NetworkSelectionStatus; import android.net.wifi.WifiInfo; import android.os.Bundle; import android.os.SystemClock; import android.util.Log; import androidx.annotation.VisibleForTesting; Loading @@ -40,6 +41,8 @@ import java.util.Map; public class WifiUtils { private static final String TAG = "WifiUtils"; private static final int INVALID_RSSI = -127; /** Loading Loading @@ -314,13 +317,17 @@ public class WifiUtils { * * @param level The number of bars to show (0-4) * @param noInternet True if a connected Wi-Fi network cannot access the Internet * @throws IllegalArgumentException if an invalid RSSI level is given. */ public static int getInternetIconResource(int level, boolean noInternet) { if (level < 0 || level >= WIFI_PIE.length) { throw new IllegalArgumentException("No Wifi icon found for level: " + level); } return noInternet ? NO_INTERNET_WIFI_PIE[level] : WIFI_PIE[level]; int wifiLevel = level; if (wifiLevel < 0) { Log.e(TAG, "Wi-Fi level is out of range! level:" + level); wifiLevel = 0; } else if (level >= WIFI_PIE.length) { Log.e(TAG, "Wi-Fi level is out of range! level:" + level); wifiLevel = WIFI_PIE.length - 1; } return noInternet ? NO_INTERNET_WIFI_PIE[wifiLevel] : WIFI_PIE[wifiLevel]; } /** Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/wifi/WifiUtilsTest.java +13 −0 Original line number Diff line number Diff line Loading @@ -187,6 +187,19 @@ public class WifiUtilsTest { assertThat(bundle.getString(WifiUtils.KEY_CHOSEN_WIFIENTRY_KEY)).isEqualTo(key); } @Test public void getInternetIconResource_levelOutOfRange_shouldNotCrash() { // Verify that Wi-Fi level is less than the minimum level (0) int level = -1; WifiUtils.getInternetIconResource(level, false /* noInternet*/); WifiUtils.getInternetIconResource(level, true /* noInternet*/); // Verify that Wi-Fi level is greater than the maximum level (4) level = WifiUtils.WIFI_PIE.length; WifiUtils.getInternetIconResource(level, false /* noInternet*/); WifiUtils.getInternetIconResource(level, true /* noInternet*/); } @Test public void testInternetIconInjector_getIcon_returnsCorrectValues() { WifiUtils.InternetIconInjector iconInjector = new WifiUtils.InternetIconInjector(mContext); Loading Loading
packages/SettingsLib/src/com/android/settingslib/wifi/WifiUtils.java +11 −4 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.net.wifi.WifiConfiguration.NetworkSelectionStatus; import android.net.wifi.WifiInfo; import android.os.Bundle; import android.os.SystemClock; import android.util.Log; import androidx.annotation.VisibleForTesting; Loading @@ -40,6 +41,8 @@ import java.util.Map; public class WifiUtils { private static final String TAG = "WifiUtils"; private static final int INVALID_RSSI = -127; /** Loading Loading @@ -314,13 +317,17 @@ public class WifiUtils { * * @param level The number of bars to show (0-4) * @param noInternet True if a connected Wi-Fi network cannot access the Internet * @throws IllegalArgumentException if an invalid RSSI level is given. */ public static int getInternetIconResource(int level, boolean noInternet) { if (level < 0 || level >= WIFI_PIE.length) { throw new IllegalArgumentException("No Wifi icon found for level: " + level); } return noInternet ? NO_INTERNET_WIFI_PIE[level] : WIFI_PIE[level]; int wifiLevel = level; if (wifiLevel < 0) { Log.e(TAG, "Wi-Fi level is out of range! level:" + level); wifiLevel = 0; } else if (level >= WIFI_PIE.length) { Log.e(TAG, "Wi-Fi level is out of range! level:" + level); wifiLevel = WIFI_PIE.length - 1; } return noInternet ? NO_INTERNET_WIFI_PIE[wifiLevel] : WIFI_PIE[wifiLevel]; } /** Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/wifi/WifiUtilsTest.java +13 −0 Original line number Diff line number Diff line Loading @@ -187,6 +187,19 @@ public class WifiUtilsTest { assertThat(bundle.getString(WifiUtils.KEY_CHOSEN_WIFIENTRY_KEY)).isEqualTo(key); } @Test public void getInternetIconResource_levelOutOfRange_shouldNotCrash() { // Verify that Wi-Fi level is less than the minimum level (0) int level = -1; WifiUtils.getInternetIconResource(level, false /* noInternet*/); WifiUtils.getInternetIconResource(level, true /* noInternet*/); // Verify that Wi-Fi level is greater than the maximum level (4) level = WifiUtils.WIFI_PIE.length; WifiUtils.getInternetIconResource(level, false /* noInternet*/); WifiUtils.getInternetIconResource(level, true /* noInternet*/); } @Test public void testInternetIconInjector_getIcon_returnsCorrectValues() { WifiUtils.InternetIconInjector iconInjector = new WifiUtils.InternetIconInjector(mContext); Loading