Merge "Cherrypick: Create ScoredNetwork Badging API changes."
am: e34e47d645
Change-Id: Ibeb6c60c30c302e12c45c7f35a7e4af904a4a6d5
This commit is contained in:
@@ -25830,10 +25830,16 @@ package android.net {
|
|||||||
ctor public ScoredNetwork(android.net.NetworkKey, android.net.RssiCurve);
|
ctor public ScoredNetwork(android.net.NetworkKey, android.net.RssiCurve);
|
||||||
ctor public ScoredNetwork(android.net.NetworkKey, android.net.RssiCurve, boolean);
|
ctor public ScoredNetwork(android.net.NetworkKey, android.net.RssiCurve, boolean);
|
||||||
ctor public ScoredNetwork(android.net.NetworkKey, android.net.RssiCurve, boolean, android.os.Bundle);
|
ctor public ScoredNetwork(android.net.NetworkKey, android.net.RssiCurve, boolean, android.os.Bundle);
|
||||||
|
method public int calculateBadge(int);
|
||||||
method public int describeContents();
|
method public int describeContents();
|
||||||
method public void writeToParcel(android.os.Parcel, int);
|
method public void writeToParcel(android.os.Parcel, int);
|
||||||
|
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_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 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 android.os.Parcelable.Creator<android.net.ScoredNetwork> CREATOR;
|
field public static final android.os.Parcelable.Creator<android.net.ScoredNetwork> CREATOR;
|
||||||
field public final android.os.Bundle attributes;
|
field public final android.os.Bundle attributes;
|
||||||
field public final boolean meteredHint;
|
field public final boolean meteredHint;
|
||||||
@@ -25841,6 +25847,9 @@ package android.net {
|
|||||||
field public final android.net.RssiCurve rssiCurve;
|
field public final android.net.RssiCurve rssiCurve;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static abstract class ScoredNetwork.Badging implements java.lang.annotation.Annotation {
|
||||||
|
}
|
||||||
|
|
||||||
public class TrafficStats {
|
public class TrafficStats {
|
||||||
ctor public TrafficStats();
|
ctor public TrafficStats();
|
||||||
method public static void clearThreadStatsTag();
|
method public static void clearThreadStatsTag();
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package android.net;
|
package android.net;
|
||||||
|
|
||||||
|
import android.annotation.IntDef;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.annotation.SystemApi;
|
import android.annotation.SystemApi;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -24,6 +25,8 @@ import android.os.Parcelable;
|
|||||||
|
|
||||||
import java.lang.Math;
|
import java.lang.Math;
|
||||||
import java.lang.UnsupportedOperationException;
|
import java.lang.UnsupportedOperationException;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,6 +36,15 @@ import java.util.Objects;
|
|||||||
*/
|
*/
|
||||||
@SystemApi
|
@SystemApi
|
||||||
public class ScoredNetwork implements Parcelable {
|
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.
|
||||||
|
*/
|
||||||
|
public static final String ATTRIBUTES_KEY_BADGING_CURVE =
|
||||||
|
"android.net.attributes.key.BADGING_CURVE";
|
||||||
/**
|
/**
|
||||||
* Extra used with {@link #attributes} to specify whether the
|
* Extra used with {@link #attributes} to specify whether the
|
||||||
* network is believed to have a captive portal.
|
* network is believed to have a captive portal.
|
||||||
@@ -58,6 +70,15 @@ public class ScoredNetwork implements Parcelable {
|
|||||||
public static final String ATTRIBUTES_KEY_RANKING_SCORE_OFFSET =
|
public static final String ATTRIBUTES_KEY_RANKING_SCORE_OFFSET =
|
||||||
"android.net.attributes.key.RANKING_SCORE_OFFSET";
|
"android.net.attributes.key.RANKING_SCORE_OFFSET";
|
||||||
|
|
||||||
|
@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;
|
||||||
|
|
||||||
/** A {@link NetworkKey} uniquely identifying this network. */
|
/** A {@link NetworkKey} uniquely identifying this network. */
|
||||||
public final NetworkKey networkKey;
|
public final NetworkKey networkKey;
|
||||||
|
|
||||||
@@ -249,6 +270,25 @@ public class ScoredNetwork implements Parcelable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the {@link 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
|
||||||
|
public int calculateBadge(int rssi) {
|
||||||
|
if (attributes != null && attributes.containsKey(ATTRIBUTES_KEY_BADGING_CURVE)) {
|
||||||
|
RssiCurve badgingCurve =
|
||||||
|
attributes.getParcelable(ATTRIBUTES_KEY_BADGING_CURVE);
|
||||||
|
return badgingCurve.lookupScore(rssi);
|
||||||
|
}
|
||||||
|
|
||||||
|
return BADGING_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
public static final Parcelable.Creator<ScoredNetwork> CREATOR =
|
public static final Parcelable.Creator<ScoredNetwork> CREATOR =
|
||||||
new Parcelable.Creator<ScoredNetwork>() {
|
new Parcelable.Creator<ScoredNetwork>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -166,4 +166,52 @@ public class ScoredNetworkTest {
|
|||||||
assertTrue(newNetwork.meteredHint);
|
assertTrue(newNetwork.meteredHint);
|
||||||
assertNull(newNetwork.attributes);
|
assertNull(newNetwork.attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void calculateBadgeShouldReturnNoBadgeWhenNoAttributesBundle() {
|
||||||
|
ScoredNetwork network = new ScoredNetwork(KEY, CURVE);
|
||||||
|
assertEquals(ScoredNetwork.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));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void calculateBadgeShouldReturn4kBadge() {
|
||||||
|
ScoredNetwork network =
|
||||||
|
buildScoredNetworkWithGivenBadgeForTestRssi(ScoredNetwork.BADGING_4K);
|
||||||
|
assertEquals(ScoredNetwork.BADGING_4K, network.calculateBadge(TEST_RSSI));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void calculateBadgeShouldReturnHdBadge() {
|
||||||
|
ScoredNetwork network =
|
||||||
|
buildScoredNetworkWithGivenBadgeForTestRssi(ScoredNetwork.BADGING_HD);
|
||||||
|
assertEquals(ScoredNetwork.BADGING_HD, network.calculateBadge(TEST_RSSI));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void calculateBadgeShouldReturnSdBadge() {
|
||||||
|
ScoredNetwork network =
|
||||||
|
buildScoredNetworkWithGivenBadgeForTestRssi(ScoredNetwork.BADGING_SD);
|
||||||
|
assertEquals(ScoredNetwork.BADGING_SD, network.calculateBadge(TEST_RSSI));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void calculateBadgeShouldReturnNoBadge() {
|
||||||
|
ScoredNetwork network =
|
||||||
|
buildScoredNetworkWithGivenBadgeForTestRssi(ScoredNetwork.BADGING_NONE);
|
||||||
|
assertEquals(ScoredNetwork.BADGING_NONE, network.calculateBadge(TEST_RSSI));
|
||||||
|
}
|
||||||
|
|
||||||
|
private ScoredNetwork buildScoredNetworkWithGivenBadgeForTestRssi(int badge) {
|
||||||
|
RssiCurve badgingCurve =
|
||||||
|
new RssiCurve(RSSI_START, 10, new byte[] {0, 0, 0, 0, 0, 0, (byte) badge});
|
||||||
|
Bundle attr = new Bundle();
|
||||||
|
attr.putParcelable(ScoredNetwork.ATTRIBUTES_KEY_BADGING_CURVE, badgingCurve);
|
||||||
|
return new ScoredNetwork(KEY, CURVE, false /* meteredHint */, attr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user