Merge "Revert "Revert "Remove connectivity dependency on Preconditions""" into sc-dev

This commit is contained in:
Remi NGUYEN VAN
2021-03-19 04:49:06 +00:00
committed by Android (Google) Code Review
6 changed files with 45 additions and 39 deletions

View File

@@ -75,7 +75,6 @@ import android.util.SparseIntArray;
import com.android.connectivity.aidl.INetworkAgent;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.Preconditions;
import libcore.net.event.NetworkEventDispatcher;
@@ -1775,7 +1774,9 @@ public class ConnectivityManager {
// Map from type to transports.
final int NOT_FOUND = -1;
final int transport = sLegacyTypeToTransport.get(type, NOT_FOUND);
Preconditions.checkArgument(transport != NOT_FOUND, "unknown legacy type: " + type);
if (transport == NOT_FOUND) {
throw new IllegalArgumentException("unknown legacy type: " + type);
}
nc.addTransportType(transport);
// Map from type to capabilities.
@@ -1880,8 +1881,8 @@ public class ConnectivityManager {
}
private PacketKeepalive(Network network, PacketKeepaliveCallback callback) {
Preconditions.checkNotNull(network, "network cannot be null");
Preconditions.checkNotNull(callback, "callback cannot be null");
Objects.requireNonNull(network, "network cannot be null");
Objects.requireNonNull(callback, "callback cannot be null");
mNetwork = network;
mExecutor = Executors.newSingleThreadExecutor();
mCallback = new ISocketKeepaliveCallback.Stub() {
@@ -2256,7 +2257,9 @@ public class ConnectivityManager {
*/
public void removeDefaultNetworkActiveListener(@NonNull OnNetworkActiveListener l) {
INetworkActivityListener rl = mNetworkActivityListeners.get(l);
Preconditions.checkArgument(rl != null, "Listener was not registered.");
if (rl == null) {
throw new IllegalArgumentException("Listener was not registered.");
}
try {
mService.registerNetworkActivityListener(rl);
} catch (RemoteException e) {
@@ -2284,8 +2287,8 @@ public class ConnectivityManager {
* {@hide}
*/
public ConnectivityManager(Context context, IConnectivityManager service) {
mContext = Preconditions.checkNotNull(context, "missing context");
mService = Preconditions.checkNotNull(service, "missing IConnectivityManager");
mContext = Objects.requireNonNull(context, "missing context");
mService = Objects.requireNonNull(service, "missing IConnectivityManager");
mTetheringManager = (TetheringManager) mContext.getSystemService(Context.TETHERING_SERVICE);
sInstance = this;
}
@@ -2552,7 +2555,7 @@ public class ConnectivityManager {
@RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED)
public void startTethering(int type, boolean showProvisioningUi,
final OnStartTetheringCallback callback, Handler handler) {
Preconditions.checkNotNull(callback, "OnStartTetheringCallback cannot be null.");
Objects.requireNonNull(callback, "OnStartTetheringCallback cannot be null.");
final Executor executor = new Executor() {
@Override
@@ -2645,7 +2648,7 @@ public class ConnectivityManager {
public void registerTetheringEventCallback(
@NonNull @CallbackExecutor Executor executor,
@NonNull final OnTetheringEventCallback callback) {
Preconditions.checkNotNull(callback, "OnTetheringEventCallback cannot be null.");
Objects.requireNonNull(callback, "OnTetheringEventCallback cannot be null.");
final TetheringEventCallback tetherCallback =
new TetheringEventCallback() {
@@ -2943,7 +2946,7 @@ public class ConnectivityManager {
public void getLatestTetheringEntitlementResult(int type, boolean showEntitlementUi,
@NonNull @CallbackExecutor Executor executor,
@NonNull final OnTetheringEntitlementResultListener listener) {
Preconditions.checkNotNull(listener, "TetheringEntitlementResultListener cannot be null.");
Objects.requireNonNull(listener, "TetheringEntitlementResultListener cannot be null.");
ResultReceiver wrappedListener = new ResultReceiver(null) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
@@ -3316,7 +3319,9 @@ public class ConnectivityManager {
}
public NetworkCallback(@Flag int flags) {
Preconditions.checkArgument((flags & VALID_FLAGS) == flags);
if ((flags & VALID_FLAGS) != flags) {
throw new IllegalArgumentException("Invalid flags");
}
mFlags = flags;
}
@@ -3602,7 +3607,7 @@ public class ConnectivityManager {
}
CallbackHandler(Handler handler) {
this(Preconditions.checkNotNull(handler, "Handler cannot be null.").getLooper());
this(Objects.requireNonNull(handler, "Handler cannot be null.").getLooper());
}
@Override
@@ -3700,9 +3705,9 @@ public class ConnectivityManager {
int timeoutMs, NetworkRequest.Type reqType, int legacyType, CallbackHandler handler) {
printStackTrace();
checkCallbackNotNull(callback);
Preconditions.checkArgument(
reqType == TRACK_DEFAULT || reqType == TRACK_SYSTEM_DEFAULT || need != null,
"null NetworkCapabilities");
if (reqType != TRACK_DEFAULT && reqType != TRACK_SYSTEM_DEFAULT && need == null) {
throw new IllegalArgumentException("null NetworkCapabilities");
}
final NetworkRequest request;
final String callingPackageName = mContext.getOpPackageName();
try {
@@ -4049,15 +4054,17 @@ public class ConnectivityManager {
}
private static void checkPendingIntentNotNull(PendingIntent intent) {
Preconditions.checkNotNull(intent, "PendingIntent cannot be null.");
Objects.requireNonNull(intent, "PendingIntent cannot be null.");
}
private static void checkCallbackNotNull(NetworkCallback callback) {
Preconditions.checkNotNull(callback, "null NetworkCallback");
Objects.requireNonNull(callback, "null NetworkCallback");
}
private static void checkTimeout(int timeoutMs) {
Preconditions.checkArgumentPositive(timeoutMs, "timeoutMs must be strictly positive.");
if (timeoutMs <= 0) {
throw new IllegalArgumentException("timeoutMs must be strictly positive.");
}
}
/**
@@ -4337,8 +4344,9 @@ 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) {
Preconditions.checkArgument(networkCallback.networkRequest != null,
"NetworkCallback was not registered");
if (networkCallback.networkRequest == null) {
throw new IllegalArgumentException("NetworkCallback was not registered");
}
if (networkCallback.networkRequest == ALREADY_UNREGISTERED) {
Log.d(TAG, "NetworkCallback was already unregistered");
return;