Loading src/com/android/settings/accessibility/HearingAidUtils.java +12 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import androidx.fragment.app.FragmentManager; import com.android.settings.bluetooth.HearingAidPairingDialogFragment; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CsipSetCoordinatorProfile; import com.android.settingslib.bluetooth.HearingAidInfo; /** Provides utility methods related hearing aids. */ Loading @@ -40,6 +41,11 @@ public final class HearingAidUtils { */ public static void launchHearingAidPairingDialog(FragmentManager fragmentManager, @NonNull CachedBluetoothDevice device) { // No need to show the pair another ear dialog if the device supports and enables CSIP. // CSIP will pair other devices in the same set automatically. if (isCsipSupportedAndEnabled(device)) { return; } if (device.isConnectedAshaHearingAidDevice() && device.getDeviceMode() == HearingAidInfo.DeviceMode.MODE_BINAURAL && device.getSubDevice() == null) { Loading @@ -56,4 +62,10 @@ public final class HearingAidUtils { HearingAidPairingDialogFragment.newInstance(device.getAddress()).show(fragmentManager, HearingAidPairingDialogFragment.TAG); } private static boolean isCsipSupportedAndEnabled(@NonNull CachedBluetoothDevice device) { return device.getProfiles().stream().anyMatch( profile -> (profile instanceof CsipSetCoordinatorProfile) && (profile.isEnabled(device.getDevice()))); } } tests/robotests/src/com/android/settings/accessibility/HearingAidUtilsTest.java +50 −0 Original line number Diff line number Diff line Loading @@ -37,8 +37,10 @@ import com.android.settings.testutils.shadow.ShadowBluetoothUtils; import com.android.settings.utils.ActivityControllerWrapper; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.CsipSetCoordinatorProfile; import com.android.settingslib.bluetooth.HearingAidInfo; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfile; import org.junit.Before; import org.junit.Rule; Loading @@ -52,6 +54,9 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import org.robolectric.shadow.api.Shadow; import java.util.ArrayList; import java.util.List; /** Tests for {@link HearingAidUtils}. */ @RunWith(RobolectricTestRunner.class) @Config(shadows = {ShadowAlertDialogCompat.class, ShadowBluetoothAdapter.class, Loading @@ -72,6 +77,8 @@ public class HearingAidUtilsTest { private LocalBluetoothManager mLocalBluetoothManager; @Mock private CachedBluetoothDeviceManager mCachedDeviceManager; @Mock private CsipSetCoordinatorProfile mCsipSetCoordinatorProfile; private BluetoothDevice mBluetoothDevice; private BluetoothAdapter mBluetoothAdapter; private ShadowBluetoothAdapter mShadowBluetoothAdapter; Loading Loading @@ -136,6 +143,38 @@ public class HearingAidUtilsTest { assertThat(dialog).isNull(); } @Test public void launchHearingAidPairingDialog_deviceSupportsCsip_csipEnabled_noDialog() { when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true); when(mCachedBluetoothDevice.getDeviceMode()).thenReturn( HearingAidInfo.DeviceMode.MODE_BINAURAL); when(mCachedBluetoothDevice.getDeviceSide()).thenReturn( HearingAidInfo.DeviceSide.SIDE_LEFT); makeDeviceSupportCsip(); makeDeviceEnableCsip(true); HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice); final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog(); assertThat(dialog).isNull(); } @Test public void launchHearingAidPairingDialog_deviceSupportsCsip_csipDisabled_dialogShown() { when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true); when(mCachedBluetoothDevice.getDeviceMode()).thenReturn( HearingAidInfo.DeviceMode.MODE_BINAURAL); when(mCachedBluetoothDevice.getDeviceSide()).thenReturn( HearingAidInfo.DeviceSide.SIDE_LEFT); makeDeviceSupportCsip(); makeDeviceEnableCsip(false); HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice); final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog(); assertThat(dialog.isShowing()).isTrue(); } @Test public void launchHearingAidPairingDialog_dialogShown() { when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true); Loading @@ -150,6 +189,17 @@ public class HearingAidUtilsTest { assertThat(dialog.isShowing()).isTrue(); } private void makeDeviceSupportCsip() { List<LocalBluetoothProfile> uuids = new ArrayList<>(); uuids.add(mCsipSetCoordinatorProfile); when(mCachedBluetoothDevice.getProfiles()).thenReturn(uuids); } private void makeDeviceEnableCsip(boolean enabled) { when(mCsipSetCoordinatorProfile.isEnabled(mCachedBluetoothDevice.getDevice())) .thenReturn(enabled); } private void setupEnvironment() { ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager; mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); Loading Loading
src/com/android/settings/accessibility/HearingAidUtils.java +12 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import androidx.fragment.app.FragmentManager; import com.android.settings.bluetooth.HearingAidPairingDialogFragment; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CsipSetCoordinatorProfile; import com.android.settingslib.bluetooth.HearingAidInfo; /** Provides utility methods related hearing aids. */ Loading @@ -40,6 +41,11 @@ public final class HearingAidUtils { */ public static void launchHearingAidPairingDialog(FragmentManager fragmentManager, @NonNull CachedBluetoothDevice device) { // No need to show the pair another ear dialog if the device supports and enables CSIP. // CSIP will pair other devices in the same set automatically. if (isCsipSupportedAndEnabled(device)) { return; } if (device.isConnectedAshaHearingAidDevice() && device.getDeviceMode() == HearingAidInfo.DeviceMode.MODE_BINAURAL && device.getSubDevice() == null) { Loading @@ -56,4 +62,10 @@ public final class HearingAidUtils { HearingAidPairingDialogFragment.newInstance(device.getAddress()).show(fragmentManager, HearingAidPairingDialogFragment.TAG); } private static boolean isCsipSupportedAndEnabled(@NonNull CachedBluetoothDevice device) { return device.getProfiles().stream().anyMatch( profile -> (profile instanceof CsipSetCoordinatorProfile) && (profile.isEnabled(device.getDevice()))); } }
tests/robotests/src/com/android/settings/accessibility/HearingAidUtilsTest.java +50 −0 Original line number Diff line number Diff line Loading @@ -37,8 +37,10 @@ import com.android.settings.testutils.shadow.ShadowBluetoothUtils; import com.android.settings.utils.ActivityControllerWrapper; import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.CachedBluetoothDeviceManager; import com.android.settingslib.bluetooth.CsipSetCoordinatorProfile; import com.android.settingslib.bluetooth.HearingAidInfo; import com.android.settingslib.bluetooth.LocalBluetoothManager; import com.android.settingslib.bluetooth.LocalBluetoothProfile; import org.junit.Before; import org.junit.Rule; Loading @@ -52,6 +54,9 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import org.robolectric.shadow.api.Shadow; import java.util.ArrayList; import java.util.List; /** Tests for {@link HearingAidUtils}. */ @RunWith(RobolectricTestRunner.class) @Config(shadows = {ShadowAlertDialogCompat.class, ShadowBluetoothAdapter.class, Loading @@ -72,6 +77,8 @@ public class HearingAidUtilsTest { private LocalBluetoothManager mLocalBluetoothManager; @Mock private CachedBluetoothDeviceManager mCachedDeviceManager; @Mock private CsipSetCoordinatorProfile mCsipSetCoordinatorProfile; private BluetoothDevice mBluetoothDevice; private BluetoothAdapter mBluetoothAdapter; private ShadowBluetoothAdapter mShadowBluetoothAdapter; Loading Loading @@ -136,6 +143,38 @@ public class HearingAidUtilsTest { assertThat(dialog).isNull(); } @Test public void launchHearingAidPairingDialog_deviceSupportsCsip_csipEnabled_noDialog() { when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true); when(mCachedBluetoothDevice.getDeviceMode()).thenReturn( HearingAidInfo.DeviceMode.MODE_BINAURAL); when(mCachedBluetoothDevice.getDeviceSide()).thenReturn( HearingAidInfo.DeviceSide.SIDE_LEFT); makeDeviceSupportCsip(); makeDeviceEnableCsip(true); HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice); final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog(); assertThat(dialog).isNull(); } @Test public void launchHearingAidPairingDialog_deviceSupportsCsip_csipDisabled_dialogShown() { when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true); when(mCachedBluetoothDevice.getDeviceMode()).thenReturn( HearingAidInfo.DeviceMode.MODE_BINAURAL); when(mCachedBluetoothDevice.getDeviceSide()).thenReturn( HearingAidInfo.DeviceSide.SIDE_LEFT); makeDeviceSupportCsip(); makeDeviceEnableCsip(false); HearingAidUtils.launchHearingAidPairingDialog(mFragmentManager, mCachedBluetoothDevice); final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog(); assertThat(dialog.isShowing()).isTrue(); } @Test public void launchHearingAidPairingDialog_dialogShown() { when(mCachedBluetoothDevice.isConnectedAshaHearingAidDevice()).thenReturn(true); Loading @@ -150,6 +189,17 @@ public class HearingAidUtilsTest { assertThat(dialog.isShowing()).isTrue(); } private void makeDeviceSupportCsip() { List<LocalBluetoothProfile> uuids = new ArrayList<>(); uuids.add(mCsipSetCoordinatorProfile); when(mCachedBluetoothDevice.getProfiles()).thenReturn(uuids); } private void makeDeviceEnableCsip(boolean enabled) { when(mCsipSetCoordinatorProfile.isEnabled(mCachedBluetoothDevice.getDevice())) .thenReturn(enabled); } private void setupEnvironment() { ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBluetoothManager; mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); Loading