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

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