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

Commit b891c0a6 authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by Android (Google) Code Review
Browse files

Merge changes from topic "networkagent"

* changes:
  Rename NetworkMisc to NetworkAgentConfig.
  Make NetworkAgent stop subclassing Handler.
parents 4defe3be d969656f
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -3173,8 +3173,8 @@ public class ConnectivityManager {
     */
    @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY)
    public int registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp,
            NetworkCapabilities nc, int score, NetworkMisc misc) {
        return registerNetworkAgent(messenger, ni, lp, nc, score, misc, NetworkProvider.ID_NONE);
            NetworkCapabilities nc, int score, NetworkAgentConfig config) {
        return registerNetworkAgent(messenger, ni, lp, nc, score, config, NetworkProvider.ID_NONE);
    }

    /**
@@ -3184,9 +3184,9 @@ public class ConnectivityManager {
     */
    @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY)
    public int registerNetworkAgent(Messenger messenger, NetworkInfo ni, LinkProperties lp,
            NetworkCapabilities nc, int score, NetworkMisc misc, int providerId) {
            NetworkCapabilities nc, int score, NetworkAgentConfig config, int providerId) {
        try {
            return mService.registerNetworkAgent(messenger, ni, lp, nc, score, misc, providerId);
            return mService.registerNetworkAgent(messenger, ni, lp, nc, score, config, providerId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+3 −2
Original line number Diff line number Diff line
@@ -20,9 +20,9 @@ import android.app.PendingIntent;
import android.net.ConnectionInfo;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkAgentConfig;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkMisc;
import android.net.NetworkQuotaInfo;
import android.net.NetworkRequest;
import android.net.NetworkState;
@@ -153,7 +153,8 @@ interface IConnectivityManager
    void declareNetworkRequestUnfulfillable(in NetworkRequest request);

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

    NetworkRequest requestNetwork(in NetworkCapabilities networkCapabilities,
            in Messenger messenger, int timeoutSec, in IBinder binder, int legacy);
+111 −102
Original line number Diff line number Diff line
@@ -43,11 +43,12 @@ import java.util.concurrent.atomic.AtomicBoolean;
 *
 * @hide
 */
public abstract class NetworkAgent extends Handler {
public abstract class NetworkAgent {
    // Guaranteed to be valid (not NETID_UNSET), otherwise registerNetworkAgent() would have thrown
    // an exception.
    public final int netId;

    private final Handler mHandler;
    private volatile AsyncChannel mAsyncChannel;
    private final String LOG_TAG;
    private static final boolean DBG = true;
@@ -222,8 +223,8 @@ public abstract class NetworkAgent extends Handler {
        this(looper, context, logTag, ni, nc, lp, score, null, NetworkProvider.ID_NONE);
    }
    public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
            NetworkCapabilities nc, LinkProperties lp, int score, NetworkMisc misc) {
        this(looper, context, logTag, ni, nc, lp, score, misc, NetworkProvider.ID_NONE);
            NetworkCapabilities nc, LinkProperties lp, int score, NetworkAgentConfig config) {
        this(looper, context, logTag, ni, nc, lp, score, config, NetworkProvider.ID_NONE);
    }

    public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
@@ -232,9 +233,9 @@ public abstract class NetworkAgent extends Handler {
    }

    public NetworkAgent(Looper looper, Context context, String logTag, NetworkInfo ni,
            NetworkCapabilities nc, LinkProperties lp, int score, NetworkMisc misc,
            NetworkCapabilities nc, LinkProperties lp, int score, NetworkAgentConfig config,
            int providerId) {
        super(looper);
        mHandler = new NetworkAgentHandler(looper);
        LOG_TAG = logTag;
        mContext = context;
        mProviderId = providerId;
@@ -245,8 +246,14 @@ public abstract class NetworkAgent extends Handler {
        if (VDBG) log("Registering NetworkAgent");
        ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService(
                Context.CONNECTIVITY_SERVICE);
        netId = cm.registerNetworkAgent(new Messenger(this), new NetworkInfo(ni),
                new LinkProperties(lp), new NetworkCapabilities(nc), score, misc, providerId);
        netId = cm.registerNetworkAgent(new Messenger(mHandler), new NetworkInfo(ni),
                new LinkProperties(lp), new NetworkCapabilities(nc), score, config,
                providerId);
    }

    private class NetworkAgentHandler extends Handler {
        NetworkAgentHandler(Looper looper) {
            super(looper);
        }

        @Override
@@ -296,14 +303,14 @@ public abstract class NetworkAgent extends Handler {
                    }
                    if (currentTimeMs >= (mLastBwRefreshTime + BW_REFRESH_MIN_WIN_MS)) {
                        mPollLceScheduled = false;
                    if (mPollLcePending.getAndSet(true) == false) {
                        if (!mPollLcePending.getAndSet(true)) {
                            pollLceData();
                        }
                    } else {
                        // deliver the request at a later time rather than discard it completely.
                        if (!mPollLceScheduled) {
                        long waitTime = mLastBwRefreshTime + BW_REFRESH_MIN_WIN_MS -
                                currentTimeMs + 1;
                            long waitTime = mLastBwRefreshTime + BW_REFRESH_MIN_WIN_MS
                                    - currentTimeMs + 1;
                            mPollLceScheduled = sendEmptyMessageDelayed(
                                    CMD_REQUEST_BANDWIDTH_UPDATE, waitTime);
                        }
@@ -313,8 +320,9 @@ public abstract class NetworkAgent extends Handler {
                case CMD_REPORT_NETWORK_STATUS: {
                    String redirectUrl = ((Bundle) msg.obj).getString(REDIRECT_URL_KEY);
                    if (VDBG) {
                    log("CMD_REPORT_NETWORK_STATUS(" +
                            (msg.arg1 == VALID_NETWORK ? "VALID, " : "INVALID, ") + redirectUrl);
                        log("CMD_REPORT_NETWORK_STATUS("
                                + (msg.arg1 == VALID_NETWORK ? "VALID, " : "INVALID, ")
                                + redirectUrl);
                    }
                    networkStatus(msg.arg1, redirectUrl);
                    break;
@@ -358,6 +366,7 @@ public abstract class NetworkAgent extends Handler {
                }
            }
        }
    }

    private void queueOrSendMessage(int what, Object obj) {
        queueOrSendMessage(what, 0, 0, obj);
+1 −1
Original line number Diff line number Diff line
@@ -16,4 +16,4 @@

package android.net;

parcelable NetworkMisc;
parcelable NetworkAgentConfig;
+25 −22
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.net;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Parcel;
import android.os.Parcelable;

@@ -26,7 +28,7 @@ import android.os.Parcelable;
 *
 * @hide
 */
public class NetworkMisc implements Parcelable {
public class NetworkAgentConfig implements Parcelable {

    /**
     * If the {@link Network} is a VPN, whether apps are allowed to bypass the
@@ -83,17 +85,17 @@ public class NetworkMisc implements Parcelable {
     */
    public boolean hasShownBroken;

    public NetworkMisc() {
    public NetworkAgentConfig() {
    }

    public NetworkMisc(NetworkMisc nm) {
        if (nm != null) {
            allowBypass = nm.allowBypass;
            explicitlySelected = nm.explicitlySelected;
            acceptUnvalidated = nm.acceptUnvalidated;
            subscriberId = nm.subscriberId;
            provisioningNotificationDisabled = nm.provisioningNotificationDisabled;
            skip464xlat = nm.skip464xlat;
    public NetworkAgentConfig(@Nullable NetworkAgentConfig nac) {
        if (nac != null) {
            allowBypass = nac.allowBypass;
            explicitlySelected = nac.explicitlySelected;
            acceptUnvalidated = nac.acceptUnvalidated;
            subscriberId = nac.subscriberId;
            provisioningNotificationDisabled = nac.provisioningNotificationDisabled;
            skip464xlat = nac.skip464xlat;
        }
    }

@@ -112,22 +114,23 @@ public class NetworkMisc implements Parcelable {
        out.writeInt(skip464xlat ? 1 : 0);
    }

    public static final @android.annotation.NonNull Creator<NetworkMisc> CREATOR = new Creator<NetworkMisc>() {
    public static final @NonNull Creator<NetworkAgentConfig> CREATOR =
            new Creator<NetworkAgentConfig>() {
        @Override
        public NetworkMisc createFromParcel(Parcel in) {
            NetworkMisc networkMisc = new NetworkMisc();
            networkMisc.allowBypass = in.readInt() != 0;
            networkMisc.explicitlySelected = in.readInt() != 0;
            networkMisc.acceptUnvalidated = in.readInt() != 0;
            networkMisc.subscriberId = in.readString();
            networkMisc.provisioningNotificationDisabled = in.readInt() != 0;
            networkMisc.skip464xlat = in.readInt() != 0;
            return networkMisc;
        public NetworkAgentConfig createFromParcel(Parcel in) {
            NetworkAgentConfig networkAgentConfig = new NetworkAgentConfig();
            networkAgentConfig.allowBypass = in.readInt() != 0;
            networkAgentConfig.explicitlySelected = in.readInt() != 0;
            networkAgentConfig.acceptUnvalidated = in.readInt() != 0;
            networkAgentConfig.subscriberId = in.readString();
            networkAgentConfig.provisioningNotificationDisabled = in.readInt() != 0;
            networkAgentConfig.skip464xlat = in.readInt() != 0;
            return networkAgentConfig;
        }

        @Override
        public NetworkMisc[] newArray(int size) {
            return new NetworkMisc[size];
        public NetworkAgentConfig[] newArray(int size) {
            return new NetworkAgentConfig[size];
        }
    };
}
Loading