diff --git a/src/com/android/settings/accessibility/HearingAidHelper.java b/src/com/android/settings/accessibility/HearingAidHelper.java index 66a37f8dd58..1b9bdc47e54 100644 --- a/src/com/android/settings/accessibility/HearingAidHelper.java +++ b/src/com/android/settings/accessibility/HearingAidHelper.java @@ -56,7 +56,8 @@ public class HearingAidHelper { * @return a list of hearing aids {@link BluetoothDevice} objects */ public List getConnectedHearingAidDeviceList() { - if (!isHearingAidSupported()) { + if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled() + || !isHearingAidSupported()) { return new ArrayList<>(); } final List deviceList = new ArrayList<>(); @@ -88,9 +89,6 @@ public class HearingAidHelper { * supported. */ public boolean isHearingAidSupported() { - if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) { - return false; - } final List supportedList = mBluetoothAdapter.getSupportedProfiles(); return supportedList.contains(BluetoothProfile.HEARING_AID) || supportedList.contains(BluetoothProfile.HAP_CLIENT); diff --git a/tests/robotests/src/com/android/settings/accessibility/HearingAidHelperTest.java b/tests/robotests/src/com/android/settings/accessibility/HearingAidHelperTest.java index 194b766dd75..3889cf04e02 100644 --- a/tests/robotests/src/com/android/settings/accessibility/HearingAidHelperTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/HearingAidHelperTest.java @@ -95,8 +95,7 @@ public class HearingAidHelperTest { } @Test - public void isHearingAidSupported_supported_returnTrue() { - mBluetoothAdapter.enable(); + public void isHearingAidSupported_ashaSupported_returnTrue() { mShadowBluetoothAdapter.clearSupportedProfiles(); mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID); @@ -104,15 +103,20 @@ public class HearingAidHelperTest { } @Test - public void isHearingAidSupported_bluetoothOff_returnFalse() { + public void isHearingAidSupported_hapSupported_returnTrue() { + mShadowBluetoothAdapter.clearSupportedProfiles(); + mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HAP_CLIENT); + + assertThat(mHelper.isHearingAidSupported()).isTrue(); + } + + @Test + public void isHearingAidSupported_unsupported_returnFalse() { mShadowBluetoothAdapter.clearSupportedProfiles(); - mShadowBluetoothAdapter.addSupportedProfiles(BluetoothProfile.HEARING_AID); - mBluetoothAdapter.disable(); assertThat(mHelper.isHearingAidSupported()).isFalse(); } - @Test public void isAllHearingAidRelatedProfilesReady_allReady_returnTrue() { when(mHearingAidProfile.isProfileReady()).thenReturn(true);