Loading src/com/android/settings/bluetooth/BluetoothDetailsAudioDeviceTypeController.java +25 −6 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import static android.media.AudioManager.AUDIO_DEVICE_CATEGORY_HEARING_AID; import static android.media.AudioManager.AUDIO_DEVICE_CATEGORY_OTHER; import static android.media.AudioManager.AUDIO_DEVICE_CATEGORY_SPEAKER; import static android.media.AudioManager.AUDIO_DEVICE_CATEGORY_UNKNOWN; import static android.media.audio.Flags.automaticBtDeviceType; import android.content.Context; import android.media.AudioManager; Loading Loading @@ -106,9 +107,15 @@ public class BluetoothDetailsAudioDeviceTypeController extends BluetoothDetailsC final int index = pref.findIndexOfValue(value); if (index >= 0) { pref.setSummary(pref.getEntries()[index]); mAudioManager.setBluetoothAudioDeviceCategory(mCachedDevice.getAddress(), if (automaticBtDeviceType()) { mAudioManager.setBluetoothAudioDeviceCategory( mCachedDevice.getAddress(), Integer.parseInt(value)); } else { mAudioManager.setBluetoothAudioDeviceCategory_legacy( mCachedDevice.getAddress(), mCachedDevice.getDevice().getType() == DEVICE_TYPE_LE, Integer.parseInt(value)); } mCachedDevice.onAudioDeviceCategoryChanged(); } } Loading Loading @@ -163,9 +170,15 @@ public class BluetoothDetailsAudioDeviceTypeController extends BluetoothDetailsC Integer.toString(AUDIO_DEVICE_CATEGORY_OTHER), }); @AudioDeviceCategory final int deviceCategory = mAudioManager.getBluetoothAudioDeviceCategory(mCachedDevice.getAddress(), @AudioDeviceCategory int deviceCategory; if (automaticBtDeviceType()) { deviceCategory = mAudioManager.getBluetoothAudioDeviceCategory( mCachedDevice.getAddress()); } else { deviceCategory = mAudioManager.getBluetoothAudioDeviceCategory_legacy( mCachedDevice.getAddress(), mCachedDevice.getDevice().getType() == DEVICE_TYPE_LE); } if (DEBUG) { Log.v(TAG, "getBluetoothAudioDeviceCategory() device: " + mCachedDevice.getDevice().getAnonymizedAddress() Loading @@ -173,6 +186,12 @@ public class BluetoothDetailsAudioDeviceTypeController extends BluetoothDetailsC } mAudioDeviceTypePreference.setValue(Integer.toString(deviceCategory)); if (automaticBtDeviceType()) { if (mAudioManager.isBluetoothAudioDeviceCategoryFixed(mCachedDevice.getAddress())) { mAudioDeviceTypePreference.setEnabled(false); } } mAudioDeviceTypePreference.setSummary(mAudioDeviceTypePreference.getEntry()); mAudioDeviceTypePreference.setOnPreferenceChangeListener(this); } Loading tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsAudioDeviceTypeControllerTest.java +14 −4 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.settings.bluetooth; import static android.bluetooth.BluetoothDevice.DEVICE_TYPE_LE; import static android.media.AudioManager.AUDIO_DEVICE_CATEGORY_SPEAKER; import static android.media.audio.Flags.automaticBtDeviceType; import static com.google.common.truth.Truth.assertThat; Loading Loading @@ -97,8 +98,12 @@ public class BluetoothDetailsAudioDeviceTypeControllerTest extends @Test public void createAudioDeviceTypePreference_btDeviceIsCategorized_checkSelection() { int deviceType = AUDIO_DEVICE_CATEGORY_SPEAKER; when(mAudioManager.getBluetoothAudioDeviceCategory(MAC_ADDRESS, /*isBle=*/true)).thenReturn( deviceType); if (automaticBtDeviceType()) { when(mAudioManager.getBluetoothAudioDeviceCategory(MAC_ADDRESS)).thenReturn(deviceType); } else { when(mAudioManager.getBluetoothAudioDeviceCategory_legacy(MAC_ADDRESS, /*isBle=*/ true)).thenReturn(deviceType); } mController.createAudioDeviceTypePreference(mContext); mAudioDeviceTypePref = mController.getAudioDeviceTypePreference(); Loading @@ -113,7 +118,12 @@ public class BluetoothDetailsAudioDeviceTypeControllerTest extends mController.onPreferenceChange(mAudioDeviceTypePref, Integer.toString(deviceType)); verify(mAudioManager).setBluetoothAudioDeviceCategory(eq(MAC_ADDRESS), eq(true), if (automaticBtDeviceType()) { verify(mAudioManager).setBluetoothAudioDeviceCategory(eq(MAC_ADDRESS), eq(AUDIO_DEVICE_CATEGORY_SPEAKER)); } else { verify(mAudioManager).setBluetoothAudioDeviceCategory_legacy(eq(MAC_ADDRESS), eq(true), eq(AUDIO_DEVICE_CATEGORY_SPEAKER)); } } } Loading
src/com/android/settings/bluetooth/BluetoothDetailsAudioDeviceTypeController.java +25 −6 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import static android.media.AudioManager.AUDIO_DEVICE_CATEGORY_HEARING_AID; import static android.media.AudioManager.AUDIO_DEVICE_CATEGORY_OTHER; import static android.media.AudioManager.AUDIO_DEVICE_CATEGORY_SPEAKER; import static android.media.AudioManager.AUDIO_DEVICE_CATEGORY_UNKNOWN; import static android.media.audio.Flags.automaticBtDeviceType; import android.content.Context; import android.media.AudioManager; Loading Loading @@ -106,9 +107,15 @@ public class BluetoothDetailsAudioDeviceTypeController extends BluetoothDetailsC final int index = pref.findIndexOfValue(value); if (index >= 0) { pref.setSummary(pref.getEntries()[index]); mAudioManager.setBluetoothAudioDeviceCategory(mCachedDevice.getAddress(), if (automaticBtDeviceType()) { mAudioManager.setBluetoothAudioDeviceCategory( mCachedDevice.getAddress(), Integer.parseInt(value)); } else { mAudioManager.setBluetoothAudioDeviceCategory_legacy( mCachedDevice.getAddress(), mCachedDevice.getDevice().getType() == DEVICE_TYPE_LE, Integer.parseInt(value)); } mCachedDevice.onAudioDeviceCategoryChanged(); } } Loading Loading @@ -163,9 +170,15 @@ public class BluetoothDetailsAudioDeviceTypeController extends BluetoothDetailsC Integer.toString(AUDIO_DEVICE_CATEGORY_OTHER), }); @AudioDeviceCategory final int deviceCategory = mAudioManager.getBluetoothAudioDeviceCategory(mCachedDevice.getAddress(), @AudioDeviceCategory int deviceCategory; if (automaticBtDeviceType()) { deviceCategory = mAudioManager.getBluetoothAudioDeviceCategory( mCachedDevice.getAddress()); } else { deviceCategory = mAudioManager.getBluetoothAudioDeviceCategory_legacy( mCachedDevice.getAddress(), mCachedDevice.getDevice().getType() == DEVICE_TYPE_LE); } if (DEBUG) { Log.v(TAG, "getBluetoothAudioDeviceCategory() device: " + mCachedDevice.getDevice().getAnonymizedAddress() Loading @@ -173,6 +186,12 @@ public class BluetoothDetailsAudioDeviceTypeController extends BluetoothDetailsC } mAudioDeviceTypePreference.setValue(Integer.toString(deviceCategory)); if (automaticBtDeviceType()) { if (mAudioManager.isBluetoothAudioDeviceCategoryFixed(mCachedDevice.getAddress())) { mAudioDeviceTypePreference.setEnabled(false); } } mAudioDeviceTypePreference.setSummary(mAudioDeviceTypePreference.getEntry()); mAudioDeviceTypePreference.setOnPreferenceChangeListener(this); } Loading
tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsAudioDeviceTypeControllerTest.java +14 −4 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.settings.bluetooth; import static android.bluetooth.BluetoothDevice.DEVICE_TYPE_LE; import static android.media.AudioManager.AUDIO_DEVICE_CATEGORY_SPEAKER; import static android.media.audio.Flags.automaticBtDeviceType; import static com.google.common.truth.Truth.assertThat; Loading Loading @@ -97,8 +98,12 @@ public class BluetoothDetailsAudioDeviceTypeControllerTest extends @Test public void createAudioDeviceTypePreference_btDeviceIsCategorized_checkSelection() { int deviceType = AUDIO_DEVICE_CATEGORY_SPEAKER; when(mAudioManager.getBluetoothAudioDeviceCategory(MAC_ADDRESS, /*isBle=*/true)).thenReturn( deviceType); if (automaticBtDeviceType()) { when(mAudioManager.getBluetoothAudioDeviceCategory(MAC_ADDRESS)).thenReturn(deviceType); } else { when(mAudioManager.getBluetoothAudioDeviceCategory_legacy(MAC_ADDRESS, /*isBle=*/ true)).thenReturn(deviceType); } mController.createAudioDeviceTypePreference(mContext); mAudioDeviceTypePref = mController.getAudioDeviceTypePreference(); Loading @@ -113,7 +118,12 @@ public class BluetoothDetailsAudioDeviceTypeControllerTest extends mController.onPreferenceChange(mAudioDeviceTypePref, Integer.toString(deviceType)); verify(mAudioManager).setBluetoothAudioDeviceCategory(eq(MAC_ADDRESS), eq(true), if (automaticBtDeviceType()) { verify(mAudioManager).setBluetoothAudioDeviceCategory(eq(MAC_ADDRESS), eq(AUDIO_DEVICE_CATEGORY_SPEAKER)); } else { verify(mAudioManager).setBluetoothAudioDeviceCategory_legacy(eq(MAC_ADDRESS), eq(true), eq(AUDIO_DEVICE_CATEGORY_SPEAKER)); } } }