diff options
| author | 2018-01-03 19:38:39 -0800 | |
|---|---|---|
| committer | 2018-01-26 13:08:00 -0800 | |
| commit | 080a0e781cd588c7bce0d91383d1d3ec240a13e9 (patch) | |
| tree | d3562716080150356616cad7a1c03c663d3d94bd | |
| parent | 03d44ce815a2cfcf963ed8d38fe3de59fc0abd8f (diff) | |
Add support for Multi-A2DP state machines per device
* Update usage of A2dpService API calls that take BluetoothDevice
as an additional argument
* Update the description for BluetoothA2dp.connect()
Exempt-From-Owner-Approval: De-facto owner of the relevant changes is
the Bluetooth team.
Bug: 69269748
Test: Manual
Change-Id: I190ed48ef65bbc8b88b45f84ebd6ab3d21cf0b4e
Merged-In: I190ed48ef65bbc8b88b45f84ebd6ab3d21cf0b4e
(cherry picked from commit 502af2192c6d291174efa434a70101f302a5bd97)
5 files changed, 39 insertions, 32 deletions
diff --git a/core/java/android/bluetooth/BluetoothA2dp.java b/core/java/android/bluetooth/BluetoothA2dp.java index 35a21a4eaf9f..b255a43cbe30 100644 --- a/core/java/android/bluetooth/BluetoothA2dp.java +++ b/core/java/android/bluetooth/BluetoothA2dp.java @@ -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"); diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/A2dpProfile.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/A2dpProfile.java index 0ff70a3dc9f7..853cbbadbdac 100755 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/A2dpProfile.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/A2dpProfile.java @@ -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) -> { diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothA2dpWrapper.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothA2dpWrapper.java index aa3e8356739a..dace1bbd5381 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothA2dpWrapper.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothA2dpWrapper.java @@ -39,7 +39,7 @@ public interface BluetoothA2dpWrapper { /** * Wraps {@code BluetoothA2dp.getCodecStatus} */ - public BluetoothCodecStatus getCodecStatus(); + public BluetoothCodecStatus getCodecStatus(BluetoothDevice device); /** * Wraps {@code BluetoothA2dp.supportsOptionalCodecs} diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothA2dpWrapperImpl.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothA2dpWrapperImpl.java index 14fa7966eab1..c49bb98d3878 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothA2dpWrapperImpl.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothA2dpWrapperImpl.java @@ -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 diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/A2dpProfileTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/A2dpProfileTest.java index 4a73c1bb61aa..876180749ca6 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/A2dpProfileTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/A2dpProfileTest.java @@ -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); |