summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothA2dp.java
diff options
context:
space:
mode:
authorRahul Sabnis <rahulsabnis@google.com>2020-02-25 22:28:00 +0000
committerRahul Sabnis <rahulsabnis@google.com>2020-03-18 11:10:24 -0700
commit7b97603ac022d44076667684ca405f20b65761dc (patch)
tree64170dc516a77dfcfd5f5f3319b550c7a0ec1709 /framework/java/android/bluetooth/BluetoothA2dp.java
parent3e9696658502b51efee1efd90e3a8b5a4d6a7ebd (diff)
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
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothA2dp.java')
-rw-r--r--framework/java/android/bluetooth/BluetoothA2dp.java34
1 files changed, 26 insertions, 8 deletions
diff --git a/framework/java/android/bluetooth/BluetoothA2dp.java b/framework/java/android/bluetooth/BluetoothA2dp.java
index d8c653c6d0..b672a0857c 100644
--- a/framework/java/android/bluetooth/BluetoothA2dp.java
+++ b/framework/java/android/bluetooth/BluetoothA2dp.java
@@ -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;