BluetoothHearingAid System APIs now throw an exception if a null
BluetoothDevice is passed in Bug: 149238489 Test: Manual Merged-In: I594f558bfe1e286bf74dd8dc3db4c8497fd0a025 Change-Id: I594f558bfe1e286bf74dd8dc3db4c8497fd0a025
This commit is contained in:
@@ -386,6 +386,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()
|
||||
@@ -435,6 +436,7 @@ public final class BluetoothHearingAid implements BluetoothProfile {
|
||||
@RequiresPermission(Manifest.permission.BLUETOOTH)
|
||||
public @ConnectionPolicy int getConnectionPolicy(@NonNull BluetoothDevice device) {
|
||||
if (VDBG) log("getConnectionPolicy(" + device + ")");
|
||||
verifyDeviceNotNull(device, "getConnectionPolicy");
|
||||
final IBluetoothHearingAid service = getService();
|
||||
try {
|
||||
if (service != null && isEnabled()
|
||||
@@ -511,6 +513,7 @@ public final class BluetoothHearingAid implements BluetoothProfile {
|
||||
if (VDBG) {
|
||||
log("getHiSyncId(" + device + ")");
|
||||
}
|
||||
verifyDeviceNotNull(device, "getConnectionPolicy");
|
||||
final IBluetoothHearingAid service = getService();
|
||||
try {
|
||||
if (service == null) {
|
||||
@@ -584,6 +587,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;
|
||||
|
||||
|
||||
@@ -174,7 +174,7 @@ public class HearingAidProfile implements LocalBluetoothProfile {
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(BluetoothDevice device) {
|
||||
if (mService == null) {
|
||||
if (mService == null || device == null) {
|
||||
return false;
|
||||
}
|
||||
return mService.getConnectionPolicy(device) > CONNECTION_POLICY_FORBIDDEN;
|
||||
@@ -182,7 +182,7 @@ public class HearingAidProfile implements LocalBluetoothProfile {
|
||||
|
||||
@Override
|
||||
public int getConnectionPolicy(BluetoothDevice device) {
|
||||
if (mService == null) {
|
||||
if (mService == null || device == null) {
|
||||
return CONNECTION_POLICY_FORBIDDEN;
|
||||
}
|
||||
return mService.getConnectionPolicy(device);
|
||||
@@ -191,7 +191,7 @@ public class HearingAidProfile implements LocalBluetoothProfile {
|
||||
@Override
|
||||
public boolean setEnabled(BluetoothDevice device, boolean enabled) {
|
||||
boolean isEnabled = false;
|
||||
if (mService == null) {
|
||||
if (mService == null || device == null) {
|
||||
return false;
|
||||
}
|
||||
if (enabled) {
|
||||
@@ -213,7 +213,7 @@ public class HearingAidProfile implements LocalBluetoothProfile {
|
||||
}
|
||||
|
||||
public long getHiSyncId(BluetoothDevice device) {
|
||||
if (mService == null) {
|
||||
if (mService == null || device == null) {
|
||||
return BluetoothHearingAid.HI_SYNC_ID_INVALID;
|
||||
}
|
||||
return mService.getHiSyncId(device);
|
||||
|
||||
Reference in New Issue
Block a user