diff options
2 files changed, 51 insertions, 10 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java index 0ffb76307b3c..616ab072ae20 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothUtils.java @@ -104,6 +104,22 @@ public class BluetoothUtils { /** * @param context to access resources from * @param cachedDevice to get class from + * @return pair containing the drawable and the description of the type of the device. The type + * could either derived from metadata or CoD. + */ + public static Pair<Drawable, String> getDerivedBtClassDrawableWithDescription( + Context context, CachedBluetoothDevice cachedDevice) { + return BluetoothUtils.isAdvancedUntetheredDevice(cachedDevice.getDevice()) + ? new Pair<>( + getBluetoothDrawable( + context, com.android.internal.R.drawable.ic_bt_headphones_a2dp), + context.getString(R.string.bluetooth_talkback_headphone)) + : BluetoothUtils.getBtClassDrawableWithDescription(context, cachedDevice); + } + + /** + * @param context to access resources from + * @param cachedDevice to get class from * @return pair containing the drawable and the description of the Bluetooth class of the * device. */ @@ -731,9 +747,7 @@ public class BluetoothUtils { int broadcastId = broadcast.getLatestBroadcastId(); return !sourceList.isEmpty() && broadcastId != UNKNOWN_VALUE_PLACEHOLDER - && sourceList.stream() - .anyMatch( - source -> isSourceMatched(source, broadcastId)); + && sourceList.stream().anyMatch(source -> isSourceMatched(source, broadcastId)); } /** Checks the connectivity status based on the provided broadcast receive state. */ @@ -1030,8 +1044,7 @@ public class BluetoothUtils { cachedDevice.getAddress()); break; case BluetoothProfile.LE_AUDIO: - if (audioDeviceCategory - == AudioManager.AUDIO_DEVICE_CATEGORY_SPEAKER) { + if (audioDeviceCategory == AudioManager.AUDIO_DEVICE_CATEGORY_SPEAKER) { saDevice = new AudioDeviceAttributes( AudioDeviceAttributes.ROLE_OUTPUT, diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java index a0e764ad3d5d..8eedb35a3181 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/bluetooth/BluetoothUtilsTest.java @@ -46,6 +46,7 @@ import android.platform.test.flag.junit.SetFlagsRule; import android.provider.Settings; import android.util.Pair; +import com.android.internal.R; import com.android.settingslib.widget.AdaptiveIcon; import com.google.common.collect.ImmutableList; @@ -118,6 +119,34 @@ public class BluetoothUtilsTest { } @Test + public void + getDerivedBtClassDrawableWithDescription_isAdvancedUntetheredDevice_returnHeadset() { + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) + .thenReturn(BOOL_METADATA.getBytes()); + when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); + Pair<Drawable, String> pair = + BluetoothUtils.getDerivedBtClassDrawableWithDescription( + mContext, mCachedBluetoothDevice); + + verify(mContext).getDrawable(R.drawable.ic_bt_headphones_a2dp); + } + + @Test + public void + getDerivedBtClassDrawableWithDescription_notAdvancedUntetheredDevice_returnPhone() { + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_IS_UNTETHERED_HEADSET)) + .thenReturn("false".getBytes()); + when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); + when(mCachedBluetoothDevice.getBtClass().getMajorDeviceClass()) + .thenReturn(BluetoothClass.Device.Major.PHONE); + Pair<Drawable, String> pair = + BluetoothUtils.getDerivedBtClassDrawableWithDescription( + mContext, mCachedBluetoothDevice); + + verify(mContext).getDrawable(R.drawable.ic_phone); + } + + @Test public void getBtClassDrawableWithDescription_typePhone_returnPhoneDrawable() { when(mCachedBluetoothDevice.getBtClass().getMajorDeviceClass()) .thenReturn(BluetoothClass.Device.Major.PHONE); @@ -681,8 +710,8 @@ public class BluetoothUtilsTest { when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(sourceList); assertThat( - BluetoothUtils.hasActiveLocalBroadcastSourceForBtDevice( - mBluetoothDevice, mLocalBluetoothManager)) + BluetoothUtils.hasActiveLocalBroadcastSourceForBtDevice( + mBluetoothDevice, mLocalBluetoothManager)) .isTrue(); } @@ -694,12 +723,11 @@ public class BluetoothUtilsTest { when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(sourceList); assertThat( - BluetoothUtils.hasActiveLocalBroadcastSourceForBtDevice( - mBluetoothDevice, mLocalBluetoothManager)) + BluetoothUtils.hasActiveLocalBroadcastSourceForBtDevice( + mBluetoothDevice, mLocalBluetoothManager)) .isFalse(); } - @Test public void isAvailableHearingDevice_isConnectedHearingAid_returnTure() { when(mCachedBluetoothDevice.isConnectedHearingAidDevice()).thenReturn(true); |