Move Badging from ScoredNetwork to NetworkingBadging.

This is a non-functional refactor. The old enums will be removed once
ag/35323372 is addressed.

Bug: 35114358
Test: Ran existing tests (see files touched).
Change-Id: I08fd8c7964463b5908ce361e61f8fe811d0ff6f3
This commit is contained in:
Sundeep Ghuman
2017-02-13 15:32:13 -08:00
parent b3f417ec3a
commit 699deaf610
11 changed files with 92 additions and 65 deletions

View File

@@ -26923,6 +26923,13 @@ package android.net {
public class NetworkBadging {
method public static android.graphics.drawable.Drawable getWifiIcon(int, int, android.content.res.Resources.Theme);
field public static final int BADGING_4K = 30; // 0x1e
field public static final int BADGING_HD = 20; // 0x14
field public static final int BADGING_NONE = 0; // 0x0
field public static final int BADGING_SD = 10; // 0xa
}
public static abstract class NetworkBadging.Badging implements java.lang.annotation.Annotation {
}
public final class NetworkCapabilities implements android.os.Parcelable {
@@ -27186,10 +27193,10 @@ package android.net {
field public static final java.lang.String ATTRIBUTES_KEY_BADGING_CURVE = "android.net.attributes.key.BADGING_CURVE";
field public static final java.lang.String ATTRIBUTES_KEY_HAS_CAPTIVE_PORTAL = "android.net.attributes.key.HAS_CAPTIVE_PORTAL";
field public static final java.lang.String ATTRIBUTES_KEY_RANKING_SCORE_OFFSET = "android.net.attributes.key.RANKING_SCORE_OFFSET";
field public static final int BADGING_4K = 30; // 0x1e
field public static final int BADGING_HD = 20; // 0x14
field public static final int BADGING_NONE = 0; // 0x0
field public static final int BADGING_SD = 10; // 0xa
field public static final deprecated int BADGING_4K = 30; // 0x1e
field public static final deprecated int BADGING_HD = 20; // 0x14
field public static final deprecated int BADGING_NONE = 0; // 0x0
field public static final deprecated int BADGING_SD = 10; // 0xa
field public static final android.os.Parcelable.Creator<android.net.ScoredNetwork> CREATOR;
field public final android.os.Bundle attributes;
field public final boolean meteredHint;
@@ -27197,7 +27204,7 @@ package android.net {
field public final android.net.RssiCurve rssiCurve;
}
public static abstract class ScoredNetwork.Badging implements java.lang.annotation.Annotation {
public static abstract deprecated class ScoredNetwork.Badging implements java.lang.annotation.Annotation {
}
public class TrafficStats {

View File

@@ -17,6 +17,7 @@
package android.net;
import android.annotation.DrawableRes;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -25,19 +26,29 @@ import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.net.ScoredNetwork.Badging;
import android.net.wifi.WifiManager;
import android.view.View;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Utility methods for working with network badging.
*
* TODO: move ScoredNetwork.Badging and related constants to this class.
*
* @hide
*/
@SystemApi
public class NetworkBadging {
@IntDef({BADGING_NONE, BADGING_SD, BADGING_HD, BADGING_4K})
@Retention(RetentionPolicy.SOURCE)
public @interface Badging {}
public static final int BADGING_NONE = 0;
public static final int BADGING_SD = 10;
public static final int BADGING_HD = 20;
public static final int BADGING_4K = 30;
private NetworkBadging() {}
/**
@@ -55,7 +66,7 @@ public class NetworkBadging {
@NonNull public static Drawable getWifiIcon(
@IntRange(from=0, to=4) int signalLevel, @Badging int badging, @Nullable Theme theme) {
Resources resources = Resources.getSystem();
if (badging == ScoredNetwork.BADGING_NONE) {
if (badging == BADGING_NONE) {
return resources.getDrawable(getWifiSignalResource(signalLevel), theme);
}
Drawable[] layers = new Drawable[] {
@@ -131,19 +142,19 @@ public class NetworkBadging {
*
* @param badging {@see ScoredNetwork#Badging} from {@link ScoredNetwork#calculateBadge(int)}.
* @return the @DrawableRes for the icon or {@link View#NO_ID} for
* {@link ScoredNetwork#BADGING_NONE}
* {@link NetworkBadging#BADGING_NONE}
* @throws IllegalArgumentException for an invalid badging value.
* @hide
*/
@DrawableRes private static int getWifiBadgeResource(@Badging int badging) {
switch (badging) {
case ScoredNetwork.BADGING_NONE:
case BADGING_NONE:
return View.NO_ID;
case ScoredNetwork.BADGING_SD:
case BADGING_SD:
return com.android.internal.R.drawable.ic_signal_wifi_badged_sd;
case ScoredNetwork.BADGING_HD:
case BADGING_HD:
return com.android.internal.R.drawable.ic_signal_wifi_badged_hd;
case ScoredNetwork.BADGING_4K:
case BADGING_4K:
return com.android.internal.R.drawable.ic_signal_wifi_badged_4k;
default:
throw new IllegalArgumentException("No resource found for badge: " + badging);

View File

@@ -41,7 +41,7 @@ public class ScoredNetwork implements Parcelable {
* Key used with the {@link #attributes} bundle to define the badging curve.
*
* <p>The badging curve is a {@link RssiCurve} used to map different RSSI values to {@link
* Badging} enums.
* NetworkBadging.Badging} enums.
*/
public static final String ATTRIBUTES_KEY_BADGING_CURVE =
"android.net.attributes.key.BADGING_CURVE";
@@ -70,17 +70,31 @@ public class ScoredNetwork implements Parcelable {
public static final String ATTRIBUTES_KEY_RANKING_SCORE_OFFSET =
"android.net.attributes.key.RANKING_SCORE_OFFSET";
/** A {@link NetworkKey} uniquely identifying this network. */
public final NetworkKey networkKey;
// TODO(b/35323372): Delete these once external references are switched.
/** @deprecated Use {@link NetworkBadging#Badging} instead. */
@Deprecated
@IntDef({BADGING_NONE, BADGING_SD, BADGING_HD, BADGING_4K})
@Retention(RetentionPolicy.SOURCE)
public @interface Badging {}
/** @deprecated Use {@link NetworkBadging#BADGING_NONE} instead. */
@Deprecated
public static final int BADGING_NONE = 0;
public static final int BADGING_SD = 10;
public static final int BADGING_HD = 20;
public static final int BADGING_4K = 30;
/** A {@link NetworkKey} uniquely identifying this network. */
public final NetworkKey networkKey;
/** @deprecated Use {@link NetworkBadging#BADGING_SD} instead. */
@Deprecated
public static final int BADGING_SD = 10;
/** @deprecated Use {@link NetworkBadging#BADGING_HD} instead. */
@Deprecated
public static final int BADGING_HD = 20;
/** @deprecated Use {@link NetworkBadging#BADGING_4K} instead. */
@Deprecated
public static final int BADGING_4K = 30;
/**
* The {@link RssiCurve} representing the scores for this network based on the RSSI.
@@ -276,14 +290,14 @@ public class ScoredNetwork implements Parcelable {
}
/**
* Return the {@link Badging} enum for this network for the given RSSI, derived from the
* Return the {@link NetworkBadging.Badging} enum for this network for the given RSSI, derived from the
* badging curve.
*
* <p>If no badging curve is present, {@link #BADGE_NONE} will be returned.
*
* @param rssi The rssi level for which the badge should be calculated
*/
@Badging
@NetworkBadging.Badging
public int calculateBadge(int rssi) {
if (attributes != null && attributes.containsKey(ATTRIBUTES_KEY_BADGING_CURVE)) {
RssiCurve badgingCurve =
@@ -291,7 +305,7 @@ public class ScoredNetwork implements Parcelable {
return badgingCurve.lookupScore(rssi);
}
return BADGING_NONE;
return NetworkBadging.BADGING_NONE;
}
public static final Parcelable.Creator<ScoredNetwork> CREATOR =

View File

@@ -18,13 +18,10 @@ package android.net;
import static org.junit.Assert.*;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcel;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -170,41 +167,41 @@ public class ScoredNetworkTest {
@Test
public void calculateBadgeShouldReturnNoBadgeWhenNoAttributesBundle() {
ScoredNetwork network = new ScoredNetwork(KEY, CURVE);
assertEquals(ScoredNetwork.BADGING_NONE, network.calculateBadge(TEST_RSSI));
assertEquals(NetworkBadging.BADGING_NONE, network.calculateBadge(TEST_RSSI));
}
@Test
public void calculateBadgeShouldReturnNoBadgeWhenNoBadgingCurveInBundle() {
ScoredNetwork network = new ScoredNetwork(KEY, CURVE, false /* meteredHint */, ATTRIBUTES);
assertEquals(ScoredNetwork.BADGING_NONE, network.calculateBadge(TEST_RSSI));
assertEquals(NetworkBadging.BADGING_NONE, network.calculateBadge(TEST_RSSI));
}
@Test
public void calculateBadgeShouldReturn4kBadge() {
ScoredNetwork network =
buildScoredNetworkWithGivenBadgeForTestRssi(ScoredNetwork.BADGING_4K);
assertEquals(ScoredNetwork.BADGING_4K, network.calculateBadge(TEST_RSSI));
buildScoredNetworkWithGivenBadgeForTestRssi(NetworkBadging.BADGING_4K);
assertEquals(NetworkBadging.BADGING_4K, network.calculateBadge(TEST_RSSI));
}
@Test
public void calculateBadgeShouldReturnHdBadge() {
ScoredNetwork network =
buildScoredNetworkWithGivenBadgeForTestRssi(ScoredNetwork.BADGING_HD);
assertEquals(ScoredNetwork.BADGING_HD, network.calculateBadge(TEST_RSSI));
buildScoredNetworkWithGivenBadgeForTestRssi(NetworkBadging.BADGING_HD);
assertEquals(NetworkBadging.BADGING_HD, network.calculateBadge(TEST_RSSI));
}
@Test
public void calculateBadgeShouldReturnSdBadge() {
ScoredNetwork network =
buildScoredNetworkWithGivenBadgeForTestRssi(ScoredNetwork.BADGING_SD);
assertEquals(ScoredNetwork.BADGING_SD, network.calculateBadge(TEST_RSSI));
buildScoredNetworkWithGivenBadgeForTestRssi(NetworkBadging.BADGING_SD);
assertEquals(NetworkBadging.BADGING_SD, network.calculateBadge(TEST_RSSI));
}
@Test
public void calculateBadgeShouldReturnNoBadge() {
ScoredNetwork network =
buildScoredNetworkWithGivenBadgeForTestRssi(ScoredNetwork.BADGING_NONE);
assertEquals(ScoredNetwork.BADGING_NONE, network.calculateBadge(TEST_RSSI));
buildScoredNetworkWithGivenBadgeForTestRssi(NetworkBadging.BADGING_NONE);
assertEquals(NetworkBadging.BADGING_NONE, network.calculateBadge(TEST_RSSI));
}
private ScoredNetwork buildScoredNetworkWithGivenBadgeForTestRssi(int badge) {

View File

@@ -16,7 +16,7 @@
package com.android.settingslib;
import android.content.Context;
import android.net.ScoredNetwork;
import android.net.NetworkBadging;
import com.android.internal.logging.MetricsLogger;
@@ -34,7 +34,7 @@ public final class TronUtils {
*
* @param context Context
* @param histogram the Tron histogram name to write to
* @param badgeEnum the {@link ScoredNetwork.Badging} badge value
* @param badgeEnum the {@link NetworkBadging.Badging} badge value
* @throws IllegalArgumentException if the given badge enum is not supported
*/
private static void logNetworkBadgeMetric(
@@ -42,16 +42,16 @@ public final class TronUtils {
throws IllegalArgumentException {
int bucket;
switch (badgeEnum) {
case ScoredNetwork.BADGING_NONE:
case NetworkBadging.BADGING_NONE:
bucket = 0;
break;
case ScoredNetwork.BADGING_SD:
case NetworkBadging.BADGING_SD:
bucket = 1;
break;
case ScoredNetwork.BADGING_HD:
case NetworkBadging.BADGING_HD:
bucket = 2;
break;
case ScoredNetwork.BADGING_4K:
case NetworkBadging.BADGING_4K:
bucket = 3;
break;
default:

View File

@@ -17,7 +17,7 @@ import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.net.ConnectivityManager;
import android.net.ScoredNetwork;
import android.net.NetworkBadging;
import android.os.BatteryManager;
import android.os.UserManager;
import android.print.PrintManager;
@@ -297,13 +297,13 @@ public class Utils {
*/
public static int getWifiBadgeResource(int badge) {
switch (badge) {
case ScoredNetwork.BADGING_NONE:
case NetworkBadging.BADGING_NONE:
return View.NO_ID;
case ScoredNetwork.BADGING_SD:
case NetworkBadging.BADGING_SD:
return com.android.internal.R.drawable.ic_signal_wifi_badged_sd;
case ScoredNetwork.BADGING_HD:
case NetworkBadging.BADGING_HD:
return com.android.internal.R.drawable.ic_signal_wifi_badged_hd;
case ScoredNetwork.BADGING_4K:
case NetworkBadging.BADGING_4K:
return com.android.internal.R.drawable.ic_signal_wifi_badged_4k;
default:
throw new IllegalArgumentException(

View File

@@ -22,12 +22,11 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.Network;
import android.net.NetworkBadging;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkInfo.DetailedState;
import android.net.NetworkInfo.State;
import android.net.NetworkKey;
import android.net.ScoredNetwork;
import android.net.wifi.IWifiManager;
import android.net.wifi.ScanResult;
@@ -51,7 +50,6 @@ import android.util.Log;
import com.android.settingslib.R;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
@@ -137,7 +135,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
private Object mTag;
private int mRankingScore = Integer.MIN_VALUE;
private int mBadge = ScoredNetwork.BADGING_NONE;
private int mBadge = NetworkBadging.BADGING_NONE;
// used to co-relate internal vs returned accesspoint.
int mId;
@@ -296,7 +294,7 @@ public class AccessPoint implements Comparable<AccessPoint> {
boolean updateScores(WifiNetworkScoreCache scoreCache) {
int oldBadge = mBadge;
int oldRankingScore = mRankingScore;
mBadge = ScoredNetwork.BADGING_NONE;
mBadge = NetworkBadging.BADGING_NONE;
mRankingScore = Integer.MIN_VALUE;
for (ScanResult result : mScanResultCache.values()) {

View File

@@ -22,7 +22,6 @@ import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.net.NetworkBadging;
import android.net.ScoredNetwork;
import android.net.wifi.WifiConfiguration;
import android.os.Looper;
import android.os.UserHandle;
@@ -61,7 +60,7 @@ public class AccessPointPreference extends Preference {
private int mLevel;
private CharSequence mContentDescription;
private int mDefaultIconResId;
private int mWifiBadge = ScoredNetwork.BADGING_NONE;
private int mWifiBadge = NetworkBadging.BADGING_NONE;
static final int[] WIFI_CONNECTION_STRENGTH = {
R.string.accessibility_wifi_one_bar,

View File

@@ -27,6 +27,7 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkBadging;
import android.net.NetworkKey;
import android.net.NetworkScoreManager;
import android.net.ScoredNetwork;
@@ -80,7 +81,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 = ScoredNetwork.BADGING_SD;
private static final int BADGE_1 = NetworkBadging.BADGING_SD;
private static final String SSID_2 = "ssid2";
private static final String BSSID_2 = "AA:AA:AA:AA:AA:AA";
@@ -88,7 +89,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 = ScoredNetwork.BADGING_HD;
private static final int BADGE_2 = NetworkBadging.BADGING_HD;
@Captor ArgumentCaptor<WifiNetworkScoreCache> mScoreCacheCaptor;
@Mock private ConnectivityManager mockConnectivityManager;
@@ -460,9 +461,9 @@ public class WifiTrackerTest {
for (AccessPoint ap : aps) {
if (ap.getSsidStr().equals(SSID_1)) {
assertEquals(ScoredNetwork.BADGING_NONE, ap.getBadge());
assertEquals(NetworkBadging.BADGING_NONE, ap.getBadge());
} else if (ap.getSsidStr().equals(SSID_2)) {
assertEquals(ScoredNetwork.BADGING_NONE, ap.getBadge());
assertEquals(NetworkBadging.BADGING_NONE, ap.getBadge());
}
}
}

View File

@@ -15,10 +15,10 @@
*/
package com.android.systemui.statusbar.policy;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.ContentObserver;
import android.net.NetworkBadging;
import android.net.NetworkCapabilities;
import android.net.NetworkKey;
import android.net.NetworkScoreManager;
@@ -155,7 +155,7 @@ public class WifiSignalController extends
@Override
public int getCurrentIconId() {
if (mCurrentState.badgeEnum != ScoredNetwork.BADGING_NONE) {
if (mCurrentState.badgeEnum != NetworkBadging.BADGING_NONE) {
return Utils.WIFI_PIE_FOR_BADGING[mCurrentState.level];
}
return super.getCurrentIconId();
@@ -201,14 +201,14 @@ public class WifiSignalController extends
*/
private int getWifiBadgeEnum() {
if (!mScoringUiEnabled || mWifiTracker.networkKey == null) {
return ScoredNetwork.BADGING_NONE;
return NetworkBadging.BADGING_NONE;
}
ScoredNetwork score = mScoreCache.getScoredNetwork(mWifiTracker.networkKey);
if (score != null) {
return score.calculateBadge(mWifiTracker.rssi);
}
return ScoredNetwork.BADGING_NONE;
return NetworkBadging.BADGING_NONE;
}
@VisibleForTesting

View File

@@ -1,6 +1,7 @@
package com.android.systemui.statusbar.policy;
import android.content.Intent;
import android.net.NetworkBadging;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkKey;
@@ -12,7 +13,6 @@ import android.net.wifi.WifiManager;
import android.net.wifi.WifiNetworkScoreCache;
import android.os.Bundle;
import android.provider.Settings;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.SmallTest;
@@ -106,7 +106,7 @@ public class NetworkControllerWifiTest extends NetworkControllerBaseTest {
setWifiState(true, TEST_SSID, TEST_BSSID);
mRequestScoresLatch.await(LATCH_TIMEOUT, TimeUnit.MILLISECONDS);
when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) ScoredNetwork.BADGING_SD);
when(mockBadgeCurve.lookupScore(anyInt())).thenReturn((byte) NetworkBadging.BADGING_SD);
ArgumentCaptor<WifiNetworkScoreCache> scoreCacheCaptor =
ArgumentCaptor.forClass(WifiNetworkScoreCache.class);
@@ -129,7 +129,7 @@ public class NetworkControllerWifiTest extends NetworkControllerBaseTest {
Utils.WIFI_PIE_FOR_BADGING[testLevel],
iconState.icon);
assertEquals("SD Badge is set",
Utils.getWifiBadgeResource(ScoredNetwork.BADGING_SD),
Utils.getWifiBadgeResource(NetworkBadging.BADGING_SD),
iconState.iconOverlay);
settingsOverrider.release();