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

Commit a27e1eef authored by Chalard Jean's avatar Chalard Jean
Browse files

Add public fields to NetworkScore and make it @SystemApi

Bug: 113554781
Bug: 146583853
Test: FrameworksNetTests
Change-Id: I19d965c0146196cb67b3417eb1790ccd90ce3233
parent e00b50b4
Loading
Loading
Loading
Loading
+51 −2
Original line number Diff line number Diff line
@@ -6274,7 +6274,7 @@ package android.net {
  }
  public abstract class NetworkAgent {
    ctor public NetworkAgent(@NonNull android.content.Context, @NonNull android.os.Looper, @NonNull String, @NonNull android.net.NetworkCapabilities, @NonNull android.net.LinkProperties, int, @NonNull android.net.NetworkAgentConfig, @Nullable android.net.NetworkProvider);
    ctor public NetworkAgent(@NonNull android.content.Context, @NonNull android.os.Looper, @NonNull String, @NonNull android.net.NetworkCapabilities, @NonNull android.net.LinkProperties, @NonNull android.net.NetworkScore, @NonNull android.net.NetworkAgentConfig, @Nullable android.net.NetworkProvider);
    method @Nullable public android.net.Network getNetwork();
    method public void onAddKeepalivePacketFilter(int, @NonNull android.net.KeepalivePacketData);
    method public void onAutomaticReconnectDisabled();
@@ -6289,7 +6289,7 @@ package android.net {
    method @NonNull public android.net.Network register();
    method public void sendLinkProperties(@NonNull android.net.LinkProperties);
    method public void sendNetworkCapabilities(@NonNull android.net.NetworkCapabilities);
    method public void sendNetworkScore(int);
    method public void sendNetworkScore(@NonNull android.net.NetworkScore);
    method public void sendSocketKeepaliveEvent(int, int);
    method public void setConnected();
    method @Deprecated public void setLegacyExtraInfo(@Nullable String);
@@ -6390,6 +6390,55 @@ package android.net {
    method @NonNull @RequiresPermission(android.Manifest.permission.NETWORK_SIGNAL_STRENGTH_WAKEUP) public android.net.NetworkRequest.Builder setSignalStrength(int);
  }
  public final class NetworkScore implements android.os.Parcelable {
    method public int describeContents();
    method @NonNull public android.net.NetworkScore.Metrics getEndToEndMetrics();
    method @NonNull public android.net.NetworkScore.Metrics getLinkLayerMetrics();
    method public int getRange();
    method @IntRange(from=android.net.NetworkScore.UNKNOWN_SIGNAL_STRENGTH, to=android.net.NetworkScore.MAX_SIGNAL_STRENGTH) public int getSignalStrength();
    method public boolean hasPolicy(int);
    method public boolean isExiting();
    method @NonNull public android.net.NetworkScore withExiting(boolean);
    method @NonNull public android.net.NetworkScore withSignalStrength(@IntRange(from=android.net.NetworkScore.UNKNOWN_SIGNAL_STRENGTH) int);
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.net.NetworkScore> CREATOR;
    field public static final int MAX_SIGNAL_STRENGTH = 1000; // 0x3e8
    field public static final int MIN_SIGNAL_STRENGTH = 0; // 0x0
    field public static final int POLICY_DEFAULT_SUBSCRIPTION = 8; // 0x8
    field public static final int POLICY_IGNORE_ON_WIFI = 4; // 0x4
    field public static final int POLICY_LOCKDOWN_VPN = 1; // 0x1
    field public static final int POLICY_VPN = 2; // 0x2
    field public static final int RANGE_CLOSE = 1; // 0x1
    field public static final int RANGE_LONG = 4; // 0x4
    field public static final int RANGE_MEDIUM = 3; // 0x3
    field public static final int RANGE_SHORT = 2; // 0x2
    field public static final int RANGE_UNKNOWN = 0; // 0x0
    field public static final int UNKNOWN_SIGNAL_STRENGTH = -1; // 0xffffffff
  }
  public static class NetworkScore.Builder {
    ctor public NetworkScore.Builder();
    method @NonNull public android.net.NetworkScore.Builder addPolicy(int);
    method @NonNull public android.net.NetworkScore build();
    method @NonNull public android.net.NetworkScore.Builder clearPolicy(int);
    method @NonNull public android.net.NetworkScore.Builder setEndToEndMetrics(@NonNull android.net.NetworkScore.Metrics);
    method @NonNull public android.net.NetworkScore.Builder setExiting(boolean);
    method @NonNull public android.net.NetworkScore.Builder setLegacyScore(int);
    method @NonNull public android.net.NetworkScore.Builder setLinkLayerMetrics(@NonNull android.net.NetworkScore.Metrics);
    method @NonNull public android.net.NetworkScore.Builder setRange(int);
    method @NonNull public android.net.NetworkScore.Builder setSignalStrength(@IntRange(from=android.net.NetworkScore.UNKNOWN_SIGNAL_STRENGTH, to=android.net.NetworkScore.MAX_SIGNAL_STRENGTH) int);
  }
  public static class NetworkScore.Metrics {
    ctor public NetworkScore.Metrics(@IntRange(from=android.net.NetworkScore.Metrics.LATENCY_UNKNOWN) int, @IntRange(from=android.net.NetworkScore.Metrics.BANDWIDTH_UNKNOWN) int, @IntRange(from=android.net.NetworkScore.Metrics.BANDWIDTH_UNKNOWN) int);
    field public static final int BANDWIDTH_UNKNOWN = -1; // 0xffffffff
    field @NonNull public static final android.net.NetworkScore.Metrics EMPTY;
    field public static final int LATENCY_UNKNOWN = -1; // 0xffffffff
    field @IntRange(from=android.net.NetworkScore.Metrics.BANDWIDTH_UNKNOWN) public final int downlinkBandwidthKBps;
    field @IntRange(from=android.net.NetworkScore.Metrics.LATENCY_UNKNOWN) public final int latencyMs;
    field @IntRange(from=android.net.NetworkScore.Metrics.BANDWIDTH_UNKNOWN) public final int uplinkBandwidthKBps;
  }
  public class NetworkScoreManager {
    method @RequiresPermission(anyOf={android.Manifest.permission.SCORE_NETWORKS, android.Manifest.permission.REQUEST_NETWORK_SCORES}) public boolean clearScores() throws java.lang.SecurityException;
    method @RequiresPermission(anyOf={android.Manifest.permission.SCORE_NETWORKS, android.Manifest.permission.REQUEST_NETWORK_SCORES}) public void disableScoring() throws java.lang.SecurityException;
+49 −0
Original line number Diff line number Diff line
@@ -1674,6 +1674,55 @@ package android.net {
    field public static final int TRANSPORT_TEST = 7; // 0x7
  }

  public final class NetworkScore implements android.os.Parcelable {
    method public int describeContents();
    method @NonNull public android.net.NetworkScore.Metrics getEndToEndMetrics();
    method @NonNull public android.net.NetworkScore.Metrics getLinkLayerMetrics();
    method public int getRange();
    method @IntRange(from=android.net.NetworkScore.UNKNOWN_SIGNAL_STRENGTH, to=android.net.NetworkScore.MAX_SIGNAL_STRENGTH) public int getSignalStrength();
    method public boolean hasPolicy(int);
    method public boolean isExiting();
    method @NonNull public android.net.NetworkScore withExiting(boolean);
    method @NonNull public android.net.NetworkScore withSignalStrength(@IntRange(from=android.net.NetworkScore.UNKNOWN_SIGNAL_STRENGTH) int);
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.net.NetworkScore> CREATOR;
    field public static final int MAX_SIGNAL_STRENGTH = 1000; // 0x3e8
    field public static final int MIN_SIGNAL_STRENGTH = 0; // 0x0
    field public static final int POLICY_DEFAULT_SUBSCRIPTION = 8; // 0x8
    field public static final int POLICY_IGNORE_ON_WIFI = 4; // 0x4
    field public static final int POLICY_LOCKDOWN_VPN = 1; // 0x1
    field public static final int POLICY_VPN = 2; // 0x2
    field public static final int RANGE_CLOSE = 1; // 0x1
    field public static final int RANGE_LONG = 4; // 0x4
    field public static final int RANGE_MEDIUM = 3; // 0x3
    field public static final int RANGE_SHORT = 2; // 0x2
    field public static final int RANGE_UNKNOWN = 0; // 0x0
    field public static final int UNKNOWN_SIGNAL_STRENGTH = -1; // 0xffffffff
  }

  public static class NetworkScore.Builder {
    ctor public NetworkScore.Builder();
    method @NonNull public android.net.NetworkScore.Builder addPolicy(int);
    method @NonNull public android.net.NetworkScore build();
    method @NonNull public android.net.NetworkScore.Builder clearPolicy(int);
    method @NonNull public android.net.NetworkScore.Builder setEndToEndMetrics(@NonNull android.net.NetworkScore.Metrics);
    method @NonNull public android.net.NetworkScore.Builder setExiting(boolean);
    method @NonNull public android.net.NetworkScore.Builder setLegacyScore(int);
    method @NonNull public android.net.NetworkScore.Builder setLinkLayerMetrics(@NonNull android.net.NetworkScore.Metrics);
    method @NonNull public android.net.NetworkScore.Builder setRange(int);
    method @NonNull public android.net.NetworkScore.Builder setSignalStrength(@IntRange(from=android.net.NetworkScore.UNKNOWN_SIGNAL_STRENGTH, to=android.net.NetworkScore.MAX_SIGNAL_STRENGTH) int);
  }

  public static class NetworkScore.Metrics {
    ctor public NetworkScore.Metrics(@IntRange(from=android.net.NetworkScore.Metrics.LATENCY_UNKNOWN) int, @IntRange(from=android.net.NetworkScore.Metrics.BANDWIDTH_UNKNOWN) int, @IntRange(from=android.net.NetworkScore.Metrics.BANDWIDTH_UNKNOWN) int);
    field public static final int BANDWIDTH_UNKNOWN = -1; // 0xffffffff
    field @NonNull public static final android.net.NetworkScore.Metrics EMPTY;
    field public static final int LATENCY_UNKNOWN = -1; // 0xffffffff
    field @IntRange(from=android.net.NetworkScore.Metrics.BANDWIDTH_UNKNOWN) public final int downlinkBandwidthKBps;
    field @IntRange(from=android.net.NetworkScore.Metrics.LATENCY_UNKNOWN) public final int latencyMs;
    field @IntRange(from=android.net.NetworkScore.Metrics.BANDWIDTH_UNKNOWN) public final int uplinkBandwidthKBps;
  }

  public class NetworkStack {
    field public static final String PERMISSION_MAINLINE_NETWORK_STACK = "android.permission.MAINLINE_NETWORK_STACK";
  }
+6 −2
Original line number Diff line number Diff line
@@ -3322,15 +3322,19 @@ public class ConnectivityManager {
    // of dependent changes that would conflict throughout the automerger graph. Having this
    // temporarily helps with the process of going through with all these dependent changes across
    // the entire tree.
    // STOPSHIP (b/148055573) : remove this before R is released.
    /**
     * @hide
     * Register a NetworkAgent with ConnectivityService.
     * @return Network corresponding to NetworkAgent.
     * @deprecated use the version that takes a NetworkScore and a provider ID.
     */
    @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY)
    @Deprecated
    public Network registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp,
            NetworkCapabilities nc, int score, NetworkAgentConfig config) {
        return registerNetworkAgent(messenger, ni, lp, nc, score, config, NetworkProvider.ID_NONE);
        final NetworkScore ns = new NetworkScore.Builder().setLegacyScore(score).build();
        return registerNetworkAgent(messenger, ni, lp, nc, ns, config, NetworkProvider.ID_NONE);
    }

    /**
@@ -3340,7 +3344,7 @@ public class ConnectivityManager {
     */
    @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY)
    public Network registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp,
            NetworkCapabilities nc, int score, NetworkAgentConfig config, int providerId) {
            NetworkCapabilities nc, NetworkScore score, NetworkAgentConfig config, int providerId) {
        try {
            return mService.registerNetworkAgent(messenger, ni, lp, nc, score, config, providerId);
        } catch (RemoteException e) {
+2 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkQuotaInfo;
import android.net.NetworkRequest;
import android.net.NetworkScore;
import android.net.NetworkState;
import android.net.ISocketKeepaliveCallback;
import android.net.ProxyInfo;
@@ -153,7 +154,7 @@ interface IConnectivityManager
    void declareNetworkRequestUnfulfillable(in NetworkRequest request);

    Network registerNetworkAgent(in Messenger messenger, in NetworkInfo ni, in LinkProperties lp,
            in NetworkCapabilities nc, int score, in NetworkAgentConfig config,
            in NetworkCapabilities nc, in NetworkScore score, in NetworkAgentConfig config,
            in int factorySerialNumber);

    NetworkRequest requestNetwork(in NetworkCapabilities networkCapabilities,
+20 −30
Original line number Diff line number Diff line
@@ -116,13 +116,6 @@ public abstract class NetworkAgent {
     */
    public static final int EVENT_NETWORK_PROPERTIES_CHANGED = BASE + 3;

    /**
     * Centralize the place where base network score, and network score scaling, will be
     * stored, so as we can consistently compare apple and oranges, or wifi, ethernet and LTE
     * @hide
     */
    public static final int WIFI_BASE_SCORE = 60;

    /**
     * Sent by the NetworkAgent to ConnectivityService to pass the current
     * network score.
@@ -272,7 +265,13 @@ public abstract class NetworkAgent {
     */
    public static final int CMD_REMOVE_KEEPALIVE_PACKET_FILTER = BASE + 17;

    // STOPSHIP (b/148055573) : remove this before R is released.
    private static NetworkScore makeNetworkScore(int score) {
        return new NetworkScore.Builder().setLegacyScore(score).build();
    }

    /** @hide TODO: remove and replace usage with the public constructor. */
    // STOPSHIP (b/148055573) : remove this before R is released.
    public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
            NetworkCapabilities nc, LinkProperties lp, int score) {
        this(looper, context, logTag, ni, nc, lp, score, null, NetworkProvider.ID_NONE);
@@ -280,6 +279,7 @@ public abstract class NetworkAgent {
    }

    /** @hide TODO: remove and replace usage with the public constructor. */
    // STOPSHIP (b/148055573) : remove this before R is released.
    public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
            NetworkCapabilities nc, LinkProperties lp, int score, NetworkAgentConfig config) {
        this(looper, context, logTag, ni, nc, lp, score, config, NetworkProvider.ID_NONE);
@@ -287,6 +287,7 @@ public abstract class NetworkAgent {
    }

    /** @hide TODO: remove and replace usage with the public constructor. */
    // STOPSHIP (b/148055573) : remove this before R is released.
    public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
            NetworkCapabilities nc, LinkProperties lp, int score, int providerId) {
        this(looper, context, logTag, ni, nc, lp, score, null, providerId);
@@ -294,10 +295,12 @@ public abstract class NetworkAgent {
    }

    /** @hide TODO: remove and replace usage with the public constructor. */
    // STOPSHIP (b/148055573) : remove this before R is released.
    public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
            NetworkCapabilities nc, LinkProperties lp, int score, NetworkAgentConfig config,
            int providerId) {
        this(looper, context, logTag, nc, lp, score, config, providerId, ni, true /* legacy */);
        this(looper, context, logTag, nc, lp, makeNetworkScore(score), config, providerId, ni,
                true /* legacy */);
        register();
    }

@@ -323,8 +326,9 @@ public abstract class NetworkAgent {
     * @param provider the {@link NetworkProvider} managing this agent.
     */
    public NetworkAgent(@NonNull Context context, @NonNull Looper looper, @NonNull String logTag,
            @NonNull NetworkCapabilities nc, @NonNull LinkProperties lp, int score,
            @NonNull NetworkAgentConfig config, @Nullable NetworkProvider provider) {
            @NonNull NetworkCapabilities nc, @NonNull LinkProperties lp,
            @NonNull NetworkScore score, @NonNull NetworkAgentConfig config,
            @Nullable NetworkProvider provider) {
        this(looper, context, logTag, nc, lp, score, config,
                provider == null ? NetworkProvider.ID_NONE : provider.getProviderId(),
                getLegacyNetworkInfo(config), false /* legacy */);
@@ -334,12 +338,12 @@ public abstract class NetworkAgent {
        public final Context context;
        public final NetworkCapabilities capabilities;
        public final LinkProperties properties;
        public final int score;
        public final NetworkScore score;
        public final NetworkAgentConfig config;
        public final NetworkInfo info;
        InitialConfiguration(@NonNull Context context, @NonNull NetworkCapabilities capabilities,
                @NonNull LinkProperties properties, int score, @NonNull NetworkAgentConfig config,
                @NonNull NetworkInfo info) {
                @NonNull LinkProperties properties, @NonNull NetworkScore score,
                @NonNull NetworkAgentConfig config, @NonNull NetworkInfo info) {
            this.context = context;
            this.capabilities = capabilities;
            this.properties = properties;
@@ -351,7 +355,7 @@ public abstract class NetworkAgent {
    private volatile InitialConfiguration mInitialConfiguration;

    private NetworkAgent(@NonNull Looper looper, @NonNull Context context, @NonNull String logTag,
            @NonNull NetworkCapabilities nc, @NonNull LinkProperties lp, int score,
            @NonNull NetworkCapabilities nc, @NonNull LinkProperties lp, NetworkScore score,
            @NonNull NetworkAgentConfig config, int providerId, @NonNull NetworkInfo ni,
            boolean legacy) {
        mHandler = new NetworkAgentHandler(looper);
@@ -646,22 +650,8 @@ public abstract class NetworkAgent {
     * Must be called by the agent to update the score of this network.
     * @param score the new score.
     */
    public void sendNetworkScore(int score) {
        if (score < 0) {
            throw new IllegalArgumentException("Score must be >= 0");
        }
        final NetworkScore ns = new NetworkScore();
        ns.putIntExtension(NetworkScore.LEGACY_SCORE, score);
        updateScore(ns);
    }

    /**
     * Must be called by the agent when it has a new {@link NetworkScore} for this network.
     * @param ns the new score.
     * @hide TODO: unhide the NetworkScore class, and rename to sendNetworkScore.
     */
    public void updateScore(@NonNull NetworkScore ns) {
        queueOrSendMessage(EVENT_NETWORK_SCORE_CHANGED, new NetworkScore(ns));
    public void sendNetworkScore(@NonNull final NetworkScore score) {
        queueOrSendMessage(EVENT_NETWORK_SCORE_CHANGED, score);
    }

    /**
Loading