From 1c7a59f125994652784637abc9df41ce9b56b402 Mon Sep 17 00:00:00 2001 From: Angela Wang Date: Wed, 14 Jun 2023 06:38:23 +0000 Subject: [PATCH 1/3] Scan LE audio hearing aids in HearingDevicePairingDetail Only ASHA hearing aids can be scanned from HearingDevicePairingDetail. Add the ability to scan LE audio hearing aids (which supports HAP profile) in hearing device page. Since we're not sure what will hearing aids vendors organize the data in the advertisement packet, add the filters as long as it's possible to increase coverage when scanning hearing aid devices. Bug: 286995224 Test: make RunSettingsRoboTests ROBOTEST_FILTER=HearingDevicePairingDetailTest Change-Id: I8faf85f38962653cf9bc988b02f3a4e5f2849b81 --- .../HearingDevicePairingDetail.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/com/android/settings/accessibility/HearingDevicePairingDetail.java b/src/com/android/settings/accessibility/HearingDevicePairingDetail.java index de86dcf6909..117a8ed131b 100644 --- a/src/com/android/settings/accessibility/HearingDevicePairingDetail.java +++ b/src/com/android/settings/accessibility/HearingDevicePairingDetail.java @@ -28,7 +28,8 @@ import com.android.settings.R; import com.android.settings.bluetooth.BluetoothDevicePairingDetailBase; import com.android.settingslib.bluetooth.CachedBluetoothDevice; -import java.util.Collections; +import java.util.ArrayList; +import java.util.List; /** * HearingDevicePairingDetail is a page to scan hearing devices. This page shows scanning icons and @@ -42,10 +43,16 @@ public class HearingDevicePairingDetail extends BluetoothDevicePairingDetailBase public HearingDevicePairingDetail() { super(); - final ScanFilter filter = new ScanFilter.Builder() - .setServiceData(BluetoothUuid.HEARING_AID, new byte[]{0}, new byte[]{0}) - .build(); - setFilter(Collections.singletonList(filter)); + final List filterList = new ArrayList<>(); + // Filters for ASHA hearing aids + filterList.add(new ScanFilter.Builder().setServiceUuid(BluetoothUuid.HEARING_AID).build()); + filterList.add(new ScanFilter.Builder() + .setServiceData(BluetoothUuid.HEARING_AID, new byte[0]).build()); + // Filters for LE audio hearing aids + filterList.add(new ScanFilter.Builder().setServiceUuid(BluetoothUuid.HAS).build()); + filterList.add(new ScanFilter.Builder() + .setServiceData(BluetoothUuid.HAS, new byte[0]).build()); + setFilter(filterList); } @Override From 291714418c6e32ed9b39a92dd6dfa524bbd1c0b6 Mon Sep 17 00:00:00 2001 From: Vincent Wang Date: Thu, 13 Jul 2023 08:13:53 +0000 Subject: [PATCH 2/3] Fix enroll introduction page was not closed in background Bug: 291023102 Test: 1. Launch FingerprintEnrollFindSensor and back to introducntion 2. Go to home screen 3. Launch FingerprintEnrollFindSensor from recent app 4. Check if FingerprintEnrollFindSensor is stopped 5. make RunSettingsRoboTests -j96 ROBOTEST_FILTER=com.android.settings.biometrics.fingerprint Change-Id: I65504f663340a0e66d1f8bcd2e7d4b3659282884 --- .../BiometricEnrollIntroduction.java | 3 ++ .../FingerprintEnrollIntroductionTest.java | 31 ++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java b/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java index 2a350f4abd5..46f534df364 100644 --- a/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java +++ b/src/com/android/settings/biometrics/BiometricEnrollIntroduction.java @@ -236,6 +236,9 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase protected void onResume() { super.onResume(); + //reset mNextClick to make sure introduction page would be closed correctly + mNextClicked = false; + final int errorMsg = checkMaxEnrolled(); if (errorMsg == 0) { mErrorText.setText(null); diff --git a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollIntroductionTest.java b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollIntroductionTest.java index 69f10d629dd..3eba91c854f 100644 --- a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollIntroductionTest.java +++ b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollIntroductionTest.java @@ -85,6 +85,7 @@ public class FingerprintEnrollIntroductionTest { private Context mContext; private TestFingerprintEnrollIntroduction mFingerprintEnrollIntroduction; + private ActivityController mController; private static final int MAX_ENROLLMENTS = 5; private static final byte[] EXPECTED_TOKEN = new byte[] { 10, 20, 30, 40 }; @@ -121,9 +122,8 @@ public class FingerprintEnrollIntroductionTest { void setupFingerprintEnrollIntroWith(@NonNull Intent intent) { - final ActivityController controller = - Robolectric.buildActivity(TestFingerprintEnrollIntroduction.class, intent); - mFingerprintEnrollIntroduction = controller.get(); + mController = Robolectric.buildActivity(TestFingerprintEnrollIntroduction.class, intent); + mFingerprintEnrollIntroduction = mController.get(); mFingerprintEnrollIntroduction.mMockedFingerprintManager = mFingerprintManager; mFingerprintEnrollIntroduction.mMockedGatekeeperPasswordProvider = mGatekeeperPasswordProvider; @@ -137,7 +137,7 @@ public class FingerprintEnrollIntroductionTest { when(mLockPatternUtils.getActivePasswordQuality(userId)) .thenReturn(PASSWORD_QUALITY_SOMETHING); - controller.create(); + mController.create(); } void setFingerprintManagerToHave(int numEnrollments) { @@ -277,6 +277,18 @@ public class FingerprintEnrollIntroductionTest { } } + @Test + public void clickNext_onActivityResult_pause_shouldFinish() { + setupFingerprintEnrollIntroWith(newTokenOnlyIntent()); + mController.resume(); + mFingerprintEnrollIntroduction.clickNextBtn(); + mController.pause().stop(); + assertThat(mFingerprintEnrollIntroduction.shouldFinishWhenBackgrounded()).isEqualTo(false); + + mController.resume().pause().stop(); + assertThat(mFingerprintEnrollIntroduction.shouldFinishWhenBackgrounded()).isEqualTo(true); + } + private Intent newTokenOnlyIntent() { return new Intent() .putExtra(EXTRA_KEY_CHALLENGE_TOKEN, new byte[] { 1 }); @@ -362,5 +374,16 @@ public class FingerprintEnrollIntroductionTest { protected void getChallenge(GenerateChallengeCallback callback) { callback.onChallengeGenerated(mNewSensorId, mUserId, mNewChallenge); } + + @Override + protected boolean shouldFinishWhenBackgrounded() { + return super.shouldFinishWhenBackgrounded(); + } + + //mock click next btn + public void clickNextBtn() { + super.onNextButtonClick(null); + } + } } From 653ff8a485d8dde8b8d8a2767560cc92a59e2124 Mon Sep 17 00:00:00 2001 From: Angela Wang Date: Tue, 13 Jun 2023 06:18:55 +0000 Subject: [PATCH 3/3] Show connecting hearing devices in A11y hearing devices page We only show connected hearing devices in the hearing devices page now. When user pairing a device from pairing page and back to the hearing devices page after the device is bonded, it's confusing no device shown in the list because the device is still connecting to profiles. We should show the connecting device to avoid confusion. Bug: 283268686 Test: make RunSettingsRoboTests ROBOTEST_FILTER=DeviceListPreferenceFragmentTest Test: make RunSettingsRoboTests ROBOTEST_FILTER=AvailableHearingDeviceUpdaterTest Change-Id: Id3b29c12b80c282736a3e6ca73bcf317e0652b89 Merged-In: Id3b29c12b80c282736a3e6ca73bcf317e0652b89 --- .../AvailableHearingDeviceUpdater.java | 9 ++--- .../bluetooth/DeviceListPreferenceFragment.kt | 39 ++++++++++++------- .../AvailableHearingDeviceUpdaterTest.java | 18 +++++---- 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/com/android/settings/accessibility/AvailableHearingDeviceUpdater.java b/src/com/android/settings/accessibility/AvailableHearingDeviceUpdater.java index b3d371528f6..f600b038ddc 100644 --- a/src/com/android/settings/accessibility/AvailableHearingDeviceUpdater.java +++ b/src/com/android/settings/accessibility/AvailableHearingDeviceUpdater.java @@ -16,7 +16,6 @@ package com.android.settings.accessibility; -import android.bluetooth.BluetoothDevice; import android.content.Context; import com.android.settings.bluetooth.AvailableMediaBluetoothDeviceUpdater; @@ -37,11 +36,9 @@ public class AvailableHearingDeviceUpdater extends AvailableMediaBluetoothDevice @Override public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) { - final BluetoothDevice device = cachedDevice.getDevice(); - final boolean isConnectedHearingAidDevice = (cachedDevice.isConnectedHearingAidDevice() - && (device.getBondState() == BluetoothDevice.BOND_BONDED)); - - return isConnectedHearingAidDevice && isDeviceInCachedDevicesList(cachedDevice); + return cachedDevice.isHearingAidDevice() + && isDeviceConnected(cachedDevice) + && isDeviceInCachedDevicesList(cachedDevice); } @Override diff --git a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.kt b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.kt index 42c24ea2140..f18ae46e18b 100644 --- a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.kt +++ b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.kt @@ -191,10 +191,11 @@ abstract class DeviceListPreferenceFragment(restrictedKey: String?) : private suspend fun addDevice(cachedDevice: CachedBluetoothDevice) = withContext(Dispatchers.Default) { + // TODO(b/289189853): Replace checking if `filter` is null or not to decide which type + // of Bluetooth scanning method will be used + val filterMatched = filter == null || filter!!.matches(cachedDevice.device) == true // Prevent updates while the list shows one of the state messages - if (mBluetoothAdapter!!.state == BluetoothAdapter.STATE_ON && - filter?.matches(cachedDevice.device) == true - ) { + if (mBluetoothAdapter!!.state == BluetoothAdapter.STATE_ON && filterMatched) { createDevicePreference(cachedDevice) } } @@ -304,17 +305,14 @@ abstract class DeviceListPreferenceFragment(restrictedKey: String?) : } } - private val scanCallback = object : ScanCallback() { + private val leScanCallback = object : ScanCallback() { override fun onScanResult(callbackType: Int, result: ScanResult) { - lifecycleScope?.launch { - withContext(Dispatchers.Default) { - if (mBluetoothAdapter!!.state == BluetoothAdapter.STATE_ON) { - val device = result.device - val cachedDevice = mCachedDeviceManager!!.findDevice(device) - ?: mCachedDeviceManager!!.addDevice(device) - createDevicePreference(cachedDevice) - } - } + handleLeScanResult(result) + } + + override fun onBatchScanResults(results: MutableList?) { + for (result in results.orEmpty()) { + handleLeScanResult(result) } } @@ -328,12 +326,23 @@ abstract class DeviceListPreferenceFragment(restrictedKey: String?) : val settings = ScanSettings.Builder() .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) .build() - scanner.startScan(leScanFilters, settings, scanCallback) + scanner.startScan(leScanFilters, settings, leScanCallback) } private fun stopLeScanning() { val scanner = mBluetoothAdapter!!.bluetoothLeScanner - scanner?.stopScan(scanCallback) + scanner?.stopScan(leScanCallback) + } + + private fun handleLeScanResult(result: ScanResult) { + lifecycleScope?.launch { + withContext(Dispatchers.Default) { + val device = result.device + val cachedDevice = mCachedDeviceManager!!.findDevice(device) + ?: mCachedDeviceManager!!.addDevice(device, leScanFilters) + addDevice(cachedDevice) + } + } } companion object { diff --git a/tests/robotests/src/com/android/settings/accessibility/AvailableHearingDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/accessibility/AvailableHearingDeviceUpdaterTest.java index 6305014a6e3..0aab5bba7be 100644 --- a/tests/robotests/src/com/android/settings/accessibility/AvailableHearingDeviceUpdaterTest.java +++ b/tests/robotests/src/com/android/settings/accessibility/AvailableHearingDeviceUpdaterTest.java @@ -18,7 +18,6 @@ package com.android.settings.accessibility; import static com.google.common.truth.Truth.assertThat; -import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; import android.bluetooth.BluetoothDevice; @@ -80,8 +79,9 @@ public class AvailableHearingDeviceUpdaterTest { @Test public void isFilterMatch_connectedHearingDevice_returnTrue() { CachedBluetoothDevice connectedHearingDevice = mCachedBluetoothDevice; - when(connectedHearingDevice.isConnectedHearingAidDevice()).thenReturn(true); - doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState(); + when(connectedHearingDevice.isHearingAidDevice()).thenReturn(true); + when(mBluetoothDevice.isConnected()).thenReturn(true); + when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn( new ArrayList<>(List.of(connectedHearingDevice))); @@ -91,8 +91,9 @@ public class AvailableHearingDeviceUpdaterTest { @Test public void isFilterMatch_nonConnectedHearingDevice_returnFalse() { CachedBluetoothDevice nonConnectedHearingDevice = mCachedBluetoothDevice; - when(nonConnectedHearingDevice.isConnectedHearingAidDevice()).thenReturn(false); - doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState(); + when(nonConnectedHearingDevice.isHearingAidDevice()).thenReturn(true); + when(mBluetoothDevice.isConnected()).thenReturn(false); + when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn( new ArrayList<>(List.of(nonConnectedHearingDevice))); @@ -103,7 +104,8 @@ public class AvailableHearingDeviceUpdaterTest { public void isFilterMatch_connectedBondingHearingDevice_returnFalse() { CachedBluetoothDevice connectedBondingHearingDevice = mCachedBluetoothDevice; when(connectedBondingHearingDevice.isHearingAidDevice()).thenReturn(true); - doReturn(BluetoothDevice.BOND_BONDING).when(mBluetoothDevice).getBondState(); + when(mBluetoothDevice.isConnected()).thenReturn(true); + when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDING); when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn( new ArrayList<>(List.of(connectedBondingHearingDevice))); @@ -114,8 +116,8 @@ public class AvailableHearingDeviceUpdaterTest { public void isFilterMatch_hearingDeviceNotInCachedDevicesList_returnFalse() { CachedBluetoothDevice notInCachedDevicesListDevice = mCachedBluetoothDevice; when(notInCachedDevicesListDevice.isHearingAidDevice()).thenReturn(true); - doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState(); - doReturn(false).when(mBluetoothDevice).isConnected(); + when(mBluetoothDevice.isConnected()).thenReturn(true); + when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(new ArrayList<>()); assertThat(mUpdater.isFilterMatched(notInCachedDevicesListDevice)).isEqualTo(false);