Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 699deaf6 authored by Sundeep Ghuman's avatar Sundeep Ghuman
Browse files

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
parent b3f417ec
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -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 {
+20 −9
Original line number Diff line number Diff line
@@ -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);
+21 −7
Original line number Diff line number Diff line
@@ -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;

    /** @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;
    public static final int BADGING_4K = 30;

    /** A {@link NetworkKey} uniquely identifying this network. */
    public final NetworkKey networkKey;
    /** @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 =
+10 −13
Original line number Diff line number Diff line
@@ -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) {
+6 −6
Original line number Diff line number Diff line
@@ -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:
Loading