diff --git a/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceController.java b/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceController.java index e4e64938866..171dd6a0b20 100644 --- a/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceController.java +++ b/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceController.java @@ -18,6 +18,8 @@ package com.android.settings.development; import android.bluetooth.BluetoothA2dp; import android.bluetooth.BluetoothCodecConfig; +import android.bluetooth.BluetoothCodecStatus; +import android.bluetooth.BluetoothDevice; import android.content.Context; import android.support.annotation.VisibleForTesting; import android.support.v7.preference.ListPreference; @@ -80,7 +82,7 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends final BluetoothCodecConfig codecConfig = mBluetoothA2dpConfigStore.createCodecConfig(); synchronized (mBluetoothA2dpConfigStore) { if (mBluetoothA2dp != null) { - setCodecConfigPreference(codecConfig); + setCodecConfigPreference(null, codecConfig); // Use current active device } } // Because the setting is not persisted into permanent storage, we cannot call update state @@ -99,13 +101,13 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends @Override public void updateState(Preference preference) { - if (getCodecConfig() == null || mPreference == null) { + if (getCodecConfig(null) == null || mPreference == null) { // Use current active device return; } BluetoothCodecConfig codecConfig; synchronized (mBluetoothA2dpConfigStore) { - codecConfig = getCodecConfig(); + codecConfig = getCodecConfig(null); // Use current active device } final int index = getCurrentA2dpSettingIndex(codecConfig); @@ -183,16 +185,19 @@ public abstract class AbstractBluetoothA2dpPreferenceController extends protected abstract int getDefaultIndex(); @VisibleForTesting - void setCodecConfigPreference(BluetoothCodecConfig config) { - mBluetoothA2dp.setCodecConfigPreference(config); + void setCodecConfigPreference(BluetoothDevice device, + BluetoothCodecConfig config) { + mBluetoothA2dp.setCodecConfigPreference(device, config); } @VisibleForTesting - BluetoothCodecConfig getCodecConfig() { - if (mBluetoothA2dp == null || mBluetoothA2dp.getCodecStatus() == null) { - return null; + BluetoothCodecConfig getCodecConfig(BluetoothDevice device) { + if (mBluetoothA2dp != null) { + BluetoothCodecStatus codecStatus = mBluetoothA2dp.getCodecStatus(device); + if (codecStatus != null) { + return codecStatus.getCodecConfig(); + } } - - return mBluetoothA2dp.getCodecStatus().getCodecConfig(); + return null; } } diff --git a/src/com/android/settings/development/BluetoothAudioCodecPreferenceController.java b/src/com/android/settings/development/BluetoothAudioCodecPreferenceController.java index 2163a7092c6..b5c40a37193 100644 --- a/src/com/android/settings/development/BluetoothAudioCodecPreferenceController.java +++ b/src/com/android/settings/development/BluetoothAudioCodecPreferenceController.java @@ -109,14 +109,14 @@ public class BluetoothAudioCodecPreferenceController extends case 6: synchronized (mBluetoothA2dpConfigStore) { if (mBluetoothA2dp != null) { - mBluetoothA2dp.enableOptionalCodecs(); + mBluetoothA2dp.enableOptionalCodecs(null); // Use current active device } } return; case 7: synchronized (mBluetoothA2dpConfigStore) { if (mBluetoothA2dp != null) { - mBluetoothA2dp.disableOptionalCodecs(); + mBluetoothA2dp.disableOptionalCodecs(null); // Use current active device } } return; diff --git a/tests/robotests/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceControllerTest.java index a7ae938f694..15df91686eb 100644 --- a/tests/robotests/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/AbstractBluetoothA2dpPreferenceControllerTest.java @@ -74,8 +74,8 @@ public class AbstractBluetoothA2dpPreferenceControllerTest { mLifecycle = new Lifecycle(mLifecycleOwner); mController = spy(new AbstractBluetoothA2dpPreferenceControllerImpl(mContext, mLifecycle, mBluetoothA2dpConfigStore)); - doReturn(mBluetoothCodecConfig).when(mController).getCodecConfig(); - doNothing().when(mController).setCodecConfigPreference(any()); + doReturn(mBluetoothCodecConfig).when(mController).getCodecConfig(null); + doNothing().when(mController).setCodecConfigPreference(any(), any()); when(mBluetoothA2dpConfigStore.createCodecConfig()).thenReturn(mBluetoothCodecConfig); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); mController.displayPreference(mScreen); @@ -87,7 +87,7 @@ public class AbstractBluetoothA2dpPreferenceControllerTest { mController.onPreferenceChange(mPreference, "" /* new value */); - verify(mController).setCodecConfigPreference(any()); + verify(mController).setCodecConfigPreference(any(), any()); } @Test @@ -96,7 +96,7 @@ public class AbstractBluetoothA2dpPreferenceControllerTest { mController.onPreferenceChange(mPreference, "" /* new value */); - verify(mController, never()).setCodecConfigPreference(any()); + verify(mController, never()).setCodecConfigPreference(any(), any()); } @Test