Loading packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java +7 −12 Original line number Diff line number Diff line Loading @@ -211,13 +211,6 @@ public class AccessPoint implements Comparable<AccessPoint> { private static final int EAP_WPA = 1; // WPA-EAP private static final int EAP_WPA2_WPA3 = 2; // RSN-EAP /** * The number of distinct wifi levels. * * <p>Must keep in sync with {@link R.array.wifi_signal} and {@link WifiManager#RSSI_LEVELS}. */ public static final int SIGNAL_LEVELS = 5; public static final int UNREACHABLE_RSSI = Integer.MIN_VALUE; public static final String KEY_PREFIX_AP = "AP:"; Loading Loading @@ -453,9 +446,10 @@ public class AccessPoint implements Comparable<AccessPoint> { return other.getSpeed() - getSpeed(); } WifiManager wifiManager = getWifiManager(); // Sort by signal strength, bucketed by level int difference = WifiManager.calculateSignalLevel(other.mRssi, SIGNAL_LEVELS) - WifiManager.calculateSignalLevel(mRssi, SIGNAL_LEVELS); int difference = wifiManager.calculateSignalLevel(other.mRssi) - wifiManager.calculateSignalLevel(mRssi); if (difference != 0) { return difference; } Loading Loading @@ -869,13 +863,14 @@ public class AccessPoint implements Comparable<AccessPoint> { } /** * Returns the number of levels to show for a Wifi icon, from 0 to {@link #SIGNAL_LEVELS}-1. * Returns the number of levels to show for a Wifi icon, from 0 to * {@link WifiManager#getMaxSignalLevel()}. * * <p>Use {@#isReachable()} to determine if an AccessPoint is in range, as this method will * <p>Use {@link #isReachable()} to determine if an AccessPoint is in range, as this method will * always return at least 0. */ public int getLevel() { return WifiManager.calculateSignalLevel(mRssi, SIGNAL_LEVELS); return getWifiManager().calculateSignalLevel(mRssi); } public int getRssi() { Loading packages/SettingsLib/src/com/android/settingslib/wifi/TestAccessPointBuilder.java +5 −2 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.net.NetworkInfo; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Bundle; import android.os.Parcelable; Loading Loading @@ -126,13 +127,15 @@ public class TestAccessPointBuilder { @Keep public TestAccessPointBuilder setLevel(int level) { // Reversal of WifiManager.calculateSignalLevels WifiManager wifiManager = mContext.getSystemService(WifiManager.class); int maxSignalLevel = wifiManager.getMaxSignalLevel(); if (level == 0) { mRssi = MIN_RSSI; } else if (level >= AccessPoint.SIGNAL_LEVELS) { } else if (level > maxSignalLevel) { mRssi = MAX_RSSI; } else { float inputRange = MAX_RSSI - MIN_RSSI; float outputRange = AccessPoint.SIGNAL_LEVELS - 1; float outputRange = maxSignalLevel; mRssi = (int) (level * inputRange / outputRange + MIN_RSSI); } return this; Loading packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.java +10 −7 Original line number Diff line number Diff line Loading @@ -83,7 +83,6 @@ import java.util.concurrent.CountDownLatch; @SmallTest @RunWith(AndroidJUnit4.class) public class AccessPointTest { private static final String TEST_SSID = "\"test_ssid\""; private static final String ROAMING_SSID = "\"roaming_ssid\""; private static final String OSU_FRIENDLY_NAME = "osu_friendly_name"; Loading @@ -98,6 +97,7 @@ public class AccessPointTest { 20 * DateUtils.MINUTE_IN_MILLIS; private Context mContext; private int mMaxSignalLevel; private WifiInfo mWifiInfo; @Mock private Context mMockContext; @Mock private WifiManager mMockWifiManager; Loading Loading @@ -128,6 +128,7 @@ public class AccessPointTest { public void setUp() { MockitoAnnotations.initMocks(this); mContext = InstrumentationRegistry.getTargetContext(); mMaxSignalLevel = mContext.getSystemService(WifiManager.class).getMaxSignalLevel(); mWifiInfo = new WifiInfo(); mWifiInfo.setSSID(WifiSsid.createFromAsciiEncoded(TEST_SSID)); mWifiInfo.setBSSID(TEST_BSSID); Loading Loading @@ -180,7 +181,7 @@ public class AccessPointTest { @Test public void testCompareTo_GivesHighLevelBeforeLowLevel() { final int highLevel = AccessPoint.SIGNAL_LEVELS - 1; final int highLevel = mMaxSignalLevel; final int lowLevel = 1; assertThat(highLevel).isGreaterThan(lowLevel); Loading Loading @@ -226,7 +227,7 @@ public class AccessPointTest { .setReachable(true).build(); AccessPoint saved = new TestAccessPointBuilder(mContext).setSaved(true).build(); AccessPoint highLevelAndReachable = new TestAccessPointBuilder(mContext) .setLevel(AccessPoint.SIGNAL_LEVELS - 1).build(); .setLevel(mMaxSignalLevel).build(); AccessPoint firstName = new TestAccessPointBuilder(mContext).setSsid("a").build(); AccessPoint lastname = new TestAccessPointBuilder(mContext).setSsid("z").build(); Loading Loading @@ -520,6 +521,8 @@ public class AccessPointTest { when(packageManager.getApplicationInfoAsUser(eq(appPackageName), anyInt(), anyInt())) .thenReturn(applicationInfo); when(applicationInfo.loadLabel(packageManager)).thenReturn(appLabel); when(context.getSystemService(Context.WIFI_SERVICE)).thenReturn(mMockWifiManager); when(mMockWifiManager.calculateSignalLevel(rssi)).thenReturn(4); NetworkInfo networkInfo = new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", ""); Loading Loading @@ -636,14 +639,14 @@ public class AccessPointTest { public void testBuilder_setLevel() { AccessPoint testAp; for (int i = 0; i < AccessPoint.SIGNAL_LEVELS; i++) { for (int i = 0; i <= mMaxSignalLevel; i++) { testAp = new TestAccessPointBuilder(mContext).setLevel(i).build(); assertThat(testAp.getLevel()).isEqualTo(i); } // numbers larger than the max level should be set to max testAp = new TestAccessPointBuilder(mContext).setLevel(AccessPoint.SIGNAL_LEVELS).build(); assertThat(testAp.getLevel()).isEqualTo(AccessPoint.SIGNAL_LEVELS - 1); testAp = new TestAccessPointBuilder(mContext).setLevel(mMaxSignalLevel + 1).build(); assertThat(testAp.getLevel()).isEqualTo(mMaxSignalLevel); // numbers less than 0 should give level 0 testAp = new TestAccessPointBuilder(mContext).setLevel(-100).build(); Loading @@ -653,7 +656,7 @@ public class AccessPointTest { @Test public void testBuilder_settingReachableAfterLevelDoesNotAffectLevel() { int level = 1; assertThat(level).isLessThan(AccessPoint.SIGNAL_LEVELS - 1); assertThat(level).isLessThan(mMaxSignalLevel); AccessPoint testAp = new TestAccessPointBuilder(mContext).setLevel(level).setReachable(true).build(); Loading Loading
packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java +7 −12 Original line number Diff line number Diff line Loading @@ -211,13 +211,6 @@ public class AccessPoint implements Comparable<AccessPoint> { private static final int EAP_WPA = 1; // WPA-EAP private static final int EAP_WPA2_WPA3 = 2; // RSN-EAP /** * The number of distinct wifi levels. * * <p>Must keep in sync with {@link R.array.wifi_signal} and {@link WifiManager#RSSI_LEVELS}. */ public static final int SIGNAL_LEVELS = 5; public static final int UNREACHABLE_RSSI = Integer.MIN_VALUE; public static final String KEY_PREFIX_AP = "AP:"; Loading Loading @@ -453,9 +446,10 @@ public class AccessPoint implements Comparable<AccessPoint> { return other.getSpeed() - getSpeed(); } WifiManager wifiManager = getWifiManager(); // Sort by signal strength, bucketed by level int difference = WifiManager.calculateSignalLevel(other.mRssi, SIGNAL_LEVELS) - WifiManager.calculateSignalLevel(mRssi, SIGNAL_LEVELS); int difference = wifiManager.calculateSignalLevel(other.mRssi) - wifiManager.calculateSignalLevel(mRssi); if (difference != 0) { return difference; } Loading Loading @@ -869,13 +863,14 @@ public class AccessPoint implements Comparable<AccessPoint> { } /** * Returns the number of levels to show for a Wifi icon, from 0 to {@link #SIGNAL_LEVELS}-1. * Returns the number of levels to show for a Wifi icon, from 0 to * {@link WifiManager#getMaxSignalLevel()}. * * <p>Use {@#isReachable()} to determine if an AccessPoint is in range, as this method will * <p>Use {@link #isReachable()} to determine if an AccessPoint is in range, as this method will * always return at least 0. */ public int getLevel() { return WifiManager.calculateSignalLevel(mRssi, SIGNAL_LEVELS); return getWifiManager().calculateSignalLevel(mRssi); } public int getRssi() { Loading
packages/SettingsLib/src/com/android/settingslib/wifi/TestAccessPointBuilder.java +5 −2 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.net.NetworkInfo; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Bundle; import android.os.Parcelable; Loading Loading @@ -126,13 +127,15 @@ public class TestAccessPointBuilder { @Keep public TestAccessPointBuilder setLevel(int level) { // Reversal of WifiManager.calculateSignalLevels WifiManager wifiManager = mContext.getSystemService(WifiManager.class); int maxSignalLevel = wifiManager.getMaxSignalLevel(); if (level == 0) { mRssi = MIN_RSSI; } else if (level >= AccessPoint.SIGNAL_LEVELS) { } else if (level > maxSignalLevel) { mRssi = MAX_RSSI; } else { float inputRange = MAX_RSSI - MIN_RSSI; float outputRange = AccessPoint.SIGNAL_LEVELS - 1; float outputRange = maxSignalLevel; mRssi = (int) (level * inputRange / outputRange + MIN_RSSI); } return this; Loading
packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.java +10 −7 Original line number Diff line number Diff line Loading @@ -83,7 +83,6 @@ import java.util.concurrent.CountDownLatch; @SmallTest @RunWith(AndroidJUnit4.class) public class AccessPointTest { private static final String TEST_SSID = "\"test_ssid\""; private static final String ROAMING_SSID = "\"roaming_ssid\""; private static final String OSU_FRIENDLY_NAME = "osu_friendly_name"; Loading @@ -98,6 +97,7 @@ public class AccessPointTest { 20 * DateUtils.MINUTE_IN_MILLIS; private Context mContext; private int mMaxSignalLevel; private WifiInfo mWifiInfo; @Mock private Context mMockContext; @Mock private WifiManager mMockWifiManager; Loading Loading @@ -128,6 +128,7 @@ public class AccessPointTest { public void setUp() { MockitoAnnotations.initMocks(this); mContext = InstrumentationRegistry.getTargetContext(); mMaxSignalLevel = mContext.getSystemService(WifiManager.class).getMaxSignalLevel(); mWifiInfo = new WifiInfo(); mWifiInfo.setSSID(WifiSsid.createFromAsciiEncoded(TEST_SSID)); mWifiInfo.setBSSID(TEST_BSSID); Loading Loading @@ -180,7 +181,7 @@ public class AccessPointTest { @Test public void testCompareTo_GivesHighLevelBeforeLowLevel() { final int highLevel = AccessPoint.SIGNAL_LEVELS - 1; final int highLevel = mMaxSignalLevel; final int lowLevel = 1; assertThat(highLevel).isGreaterThan(lowLevel); Loading Loading @@ -226,7 +227,7 @@ public class AccessPointTest { .setReachable(true).build(); AccessPoint saved = new TestAccessPointBuilder(mContext).setSaved(true).build(); AccessPoint highLevelAndReachable = new TestAccessPointBuilder(mContext) .setLevel(AccessPoint.SIGNAL_LEVELS - 1).build(); .setLevel(mMaxSignalLevel).build(); AccessPoint firstName = new TestAccessPointBuilder(mContext).setSsid("a").build(); AccessPoint lastname = new TestAccessPointBuilder(mContext).setSsid("z").build(); Loading Loading @@ -520,6 +521,8 @@ public class AccessPointTest { when(packageManager.getApplicationInfoAsUser(eq(appPackageName), anyInt(), anyInt())) .thenReturn(applicationInfo); when(applicationInfo.loadLabel(packageManager)).thenReturn(appLabel); when(context.getSystemService(Context.WIFI_SERVICE)).thenReturn(mMockWifiManager); when(mMockWifiManager.calculateSignalLevel(rssi)).thenReturn(4); NetworkInfo networkInfo = new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", ""); Loading Loading @@ -636,14 +639,14 @@ public class AccessPointTest { public void testBuilder_setLevel() { AccessPoint testAp; for (int i = 0; i < AccessPoint.SIGNAL_LEVELS; i++) { for (int i = 0; i <= mMaxSignalLevel; i++) { testAp = new TestAccessPointBuilder(mContext).setLevel(i).build(); assertThat(testAp.getLevel()).isEqualTo(i); } // numbers larger than the max level should be set to max testAp = new TestAccessPointBuilder(mContext).setLevel(AccessPoint.SIGNAL_LEVELS).build(); assertThat(testAp.getLevel()).isEqualTo(AccessPoint.SIGNAL_LEVELS - 1); testAp = new TestAccessPointBuilder(mContext).setLevel(mMaxSignalLevel + 1).build(); assertThat(testAp.getLevel()).isEqualTo(mMaxSignalLevel); // numbers less than 0 should give level 0 testAp = new TestAccessPointBuilder(mContext).setLevel(-100).build(); Loading @@ -653,7 +656,7 @@ public class AccessPointTest { @Test public void testBuilder_settingReachableAfterLevelDoesNotAffectLevel() { int level = 1; assertThat(level).isLessThan(AccessPoint.SIGNAL_LEVELS - 1); assertThat(level).isLessThan(mMaxSignalLevel); AccessPoint testAp = new TestAccessPointBuilder(mContext).setLevel(level).setReachable(true).build(); Loading