Merge "Add support for Multi-A2DP state machines per device"
am: bb5318df8a
Change-Id: I9fabffc6d7fdb3cb001b685618532f10000dd4ac
This commit is contained in:
@@ -300,11 +300,7 @@ public final class BluetoothA2dp implements BluetoothProfile {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate connection to a profile of the remote bluetooth device.
|
||||
*
|
||||
* <p> Currently, the system supports only 1 connection to the
|
||||
* A2DP profile. The API will automatically disconnect connected
|
||||
* devices before connecting.
|
||||
* Initiate connection to a profile of the remote Bluetooth device.
|
||||
*
|
||||
* <p> This API returns false in scenarios like the profile on the
|
||||
* device is already connected or Bluetooth is not turned on.
|
||||
@@ -699,15 +695,17 @@ public final class BluetoothA2dp implements BluetoothProfile {
|
||||
/**
|
||||
* Gets the current codec status (configuration and capability).
|
||||
*
|
||||
* @param device the remote Bluetooth device. If null, use the current
|
||||
* active A2DP Bluetooth device.
|
||||
* @return the current codec status
|
||||
* @hide
|
||||
*/
|
||||
public BluetoothCodecStatus getCodecStatus() {
|
||||
if (DBG) Log.d(TAG, "getCodecStatus");
|
||||
public BluetoothCodecStatus getCodecStatus(BluetoothDevice device) {
|
||||
if (DBG) Log.d(TAG, "getCodecStatus(" + device + ")");
|
||||
try {
|
||||
mServiceLock.readLock().lock();
|
||||
if (mService != null && isEnabled()) {
|
||||
return mService.getCodecStatus();
|
||||
return mService.getCodecStatus(device);
|
||||
}
|
||||
if (mService == null) {
|
||||
Log.w(TAG, "Proxy not attached to service");
|
||||
@@ -724,15 +722,18 @@ public final class BluetoothA2dp implements BluetoothProfile {
|
||||
/**
|
||||
* Sets the codec configuration preference.
|
||||
*
|
||||
* @param device the remote Bluetooth device. If null, use the current
|
||||
* active A2DP Bluetooth device.
|
||||
* @param codecConfig the codec configuration preference
|
||||
* @hide
|
||||
*/
|
||||
public void setCodecConfigPreference(BluetoothCodecConfig codecConfig) {
|
||||
if (DBG) Log.d(TAG, "setCodecConfigPreference");
|
||||
public void setCodecConfigPreference(BluetoothDevice device,
|
||||
BluetoothCodecConfig codecConfig) {
|
||||
if (DBG) Log.d(TAG, "setCodecConfigPreference(" + device + ")");
|
||||
try {
|
||||
mServiceLock.readLock().lock();
|
||||
if (mService != null && isEnabled()) {
|
||||
mService.setCodecConfigPreference(codecConfig);
|
||||
mService.setCodecConfigPreference(device, codecConfig);
|
||||
}
|
||||
if (mService == null) Log.w(TAG, "Proxy not attached to service");
|
||||
return;
|
||||
@@ -747,36 +748,42 @@ public final class BluetoothA2dp implements BluetoothProfile {
|
||||
/**
|
||||
* Enables the optional codecs.
|
||||
*
|
||||
* @param device the remote Bluetooth device. If null, use the currect
|
||||
* active A2DP Bluetooth device.
|
||||
* @hide
|
||||
*/
|
||||
public void enableOptionalCodecs() {
|
||||
if (DBG) Log.d(TAG, "enableOptionalCodecs");
|
||||
enableDisableOptionalCodecs(true);
|
||||
public void enableOptionalCodecs(BluetoothDevice device) {
|
||||
if (DBG) Log.d(TAG, "enableOptionalCodecs(" + device + ")");
|
||||
enableDisableOptionalCodecs(device, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the optional codecs.
|
||||
*
|
||||
* @param device the remote Bluetooth device. If null, use the currect
|
||||
* active A2DP Bluetooth device.
|
||||
* @hide
|
||||
*/
|
||||
public void disableOptionalCodecs() {
|
||||
if (DBG) Log.d(TAG, "disableOptionalCodecs");
|
||||
enableDisableOptionalCodecs(false);
|
||||
public void disableOptionalCodecs(BluetoothDevice device) {
|
||||
if (DBG) Log.d(TAG, "disableOptionalCodecs(" + device + ")");
|
||||
enableDisableOptionalCodecs(device, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables the optional codecs.
|
||||
*
|
||||
* @param device the remote Bluetooth device. If null, use the currect
|
||||
* active A2DP Bluetooth device.
|
||||
* @param enable if true, enable the optional codecs, other disable them
|
||||
*/
|
||||
private void enableDisableOptionalCodecs(boolean enable) {
|
||||
private void enableDisableOptionalCodecs(BluetoothDevice device, boolean enable) {
|
||||
try {
|
||||
mServiceLock.readLock().lock();
|
||||
if (mService != null && isEnabled()) {
|
||||
if (enable) {
|
||||
mService.enableOptionalCodecs();
|
||||
mService.enableOptionalCodecs(device);
|
||||
} else {
|
||||
mService.disableOptionalCodecs();
|
||||
mService.disableOptionalCodecs(device);
|
||||
}
|
||||
}
|
||||
if (mService == null) Log.w(TAG, "Proxy not attached to service");
|
||||
|
||||
@@ -220,8 +220,8 @@ public class A2dpProfile implements LocalBluetoothProfile {
|
||||
return true;
|
||||
}
|
||||
BluetoothCodecConfig codecConfig = null;
|
||||
if (mServiceWrapper.getCodecStatus() != null) {
|
||||
codecConfig = mServiceWrapper.getCodecStatus().getCodecConfig();
|
||||
if (mServiceWrapper.getCodecStatus(device) != null) {
|
||||
codecConfig = mServiceWrapper.getCodecStatus(device).getCodecConfig();
|
||||
}
|
||||
if (codecConfig != null) {
|
||||
return !codecConfig.isMandatoryCodec();
|
||||
@@ -239,9 +239,9 @@ public class A2dpProfile implements LocalBluetoothProfile {
|
||||
return;
|
||||
}
|
||||
if (enabled) {
|
||||
mService.enableOptionalCodecs();
|
||||
mService.enableOptionalCodecs(device);
|
||||
} else {
|
||||
mService.disableOptionalCodecs();
|
||||
mService.disableOptionalCodecs(device);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,8 +254,8 @@ public class A2dpProfile implements LocalBluetoothProfile {
|
||||
// We want to get the highest priority codec, since that's the one that will be used with
|
||||
// this device, and see if it is high-quality (ie non-mandatory).
|
||||
BluetoothCodecConfig[] selectable = null;
|
||||
if (mServiceWrapper.getCodecStatus() != null) {
|
||||
selectable = mServiceWrapper.getCodecStatus().getCodecsSelectableCapabilities();
|
||||
if (mServiceWrapper.getCodecStatus(device) != null) {
|
||||
selectable = mServiceWrapper.getCodecStatus(device).getCodecsSelectableCapabilities();
|
||||
// To get the highest priority, we sort in reverse.
|
||||
Arrays.sort(selectable,
|
||||
(a, b) -> {
|
||||
|
||||
@@ -39,7 +39,7 @@ public interface BluetoothA2dpWrapper {
|
||||
/**
|
||||
* Wraps {@code BluetoothA2dp.getCodecStatus}
|
||||
*/
|
||||
public BluetoothCodecStatus getCodecStatus();
|
||||
public BluetoothCodecStatus getCodecStatus(BluetoothDevice device);
|
||||
|
||||
/**
|
||||
* Wraps {@code BluetoothA2dp.supportsOptionalCodecs}
|
||||
|
||||
@@ -41,8 +41,8 @@ public class BluetoothA2dpWrapperImpl implements BluetoothA2dpWrapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BluetoothCodecStatus getCodecStatus() {
|
||||
return mService.getCodecStatus();
|
||||
public BluetoothCodecStatus getCodecStatus(BluetoothDevice device) {
|
||||
return mService.getCodecStatus(device);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -122,7 +122,7 @@ public class A2dpProfileTest {
|
||||
when(mBluetoothA2dp.getConnectionState(any())).thenReturn(
|
||||
BluetoothProfile.STATE_CONNECTED);
|
||||
BluetoothCodecStatus status = mock(BluetoothCodecStatus.class);
|
||||
when(mBluetoothA2dpWrapper.getCodecStatus()).thenReturn(status);
|
||||
when(mBluetoothA2dpWrapper.getCodecStatus(mDevice)).thenReturn(status);
|
||||
BluetoothCodecConfig config = mock(BluetoothCodecConfig.class);
|
||||
when(status.getCodecConfig()).thenReturn(config);
|
||||
when(config.isMandatoryCodec()).thenReturn(false);
|
||||
@@ -185,7 +185,7 @@ public class A2dpProfileTest {
|
||||
BluetoothCodecStatus status = mock(BluetoothCodecStatus.class);
|
||||
BluetoothCodecConfig config = mock(BluetoothCodecConfig.class);
|
||||
BluetoothCodecConfig[] configs = {config};
|
||||
when(mBluetoothA2dpWrapper.getCodecStatus()).thenReturn(status);
|
||||
when(mBluetoothA2dpWrapper.getCodecStatus(mDevice)).thenReturn(status);
|
||||
when(status.getCodecsSelectableCapabilities()).thenReturn(configs);
|
||||
|
||||
when(config.isMandatoryCodec()).thenReturn(true);
|
||||
@@ -200,7 +200,7 @@ public class A2dpProfileTest {
|
||||
BluetoothCodecStatus status = mock(BluetoothCodecStatus.class);
|
||||
BluetoothCodecConfig config = mock(BluetoothCodecConfig.class);
|
||||
BluetoothCodecConfig[] configs = {config};
|
||||
when(mBluetoothA2dpWrapper.getCodecStatus()).thenReturn(status);
|
||||
when(mBluetoothA2dpWrapper.getCodecStatus(mDevice)).thenReturn(status);
|
||||
when(status.getCodecsSelectableCapabilities()).thenReturn(configs);
|
||||
|
||||
when(config.isMandatoryCodec()).thenReturn(false);
|
||||
|
||||
Reference in New Issue
Block a user