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: robotests
Merged-In: I5aecfa4b5a8e371b914573ddd080acb98078bfca
Change-Id: I5aecfa4b5a8e371b914573ddd080acb98078bfca
This commit is contained in:
Rahul Sabnis
2020-02-25 22:28:00 +00:00
parent ac2c706809
commit 27d9ac4f1e
2 changed files with 37 additions and 7 deletions

View File

@@ -83,7 +83,11 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends
final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig(); final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig();
synchronized (mBluetoothA2dpConfigStore) { synchronized (mBluetoothA2dpConfigStore) {
if (mBluetoothA2dp != null) { if (mBluetoothA2dp != null) {
setCodecConfigPreference(null, codecConfig); // Use current active device BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
if (activeDevice == null) {
return false;
}
setCodecConfigPreference(activeDevice, codecConfig);
} }
} }
// Because the setting is not persisted into permanent storage, we cannot call update state // Because the setting is not persisted into permanent storage, we cannot call update state
@@ -102,13 +106,17 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends
@Override @Override
public void updateState(Preference preference) { public void updateState(Preference preference) {
if (getCodecConfig(null) == null || mPreference == null) { // Use current active device if (mBluetoothA2dp == null) {
return;
}
BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
if (activeDevice == null || getCodecConfig(activeDevice) == null || mPreference == null) {
return; return;
} }
BluetoothCodecConfig codecConfig; BluetoothCodecConfig codecConfig;
synchronized (mBluetoothA2dpConfigStore) { synchronized (mBluetoothA2dpConfigStore) {
codecConfig = getCodecConfig(null); // Use current active device codecConfig = getCodecConfig(activeDevice);
} }
final int index = getCurrentA2dpSettingIndex(codecConfig); final int index = getCurrentA2dpSettingIndex(codecConfig);
@@ -178,13 +186,26 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends
@VisibleForTesting @VisibleForTesting
void setCodecConfigPreference(BluetoothDevice device, void setCodecConfigPreference(BluetoothDevice device,
BluetoothCodecConfig config) { BluetoothCodecConfig config) {
mBluetoothA2dp.setCodecConfigPreference(device, config); if (mBluetoothA2dp == null) {
return;
}
BluetoothDevice bluetoothDevice =
(device != null) ? device : mBluetoothA2dp.getActiveDevice();
if (bluetoothDevice == null) {
return;
}
mBluetoothA2dp.setCodecConfigPreference(bluetoothDevice, config);
} }
@VisibleForTesting @VisibleForTesting
BluetoothCodecConfig getCodecConfig(BluetoothDevice device) { BluetoothCodecConfig getCodecConfig(BluetoothDevice device) {
if (mBluetoothA2dp != null) { if (mBluetoothA2dp != null) {
BluetoothCodecStatus codecStatus = mBluetoothA2dp.getCodecStatus(device); BluetoothDevice bluetoothDevice =
(device != null) ? device : mBluetoothA2dp.getActiveDevice();
if (bluetoothDevice == null) {
return null;
}
BluetoothCodecStatus codecStatus = mBluetoothA2dp.getCodecStatus(bluetoothDevice);
if (codecStatus != null) { if (codecStatus != null) {
return codecStatus.getCodecConfig(); return codecStatus.getCodecConfig();
} }

View File

@@ -17,6 +17,7 @@
package com.android.settings.development; package com.android.settings.development;
import android.bluetooth.BluetoothCodecConfig; import android.bluetooth.BluetoothCodecConfig;
import android.bluetooth.BluetoothDevice;
import android.content.Context; import android.content.Context;
import com.android.settings.R; import com.android.settings.R;
@@ -109,14 +110,22 @@ public class BluetoothAudioCodecPreferenceController extends
case 6: case 6:
synchronized (mBluetoothA2dpConfigStore) { synchronized (mBluetoothA2dpConfigStore) {
if (mBluetoothA2dp != null) { if (mBluetoothA2dp != null) {
mBluetoothA2dp.enableOptionalCodecs(null); // Use current active device BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
if (activeDevice == null) {
return;
}
mBluetoothA2dp.enableOptionalCodecs(activeDevice);
} }
} }
return; return;
case 7: case 7:
synchronized (mBluetoothA2dpConfigStore) { synchronized (mBluetoothA2dpConfigStore) {
if (mBluetoothA2dp != null) { if (mBluetoothA2dp != null) {
mBluetoothA2dp.disableOptionalCodecs(null); // Use current active device BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
if (activeDevice == null) {
return;
}
mBluetoothA2dp.disableOptionalCodecs(activeDevice);
} }
} }
return; return;