Revert "Revert "Require user pass in a non-null BluetoothDevice ..."

Revert "Revert "Pass in active device to all BluetoothA2dp APIs ..."

Revert "Revert "Pass in active device to all BluetoothA2dp APIs ..."

Revert submission 10303287-revert-10253996-bt-a2dp-no-null-FQRXACWPIA

Reason for revert: Fixing breakage
Reverted Changes:
I4d9f2f819:Revert "Make sure calls to BluetoothA2dp APIs pass...
I771ca0d57:Revert "Need to now pass in active device instead ...
I76529c7a1:Revert "Pass in active device to all BluetoothA2dp...
I297bda68d:Revert "Require user pass in a non-null BluetoothD...
I525327959:Revert "Pass in active device to all BluetoothA2dp...
I1d8660b11:Revert "Pass in active device to all BluetoothA2dp...

Bug: 147287141
Test: Manual
Merged-In: I91ee6878cac1b84bd289278a1b965658a26fe4db
Merged-In: I4d7d971af75bff8967fd807d34dad90c32e24eba
Change-Id: I4d7d971af75bff8967fd807d34dad90c32e24eba
This commit is contained in:
Rahul Sabnis
2020-02-25 22:28:00 +00:00
parent 30537f3d7d
commit cd3bee95ed
4 changed files with 68 additions and 36 deletions

View File

@@ -643,8 +643,9 @@ public final class BluetoothA2dp implements BluetoothProfile {
@SystemApi
@Nullable
@RequiresPermission(Manifest.permission.BLUETOOTH)
public BluetoothCodecStatus getCodecStatus(@Nullable BluetoothDevice device) {
public BluetoothCodecStatus getCodecStatus(@NonNull BluetoothDevice device) {
if (DBG) Log.d(TAG, "getCodecStatus(" + device + ")");
verifyDeviceNotNull(device, "getCodecStatus");
try {
final IBluetoothA2dp service = getService();
if (service != null && isEnabled()) {
@@ -670,9 +671,14 @@ public final class BluetoothA2dp implements BluetoothProfile {
*/
@SystemApi
@RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
public void setCodecConfigPreference(@Nullable BluetoothDevice device,
@Nullable BluetoothCodecConfig codecConfig) {
public void setCodecConfigPreference(@NonNull BluetoothDevice device,
@NonNull BluetoothCodecConfig codecConfig) {
if (DBG) Log.d(TAG, "setCodecConfigPreference(" + device + ")");
verifyDeviceNotNull(device, "setCodecConfigPreference");
if (codecConfig == null) {
Log.e(TAG, "setCodecConfigPreference: Codec config can't be null");
throw new IllegalArgumentException("codecConfig cannot be null");
}
try {
final IBluetoothA2dp service = getService();
if (service != null && isEnabled()) {
@@ -695,8 +701,9 @@ public final class BluetoothA2dp implements BluetoothProfile {
*/
@SystemApi
@RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
public void enableOptionalCodecs(@Nullable BluetoothDevice device) {
public void enableOptionalCodecs(@NonNull BluetoothDevice device) {
if (DBG) Log.d(TAG, "enableOptionalCodecs(" + device + ")");
verifyDeviceNotNull(device, "enableOptionalCodecs");
enableDisableOptionalCodecs(device, true);
}
@@ -709,8 +716,9 @@ public final class BluetoothA2dp implements BluetoothProfile {
*/
@SystemApi
@RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
public void disableOptionalCodecs(@Nullable BluetoothDevice device) {
public void disableOptionalCodecs(@NonNull BluetoothDevice device) {
if (DBG) Log.d(TAG, "disableOptionalCodecs(" + device + ")");
verifyDeviceNotNull(device, "disableOptionalCodecs");
enableDisableOptionalCodecs(device, false);
}
@@ -750,7 +758,8 @@ public final class BluetoothA2dp implements BluetoothProfile {
@SystemApi
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
@OptionalCodecsSupportStatus
public int supportsOptionalCodecs(@Nullable BluetoothDevice device) {
public int isOptionalCodecsSupported(@NonNull BluetoothDevice device) {
verifyDeviceNotNull(device, "isOptionalCodecsSupported");
try {
final IBluetoothA2dp service = getService();
if (service != null && isEnabled() && isValidDevice(device)) {
@@ -775,7 +784,8 @@ public final class BluetoothA2dp implements BluetoothProfile {
@SystemApi
@RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
@OptionalCodecsPreferenceStatus
public int getOptionalCodecsEnabled(@Nullable BluetoothDevice device) {
public int isOptionalCodecsEnabled(@NonNull BluetoothDevice device) {
verifyDeviceNotNull(device, "isOptionalCodecsEnabled");
try {
final IBluetoothA2dp service = getService();
if (service != null && isEnabled() && isValidDevice(device)) {
@@ -800,8 +810,9 @@ public final class BluetoothA2dp implements BluetoothProfile {
*/
@SystemApi
@RequiresPermission(Manifest.permission.BLUETOOTH_PRIVILEGED)
public void setOptionalCodecsEnabled(@Nullable BluetoothDevice device,
public void setOptionalCodecsEnabled(@NonNull BluetoothDevice device,
@OptionalCodecsPreferenceStatus int value) {
verifyDeviceNotNull(device, "setOptionalCodecsEnabled");
try {
if (value != BluetoothA2dp.OPTIONAL_CODECS_PREF_UNKNOWN
&& value != BluetoothA2dp.OPTIONAL_CODECS_PREF_DISABLED
@@ -854,6 +865,13 @@ public final class BluetoothA2dp 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;