Revert "Revert "Pass in active device to all BluetoothA2dp APIs ..." am: 39b5b839bd am: 18ae74f65a

Change-Id: Ib894524ce72a10cd635d3e86f091d90e920d0952
diff --git a/PMC/src/com/android/pmc/A2dpReceiver.java b/PMC/src/com/android/pmc/A2dpReceiver.java
index 843f7ae..162d864 100644
--- a/PMC/src/com/android/pmc/A2dpReceiver.java
+++ b/PMC/src/com/android/pmc/A2dpReceiver.java
@@ -403,7 +403,12 @@
         BluetoothCodecConfig[] codecsSelectableCapabilities = null;
 
         if (mBluetoothA2dp != null) {
-            codecStatus = mBluetoothA2dp.getCodecStatus(null);  // Use current active device
+            BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
+            if (activeDevice == null) {
+                Log.e(TAG, "getCodecValue: Active device is null");
+                return null;
+            }
+            codecStatus = mBluetoothA2dp.getCodecStatus(activeDevice);
             if (codecStatus != null) {
                 codecConfig = codecStatus.getCodecConfig();
                 codecsLocalCapabilities = codecStatus.getCodecsLocalCapabilities();
@@ -465,8 +470,13 @@
         }
 
         if (mBluetoothA2dp != null) {
+            BluetoothDevice activeDevice = mBluetoothA2dp.getActiveDevice();
+            if (activeDevice == null) {
+                Log.e(TAG, "setCodecValue: Active device is null. Codec is not set.");
+                return false;
+            }
             Log.d(TAG, "setCodecConfigPreference()");
-            mBluetoothA2dp.setCodecConfigPreference(null, codecConfig); // Use current active device
+            mBluetoothA2dp.setCodecConfigPreference(mBluetoothA2dp.getActiveDevice(), codecConfig);
         } else {
             Log.e(TAG, "mBluetoothA2dp is null. Codec is not set");
             return false;