Revert "Remove connectivity dependency on Preconditions"

This reverts commit fa5eacc89f.

Reason for revert: Build broken: b/182721112

Change-Id: Ibc84ec6d7900fdcf0bc14cd7036f9c08287711db
This commit is contained in:
Remi NGUYEN VAN
2021-03-15 07:27:44 +00:00
parent fa5eacc89f
commit 3f0e7dd4e7
6 changed files with 38 additions and 42 deletions

View File

@@ -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 */

View File

@@ -69,6 +69,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;
@@ -1732,9 +1733,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.
@@ -1839,8 +1838,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() {
@@ -2215,9 +2214,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) {
@@ -2245,8 +2242,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;
}
@@ -2513,7 +2510,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
@@ -2606,7 +2603,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() {
@@ -2904,7 +2901,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) {
@@ -3528,7 +3525,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
@@ -3626,9 +3623,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 {
@@ -3974,17 +3971,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.");
}
/**
@@ -4234,9 +4229,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;

View File

@@ -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);
}

View File

@@ -34,6 +34,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;
@@ -2072,9 +2073,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) {
@@ -2082,9 +2082,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");
}
/**

View File

@@ -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;
}

View File

@@ -21,9 +21,10 @@ import android.annotation.SystemApi;
import android.os.IBinder;
import android.os.RemoteException;
import com.android.internal.util.Preconditions;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
/**
* Class that allows creation and management of per-app, test-only networks
@@ -49,7 +50,7 @@ public class TestNetworkManager {
/** @hide */
public TestNetworkManager(@NonNull ITestNetworkManager service) {
mService = Objects.requireNonNull(service, "missing ITestNetworkManager");
mService = Preconditions.checkNotNull(service, "missing ITestNetworkManager");
}
/**
@@ -92,7 +93,7 @@ public class TestNetworkManager {
*/
public void setupTestNetwork(
@NonNull LinkProperties lp, boolean isMetered, @NonNull IBinder binder) {
Objects.requireNonNull(lp, "Invalid LinkProperties");
Preconditions.checkNotNull(lp, "Invalid LinkProperties");
setupTestNetwork(lp.getInterfaceName(), lp, isMetered, new int[0], binder);
}