OSDN Git Service

Update the A2DP Codec Config API
authorPavlin Radoslavov <pavlin@google.com>
Sat, 28 Jan 2017 01:19:56 +0000 (17:19 -0800)
committerPavlin Radoslavov <pavlin@google.com>
Tue, 31 Jan 2017 00:22:24 +0000 (16:22 -0800)
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

src/com/android/settings/DevelopmentSettings.java

index 9f8c140..db599c5 100644 (file)
@@ -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();
+            }
         }
     };