Loading core/java/android/bluetooth/BluetoothA2dp.java +27 −20 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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"); Loading @@ -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; Loading @@ -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"); Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/A2dpProfile.java +6 −6 Original line number Diff line number Diff line Loading @@ -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(); Loading @@ -239,9 +239,9 @@ public class A2dpProfile implements LocalBluetoothProfile { return; } if (enabled) { mService.enableOptionalCodecs(); mService.enableOptionalCodecs(device); } else { mService.disableOptionalCodecs(); mService.disableOptionalCodecs(device); } } Loading @@ -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) -> { Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothA2dpWrapper.java +1 −1 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ public interface BluetoothA2dpWrapper { /** * Wraps {@code BluetoothA2dp.getCodecStatus} */ public BluetoothCodecStatus getCodecStatus(); public BluetoothCodecStatus getCodecStatus(BluetoothDevice device); /** * Wraps {@code BluetoothA2dp.supportsOptionalCodecs} Loading packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothA2dpWrapperImpl.java +2 −2 Original line number Diff line number Diff line Loading @@ -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 Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/A2dpProfileTest.java +3 −3 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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); Loading @@ -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); Loading Loading
core/java/android/bluetooth/BluetoothA2dp.java +27 −20 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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"); Loading @@ -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; Loading @@ -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"); Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/A2dpProfile.java +6 −6 Original line number Diff line number Diff line Loading @@ -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(); Loading @@ -239,9 +239,9 @@ public class A2dpProfile implements LocalBluetoothProfile { return; } if (enabled) { mService.enableOptionalCodecs(); mService.enableOptionalCodecs(device); } else { mService.disableOptionalCodecs(); mService.disableOptionalCodecs(device); } } Loading @@ -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) -> { Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothA2dpWrapper.java +1 −1 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ public interface BluetoothA2dpWrapper { /** * Wraps {@code BluetoothA2dp.getCodecStatus} */ public BluetoothCodecStatus getCodecStatus(); public BluetoothCodecStatus getCodecStatus(BluetoothDevice device); /** * Wraps {@code BluetoothA2dp.supportsOptionalCodecs} Loading
packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothA2dpWrapperImpl.java +2 −2 Original line number Diff line number Diff line Loading @@ -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 Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/A2dpProfileTest.java +3 −3 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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); Loading @@ -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); Loading