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

@@ -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 =