Merge "BluetoothHearingAid System APIs now throw an exception if a null BluetoothDevice is passed in" into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
fc099117fc
@@ -379,6 +379,7 @@ public final class BluetoothHearingAid implements BluetoothProfile {
|
||||
public boolean setConnectionPolicy(@NonNull BluetoothDevice device,
|
||||
@ConnectionPolicy int connectionPolicy) {
|
||||
if (DBG) log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")");
|
||||
verifyDeviceNotNull(device, "setConnectionPolicy");
|
||||
final IBluetoothHearingAid service = getService();
|
||||
try {
|
||||
if (service != null && isEnabled()
|
||||
@@ -428,6 +429,7 @@ public final class BluetoothHearingAid implements BluetoothProfile {
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
|
||||
public @ConnectionPolicy int getConnectionPolicy(@NonNull BluetoothDevice device) {
|
||||
if (VDBG) log("getConnectionPolicy(" + device + ")");
|
||||
verifyDeviceNotNull(device, "getConnectionPolicy");
|
||||
final IBluetoothHearingAid service = getService();
|
||||
try {
|
||||
if (service != null && isEnabled()
|
||||
@@ -504,6 +506,7 @@ public final class BluetoothHearingAid implements BluetoothProfile {
|
||||
if (VDBG) {
|
||||
log("getHiSyncId(" + device + ")");
|
||||
}
|
||||
verifyDeviceNotNull(device, "getConnectionPolicy");
|
||||
final IBluetoothHearingAid service = getService();
|
||||
try {
|
||||
if (service == null) {
|
||||
@@ -577,6 +580,13 @@ public final class BluetoothHearingAid implements BluetoothProfile {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void verifyDeviceNotNull(BluetoothDevice device, String methodName) {
|
||||
if (device == null) {
|
||||
Log.e(TAG, methodName + ": device param is null");
|
||||
throw new IllegalArgumentException("Device cannot be null");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValidDevice(BluetoothDevice device) {
|
||||
if (device == null) return false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user