Merge "Replace com.android.internal.util.Preconditions.checkNotNull with java.util.Objects.requireNonNull"
diff --git a/core/java/android/hardware/hdmi/HdmiControlManager.java b/core/java/android/hardware/hdmi/HdmiControlManager.java
index 2295d2b..65a8e15 100644
--- a/core/java/android/hardware/hdmi/HdmiControlManager.java
+++ b/core/java/android/hardware/hdmi/HdmiControlManager.java
@@ -36,10 +36,10 @@
import android.util.Log;
import com.android.internal.annotations.GuardedBy;
-import com.android.internal.util.Preconditions;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
/**
* The {@link HdmiControlManager} class is used to send HDMI control messages
@@ -532,7 +532,7 @@
*/
@SystemApi
public void powerOffDevice(@NonNull HdmiDeviceInfo deviceInfo) {
- Preconditions.checkNotNull(deviceInfo);
+ Objects.requireNonNull(deviceInfo);
try {
mService.powerOffRemoteDevice(
deviceInfo.getLogicalAddress(), deviceInfo.getDevicePowerStatus());
@@ -549,7 +549,7 @@
@Deprecated
@SystemApi
public void powerOffRemoteDevice(@NonNull HdmiDeviceInfo deviceInfo) {
- Preconditions.checkNotNull(deviceInfo);
+ Objects.requireNonNull(deviceInfo);
try {
mService.powerOffRemoteDevice(
deviceInfo.getLogicalAddress(), deviceInfo.getDevicePowerStatus());
@@ -569,7 +569,7 @@
* @hide
*/
public void powerOnDevice(HdmiDeviceInfo deviceInfo) {
- Preconditions.checkNotNull(deviceInfo);
+ Objects.requireNonNull(deviceInfo);
try {
mService.powerOnRemoteDevice(
deviceInfo.getLogicalAddress(), deviceInfo.getDevicePowerStatus());
@@ -586,7 +586,7 @@
@Deprecated
@SystemApi
public void powerOnRemoteDevice(HdmiDeviceInfo deviceInfo) {
- Preconditions.checkNotNull(deviceInfo);
+ Objects.requireNonNull(deviceInfo);
try {
mService.powerOnRemoteDevice(
deviceInfo.getLogicalAddress(), deviceInfo.getDevicePowerStatus());
@@ -610,7 +610,7 @@
*/
@SystemApi
public void setActiveSource(@NonNull HdmiDeviceInfo deviceInfo) {
- Preconditions.checkNotNull(deviceInfo);
+ Objects.requireNonNull(deviceInfo);
try {
mService.askRemoteDeviceToBecomeActiveSource(deviceInfo.getPhysicalAddress());
} catch (RemoteException e) {
@@ -626,7 +626,7 @@
@Deprecated
@SystemApi
public void requestRemoteDeviceToBecomeActiveSource(@NonNull HdmiDeviceInfo deviceInfo) {
- Preconditions.checkNotNull(deviceInfo);
+ Objects.requireNonNull(deviceInfo);
try {
mService.askRemoteDeviceToBecomeActiveSource(deviceInfo.getPhysicalAddress());
} catch (RemoteException e) {
@@ -689,7 +689,7 @@
*/
@SystemApi
public boolean isDeviceConnected(@NonNull HdmiDeviceInfo targetDevice) {
- Preconditions.checkNotNull(targetDevice);
+ Objects.requireNonNull(targetDevice);
int physicalAddress = getLocalPhysicalAddress();
if (physicalAddress == INVALID_PHYSICAL_ADDRESS) {
return false;
@@ -710,7 +710,7 @@
@Deprecated
@SystemApi
public boolean isRemoteDeviceConnected(@NonNull HdmiDeviceInfo targetDevice) {
- Preconditions.checkNotNull(targetDevice);
+ Objects.requireNonNull(targetDevice);
int physicalAddress = getLocalPhysicalAddress();
if (physicalAddress == INVALID_PHYSICAL_ADDRESS) {
return false;
diff --git a/core/java/android/hardware/hdmi/HdmiSwitchClient.java b/core/java/android/hardware/hdmi/HdmiSwitchClient.java
index 6a72a4a..7833653 100644
--- a/core/java/android/hardware/hdmi/HdmiSwitchClient.java
+++ b/core/java/android/hardware/hdmi/HdmiSwitchClient.java
@@ -23,10 +23,9 @@
import android.os.RemoteException;
import android.util.Log;
-import com.android.internal.util.Preconditions;
-
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
import java.util.concurrent.Executor;
/**
@@ -70,7 +69,7 @@
* @hide
*/
public void selectDevice(int logicalAddress, @NonNull OnSelectListener listener) {
- Preconditions.checkNotNull(listener);
+ Objects.requireNonNull(listener);
try {
mService.deviceSelect(logicalAddress, getCallbackWrapper(listener));
} catch (RemoteException e) {
@@ -91,7 +90,7 @@
*/
@SystemApi
public void selectPort(int portId, @NonNull OnSelectListener listener) {
- Preconditions.checkNotNull(listener);
+ Objects.requireNonNull(listener);
try {
mService.portSelect(portId, getCallbackWrapper(listener));
} catch (RemoteException e) {
@@ -114,7 +113,7 @@
int logicalAddress,
@NonNull @CallbackExecutor Executor executor,
@NonNull OnSelectListener listener) {
- Preconditions.checkNotNull(listener);
+ Objects.requireNonNull(listener);
try {
mService.deviceSelect(logicalAddress,
new IHdmiControlCallback.Stub() {
@@ -146,7 +145,7 @@
int portId,
@NonNull @CallbackExecutor Executor executor,
@NonNull OnSelectListener listener) {
- Preconditions.checkNotNull(listener);
+ Objects.requireNonNull(listener);
try {
mService.portSelect(portId,
new IHdmiControlCallback.Stub() {
diff --git a/core/java/android/hardware/location/ContextHubClient.java b/core/java/android/hardware/location/ContextHubClient.java
index 3adc101..c6a5dd0 100644
--- a/core/java/android/hardware/location/ContextHubClient.java
+++ b/core/java/android/hardware/location/ContextHubClient.java
@@ -22,11 +22,10 @@
import android.os.RemoteException;
import android.util.Log;
-import com.android.internal.util.Preconditions;
-
import dalvik.system.CloseGuard;
import java.io.Closeable;
+import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
/**
@@ -80,7 +79,7 @@
* @param clientProxy the proxy of the client at the service
*/
/* package */ void setClientProxy(IContextHubClient clientProxy) {
- Preconditions.checkNotNull(clientProxy, "IContextHubClient cannot be null");
+ Objects.requireNonNull(clientProxy, "IContextHubClient cannot be null");
if (mClientProxy != null) {
throw new IllegalStateException("Cannot change client proxy multiple times");
}
@@ -140,7 +139,7 @@
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
@ContextHubTransaction.Result
public int sendMessageToNanoApp(@NonNull NanoAppMessage message) {
- Preconditions.checkNotNull(message, "NanoAppMessage cannot be null");
+ Objects.requireNonNull(message, "NanoAppMessage cannot be null");
int maxPayloadBytes = mAttachedHub.getMaxPacketLengthBytes();
byte[] payload = message.getMessageBody();
diff --git a/core/java/android/hardware/location/ContextHubIntentEvent.java b/core/java/android/hardware/location/ContextHubIntentEvent.java
index 754327a..917f62b 100644
--- a/core/java/android/hardware/location/ContextHubIntentEvent.java
+++ b/core/java/android/hardware/location/ContextHubIntentEvent.java
@@ -21,7 +21,7 @@
import android.app.PendingIntent;
import android.content.Intent;
-import com.android.internal.util.Preconditions;
+import java.util.Objects;
/**
* A helper class to retrieve information about a Intent event received for a PendingIntent
@@ -89,7 +89,7 @@
*/
@NonNull
public static ContextHubIntentEvent fromIntent(@NonNull Intent intent) {
- Preconditions.checkNotNull(intent, "Intent cannot be null");
+ Objects.requireNonNull(intent, "Intent cannot be null");
hasExtraOrThrow(intent, ContextHubManager.EXTRA_CONTEXT_HUB_INFO);
ContextHubInfo info = intent.getParcelableExtra(ContextHubManager.EXTRA_CONTEXT_HUB_INFO);
diff --git a/core/java/android/hardware/location/ContextHubManager.java b/core/java/android/hardware/location/ContextHubManager.java
index 7639302..a51d2c9 100644
--- a/core/java/android/hardware/location/ContextHubManager.java
+++ b/core/java/android/hardware/location/ContextHubManager.java
@@ -34,11 +34,10 @@
import android.os.ServiceManager.ServiceNotFoundException;
import android.util.Log;
-import com.android.internal.util.Preconditions;
-
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
+import java.util.Objects;
import java.util.concurrent.Executor;
/**
@@ -470,8 +469,8 @@
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
@NonNull public ContextHubTransaction<Void> loadNanoApp(
@NonNull ContextHubInfo hubInfo, @NonNull NanoAppBinary appBinary) {
- Preconditions.checkNotNull(hubInfo, "ContextHubInfo cannot be null");
- Preconditions.checkNotNull(appBinary, "NanoAppBinary cannot be null");
+ Objects.requireNonNull(hubInfo, "ContextHubInfo cannot be null");
+ Objects.requireNonNull(appBinary, "NanoAppBinary cannot be null");
ContextHubTransaction<Void> transaction =
new ContextHubTransaction<>(ContextHubTransaction.TYPE_LOAD_NANOAPP);
@@ -499,7 +498,7 @@
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
@NonNull public ContextHubTransaction<Void> unloadNanoApp(
@NonNull ContextHubInfo hubInfo, long nanoAppId) {
- Preconditions.checkNotNull(hubInfo, "ContextHubInfo cannot be null");
+ Objects.requireNonNull(hubInfo, "ContextHubInfo cannot be null");
ContextHubTransaction<Void> transaction =
new ContextHubTransaction<>(ContextHubTransaction.TYPE_UNLOAD_NANOAPP);
@@ -527,7 +526,7 @@
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
@NonNull public ContextHubTransaction<Void> enableNanoApp(
@NonNull ContextHubInfo hubInfo, long nanoAppId) {
- Preconditions.checkNotNull(hubInfo, "ContextHubInfo cannot be null");
+ Objects.requireNonNull(hubInfo, "ContextHubInfo cannot be null");
ContextHubTransaction<Void> transaction =
new ContextHubTransaction<>(ContextHubTransaction.TYPE_ENABLE_NANOAPP);
@@ -555,7 +554,7 @@
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
@NonNull public ContextHubTransaction<Void> disableNanoApp(
@NonNull ContextHubInfo hubInfo, long nanoAppId) {
- Preconditions.checkNotNull(hubInfo, "ContextHubInfo cannot be null");
+ Objects.requireNonNull(hubInfo, "ContextHubInfo cannot be null");
ContextHubTransaction<Void> transaction =
new ContextHubTransaction<>(ContextHubTransaction.TYPE_DISABLE_NANOAPP);
@@ -582,7 +581,7 @@
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
@NonNull public ContextHubTransaction<List<NanoAppState>> queryNanoApps(
@NonNull ContextHubInfo hubInfo) {
- Preconditions.checkNotNull(hubInfo, "ContextHubInfo cannot be null");
+ Objects.requireNonNull(hubInfo, "ContextHubInfo cannot be null");
ContextHubTransaction<List<NanoAppState>> transaction =
new ContextHubTransaction<>(ContextHubTransaction.TYPE_QUERY_NANOAPPS);
@@ -729,9 +728,9 @@
@NonNull public ContextHubClient createClient(
@NonNull ContextHubInfo hubInfo, @NonNull ContextHubClientCallback callback,
@NonNull @CallbackExecutor Executor executor) {
- Preconditions.checkNotNull(callback, "Callback cannot be null");
- Preconditions.checkNotNull(hubInfo, "ContextHubInfo cannot be null");
- Preconditions.checkNotNull(executor, "Executor cannot be null");
+ Objects.requireNonNull(callback, "Callback cannot be null");
+ Objects.requireNonNull(hubInfo, "ContextHubInfo cannot be null");
+ Objects.requireNonNull(executor, "Executor cannot be null");
ContextHubClient client = new ContextHubClient(hubInfo, false /* persistent */);
IContextHubClientCallback clientInterface = createClientCallback(
@@ -808,8 +807,8 @@
@RequiresPermission(android.Manifest.permission.LOCATION_HARDWARE)
@NonNull public ContextHubClient createClient(
@NonNull ContextHubInfo hubInfo, @NonNull PendingIntent pendingIntent, long nanoAppId) {
- Preconditions.checkNotNull(pendingIntent);
- Preconditions.checkNotNull(hubInfo);
+ Objects.requireNonNull(pendingIntent);
+ Objects.requireNonNull(hubInfo);
ContextHubClient client = new ContextHubClient(hubInfo, true /* persistent */);
diff --git a/core/java/android/hardware/location/ContextHubTransaction.java b/core/java/android/hardware/location/ContextHubTransaction.java
index bc7efef..d11e0a9 100644
--- a/core/java/android/hardware/location/ContextHubTransaction.java
+++ b/core/java/android/hardware/location/ContextHubTransaction.java
@@ -22,10 +22,9 @@
import android.os.Handler;
import android.os.HandlerExecutor;
-import com.android.internal.util.Preconditions;
-
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
@@ -291,8 +290,8 @@
@NonNull ContextHubTransaction.OnCompleteListener<T> listener,
@NonNull @CallbackExecutor Executor executor) {
synchronized (this) {
- Preconditions.checkNotNull(listener, "OnCompleteListener cannot be null");
- Preconditions.checkNotNull(executor, "Executor cannot be null");
+ Objects.requireNonNull(listener, "OnCompleteListener cannot be null");
+ Objects.requireNonNull(executor, "Executor cannot be null");
if (mListener != null) {
throw new IllegalStateException(
"Cannot set ContextHubTransaction listener multiple times");
@@ -340,7 +339,7 @@
*/
/* package */ void setResponse(ContextHubTransaction.Response<T> response) {
synchronized (this) {
- Preconditions.checkNotNull(response, "Response cannot be null");
+ Objects.requireNonNull(response, "Response cannot be null");
if (mIsResponseSet) {
throw new IllegalStateException(
"Cannot set response of ContextHubTransaction multiple times");
diff --git a/core/java/android/hardware/location/NanoApp.java b/core/java/android/hardware/location/NanoApp.java
index 6a734f3..242c9e2 100644
--- a/core/java/android/hardware/location/NanoApp.java
+++ b/core/java/android/hardware/location/NanoApp.java
@@ -21,7 +21,7 @@
import android.os.Parcelable;
import android.util.Log;
-import com.android.internal.util.Preconditions;
+import java.util.Objects;
/** A class describing nano apps.
* A nano app is a piece of executable code that can be
@@ -198,12 +198,12 @@
* needed Sensors
*/
public void setNeededSensors(int[] neededSensors) {
- Preconditions.checkNotNull(neededSensors, "neededSensors must not be null");
+ Objects.requireNonNull(neededSensors, "neededSensors must not be null");
mNeededSensors = neededSensors;
}
public void setOutputEvents(int[] outputEvents) {
- Preconditions.checkNotNull(outputEvents, "outputEvents must not be null");
+ Objects.requireNonNull(outputEvents, "outputEvents must not be null");
mOutputEvents = outputEvents;
}
@@ -213,7 +213,7 @@
* @param appBinary generated events
*/
public void setAppBinary(byte[] appBinary) {
- Preconditions.checkNotNull(appBinary, "appBinary must not be null");
+ Objects.requireNonNull(appBinary, "appBinary must not be null");
mAppBinary = appBinary;
}
diff --git a/core/java/android/hardware/usb/UsbAccessory.java b/core/java/android/hardware/usb/UsbAccessory.java
index a76e4ad..a725205 100644
--- a/core/java/android/hardware/usb/UsbAccessory.java
+++ b/core/java/android/hardware/usb/UsbAccessory.java
@@ -24,6 +24,7 @@
import android.os.RemoteException;
import com.android.internal.util.Preconditions;
+import java.util.Objects;
/**
* A class representing a USB accessory, which is an external hardware component
@@ -79,8 +80,8 @@
public UsbAccessory(@NonNull String manufacturer, @NonNull String model,
@Nullable String description, @Nullable String version, @Nullable String uri,
@NonNull IUsbSerialReader serialNumberReader) {
- mManufacturer = Preconditions.checkNotNull(manufacturer);
- mModel = Preconditions.checkNotNull(model);
+ mManufacturer = Objects.requireNonNull(manufacturer);
+ mModel = Objects.requireNonNull(model);
mDescription = description;
mVersion = version;
mUri = uri;
diff --git a/core/java/android/hardware/usb/UsbDevice.java b/core/java/android/hardware/usb/UsbDevice.java
index ee2e262..67e05c8 100644
--- a/core/java/android/hardware/usb/UsbDevice.java
+++ b/core/java/android/hardware/usb/UsbDevice.java
@@ -25,6 +25,7 @@
import android.os.RemoteException;
import com.android.internal.util.Preconditions;
+import java.util.Objects;
/**
* This class represents a USB device attached to the android device with the android device
@@ -81,7 +82,7 @@
@NonNull IUsbSerialReader serialNumberReader,
boolean hasAudioPlayback, boolean hasAudioCapture, boolean hasMidi,
boolean hasVideoPlayback, boolean hasVideoCapture) {
- mName = Preconditions.checkNotNull(name);
+ mName = Objects.requireNonNull(name);
mVendorId = vendorId;
mProductId = productId;
mClass = Class;
@@ -91,7 +92,7 @@
mProductName = productName;
mVersion = Preconditions.checkStringNotEmpty(version);
mConfigurations = Preconditions.checkArrayElementsNotNull(configurations, "configurations");
- mSerialNumberReader = Preconditions.checkNotNull(serialNumberReader);
+ mSerialNumberReader = Objects.requireNonNull(serialNumberReader);
mHasAudioPlayback = hasAudioPlayback;
mHasAudioCapture = hasAudioCapture;
mHasMidi = hasMidi;
@@ -441,7 +442,7 @@
@Nullable String serialNumber,
boolean hasAudioPlayback, boolean hasAudioCapture, boolean hasMidi,
boolean hasVideoPlayback, boolean hasVideoCapture) {
- mName = Preconditions.checkNotNull(name);
+ mName = Objects.requireNonNull(name);
mVendorId = vendorId;
mProductId = productId;
mClass = Class;
diff --git a/core/java/android/hardware/usb/UsbPort.java b/core/java/android/hardware/usb/UsbPort.java
index 506230e..274e23f 100644
--- a/core/java/android/hardware/usb/UsbPort.java
+++ b/core/java/android/hardware/usb/UsbPort.java
@@ -42,6 +42,8 @@
import com.android.internal.util.Preconditions;
+import java.util.Objects;
+
/**
* Represents a physical USB port and describes its characteristics.
*
@@ -67,7 +69,7 @@
int supportedContaminantProtectionModes,
boolean supportsEnableContaminantPresenceProtection,
boolean supportsEnableContaminantPresenceDetection) {
- Preconditions.checkNotNull(id);
+ Objects.requireNonNull(id);
Preconditions.checkFlagsArgument(supportedModes,
MODE_DFP | MODE_UFP | MODE_AUDIO_ACCESSORY | MODE_DEBUG_ACCESSORY);
diff --git a/core/java/android/hardware/usb/UsbRequest.java b/core/java/android/hardware/usb/UsbRequest.java
index cc4ba08..d464ab5 100644
--- a/core/java/android/hardware/usb/UsbRequest.java
+++ b/core/java/android/hardware/usb/UsbRequest.java
@@ -27,6 +27,7 @@
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
+import java.util.Objects;
/**
* A class representing USB request packet.
@@ -96,7 +97,7 @@
*/
public boolean initialize(UsbDeviceConnection connection, UsbEndpoint endpoint) {
mEndpoint = endpoint;
- mConnection = Preconditions.checkNotNull(connection, "connection");
+ mConnection = Objects.requireNonNull(connection, "connection");
boolean wasInitialized = native_init(connection, endpoint.getAddress(),
endpoint.getAttributes(), endpoint.getMaxPacketSize(), endpoint.getInterval());