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

Commit 33594b42 authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN Committed by Automerger Merge Worker
Browse files

Merge "Revert "Remove connectivity dependency on Preconditions"" am:...

Merge "Revert "Remove connectivity dependency on Preconditions"" am: 84319f2f am: 4ac52e88 am: b5437344 am: 7af62a21

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

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I801c7145ecc5e0e575b90f108a0db214c51b903d
parents dce29ecd 7af62a21
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.os.PersistableBundle;
import android.os.RemoteException;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.Preconditions;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -69,8 +70,8 @@ public class ConnectivityDiagnosticsManager {

    /** @hide */
    public ConnectivityDiagnosticsManager(Context context, IConnectivityManager service) {
        mContext = Objects.requireNonNull(context, "missing context");
        mService = Objects.requireNonNull(service, "missing IConnectivityManager");
        mContext = Preconditions.checkNotNull(context, "missing context");
        mService = Preconditions.checkNotNull(service, "missing IConnectivityManager");
    }

    /** @hide */
+19 −25
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ import android.util.SparseIntArray;

import com.android.connectivity.aidl.INetworkAgent;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.Preconditions;
import com.android.internal.util.Protocol;

import libcore.net.event.NetworkEventDispatcher;
@@ -1749,9 +1750,7 @@ public class ConnectivityManager {
        // Map from type to transports.
        final int NOT_FOUND = -1;
        final int transport = sLegacyTypeToTransport.get(type, NOT_FOUND);
        if (transport == NOT_FOUND) {
            throw new IllegalArgumentException("unknown legacy type: " + type);
        }
        Preconditions.checkArgument(transport != NOT_FOUND, "unknown legacy type: " + type);
        nc.addTransportType(transport);

        // Map from type to capabilities.
@@ -1856,8 +1855,8 @@ public class ConnectivityManager {
        }

        private PacketKeepalive(Network network, PacketKeepaliveCallback callback) {
            Objects.requireNonNull(network, "network cannot be null");
            Objects.requireNonNull(callback, "callback cannot be null");
            Preconditions.checkNotNull(network, "network cannot be null");
            Preconditions.checkNotNull(callback, "callback cannot be null");
            mNetwork = network;
            mExecutor = Executors.newSingleThreadExecutor();
            mCallback = new ISocketKeepaliveCallback.Stub() {
@@ -2232,9 +2231,7 @@ public class ConnectivityManager {
     */
    public void removeDefaultNetworkActiveListener(@NonNull OnNetworkActiveListener l) {
        INetworkActivityListener rl = mNetworkActivityListeners.get(l);
        if (rl == null) {
            throw new IllegalArgumentException("Listener was not registered.");
        }
        Preconditions.checkArgument(rl != null, "Listener was not registered.");
        try {
            mService.registerNetworkActivityListener(rl);
        } catch (RemoteException e) {
@@ -2262,8 +2259,8 @@ public class ConnectivityManager {
     * {@hide}
     */
    public ConnectivityManager(Context context, IConnectivityManager service) {
        mContext = Objects.requireNonNull(context, "missing context");
        mService = Objects.requireNonNull(service, "missing IConnectivityManager");
        mContext = Preconditions.checkNotNull(context, "missing context");
        mService = Preconditions.checkNotNull(service, "missing IConnectivityManager");
        mTetheringManager = (TetheringManager) mContext.getSystemService(Context.TETHERING_SERVICE);
        sInstance = this;
    }
@@ -2530,7 +2527,7 @@ public class ConnectivityManager {
    @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
    public void startTethering(int type, boolean showProvisioningUi,
            final OnStartTetheringCallback callback, Handler handler) {
        Objects.requireNonNull(callback, "OnStartTetheringCallback cannot be null.");
        Preconditions.checkNotNull(callback, "OnStartTetheringCallback cannot be null.");

        final Executor executor = new Executor() {
            @Override
@@ -2623,7 +2620,7 @@ public class ConnectivityManager {
    public void registerTetheringEventCallback(
            @NonNull @CallbackExecutor Executor executor,
            @NonNull final OnTetheringEventCallback callback) {
        Objects.requireNonNull(callback, "OnTetheringEventCallback cannot be null.");
        Preconditions.checkNotNull(callback, "OnTetheringEventCallback cannot be null.");

        final TetheringEventCallback tetherCallback =
                new TetheringEventCallback() {
@@ -2921,7 +2918,7 @@ public class ConnectivityManager {
    public void getLatestTetheringEntitlementResult(int type, boolean showEntitlementUi,
            @NonNull @CallbackExecutor Executor executor,
            @NonNull final OnTetheringEntitlementResultListener listener) {
        Objects.requireNonNull(listener, "TetheringEntitlementResultListener cannot be null.");
        Preconditions.checkNotNull(listener, "TetheringEntitlementResultListener cannot be null.");
        ResultReceiver wrappedListener = new ResultReceiver(null) {
            @Override
            protected void onReceiveResult(int resultCode, Bundle resultData) {
@@ -3594,7 +3591,7 @@ public class ConnectivityManager {
        }

        CallbackHandler(Handler handler) {
            this(Objects.requireNonNull(handler, "Handler cannot be null.").getLooper());
            this(Preconditions.checkNotNull(handler, "Handler cannot be null.").getLooper());
        }

        @Override
@@ -3692,9 +3689,9 @@ public class ConnectivityManager {
            int timeoutMs, NetworkRequest.Type reqType, int legacyType, CallbackHandler handler) {
        printStackTrace();
        checkCallbackNotNull(callback);
        if (reqType != TRACK_DEFAULT && reqType != TRACK_SYSTEM_DEFAULT && need == null) {
            throw new IllegalArgumentException("null NetworkCapabilities");
        }
        Preconditions.checkArgument(
                reqType == TRACK_DEFAULT || reqType == TRACK_SYSTEM_DEFAULT || need != null,
                "null NetworkCapabilities");
        final NetworkRequest request;
        final String callingPackageName = mContext.getOpPackageName();
        try {
@@ -4041,17 +4038,15 @@ public class ConnectivityManager {
    }

    private static void checkPendingIntentNotNull(PendingIntent intent) {
        Objects.requireNonNull(intent, "PendingIntent cannot be null.");
        Preconditions.checkNotNull(intent, "PendingIntent cannot be null.");
    }

    private static void checkCallbackNotNull(NetworkCallback callback) {
        Objects.requireNonNull(callback, "null NetworkCallback");
        Preconditions.checkNotNull(callback, "null NetworkCallback");
    }

    private static void checkTimeout(int timeoutMs) {
        if (timeoutMs <= 0) {
            throw new IllegalArgumentException("timeoutMs must be strictly positive.");
        }
        Preconditions.checkArgumentPositive(timeoutMs, "timeoutMs must be strictly positive.");
    }

    /**
@@ -4313,9 +4308,8 @@ public class ConnectivityManager {
        // Find all requests associated to this callback and stop callback triggers immediately.
        // Callback is reusable immediately. http://b/20701525, http://b/35921499.
        synchronized (sCallbacks) {
            if (networkCallback.networkRequest == null) {
                throw new IllegalArgumentException("NetworkCallback was not registered");
            }
            Preconditions.checkArgument(networkCallback.networkRequest != null,
                    "NetworkCallback was not registered");
            if (networkCallback.networkRequest == ALREADY_UNREGISTERED) {
                Log.d(TAG, "NetworkCallback was already unregistered");
                return;
+5 −5
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;

import com.android.internal.util.Preconditions;
import com.android.net.module.util.MacAddressUtils;

import java.lang.annotation.Retention;
@@ -33,7 +34,6 @@ import java.net.Inet6Address;
import java.net.UnknownHostException;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Objects;

/**
 * Representation of a MAC address.
@@ -229,7 +229,7 @@ public final class MacAddress implements Parcelable {
     * @hide
     */
    public static @NonNull byte[] byteAddrFromStringAddr(String addr) {
        Objects.requireNonNull(addr);
        Preconditions.checkNotNull(addr);
        String[] parts = addr.split(":");
        if (parts.length != ETHER_ADDR_LEN) {
            throw new IllegalArgumentException(addr + " was not a valid MAC address");
@@ -275,7 +275,7 @@ public final class MacAddress implements Parcelable {
    // Internal conversion function equivalent to longAddrFromByteAddr(byteAddrFromStringAddr(addr))
    // that avoids the allocation of an intermediary byte[].
    private static long longAddrFromStringAddr(String addr) {
        Objects.requireNonNull(addr);
        Preconditions.checkNotNull(addr);
        String[] parts = addr.split(":");
        if (parts.length != ETHER_ADDR_LEN) {
            throw new IllegalArgumentException(addr + " was not a valid MAC address");
@@ -364,8 +364,8 @@ public final class MacAddress implements Parcelable {
     *
     */
    public boolean matches(@NonNull MacAddress baseAddress, @NonNull MacAddress mask) {
        Objects.requireNonNull(baseAddress);
        Objects.requireNonNull(mask);
        Preconditions.checkNotNull(baseAddress);
        Preconditions.checkNotNull(mask);
        return (mAddr & mask.mAddr) == (baseAddress.mAddr & mask.mAddr);
    }

+5 −6
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.util.ArraySet;
import android.util.proto.ProtoOutputStream;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.Preconditions;
import com.android.net.module.util.CollectionUtils;
import com.android.net.module.util.NetworkCapabilitiesUtils;

@@ -2098,9 +2099,8 @@ public final class NetworkCapabilities implements Parcelable {
    }

    private static void checkValidTransportType(@Transport int transport) {
        if (!isValidTransport(transport)) {
            throw new IllegalArgumentException("Invalid TransportType " + transport);
        }
        Preconditions.checkArgument(
                isValidTransport(transport), "Invalid TransportType " + transport);
    }

    private static boolean isValidCapability(@NetworkCapabilities.NetCapability int capability) {
@@ -2108,9 +2108,8 @@ public final class NetworkCapabilities implements Parcelable {
    }

    private static void checkValidCapability(@NetworkCapabilities.NetCapability int capability) {
        if (!isValidCapability(capability)) {
            throw new IllegalArgumentException("NetworkCapability " + capability + "out of range");
        }
        Preconditions.checkArgument(isValidCapability(capability),
                "NetworkCapability " + capability + "out of range");
    }

    /**
+2 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;

import com.android.internal.util.Preconditions;
import com.android.net.module.util.InetAddressUtils;

import java.net.InetAddress;
@@ -152,7 +153,7 @@ public final class StaticIpConfiguration implements Parcelable {
         * @return The {@link Builder} for chaining.
         */
        public @NonNull Builder setDnsServers(@NonNull Iterable<InetAddress> dnsServers) {
            Objects.requireNonNull(dnsServers);
            Preconditions.checkNotNull(dnsServers);
            mDnsServers = dnsServers;
            return this;
        }
Loading