Loading src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java +6 −3 Original line number Diff line number Diff line Loading @@ -308,7 +308,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll * Helper to get the list of connectable and special profiles. */ private List<LocalBluetoothProfile> getProfiles() { List<LocalBluetoothProfile> result = new ArrayList<LocalBluetoothProfile>(); List<LocalBluetoothProfile> result = new ArrayList<>(); mProfileDeviceMap.clear(); if (mAllOfCachedDevices == null || mAllOfCachedDevices.isEmpty()) { return result; Loading @@ -319,8 +319,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll if (mProfileDeviceMap.containsKey(profile.toString())) { mProfileDeviceMap.get(profile.toString()).add(cachedItem); } else { List<CachedBluetoothDevice> tmpCachedDeviceList = new ArrayList<CachedBluetoothDevice>(); List<CachedBluetoothDevice> tmpCachedDeviceList = new ArrayList<>(); tmpCachedDeviceList.add(cachedItem); mProfileDeviceMap.put(profile.toString(), tmpCachedDeviceList); result.add(profile); Loading Loading @@ -356,6 +355,10 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll } boolean hearingAidSupported = result.contains( mManager.getProfileManager().getHearingAidProfile()); // Remove hearing aids toggle anyway since showing the toggle will confuse users if (hearingAidSupported) { result.remove(mManager.getProfileManager().getHearingAidProfile()); } if (leAudioSupported && !classicAudioSupported && !hearingAidSupported) { mIsLeAudioOnlyDevice = true; } Loading tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsProfilesControllerTest.java +44 −6 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ import com.android.settings.testutils.shadow.ShadowBluetoothDevice; import com.android.settingslib.R; import com.android.settingslib.bluetooth.A2dpProfile; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.HearingAidProfile; import com.android.settingslib.bluetooth.LeAudioProfile; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfile; Loading Loading @@ -90,8 +91,12 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont @Mock private CachedBluetoothDeviceManager mCachedBluetoothDeviceManager; private @Mock A2dpProfile mA2dpProfile; private @Mock LeAudioProfile mLeAudioProfile; @Mock private A2dpProfile mA2dpProfile; @Mock private LeAudioProfile mLeAudioProfile; @Mock private HearingAidProfile mHearingAidProfile; @Override public void setUp() { Loading Loading @@ -399,18 +404,23 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont when(mProfileManager.getProfileByName(eq(mA2dpProfile.toString()))) .thenReturn(mA2dpProfile); when(mA2dpProfile.getNameResource(any())) .thenReturn(com.android.settingslib.R.string.bluetooth_profile_a2dp); .thenReturn(R.string.bluetooth_profile_a2dp); when(mA2dpProfile.getHighQualityAudioOptionLabel(any())).thenReturn( mContext.getString(com.android.settingslib.R .string.bluetooth_profile_a2dp_high_quality_unknown_codec)); mContext.getString(R.string.bluetooth_profile_a2dp_high_quality_unknown_codec)); when(mA2dpProfile.isProfileReady()).thenReturn(true); when(mProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile); when(mLeAudioProfile.toString()).thenReturn("LE_AUDIO"); when(mLeAudioProfile.getNameResource(any())) .thenReturn(com.android.settingslib.R.string.bluetooth_profile_le_audio); .thenReturn(R.string.bluetooth_profile_le_audio); when(mLeAudioProfile.isProfileReady()).thenReturn(true); when(mProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile); when(mHearingAidProfile.toString()).thenReturn("HearingAid"); when(mHearingAidProfile.getNameResource(any())) .thenReturn(R.string.bluetooth_profile_hearing_aid); when(mHearingAidProfile.isProfileReady()).thenReturn(true); when(mProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile); } private void addA2dpProfileToDevice(boolean preferred, boolean supportsHighQualityAudio, Loading @@ -426,6 +436,11 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont mConnectableProfiles.add(mLeAudioProfile); } private void addHearingAidProfileToDevice(boolean enabled) { when(mHearingAidProfile.isEnabled(any())).thenReturn(enabled); mConnectableProfiles.add(mHearingAidProfile); } private SwitchPreferenceCompat getHighQualityAudioPref() { return (SwitchPreferenceCompat) mScreen.findPreference( BluetoothDetailsProfilesController.HIGH_QUALITY_AUDIO_PREF_TAG); Loading Loading @@ -591,4 +606,27 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont List<SwitchPreferenceCompat> switches = getProfileSwitches(false); assertThat(switches.get(0).isVisible()).isFalse(); } @Test public void ashaHearingAid_hideAshaToggle() { setupDevice(makeDefaultDeviceConfig()); addHearingAidProfileToDevice(true); showScreen(mController); List<SwitchPreferenceCompat> switches = getProfileSwitches(false); assertThat(switches.isEmpty()).isTrue(); } @Test public void ashaHearingAidWithLeAudio_showLeAudioToggle() { setupDevice(makeDefaultDeviceConfig()); addHearingAidProfileToDevice(false); addLeAudioProfileToDevice(true); showScreen(mController); List<SwitchPreferenceCompat> switches = getProfileSwitches(false); assertThat(switches.getFirst().getTitle()).isEqualTo( mContext.getString(mLeAudioProfile.getNameResource(mDevice))); } } Loading
src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java +6 −3 Original line number Diff line number Diff line Loading @@ -308,7 +308,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll * Helper to get the list of connectable and special profiles. */ private List<LocalBluetoothProfile> getProfiles() { List<LocalBluetoothProfile> result = new ArrayList<LocalBluetoothProfile>(); List<LocalBluetoothProfile> result = new ArrayList<>(); mProfileDeviceMap.clear(); if (mAllOfCachedDevices == null || mAllOfCachedDevices.isEmpty()) { return result; Loading @@ -319,8 +319,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll if (mProfileDeviceMap.containsKey(profile.toString())) { mProfileDeviceMap.get(profile.toString()).add(cachedItem); } else { List<CachedBluetoothDevice> tmpCachedDeviceList = new ArrayList<CachedBluetoothDevice>(); List<CachedBluetoothDevice> tmpCachedDeviceList = new ArrayList<>(); tmpCachedDeviceList.add(cachedItem); mProfileDeviceMap.put(profile.toString(), tmpCachedDeviceList); result.add(profile); Loading Loading @@ -356,6 +355,10 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll } boolean hearingAidSupported = result.contains( mManager.getProfileManager().getHearingAidProfile()); // Remove hearing aids toggle anyway since showing the toggle will confuse users if (hearingAidSupported) { result.remove(mManager.getProfileManager().getHearingAidProfile()); } if (leAudioSupported && !classicAudioSupported && !hearingAidSupported) { mIsLeAudioOnlyDevice = true; } Loading
tests/robotests/src/com/android/settings/bluetooth/BluetoothDetailsProfilesControllerTest.java +44 −6 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ import com.android.settings.testutils.shadow.ShadowBluetoothDevice; import com.android.settingslib.R; import com.android.settingslib.bluetooth.A2dpProfile; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.HearingAidProfile; import com.android.settingslib.bluetooth.LeAudioProfile; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfile; Loading Loading @@ -90,8 +91,12 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont @Mock private CachedBluetoothDeviceManager mCachedBluetoothDeviceManager; private @Mock A2dpProfile mA2dpProfile; private @Mock LeAudioProfile mLeAudioProfile; @Mock private A2dpProfile mA2dpProfile; @Mock private LeAudioProfile mLeAudioProfile; @Mock private HearingAidProfile mHearingAidProfile; @Override public void setUp() { Loading Loading @@ -399,18 +404,23 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont when(mProfileManager.getProfileByName(eq(mA2dpProfile.toString()))) .thenReturn(mA2dpProfile); when(mA2dpProfile.getNameResource(any())) .thenReturn(com.android.settingslib.R.string.bluetooth_profile_a2dp); .thenReturn(R.string.bluetooth_profile_a2dp); when(mA2dpProfile.getHighQualityAudioOptionLabel(any())).thenReturn( mContext.getString(com.android.settingslib.R .string.bluetooth_profile_a2dp_high_quality_unknown_codec)); mContext.getString(R.string.bluetooth_profile_a2dp_high_quality_unknown_codec)); when(mA2dpProfile.isProfileReady()).thenReturn(true); when(mProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile); when(mLeAudioProfile.toString()).thenReturn("LE_AUDIO"); when(mLeAudioProfile.getNameResource(any())) .thenReturn(com.android.settingslib.R.string.bluetooth_profile_le_audio); .thenReturn(R.string.bluetooth_profile_le_audio); when(mLeAudioProfile.isProfileReady()).thenReturn(true); when(mProfileManager.getLeAudioProfile()).thenReturn(mLeAudioProfile); when(mHearingAidProfile.toString()).thenReturn("HearingAid"); when(mHearingAidProfile.getNameResource(any())) .thenReturn(R.string.bluetooth_profile_hearing_aid); when(mHearingAidProfile.isProfileReady()).thenReturn(true); when(mProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile); } private void addA2dpProfileToDevice(boolean preferred, boolean supportsHighQualityAudio, Loading @@ -426,6 +436,11 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont mConnectableProfiles.add(mLeAudioProfile); } private void addHearingAidProfileToDevice(boolean enabled) { when(mHearingAidProfile.isEnabled(any())).thenReturn(enabled); mConnectableProfiles.add(mHearingAidProfile); } private SwitchPreferenceCompat getHighQualityAudioPref() { return (SwitchPreferenceCompat) mScreen.findPreference( BluetoothDetailsProfilesController.HIGH_QUALITY_AUDIO_PREF_TAG); Loading Loading @@ -591,4 +606,27 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont List<SwitchPreferenceCompat> switches = getProfileSwitches(false); assertThat(switches.get(0).isVisible()).isFalse(); } @Test public void ashaHearingAid_hideAshaToggle() { setupDevice(makeDefaultDeviceConfig()); addHearingAidProfileToDevice(true); showScreen(mController); List<SwitchPreferenceCompat> switches = getProfileSwitches(false); assertThat(switches.isEmpty()).isTrue(); } @Test public void ashaHearingAidWithLeAudio_showLeAudioToggle() { setupDevice(makeDefaultDeviceConfig()); addHearingAidProfileToDevice(false); addLeAudioProfileToDevice(true); showScreen(mController); List<SwitchPreferenceCompat> switches = getProfileSwitches(false); assertThat(switches.getFirst().getTitle()).isEqualTo( mContext.getString(mLeAudioProfile.getNameResource(mDevice))); } }