From 011597b5a933e8291d0bca9c3f3b17b9e816d654 Mon Sep 17 00:00:00 2001 From: Pavlin Radoslavov Date: Fri, 24 Feb 2017 10:19:14 -0800 Subject: [PATCH] Add new internal API: enableOptionalCodecs()/disableOptionalCodecs() This API can be used to enable the optional codecs, or disable them and use only the mandatory SBC. Internally, it is implemented by raising the SBC priority to highest (so SBC will be used/selected), or reducing the SBC priority to its default value (lowest). Test: A2DP streaming and enabling/disabling/selecting optional codecs Bug: 35873828 Change-Id: Ia82036ac33590a3a402b1f5a36102264d47a9029 (cherry picked from commit 61075105ca95a2389c23733bf72b5d49b0da4b28) --- .../java/android/bluetooth/BluetoothA2dp.java | 45 +++++++++++++++++++ .../bluetooth/BluetoothCodecConfig.java | 22 ++++++++- .../android/bluetooth/IBluetoothA2dp.aidl | 2 + packages/SettingsLib/res/values/arrays.xml | 6 +++ 4 files changed, 74 insertions(+), 1 deletion(-) diff --git a/core/java/android/bluetooth/BluetoothA2dp.java b/core/java/android/bluetooth/BluetoothA2dp.java index 6e31d807a0448..1ca2be5b2a1f9 100644 --- a/core/java/android/bluetooth/BluetoothA2dp.java +++ b/core/java/android/bluetooth/BluetoothA2dp.java @@ -611,6 +611,51 @@ public final class BluetoothA2dp implements BluetoothProfile { } } + /** + * Enables the optional codecs. + * + * @hide + */ + public void enableOptionalCodecs() { + if (DBG) Log.d(TAG, "enableOptionalCodecs"); + enableDisableOptionalCodecs(true); + } + + /** + * Disables the optional codecs. + * + * @hide + */ + public void disableOptionalCodecs() { + if (DBG) Log.d(TAG, "disableOptionalCodecs"); + enableDisableOptionalCodecs(false); + } + + /** + * Enables or disables the optional codecs. + * + * @param enable if true, enable the optional codecs, other disable them + */ + private void enableDisableOptionalCodecs(boolean enable) { + try { + mServiceLock.readLock().lock(); + if (mService != null && isEnabled()) { + if (enable) { + mService.enableOptionalCodecs(); + } else { + mService.disableOptionalCodecs(); + } + } + if (mService == null) Log.w(TAG, "Proxy not attached to service"); + return; + } catch (RemoteException e) { + Log.e(TAG, "Error talking to BT service in enableDisableOptionalCodecs()", e); + return; + } finally { + mServiceLock.readLock().unlock(); + } + } + /** * Helper for converting a state to a string. * diff --git a/core/java/android/bluetooth/BluetoothCodecConfig.java b/core/java/android/bluetooth/BluetoothCodecConfig.java index 176e48fb6e082..d5e1429810135 100644 --- a/core/java/android/bluetooth/BluetoothCodecConfig.java +++ b/core/java/android/bluetooth/BluetoothCodecConfig.java @@ -63,7 +63,7 @@ public final class BluetoothCodecConfig implements Parcelable { public static final int CHANNEL_MODE_STEREO = 0x1 << 1; private final int mCodecType; - private final int mCodecPriority; + private int mCodecPriority; private final int mSampleRate; private final int mBitsPerSample; private final int mChannelMode; @@ -279,6 +279,15 @@ public final class BluetoothCodecConfig implements Parcelable { return mCodecType; } + /** + * Checks whether the codec is mandatory. + * + * @return true if the codec is mandatory, otherwise false. + */ + public boolean isMandatoryCodec() { + return mCodecType == SOURCE_CODEC_TYPE_SBC; + } + /** * Gets the codec selection priority. * The codec selection priority is relative to other codecs: larger value @@ -290,6 +299,17 @@ public final class BluetoothCodecConfig implements Parcelable { return mCodecPriority; } + /** + * Sets the codec selection priority. + * The codec selection priority is relative to other codecs: larger value + * means higher priority. If 0, reset to default. + * + * @param codecPriority the codec priority + */ + public void setCodecPriority(int codecPriority) { + mCodecPriority = codecPriority; + } + /** * Gets the codec sample rate. The value can be a bitmask with all * supported sample rates: diff --git a/core/java/android/bluetooth/IBluetoothA2dp.aidl b/core/java/android/bluetooth/IBluetoothA2dp.aidl index dbb5b7d7944b5..a775a1f90b8e6 100644 --- a/core/java/android/bluetooth/IBluetoothA2dp.aidl +++ b/core/java/android/bluetooth/IBluetoothA2dp.aidl @@ -40,4 +40,6 @@ interface IBluetoothA2dp { boolean isA2dpPlaying(in BluetoothDevice device); BluetoothCodecStatus getCodecStatus(); oneway void setCodecConfigPreference(in BluetoothCodecConfig codecConfig); + oneway void enableOptionalCodecs(); + oneway void disableOptionalCodecs(); } diff --git a/packages/SettingsLib/res/values/arrays.xml b/packages/SettingsLib/res/values/arrays.xml index 28f687718d15d..db3274ab478c0 100644 --- a/packages/SettingsLib/res/values/arrays.xml +++ b/packages/SettingsLib/res/values/arrays.xml @@ -124,6 +124,8 @@ aptX aptX HD LDAC + Enable Optional Codecs + Disable Optional Codecs @@ -134,6 +136,8 @@ 2 3 4 + 5 + 6 @@ -144,6 +148,8 @@ aptX aptX HD LDAC + Enable Optional Codecs + Disable Optional Codecs