Merge "Replace com.android.internal.util.Preconditions.checkNotNull with java.util.Objects.requireNonNull"

This commit is contained in:
Cody Kesting
2020-03-16 17:11:54 +00:00
committed by Gerrit Code Review

View File

@@ -16,8 +16,6 @@
package com.android.server; package com.android.server;
import static com.android.internal.util.Preconditions.checkNotNull;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.content.Context; import android.content.Context;
@@ -55,6 +53,7 @@ import java.net.InterfaceAddress;
import java.net.NetworkInterface; import java.net.NetworkInterface;
import java.net.SocketException; import java.net.SocketException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/** @hide */ /** @hide */
@@ -82,9 +81,9 @@ class TestNetworkService extends ITestNetworkManager.Stub {
mHandlerThread.start(); mHandlerThread.start();
mHandler = new Handler(mHandlerThread.getLooper()); mHandler = new Handler(mHandlerThread.getLooper());
mContext = checkNotNull(context, "missing Context"); mContext = Objects.requireNonNull(context, "missing Context");
mNMS = checkNotNull(netManager, "missing INetworkManagementService"); mNMS = Objects.requireNonNull(netManager, "missing INetworkManagementService");
mNetd = checkNotNull(NetdService.getInstance(), "could not get netd instance"); mNetd = Objects.requireNonNull(NetdService.getInstance(), "could not get netd instance");
} }
/** /**
@@ -96,7 +95,7 @@ class TestNetworkService extends ITestNetworkManager.Stub {
private TestNetworkInterface createInterface(boolean isTun, LinkAddress[] linkAddrs) { private TestNetworkInterface createInterface(boolean isTun, LinkAddress[] linkAddrs) {
enforceTestNetworkPermissions(mContext); enforceTestNetworkPermissions(mContext);
checkNotNull(linkAddrs, "missing linkAddrs"); Objects.requireNonNull(linkAddrs, "missing linkAddrs");
String ifacePrefix = isTun ? TEST_TUN_PREFIX : TEST_TAP_PREFIX; String ifacePrefix = isTun ? TEST_TUN_PREFIX : TEST_TAP_PREFIX;
String iface = ifacePrefix + sTestTunIndex.getAndIncrement(); String iface = ifacePrefix + sTestTunIndex.getAndIncrement();
@@ -233,8 +232,8 @@ class TestNetworkService extends ITestNetworkManager.Stub {
int callingUid, int callingUid,
@NonNull IBinder binder) @NonNull IBinder binder)
throws RemoteException, SocketException { throws RemoteException, SocketException {
checkNotNull(looper, "missing Looper"); Objects.requireNonNull(looper, "missing Looper");
checkNotNull(context, "missing Context"); Objects.requireNonNull(context, "missing Context");
// iface and binder validity checked by caller // iface and binder validity checked by caller
// Build network info with special testing type // Build network info with special testing type
@@ -267,7 +266,7 @@ class TestNetworkService extends ITestNetworkManager.Stub {
// Find the currently assigned addresses, and add them to LinkProperties // Find the currently assigned addresses, and add them to LinkProperties
boolean allowIPv4 = false, allowIPv6 = false; boolean allowIPv4 = false, allowIPv6 = false;
NetworkInterface netIntf = NetworkInterface.getByName(iface); NetworkInterface netIntf = NetworkInterface.getByName(iface);
checkNotNull(netIntf, "No such network interface found: " + netIntf); Objects.requireNonNull(netIntf, "No such network interface found: " + netIntf);
for (InterfaceAddress intfAddr : netIntf.getInterfaceAddresses()) { for (InterfaceAddress intfAddr : netIntf.getInterfaceAddresses()) {
lp.addLinkAddress( lp.addLinkAddress(
@@ -305,8 +304,8 @@ class TestNetworkService extends ITestNetworkManager.Stub {
@NonNull IBinder binder) { @NonNull IBinder binder) {
enforceTestNetworkPermissions(mContext); enforceTestNetworkPermissions(mContext);
checkNotNull(iface, "missing Iface"); Objects.requireNonNull(iface, "missing Iface");
checkNotNull(binder, "missing IBinder"); Objects.requireNonNull(binder, "missing IBinder");
if (!(iface.startsWith(INetd.IPSEC_INTERFACE_PREFIX) if (!(iface.startsWith(INetd.IPSEC_INTERFACE_PREFIX)
|| iface.startsWith(TEST_TUN_PREFIX))) { || iface.startsWith(TEST_TUN_PREFIX))) {