Loading packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java +50 −19 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ import android.content.pm.ApplicationInfo; import android.content.pm.IPackageManager; import android.content.pm.PackageManager; import android.net.ConnectivityManager; import android.net.NetworkBadging; import android.net.NetworkCapabilities; import android.net.NetworkInfo; import android.net.NetworkInfo.DetailedState; Loading Loading @@ -83,6 +82,35 @@ public class AccessPoint implements Comparable<AccessPoint> { */ public static final int HIGHER_FREQ_5GHZ = 5900; /** * Constant value representing an unlabeled / unscored network. */ @VisibleForTesting static final int SPEED_NONE = 0; /** * Constant value representing a slow speed network connection. */ @VisibleForTesting static final int SPEED_SLOW = 5; /** * Constant value representing a medium speed network connection. */ @VisibleForTesting static final int SPEED_MEDIUM = 10; /** * Constant value representing a fast speed network connection. */ @VisibleForTesting static final int SPEED_FAST = 20; /** * Constant value representing a very fast speed network connection. */ @VisibleForTesting static final int SPEED_VERY_FAST = 30; /** * Experimental: we should be able to show the user the list of BSSIDs and bands Loading Loading @@ -149,7 +177,7 @@ public class AccessPoint implements Comparable<AccessPoint> { private Object mTag; private int mRankingScore = Integer.MIN_VALUE; private int mBadge = NetworkBadging.BADGING_NONE; private int mSpeed = AccessPoint.SPEED_NONE; private boolean mIsScoredNetworkMetered = false; // used to co-relate internal vs returned accesspoint. Loading Loading @@ -249,7 +277,7 @@ public class AccessPoint implements Comparable<AccessPoint> { this.mScanResultCache.clear(); this.mScanResultCache.putAll(that.mScanResultCache); this.mId = that.mId; this.mBadge = that.mBadge; this.mSpeed = that.mSpeed; this.mIsScoredNetworkMetered = that.mIsScoredNetworkMetered; this.mRankingScore = that.mRankingScore; } Loading Loading @@ -340,8 +368,8 @@ public class AccessPoint implements Comparable<AccessPoint> { if (mRankingScore != Integer.MIN_VALUE) { builder.append(",rankingScore=").append(mRankingScore); } if (mBadge != NetworkBadging.BADGING_NONE) { builder.append(",badge=").append(mBadge); if (mSpeed != SPEED_NONE) { builder.append(",speed=").append(mSpeed); } builder.append(",metered=").append(isMetered()); Loading @@ -349,7 +377,7 @@ public class AccessPoint implements Comparable<AccessPoint> { } /** * Updates the AccessPoint rankingScore, metering, and badge, returning true if the data has * Updates the AccessPoint rankingScore, metering, and speed, returning true if the data has * changed. * * @param scoreCache The score cache to use to retrieve scores. Loading @@ -364,14 +392,14 @@ public class AccessPoint implements Comparable<AccessPoint> { } /** * Updates the AccessPoint rankingScore and badge, returning true if the data has changed. * Updates the AccessPoint rankingScore and speed, returning true if the data has changed. * * @param scoreCache The score cache to use to retrieve scores. */ private boolean updateScores(WifiNetworkScoreCache scoreCache) { int oldBadge = mBadge; int oldSpeed = mSpeed; int oldRankingScore = mRankingScore; mBadge = NetworkBadging.BADGING_NONE; mSpeed = SPEED_NONE; mRankingScore = Integer.MIN_VALUE; for (ScanResult result : mScanResultCache.values()) { Loading @@ -383,10 +411,11 @@ public class AccessPoint implements Comparable<AccessPoint> { if (score.hasRankingScore()) { mRankingScore = Math.max(mRankingScore, score.calculateRankingScore(result.level)); } mBadge = Math.max(mBadge, score.calculateBadge(result.level)); // TODO(sghuman): Rename calculateBadge API mSpeed = Math.max(mSpeed, score.calculateBadge(result.level)); } return (oldBadge != mBadge || oldRankingScore != mRankingScore); return (oldSpeed != mSpeed || oldRankingScore != mRankingScore); } /** Loading Loading @@ -643,7 +672,7 @@ public class AccessPoint implements Comparable<AccessPoint> { // TODO(b/62354743): Standardize and international delimiter usage final String concatenator = " / "; if (mBadge != NetworkBadging.BADGING_NONE) { if (mSpeed != SPEED_NONE) { summary.append(getSpeedLabel() + concatenator); } Loading Loading @@ -764,7 +793,7 @@ public class AccessPoint implements Comparable<AccessPoint> { if (mRankingScore != Integer.MIN_VALUE) { visibility.append(" rankingScore=").append(getRankingScore()); } if (mBadge != NetworkBadging.BADGING_NONE) { if (mSpeed != SPEED_NONE) { visibility.append(" speed=").append(getSpeedLabel()); } visibility.append(String.format(" tx=%.1f,", mInfo.txSuccessRate)); Loading Loading @@ -1062,18 +1091,20 @@ public class AccessPoint implements Comparable<AccessPoint> { return mRankingScore; } int getBadge() { return mBadge;} int getSpeed() { return mSpeed;} @Nullable String getSpeedLabel() { switch (mBadge) { case NetworkBadging.BADGING_4K: switch (mSpeed) { case SPEED_VERY_FAST: return mContext.getString(R.string.speed_label_very_fast); case NetworkBadging.BADGING_HD: case SPEED_FAST: return mContext.getString(R.string.speed_label_fast); case NetworkBadging.BADGING_SD: case SPEED_MEDIUM: return mContext.getString(R.string.speed_label_okay); case NetworkBadging.BADGING_NONE: case SPEED_SLOW: return mContext.getString(R.string.speed_label_slow); case SPEED_NONE: default: return null; } Loading packages/SettingsLib/src/com/android/settingslib/wifi/AccessPointPreference.java +5 −5 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ public class AccessPointPreference extends Preference { private int mLevel; private CharSequence mContentDescription; private int mDefaultIconResId; private int mWifiBadge = NetworkBadging.BADGING_NONE; private int mWifiSpeed = NetworkBadging.BADGING_NONE; static final int[] WIFI_CONNECTION_STRENGTH = { R.string.accessibility_no_wifi, Loading Loading @@ -161,7 +161,7 @@ public class AccessPointPreference extends Preference { safeSetDefaultIcon(); return; } TronUtils.logWifiSettingsBadge(context, mWifiBadge); TronUtils.logWifiSettingsBadge(context, mWifiSpeed); // TODO(b/62355275): Revert this to N code after deleting NetworkBadging API Drawable drawable = NetworkBadging.getWifiIcon( Loading Loading @@ -223,10 +223,10 @@ public class AccessPointPreference extends Preference { final Context context = getContext(); int level = mAccessPoint.getLevel(); int wifiBadge = mAccessPoint.getBadge(); if (level != mLevel || wifiBadge != mWifiBadge) { int wifiSpeed = mAccessPoint.getSpeed(); if (level != mLevel || wifiSpeed != mWifiSpeed) { mLevel = level; mWifiBadge = wifiBadge; mWifiSpeed = wifiSpeed; updateIcon(mLevel, context); notifyChanged(); } Loading packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.java +26 −12 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ import static org.mockito.Mockito.when; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkBadging; import android.net.NetworkInfo; import android.net.NetworkKey; import android.net.RssiCurve; Loading Loading @@ -330,57 +329,72 @@ public class AccessPointTest { } @Test public void testSpeedLabel_returnsVeryFastWhen4kBadgeIsSet() { public void testSpeedLabel_returnsVeryFast() { AccessPoint ap = createAccessPointWithScanResultCache(); when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class))) .thenReturn(buildScoredNetworkWithMockBadgeCurve()); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) NetworkBadging.BADGING_4K); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.SPEED_VERY_FAST); ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */); assertThat(ap.getBadge()).isEqualTo(NetworkBadging.BADGING_4K); assertThat(ap.getSpeed()).isEqualTo(AccessPoint.SPEED_VERY_FAST); assertThat(ap.getSpeedLabel()) .isEqualTo(mContext.getString(R.string.speed_label_very_fast)); } @Test public void testSpeedLabel_returnsFastWhenHdBadgeIsSet() { public void testSpeedLabel_returnsFast() { AccessPoint ap = createAccessPointWithScanResultCache(); when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class))) .thenReturn(buildScoredNetworkWithMockBadgeCurve()); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) NetworkBadging.BADGING_HD); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.SPEED_FAST); ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */); assertThat(ap.getBadge()).isEqualTo(NetworkBadging.BADGING_HD); assertThat(ap.getSpeed()).isEqualTo(AccessPoint.SPEED_FAST); assertThat(ap.getSpeedLabel()) .isEqualTo(mContext.getString(R.string.speed_label_fast)); } @Test public void testSpeedLabel_returnsOkayWhenSdBadgeIsSet() { public void testSpeedLabel_returnsOkay() { AccessPoint ap = createAccessPointWithScanResultCache(); when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class))) .thenReturn(buildScoredNetworkWithMockBadgeCurve()); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) NetworkBadging.BADGING_SD); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.SPEED_MEDIUM); ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */); assertThat(ap.getBadge()).isEqualTo(NetworkBadging.BADGING_SD); assertThat(ap.getSpeed()).isEqualTo(AccessPoint.SPEED_MEDIUM); assertThat(ap.getSpeedLabel()) .isEqualTo(mContext.getString(R.string.speed_label_okay)); } @Test public void testSpeedLabel_returnsSlow() { AccessPoint ap = createAccessPointWithScanResultCache(); when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class))) .thenReturn(buildScoredNetworkWithMockBadgeCurve()); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.SPEED_SLOW); ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */); assertThat(ap.getSpeed()).isEqualTo(AccessPoint.SPEED_SLOW); assertThat(ap.getSpeedLabel()) .isEqualTo(mContext.getString(R.string.speed_label_slow)); } @Test public void testSummaryString_showsSpeedLabel() { AccessPoint ap = createAccessPointWithScanResultCache(); when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class))) .thenReturn(buildScoredNetworkWithMockBadgeCurve()); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) NetworkBadging.BADGING_4K); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.SPEED_VERY_FAST); ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */); Loading @@ -394,7 +408,7 @@ public class AccessPointTest { when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class))) .thenReturn(buildScoredNetworkWithMockBadgeCurve()); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) NetworkBadging.BADGING_4K); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.SPEED_VERY_FAST); ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */); Loading packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java +9 −9 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; import android.net.Network; import android.net.NetworkBadging; import android.net.NetworkInfo; import android.net.NetworkKey; import android.net.NetworkScoreManager; Loading Loading @@ -94,7 +93,7 @@ public class WifiTrackerTest { new NetworkKey(new WifiKey('"' + SSID_1 + '"', BSSID_1)); private static final int RSSI_1 = -30; private static final byte SCORE_1 = 10; private static final int BADGE_1 = NetworkBadging.BADGING_SD; private static final int BADGE_1 = AccessPoint.SPEED_MEDIUM; private static final String SSID_2 = "ssid2"; private static final String BSSID_2 = "AA:AA:AA:AA:AA:AA"; Loading @@ -102,7 +101,7 @@ public class WifiTrackerTest { new NetworkKey(new WifiKey('"' + SSID_2 + '"', BSSID_2)); private static final int RSSI_2 = -30; private static final byte SCORE_2 = 15; private static final int BADGE_2 = NetworkBadging.BADGING_HD; private static final int BADGE_2 = AccessPoint.SPEED_FAST; private static final int CONNECTED_NETWORK_ID = 123; private static final int CONNECTED_RSSI = -50; Loading Loading @@ -511,7 +510,8 @@ public class WifiTrackerTest { } @Test public void scoreCacheUpdateScoresShouldInsertBadgeIntoAccessPoint() throws InterruptedException { public void scoreCacheUpdateScoresShouldInsertSpeedIntoAccessPoint() throws InterruptedException { WifiTracker tracker = createTrackerWithImmediateBroadcastsAndInjectInitialScanResults(); updateScoresAndWaitForAccessPointsChangedCallback(); Loading @@ -519,9 +519,9 @@ public class WifiTrackerTest { for (AccessPoint ap : aps) { if (ap.getSsidStr().equals(SSID_1)) { assertEquals(BADGE_1, ap.getBadge()); assertEquals(BADGE_1, ap.getSpeed()); } else if (ap.getSsidStr().equals(SSID_2)) { assertEquals(BADGE_2, ap.getBadge()); assertEquals(BADGE_2, ap.getSpeed()); } } } Loading @@ -544,7 +544,7 @@ public class WifiTrackerTest { } @Test public void noBadgesShouldBeInsertedIntoAccessPointWhenScoringUiDisabled() public void noSpeedsShouldBeInsertedIntoAccessPointWhenScoringUiDisabled() throws InterruptedException { Settings.Global.putInt( InstrumentationRegistry.getTargetContext().getContentResolver(), Loading @@ -558,9 +558,9 @@ public class WifiTrackerTest { for (AccessPoint ap : aps) { if (ap.getSsidStr().equals(SSID_1)) { assertEquals(NetworkBadging.BADGING_NONE, ap.getBadge()); assertEquals(AccessPoint.SPEED_NONE, ap.getSpeed()); } else if (ap.getSsidStr().equals(SSID_2)) { assertEquals(NetworkBadging.BADGING_NONE, ap.getBadge()); assertEquals(AccessPoint.SPEED_NONE, ap.getSpeed()); } } } Loading Loading
packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java +50 −19 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ import android.content.pm.ApplicationInfo; import android.content.pm.IPackageManager; import android.content.pm.PackageManager; import android.net.ConnectivityManager; import android.net.NetworkBadging; import android.net.NetworkCapabilities; import android.net.NetworkInfo; import android.net.NetworkInfo.DetailedState; Loading Loading @@ -83,6 +82,35 @@ public class AccessPoint implements Comparable<AccessPoint> { */ public static final int HIGHER_FREQ_5GHZ = 5900; /** * Constant value representing an unlabeled / unscored network. */ @VisibleForTesting static final int SPEED_NONE = 0; /** * Constant value representing a slow speed network connection. */ @VisibleForTesting static final int SPEED_SLOW = 5; /** * Constant value representing a medium speed network connection. */ @VisibleForTesting static final int SPEED_MEDIUM = 10; /** * Constant value representing a fast speed network connection. */ @VisibleForTesting static final int SPEED_FAST = 20; /** * Constant value representing a very fast speed network connection. */ @VisibleForTesting static final int SPEED_VERY_FAST = 30; /** * Experimental: we should be able to show the user the list of BSSIDs and bands Loading Loading @@ -149,7 +177,7 @@ public class AccessPoint implements Comparable<AccessPoint> { private Object mTag; private int mRankingScore = Integer.MIN_VALUE; private int mBadge = NetworkBadging.BADGING_NONE; private int mSpeed = AccessPoint.SPEED_NONE; private boolean mIsScoredNetworkMetered = false; // used to co-relate internal vs returned accesspoint. Loading Loading @@ -249,7 +277,7 @@ public class AccessPoint implements Comparable<AccessPoint> { this.mScanResultCache.clear(); this.mScanResultCache.putAll(that.mScanResultCache); this.mId = that.mId; this.mBadge = that.mBadge; this.mSpeed = that.mSpeed; this.mIsScoredNetworkMetered = that.mIsScoredNetworkMetered; this.mRankingScore = that.mRankingScore; } Loading Loading @@ -340,8 +368,8 @@ public class AccessPoint implements Comparable<AccessPoint> { if (mRankingScore != Integer.MIN_VALUE) { builder.append(",rankingScore=").append(mRankingScore); } if (mBadge != NetworkBadging.BADGING_NONE) { builder.append(",badge=").append(mBadge); if (mSpeed != SPEED_NONE) { builder.append(",speed=").append(mSpeed); } builder.append(",metered=").append(isMetered()); Loading @@ -349,7 +377,7 @@ public class AccessPoint implements Comparable<AccessPoint> { } /** * Updates the AccessPoint rankingScore, metering, and badge, returning true if the data has * Updates the AccessPoint rankingScore, metering, and speed, returning true if the data has * changed. * * @param scoreCache The score cache to use to retrieve scores. Loading @@ -364,14 +392,14 @@ public class AccessPoint implements Comparable<AccessPoint> { } /** * Updates the AccessPoint rankingScore and badge, returning true if the data has changed. * Updates the AccessPoint rankingScore and speed, returning true if the data has changed. * * @param scoreCache The score cache to use to retrieve scores. */ private boolean updateScores(WifiNetworkScoreCache scoreCache) { int oldBadge = mBadge; int oldSpeed = mSpeed; int oldRankingScore = mRankingScore; mBadge = NetworkBadging.BADGING_NONE; mSpeed = SPEED_NONE; mRankingScore = Integer.MIN_VALUE; for (ScanResult result : mScanResultCache.values()) { Loading @@ -383,10 +411,11 @@ public class AccessPoint implements Comparable<AccessPoint> { if (score.hasRankingScore()) { mRankingScore = Math.max(mRankingScore, score.calculateRankingScore(result.level)); } mBadge = Math.max(mBadge, score.calculateBadge(result.level)); // TODO(sghuman): Rename calculateBadge API mSpeed = Math.max(mSpeed, score.calculateBadge(result.level)); } return (oldBadge != mBadge || oldRankingScore != mRankingScore); return (oldSpeed != mSpeed || oldRankingScore != mRankingScore); } /** Loading Loading @@ -643,7 +672,7 @@ public class AccessPoint implements Comparable<AccessPoint> { // TODO(b/62354743): Standardize and international delimiter usage final String concatenator = " / "; if (mBadge != NetworkBadging.BADGING_NONE) { if (mSpeed != SPEED_NONE) { summary.append(getSpeedLabel() + concatenator); } Loading Loading @@ -764,7 +793,7 @@ public class AccessPoint implements Comparable<AccessPoint> { if (mRankingScore != Integer.MIN_VALUE) { visibility.append(" rankingScore=").append(getRankingScore()); } if (mBadge != NetworkBadging.BADGING_NONE) { if (mSpeed != SPEED_NONE) { visibility.append(" speed=").append(getSpeedLabel()); } visibility.append(String.format(" tx=%.1f,", mInfo.txSuccessRate)); Loading Loading @@ -1062,18 +1091,20 @@ public class AccessPoint implements Comparable<AccessPoint> { return mRankingScore; } int getBadge() { return mBadge;} int getSpeed() { return mSpeed;} @Nullable String getSpeedLabel() { switch (mBadge) { case NetworkBadging.BADGING_4K: switch (mSpeed) { case SPEED_VERY_FAST: return mContext.getString(R.string.speed_label_very_fast); case NetworkBadging.BADGING_HD: case SPEED_FAST: return mContext.getString(R.string.speed_label_fast); case NetworkBadging.BADGING_SD: case SPEED_MEDIUM: return mContext.getString(R.string.speed_label_okay); case NetworkBadging.BADGING_NONE: case SPEED_SLOW: return mContext.getString(R.string.speed_label_slow); case SPEED_NONE: default: return null; } Loading
packages/SettingsLib/src/com/android/settingslib/wifi/AccessPointPreference.java +5 −5 Original line number Diff line number Diff line Loading @@ -60,7 +60,7 @@ public class AccessPointPreference extends Preference { private int mLevel; private CharSequence mContentDescription; private int mDefaultIconResId; private int mWifiBadge = NetworkBadging.BADGING_NONE; private int mWifiSpeed = NetworkBadging.BADGING_NONE; static final int[] WIFI_CONNECTION_STRENGTH = { R.string.accessibility_no_wifi, Loading Loading @@ -161,7 +161,7 @@ public class AccessPointPreference extends Preference { safeSetDefaultIcon(); return; } TronUtils.logWifiSettingsBadge(context, mWifiBadge); TronUtils.logWifiSettingsBadge(context, mWifiSpeed); // TODO(b/62355275): Revert this to N code after deleting NetworkBadging API Drawable drawable = NetworkBadging.getWifiIcon( Loading Loading @@ -223,10 +223,10 @@ public class AccessPointPreference extends Preference { final Context context = getContext(); int level = mAccessPoint.getLevel(); int wifiBadge = mAccessPoint.getBadge(); if (level != mLevel || wifiBadge != mWifiBadge) { int wifiSpeed = mAccessPoint.getSpeed(); if (level != mLevel || wifiSpeed != mWifiSpeed) { mLevel = level; mWifiBadge = wifiBadge; mWifiSpeed = wifiSpeed; updateIcon(mLevel, context); notifyChanged(); } Loading
packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/AccessPointTest.java +26 −12 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ import static org.mockito.Mockito.when; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkBadging; import android.net.NetworkInfo; import android.net.NetworkKey; import android.net.RssiCurve; Loading Loading @@ -330,57 +329,72 @@ public class AccessPointTest { } @Test public void testSpeedLabel_returnsVeryFastWhen4kBadgeIsSet() { public void testSpeedLabel_returnsVeryFast() { AccessPoint ap = createAccessPointWithScanResultCache(); when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class))) .thenReturn(buildScoredNetworkWithMockBadgeCurve()); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) NetworkBadging.BADGING_4K); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.SPEED_VERY_FAST); ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */); assertThat(ap.getBadge()).isEqualTo(NetworkBadging.BADGING_4K); assertThat(ap.getSpeed()).isEqualTo(AccessPoint.SPEED_VERY_FAST); assertThat(ap.getSpeedLabel()) .isEqualTo(mContext.getString(R.string.speed_label_very_fast)); } @Test public void testSpeedLabel_returnsFastWhenHdBadgeIsSet() { public void testSpeedLabel_returnsFast() { AccessPoint ap = createAccessPointWithScanResultCache(); when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class))) .thenReturn(buildScoredNetworkWithMockBadgeCurve()); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) NetworkBadging.BADGING_HD); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.SPEED_FAST); ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */); assertThat(ap.getBadge()).isEqualTo(NetworkBadging.BADGING_HD); assertThat(ap.getSpeed()).isEqualTo(AccessPoint.SPEED_FAST); assertThat(ap.getSpeedLabel()) .isEqualTo(mContext.getString(R.string.speed_label_fast)); } @Test public void testSpeedLabel_returnsOkayWhenSdBadgeIsSet() { public void testSpeedLabel_returnsOkay() { AccessPoint ap = createAccessPointWithScanResultCache(); when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class))) .thenReturn(buildScoredNetworkWithMockBadgeCurve()); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) NetworkBadging.BADGING_SD); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.SPEED_MEDIUM); ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */); assertThat(ap.getBadge()).isEqualTo(NetworkBadging.BADGING_SD); assertThat(ap.getSpeed()).isEqualTo(AccessPoint.SPEED_MEDIUM); assertThat(ap.getSpeedLabel()) .isEqualTo(mContext.getString(R.string.speed_label_okay)); } @Test public void testSpeedLabel_returnsSlow() { AccessPoint ap = createAccessPointWithScanResultCache(); when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class))) .thenReturn(buildScoredNetworkWithMockBadgeCurve()); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.SPEED_SLOW); ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */); assertThat(ap.getSpeed()).isEqualTo(AccessPoint.SPEED_SLOW); assertThat(ap.getSpeedLabel()) .isEqualTo(mContext.getString(R.string.speed_label_slow)); } @Test public void testSummaryString_showsSpeedLabel() { AccessPoint ap = createAccessPointWithScanResultCache(); when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class))) .thenReturn(buildScoredNetworkWithMockBadgeCurve()); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) NetworkBadging.BADGING_4K); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.SPEED_VERY_FAST); ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */); Loading @@ -394,7 +408,7 @@ public class AccessPointTest { when(mockWifiNetworkScoreCache.getScoredNetwork(any(ScanResult.class))) .thenReturn(buildScoredNetworkWithMockBadgeCurve()); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) NetworkBadging.BADGING_4K); when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) AccessPoint.SPEED_VERY_FAST); ap.update(mockWifiNetworkScoreCache, true /* scoringUiEnabled */); Loading
packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java +9 −9 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; import android.net.Network; import android.net.NetworkBadging; import android.net.NetworkInfo; import android.net.NetworkKey; import android.net.NetworkScoreManager; Loading Loading @@ -94,7 +93,7 @@ public class WifiTrackerTest { new NetworkKey(new WifiKey('"' + SSID_1 + '"', BSSID_1)); private static final int RSSI_1 = -30; private static final byte SCORE_1 = 10; private static final int BADGE_1 = NetworkBadging.BADGING_SD; private static final int BADGE_1 = AccessPoint.SPEED_MEDIUM; private static final String SSID_2 = "ssid2"; private static final String BSSID_2 = "AA:AA:AA:AA:AA:AA"; Loading @@ -102,7 +101,7 @@ public class WifiTrackerTest { new NetworkKey(new WifiKey('"' + SSID_2 + '"', BSSID_2)); private static final int RSSI_2 = -30; private static final byte SCORE_2 = 15; private static final int BADGE_2 = NetworkBadging.BADGING_HD; private static final int BADGE_2 = AccessPoint.SPEED_FAST; private static final int CONNECTED_NETWORK_ID = 123; private static final int CONNECTED_RSSI = -50; Loading Loading @@ -511,7 +510,8 @@ public class WifiTrackerTest { } @Test public void scoreCacheUpdateScoresShouldInsertBadgeIntoAccessPoint() throws InterruptedException { public void scoreCacheUpdateScoresShouldInsertSpeedIntoAccessPoint() throws InterruptedException { WifiTracker tracker = createTrackerWithImmediateBroadcastsAndInjectInitialScanResults(); updateScoresAndWaitForAccessPointsChangedCallback(); Loading @@ -519,9 +519,9 @@ public class WifiTrackerTest { for (AccessPoint ap : aps) { if (ap.getSsidStr().equals(SSID_1)) { assertEquals(BADGE_1, ap.getBadge()); assertEquals(BADGE_1, ap.getSpeed()); } else if (ap.getSsidStr().equals(SSID_2)) { assertEquals(BADGE_2, ap.getBadge()); assertEquals(BADGE_2, ap.getSpeed()); } } } Loading @@ -544,7 +544,7 @@ public class WifiTrackerTest { } @Test public void noBadgesShouldBeInsertedIntoAccessPointWhenScoringUiDisabled() public void noSpeedsShouldBeInsertedIntoAccessPointWhenScoringUiDisabled() throws InterruptedException { Settings.Global.putInt( InstrumentationRegistry.getTargetContext().getContentResolver(), Loading @@ -558,9 +558,9 @@ public class WifiTrackerTest { for (AccessPoint ap : aps) { if (ap.getSsidStr().equals(SSID_1)) { assertEquals(NetworkBadging.BADGING_NONE, ap.getBadge()); assertEquals(AccessPoint.SPEED_NONE, ap.getSpeed()); } else if (ap.getSsidStr().equals(SSID_2)) { assertEquals(NetworkBadging.BADGING_NONE, ap.getBadge()); assertEquals(AccessPoint.SPEED_NONE, ap.getSpeed()); } } } Loading