Add support for Multi-A2DP state machines per device
Update usage of A2dpService API calls that take BluetoothDevice as an additional argument. If the BluetoothDevice argument is null, the API applies to the device that is currently the Active A2DP device. Exempt-From-Owner-Approval: De-facto owner of the relevant changes is the Bluetooth team. Bug: 69269748 Test: Manual Change-Id: I7417b7b0741f706df475cb2b27fbe6525f744269
This commit is contained in:
@@ -18,6 +18,8 @@ package com.android.settings.development;
|
|||||||
|
|
||||||
import android.bluetooth.BluetoothA2dp;
|
import android.bluetooth.BluetoothA2dp;
|
||||||
import android.bluetooth.BluetoothCodecConfig;
|
import android.bluetooth.BluetoothCodecConfig;
|
||||||
|
import android.bluetooth.BluetoothCodecStatus;
|
||||||
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.support.v7.preference.ListPreference;
|
import android.support.v7.preference.ListPreference;
|
||||||
@@ -80,7 +82,7 @@ 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(codecConfig);
|
setCodecConfigPreference(null, codecConfig); // Use current active device
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 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
|
||||||
@@ -99,13 +101,13 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (getCodecConfig() == null || mPreference == null) {
|
if (getCodecConfig(null) == null || mPreference == null) { // Use current active device
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BluetoothCodecConfig codecConfig;
|
BluetoothCodecConfig codecConfig;
|
||||||
synchronized (mBluetoothA2dpConfigStore) {
|
synchronized (mBluetoothA2dpConfigStore) {
|
||||||
codecConfig = getCodecConfig();
|
codecConfig = getCodecConfig(null); // Use current active device
|
||||||
}
|
}
|
||||||
|
|
||||||
final int index = getCurrentA2dpSettingIndex(codecConfig);
|
final int index = getCurrentA2dpSettingIndex(codecConfig);
|
||||||
@@ -183,16 +185,19 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends
|
|||||||
protected abstract int getDefaultIndex();
|
protected abstract int getDefaultIndex();
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void setCodecConfigPreference(BluetoothCodecConfig config) {
|
void setCodecConfigPreference(BluetoothDevice device,
|
||||||
mBluetoothA2dp.setCodecConfigPreference(config);
|
BluetoothCodecConfig config) {
|
||||||
|
mBluetoothA2dp.setCodecConfigPreference(device, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
BluetoothCodecConfig getCodecConfig() {
|
BluetoothCodecConfig getCodecConfig(BluetoothDevice device) {
|
||||||
if (mBluetoothA2dp == null || mBluetoothA2dp.getCodecStatus() == null) {
|
if (mBluetoothA2dp != null) {
|
||||||
return null;
|
BluetoothCodecStatus codecStatus = mBluetoothA2dp.getCodecStatus(device);
|
||||||
|
if (codecStatus != null) {
|
||||||
|
return codecStatus.getCodecConfig();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
return mBluetoothA2dp.getCodecStatus().getCodecConfig();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -109,14 +109,14 @@ public class BluetoothAudioCodecPreferenceController extends
|
|||||||
case 6:
|
case 6:
|
||||||
synchronized (mBluetoothA2dpConfigStore) {
|
synchronized (mBluetoothA2dpConfigStore) {
|
||||||
if (mBluetoothA2dp != null) {
|
if (mBluetoothA2dp != null) {
|
||||||
mBluetoothA2dp.enableOptionalCodecs();
|
mBluetoothA2dp.enableOptionalCodecs(null); // Use current active device
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case 7:
|
case 7:
|
||||||
synchronized (mBluetoothA2dpConfigStore) {
|
synchronized (mBluetoothA2dpConfigStore) {
|
||||||
if (mBluetoothA2dp != null) {
|
if (mBluetoothA2dp != null) {
|
||||||
mBluetoothA2dp.disableOptionalCodecs();
|
mBluetoothA2dp.disableOptionalCodecs(null); // Use current active device
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@@ -74,8 +74,8 @@ public class AbstractBluetoothA2dpPreferenceControllerTest {
|
|||||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||||
mController = spy(new AbstractBluetoothA2dpPreferenceControllerImpl(mContext, mLifecycle,
|
mController = spy(new AbstractBluetoothA2dpPreferenceControllerImpl(mContext, mLifecycle,
|
||||||
mBluetoothA2dpConfigStore));
|
mBluetoothA2dpConfigStore));
|
||||||
doReturn(mBluetoothCodecConfig).when(mController).getCodecConfig();
|
doReturn(mBluetoothCodecConfig).when(mController).getCodecConfig(null);
|
||||||
doNothing().when(mController).setCodecConfigPreference(any());
|
doNothing().when(mController).setCodecConfigPreference(any(), any());
|
||||||
when(mBluetoothA2dpConfigStore.createCodecConfig()).thenReturn(mBluetoothCodecConfig);
|
when(mBluetoothA2dpConfigStore.createCodecConfig()).thenReturn(mBluetoothCodecConfig);
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
@@ -87,7 +87,7 @@ public class AbstractBluetoothA2dpPreferenceControllerTest {
|
|||||||
|
|
||||||
mController.onPreferenceChange(mPreference, "" /* new value */);
|
mController.onPreferenceChange(mPreference, "" /* new value */);
|
||||||
|
|
||||||
verify(mController).setCodecConfigPreference(any());
|
verify(mController).setCodecConfigPreference(any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -96,7 +96,7 @@ public class AbstractBluetoothA2dpPreferenceControllerTest {
|
|||||||
|
|
||||||
mController.onPreferenceChange(mPreference, "" /* new value */);
|
mController.onPreferenceChange(mPreference, "" /* new value */);
|
||||||
|
|
||||||
verify(mController, never()).setCodecConfigPreference(any());
|
verify(mController, never()).setCodecConfigPreference(any(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user