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

Commit e9cb94f8 authored by Chalard Jean's avatar Chalard Jean Committed by Automerger Merge Worker
Browse files

Merge changes from topic "ns05" into sc-dev am: 6c67db7b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13929760

Change-Id: I0a96d6765990ee33b0d032c897f7a4cca9a1adb4
parents c93a7574 6c67db7b
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -314,9 +314,16 @@ package android.net {
    method public int getProviderId();
    method public void onNetworkRequestWithdrawn(@NonNull android.net.NetworkRequest);
    method public void onNetworkRequested(@NonNull android.net.NetworkRequest, @IntRange(from=0, to=99) int, int);
    method @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY) public void registerNetworkOffer(@NonNull android.net.NetworkScore, @NonNull android.net.NetworkCapabilities, @NonNull java.util.concurrent.Executor, @NonNull android.net.NetworkProvider.NetworkOfferCallback);
    method @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY) public void unregisterNetworkOffer(@NonNull android.net.NetworkProvider.NetworkOfferCallback);
    field public static final int ID_NONE = -1; // 0xffffffff
  }

  public static interface NetworkProvider.NetworkOfferCallback {
    method public void onNetworkNeeded(@NonNull android.net.NetworkRequest);
    method public void onNetworkUnneeded(@NonNull android.net.NetworkRequest);
  }

  public class NetworkReleasedException extends java.lang.Exception {
  }

@@ -331,14 +338,18 @@ package android.net {

  public final class NetworkScore implements android.os.Parcelable {
    method public int describeContents();
    method public int getKeepConnectedReason();
    method public int getLegacyInt();
    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 KEEP_CONNECTED_FOR_HANDOVER = 1; // 0x1
    field public static final int KEEP_CONNECTED_NONE = 0; // 0x0
  }

  public static final class NetworkScore.Builder {
    ctor public NetworkScore.Builder();
    method @NonNull public android.net.NetworkScore build();
    method @NonNull public android.net.NetworkScore.Builder setKeepConnectedReason(int);
    method @NonNull public android.net.NetworkScore.Builder setLegacyInt(int);
  }

+2 −2
Original line number Diff line number Diff line
@@ -3345,7 +3345,7 @@ public class ConnectivityManager {
     * @param score The prospective score of the network.
     * @param caps The prospective capabilities of the network.
     * @param callback The callback to call when this offer is needed or unneeded.
     * @hide
     * @hide exposed via the NetworkProvider class.
     */
    @RequiresPermission(anyOf = {
            NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK,
@@ -3368,7 +3368,7 @@ public class ConnectivityManager {
     *
     * @param callback The callback passed at registration time. This must be the same object
     *                 that was passed to {@link #offerNetwork}
     * @hide
     * @hide exposed via the NetworkProvider class.
     */
    public void unofferNetwork(@NonNull final INetworkOfferCallback callback) {
        try {
+1 −3
Original line number Diff line number Diff line
@@ -51,10 +51,8 @@ oneway interface INetworkOfferCallback {
    /**
     * Called when a network for this offer is needed to fulfill this request.
     * @param networkRequest the request to satisfy
     * @param providerId the ID of the provider currently satisfying
     *          this request, or NetworkProvider.ID_NONE if none.
     */
    void onNetworkNeeded(in NetworkRequest networkRequest, int providerId);
    void onNetworkNeeded(in NetworkRequest networkRequest);

    /**
     * Informs the registrant that the offer is no longer valuable to fulfill this request.
+20 −14
Original line number Diff line number Diff line
@@ -168,12 +168,16 @@ public class NetworkProvider {
    }

    /** @hide */
    // TODO : make @SystemApi when the impl is complete
    @SystemApi
    public interface NetworkOfferCallback {
        /** Called by the system when a network for this offer is needed to satisfy some
         *  networking request. */
        void onNetworkNeeded(@NonNull NetworkRequest request, int providerId);
        /** Called by the system when this offer is no longer valuable for this request. */
        /**
         * Called by the system when a network for this offer is needed to satisfy some
         * networking request.
         */
        void onNetworkNeeded(@NonNull NetworkRequest request);
        /**
         * Called by the system when this offer is no longer valuable for this request.
         */
        void onNetworkUnneeded(@NonNull NetworkRequest request);
    }

@@ -188,9 +192,8 @@ public class NetworkProvider {
        }

        @Override
        public void onNetworkNeeded(final @NonNull NetworkRequest request,
                final int providerId) {
            mExecutor.execute(() -> callback.onNetworkNeeded(request, providerId));
        public void onNetworkNeeded(final @NonNull NetworkRequest request) {
            mExecutor.execute(() -> callback.onNetworkNeeded(request));
        }

        @Override
@@ -254,8 +257,11 @@ public class NetworkProvider {
     *
     * The capabilities and score act as filters as to what requests the provider will see.
     * They are not promises, but for best performance, the providers should strive to put
     * as much known information as possible in the offer. For capabilities in particular, it
     * should put all NetworkAgent-managed capabilities a network may have, even if it doesn't
     * as much known information as possible in the offer. For the score, it should put as
     * strong a score as the networks will have, since this will filter what requests the
     * provider sees – it's not a promise, it only serves to avoid sending requests that
     * the provider can't ever hope to satisfy better than any current network. For capabilities,
     * it should put all NetworkAgent-managed capabilities a network may have, even if it doesn't
     * have them at first. This applies to INTERNET, for example ; if a provider thinks the
     * network it can bring up for this offer may offer Internet access it should include the
     * INTERNET bit. It's fine if the brought up network ends up not actually having INTERNET.
@@ -268,9 +274,9 @@ public class NetworkProvider {
     *
     * @hide
     */
    // TODO : make @SystemApi when the impl is complete
    @SystemApi
    @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY)
    public void offerNetwork(@NonNull final NetworkScore score,
    public void registerNetworkOffer(@NonNull final NetworkScore score,
            @NonNull final NetworkCapabilities caps, @NonNull final Executor executor,
            @NonNull final NetworkOfferCallback callback) {
        // Can't offer a network with a provider that is not yet registered or already unregistered.
@@ -307,9 +313,9 @@ public class NetworkProvider {
     *
     * @hide
     */
    // TODO : make @SystemApi when the impl is complete
    @SystemApi
    @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY)
    public void unofferNetwork(final @NonNull NetworkOfferCallback callback) {
    public void unregisterNetworkOffer(final @NonNull NetworkOfferCallback callback) {
        final NetworkOfferCallbackProxy proxy = findProxyForCallback(callback);
        if (null == proxy) return;
        mProxies.remove(proxy);
+42 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.net;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.os.Parcel;
@@ -23,6 +24,9 @@ import android.os.Parcelable;

import com.android.internal.annotations.VisibleForTesting;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Object representing the quality of a network as perceived by the user.
 *
@@ -36,6 +40,17 @@ public final class NetworkScore implements Parcelable {
    // a migration.
    private final int mLegacyInt;

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(value = {
            KEEP_CONNECTED_NONE,
            KEEP_CONNECTED_FOR_HANDOVER
    })
    public @interface KeepConnectedReason { }

    public static final int KEEP_CONNECTED_NONE = 0;
    public static final int KEEP_CONNECTED_FOR_HANDOVER = 1;

    // Agent-managed policies
    // TODO : add them here, starting from 1
    /** @hide */
@@ -46,21 +61,33 @@ public final class NetworkScore implements Parcelable {
    // Bitmask of all the policies applied to this score.
    private final long mPolicies;

    private final int mKeepConnectedReason;

    /** @hide */
    NetworkScore(final int legacyInt, final long policies) {
    NetworkScore(final int legacyInt, final long policies,
            @KeepConnectedReason final int keepConnectedReason) {
        mLegacyInt = legacyInt;
        mPolicies = policies;
        mKeepConnectedReason = keepConnectedReason;
    }

    private NetworkScore(@NonNull final Parcel in) {
        mLegacyInt = in.readInt();
        mPolicies = in.readLong();
        mKeepConnectedReason = in.readInt();
    }

    public int getLegacyInt() {
        return mLegacyInt;
    }

    /**
     * Returns the keep-connected reason, or KEEP_CONNECTED_NONE.
     */
    public int getKeepConnectedReason() {
        return mKeepConnectedReason;
    }

    /**
     * @return whether this score has a particular policy.
     *
@@ -80,6 +107,7 @@ public final class NetworkScore implements Parcelable {
    public void writeToParcel(@NonNull final Parcel dest, final int flags) {
        dest.writeInt(mLegacyInt);
        dest.writeLong(mPolicies);
        dest.writeInt(mKeepConnectedReason);
    }

    @Override
@@ -108,6 +136,7 @@ public final class NetworkScore implements Parcelable {
        private static final long POLICY_NONE = 0L;
        private static final int INVALID_LEGACY_INT = Integer.MIN_VALUE;
        private int mLegacyInt = INVALID_LEGACY_INT;
        private int mKeepConnectedReason = KEEP_CONNECTED_NONE;

        /**
         * Sets the legacy int for this score.
@@ -123,13 +152,24 @@ public final class NetworkScore implements Parcelable {
            return this;
        }

        /**
         * Set the keep-connected reason.
         *
         * This can be reset by calling it again with {@link KEEP_CONNECTED_NONE}.
         */
        @NonNull
        public Builder setKeepConnectedReason(@KeepConnectedReason final int reason) {
            mKeepConnectedReason = reason;
            return this;
        }

        /**
         * Builds this NetworkScore.
         * @return The built NetworkScore object.
         */
        @NonNull
        public NetworkScore build() {
            return new NetworkScore(mLegacyInt, POLICY_NONE);
            return new NetworkScore(mLegacyInt, POLICY_NONE, mKeepConnectedReason);
        }
    }
}
Loading