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

Commit 543ff5f0 authored by Chalard Jean's avatar Chalard Jean Committed by Android (Google) Code Review
Browse files

Merge "Revert "Add public fields to NetworkScore and make it @SystemApi"" into rvc-dev

parents 81ef2afa a11593c2
Loading
Loading
Loading
Loading
+2 −51
Original line number Diff line number Diff line
@@ -6281,7 +6281,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, @NonNull android.net.NetworkScore, @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, int, @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();
@@ -6296,7 +6296,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(@NonNull android.net.NetworkScore);
    method public void sendNetworkScore(int);
    method public void sendSocketKeepaliveEvent(int, int);
    method public void setConnected();
    method @Deprecated public void setLegacyExtraInfo(@Nullable String);
@@ -6403,55 +6403,6 @@ 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;
+0 −49
Original line number Diff line number Diff line
@@ -1799,55 +1799,6 @@ 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";
  }
+2 −6
Original line number Diff line number Diff line
@@ -3323,19 +3323,15 @@ 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) {
        final NetworkScore ns = new NetworkScore.Builder().setLegacyScore(score).build();
        return registerNetworkAgent(messenger, ni, lp, nc, ns, config, NetworkProvider.ID_NONE);
        return registerNetworkAgent(messenger, ni, lp, nc, score, config, NetworkProvider.ID_NONE);
    }

    /**
@@ -3345,7 +3341,7 @@ public class ConnectivityManager {
     */
    @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY)
    public Network registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp,
            NetworkCapabilities nc, NetworkScore score, NetworkAgentConfig config, int providerId) {
            NetworkCapabilities nc, int score, NetworkAgentConfig config, int providerId) {
        try {
            return mService.registerNetworkAgent(messenger, ni, lp, nc, score, config, providerId);
        } catch (RemoteException e) {
+1 −2
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ 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;
@@ -164,7 +163,7 @@ interface IConnectivityManager
    void declareNetworkRequestUnfulfillable(in NetworkRequest request);

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

    NetworkRequest requestNetwork(in NetworkCapabilities networkCapabilities,
+30 −20
Original line number Diff line number Diff line
@@ -116,6 +116,13 @@ 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.
@@ -265,13 +272,7 @@ 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);
@@ -279,7 +280,6 @@ 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,7 +287,6 @@ 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);
@@ -295,12 +294,10 @@ 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, makeNetworkScore(score), config, providerId, ni,
                true /* legacy */);
        this(looper, context, logTag, nc, lp, score, config, providerId, ni, true /* legacy */);
        register();
    }

@@ -326,9 +323,8 @@ 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,
            @NonNull NetworkScore score, @NonNull NetworkAgentConfig config,
            @Nullable NetworkProvider provider) {
            @NonNull NetworkCapabilities nc, @NonNull LinkProperties lp, int 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 */);
@@ -338,12 +334,12 @@ public abstract class NetworkAgent {
        public final Context context;
        public final NetworkCapabilities capabilities;
        public final LinkProperties properties;
        public final NetworkScore score;
        public final int score;
        public final NetworkAgentConfig config;
        public final NetworkInfo info;
        InitialConfiguration(@NonNull Context context, @NonNull NetworkCapabilities capabilities,
                @NonNull LinkProperties properties, @NonNull NetworkScore score,
                @NonNull NetworkAgentConfig config, @NonNull NetworkInfo info) {
                @NonNull LinkProperties properties, int score, @NonNull NetworkAgentConfig config,
                @NonNull NetworkInfo info) {
            this.context = context;
            this.capabilities = capabilities;
            this.properties = properties;
@@ -355,7 +351,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, NetworkScore score,
            @NonNull NetworkCapabilities nc, @NonNull LinkProperties lp, int score,
            @NonNull NetworkAgentConfig config, int providerId, @NonNull NetworkInfo ni,
            boolean legacy) {
        mHandler = new NetworkAgentHandler(looper);
@@ -650,8 +646,22 @@ 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(@NonNull final NetworkScore score) {
        queueOrSendMessage(EVENT_NETWORK_SCORE_CHANGED, 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));
    }

    /**
Loading