Merge "Update nullability checks to use Objects#requireNonNull instead of deprecated method in Preconditions class"

This commit is contained in:
Treehugger Robot
2021-06-15 22:45:39 +00:00
committed by Gerrit Code Review
3 changed files with 23 additions and 23 deletions

View File

@@ -17,6 +17,8 @@
package android.bluetooth; package android.bluetooth;
import static java.util.Objects.requireNonNull;
import android.Manifest; import android.Manifest;
import android.annotation.CallbackExecutor; import android.annotation.CallbackExecutor;
import android.annotation.IntDef; import android.annotation.IntDef;
@@ -53,8 +55,6 @@ import android.os.SystemProperties;
import android.util.Log; import android.util.Log;
import android.util.Pair; import android.util.Pair;
import com.android.internal.util.Preconditions;
import java.io.IOException; import java.io.IOException;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@@ -3091,8 +3091,8 @@ public final class BluetoothAdapter {
*/ */
WrappedOobDataCallback(@NonNull OobDataCallback callback, WrappedOobDataCallback(@NonNull OobDataCallback callback,
@NonNull @CallbackExecutor Executor executor) { @NonNull @CallbackExecutor Executor executor) {
Preconditions.checkNotNull(callback); requireNonNull(callback);
Preconditions.checkNotNull(executor); requireNonNull(executor);
mCallback = callback; mCallback = callback;
mExecutor = executor; mExecutor = executor;
} }
@@ -3158,7 +3158,7 @@ public final class BluetoothAdapter {
!= BluetoothDevice.TRANSPORT_LE) { != BluetoothDevice.TRANSPORT_LE) {
throw new IllegalArgumentException("Invalid transport '" + transport + "'!"); throw new IllegalArgumentException("Invalid transport '" + transport + "'!");
} }
Preconditions.checkNotNull(callback); requireNonNull(callback);
if (!isEnabled()) { if (!isEnabled()) {
Log.w(TAG, "generateLocalOobData(): Adapter isn't enabled!"); Log.w(TAG, "generateLocalOobData(): Adapter isn't enabled!");
callback.onError(OOB_ERROR_ADAPTER_DISABLED); callback.onError(OOB_ERROR_ADAPTER_DISABLED);
@@ -3293,7 +3293,7 @@ public final class BluetoothAdapter {
* @hide * @hide
*/ */
public static boolean isAddressRandomStatic(@NonNull String address) { public static boolean isAddressRandomStatic(@NonNull String address) {
Preconditions.checkNotNull(address); requireNonNull(address);
return checkBluetoothAddress(address) return checkBluetoothAddress(address)
&& (Integer.parseInt(address.split(":")[5], 16) & 0b11) == 0b11; && (Integer.parseInt(address.split(":")[5], 16) & 0b11) == 0b11;
} }

View File

@@ -16,6 +16,8 @@
package android.bluetooth; package android.bluetooth;
import static java.util.Objects.requireNonNull;
import android.annotation.IntDef; import android.annotation.IntDef;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
@@ -23,8 +25,6 @@ import android.annotation.SystemApi;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import com.android.internal.util.Preconditions;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@@ -214,7 +214,7 @@ public final class OobData implements Parcelable {
@NonNull @NonNull
@SystemApi @SystemApi
public LeBuilder setDeviceName(@NonNull byte[] deviceName) { public LeBuilder setDeviceName(@NonNull byte[] deviceName) {
Preconditions.checkNotNull(deviceName); requireNonNull(deviceName);
this.mDeviceName = deviceName; this.mDeviceName = deviceName;
return this; return this;
} }
@@ -308,8 +308,8 @@ public final class OobData implements Parcelable {
@SystemApi @SystemApi
public LeBuilder(@NonNull byte[] confirmationHash, @NonNull byte[] deviceAddressWithType, public LeBuilder(@NonNull byte[] confirmationHash, @NonNull byte[] deviceAddressWithType,
@LeRole int leDeviceRole) { @LeRole int leDeviceRole) {
Preconditions.checkNotNull(confirmationHash); requireNonNull(confirmationHash);
Preconditions.checkNotNull(deviceAddressWithType); requireNonNull(deviceAddressWithType);
if (confirmationHash.length != OobData.CONFIRMATION_OCTETS) { if (confirmationHash.length != OobData.CONFIRMATION_OCTETS) {
throw new IllegalArgumentException("confirmationHash must be " throw new IllegalArgumentException("confirmationHash must be "
+ OobData.CONFIRMATION_OCTETS + " octets in length."); + OobData.CONFIRMATION_OCTETS + " octets in length.");
@@ -344,7 +344,7 @@ public final class OobData implements Parcelable {
@NonNull @NonNull
@SystemApi @SystemApi
public LeBuilder setLeTemporaryKey(@NonNull byte[] leTemporaryKey) { public LeBuilder setLeTemporaryKey(@NonNull byte[] leTemporaryKey) {
Preconditions.checkNotNull(leTemporaryKey); requireNonNull(leTemporaryKey);
if (leTemporaryKey.length != LE_TK_OCTETS) { if (leTemporaryKey.length != LE_TK_OCTETS) {
throw new IllegalArgumentException("leTemporaryKey must be " throw new IllegalArgumentException("leTemporaryKey must be "
+ LE_TK_OCTETS + " octets in length."); + LE_TK_OCTETS + " octets in length.");
@@ -366,7 +366,7 @@ public final class OobData implements Parcelable {
@NonNull @NonNull
@SystemApi @SystemApi
public LeBuilder setRandomizerHash(@NonNull byte[] randomizerHash) { public LeBuilder setRandomizerHash(@NonNull byte[] randomizerHash) {
Preconditions.checkNotNull(randomizerHash); requireNonNull(randomizerHash);
if (randomizerHash.length != OobData.RANDOMIZER_OCTETS) { if (randomizerHash.length != OobData.RANDOMIZER_OCTETS) {
throw new IllegalArgumentException("randomizerHash must be " throw new IllegalArgumentException("randomizerHash must be "
+ OobData.RANDOMIZER_OCTETS + " octets in length."); + OobData.RANDOMIZER_OCTETS + " octets in length.");
@@ -534,9 +534,9 @@ public final class OobData implements Parcelable {
@SystemApi @SystemApi
public ClassicBuilder(@NonNull byte[] confirmationHash, @NonNull byte[] classicLength, public ClassicBuilder(@NonNull byte[] confirmationHash, @NonNull byte[] classicLength,
@NonNull byte[] deviceAddressWithType) { @NonNull byte[] deviceAddressWithType) {
Preconditions.checkNotNull(confirmationHash); requireNonNull(confirmationHash);
Preconditions.checkNotNull(classicLength); requireNonNull(classicLength);
Preconditions.checkNotNull(deviceAddressWithType); requireNonNull(deviceAddressWithType);
if (confirmationHash.length != OobData.CONFIRMATION_OCTETS) { if (confirmationHash.length != OobData.CONFIRMATION_OCTETS) {
throw new IllegalArgumentException("confirmationHash must be " throw new IllegalArgumentException("confirmationHash must be "
+ OobData.CONFIRMATION_OCTETS + " octets in length."); + OobData.CONFIRMATION_OCTETS + " octets in length.");
@@ -567,7 +567,7 @@ public final class OobData implements Parcelable {
@NonNull @NonNull
@SystemApi @SystemApi
public ClassicBuilder setRandomizerHash(@NonNull byte[] randomizerHash) { public ClassicBuilder setRandomizerHash(@NonNull byte[] randomizerHash) {
Preconditions.checkNotNull(randomizerHash); requireNonNull(randomizerHash);
if (randomizerHash.length != OobData.RANDOMIZER_OCTETS) { if (randomizerHash.length != OobData.RANDOMIZER_OCTETS) {
throw new IllegalArgumentException("randomizerHash must be " throw new IllegalArgumentException("randomizerHash must be "
+ OobData.RANDOMIZER_OCTETS + " octets in length."); + OobData.RANDOMIZER_OCTETS + " octets in length.");
@@ -592,7 +592,7 @@ public final class OobData implements Parcelable {
@NonNull @NonNull
@SystemApi @SystemApi
public ClassicBuilder setDeviceName(@NonNull byte[] deviceName) { public ClassicBuilder setDeviceName(@NonNull byte[] deviceName) {
Preconditions.checkNotNull(deviceName); requireNonNull(deviceName);
this.mDeviceName = deviceName; this.mDeviceName = deviceName;
return this; return this;
} }
@@ -617,7 +617,7 @@ public final class OobData implements Parcelable {
@NonNull @NonNull
@SystemApi @SystemApi
public ClassicBuilder setClassOfDevice(@NonNull byte[] classOfDevice) { public ClassicBuilder setClassOfDevice(@NonNull byte[] classOfDevice) {
Preconditions.checkNotNull(classOfDevice); requireNonNull(classOfDevice);
if (classOfDevice.length != OobData.CLASS_OF_DEVICE_OCTETS) { if (classOfDevice.length != OobData.CLASS_OF_DEVICE_OCTETS) {
throw new IllegalArgumentException("classOfDevice must be " throw new IllegalArgumentException("classOfDevice must be "
+ OobData.CLASS_OF_DEVICE_OCTETS + " octets in length."); + OobData.CLASS_OF_DEVICE_OCTETS + " octets in length.");

View File

@@ -16,7 +16,8 @@
package android.bluetooth.le; package android.bluetooth.le;
import android.annotation.IntDef; import static java.util.Objects.requireNonNull;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.annotation.SystemApi; import android.annotation.SystemApi;
@@ -28,7 +29,6 @@ import android.os.ParcelUuid;
import android.os.Parcelable; import android.os.Parcelable;
import com.android.internal.util.BitUtils; import com.android.internal.util.BitUtils;
import com.android.internal.util.Preconditions;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -647,7 +647,7 @@ public final class ScanFilter implements Parcelable {
public Builder setDeviceAddress(@NonNull String deviceAddress, public Builder setDeviceAddress(@NonNull String deviceAddress,
@AddressType int addressType, @AddressType int addressType,
@NonNull byte[] irk) { @NonNull byte[] irk) {
Preconditions.checkNotNull(irk); requireNonNull(irk);
if (irk.length != LEN_IRK_OCTETS) { if (irk.length != LEN_IRK_OCTETS) {
throw new IllegalArgumentException("'irk' is invalid length!"); throw new IllegalArgumentException("'irk' is invalid length!");
} }
@@ -679,7 +679,7 @@ public final class ScanFilter implements Parcelable {
@Nullable byte[] irk) { @Nullable byte[] irk) {
// Make sure our deviceAddress is valid! // Make sure our deviceAddress is valid!
Preconditions.checkNotNull(deviceAddress); requireNonNull(deviceAddress);
if (!BluetoothAdapter.checkBluetoothAddress(deviceAddress)) { if (!BluetoothAdapter.checkBluetoothAddress(deviceAddress)) {
throw new IllegalArgumentException("invalid device address " + deviceAddress); throw new IllegalArgumentException("invalid device address " + deviceAddress);
} }