From 2829ca322ac253f421f33053abbf6eb6d9367c7e Mon Sep 17 00:00:00 2001 From: Pavlin Radoslavov Date: Fri, 27 Jan 2017 17:19:56 -0800 Subject: [PATCH] Update the A2DP Codec Config API Previously, the JNI upcall would contain only the current codec config. In the new API, the upcall contains: 1. The current codec config 2. The list of codecs containing the local codecs capabilities 3. The list of codecs containing the selectable codecs capabilities. This list is the intersection of the local codecs capabilities and the capabilities of the paired device. Also, refactored the Java internals to accomodate the extra information: * Added new class BluetoothCodecStatus that contains the extra info: current codec config, local codecs capabilities and selectable codecs capabilities * Renamed method getCodecConfig() to getCodecStatus() and return the corresponding BluetoothCodecStatus object. * Updates to class BluetoothCodecConfig: new methods isValid(), getCodecName(), and updated toString() so it is more user friendly * Removed BluetoothCodecConfig.EXTRA_CODEC_CONFIG and EXTRA_PREVIOUS_CODEC_CONFIG. The former is superseded by BluetoothCodecStatus.EXTRA_CODEC_STATUS; the latter is not really used. Test: A2DP streaming with headsets and switching the codecs Change-Id: I490a70c82b686be7105862aeaeafcff495369dae --- .../android/settings/DevelopmentSettings.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java index 9f8c140210b..db599c5b981 100644 --- a/src/com/android/settings/DevelopmentSettings.java +++ b/src/com/android/settings/DevelopmentSettings.java @@ -28,6 +28,7 @@ import android.app.backup.IBackupManager; import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothCodecConfig; +import android.bluetooth.BluetoothCodecStatus; import android.bluetooth.BluetoothProfile; import android.content.BroadcastReceiver; import android.content.ComponentName; @@ -1819,12 +1820,18 @@ public class DevelopmentSettings extends RestrictedSettingsFragment private void updateBluetoothA2dpConfigurationValues() { int index; String[] summaries; + BluetoothCodecStatus codecStatus = null; BluetoothCodecConfig codecConfig = null; + BluetoothCodecConfig[] codecsLocalCapabilities = null; + BluetoothCodecConfig[] codecsSelectableCapabilities = null; String streaming; synchronized (mBluetoothA2dpLock) { if (mBluetoothA2dp != null) { - codecConfig = mBluetoothA2dp.getCodecConfig(); + codecStatus = mBluetoothA2dp.getCodecStatus(); + codecConfig = codecStatus.getCodecConfig(); + codecsLocalCapabilities = codecStatus.getCodecsLocalCapabilities(); + codecsSelectableCapabilities = codecStatus.getCodecsSelectableCapabilities(); } } if (codecConfig == null) @@ -2674,7 +2681,15 @@ public class DevelopmentSettings extends RestrictedSettingsFragment private BroadcastReceiver mBluetoothA2dpReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - updateBluetoothA2dpConfigurationValues(); + Log.d(TAG, "mBluetoothA2dpReceiver.onReceive intent=" + intent); + String action = intent.getAction(); + + if (BluetoothA2dp.ACTION_CODEC_CONFIG_CHANGED.equals(action)) { + BluetoothCodecStatus codecStatus = + (BluetoothCodecStatus)intent.getParcelableExtra(BluetoothCodecStatus.EXTRA_CODEC_STATUS); + Log.d(TAG, "Received BluetoothCodecStatus=" + codecStatus); + updateBluetoothA2dpConfigurationValues(); + } } };