Snap for 10542431 from 11b9933fea to udc-qpr1-release

Change-Id: Id0fb1cf20ff23c329c180d60759ca0cd6f384dba
This commit is contained in:
Android Build Coastguard Worker
2023-07-22 01:23:40 +00:00
6 changed files with 79 additions and 38 deletions

View File

@@ -16,7 +16,6 @@
package com.android.settings.accessibility; package com.android.settings.accessibility;
import android.bluetooth.BluetoothDevice;
import android.content.Context; import android.content.Context;
import com.android.settings.bluetooth.AvailableMediaBluetoothDeviceUpdater; import com.android.settings.bluetooth.AvailableMediaBluetoothDeviceUpdater;
@@ -37,11 +36,9 @@ public class AvailableHearingDeviceUpdater extends AvailableMediaBluetoothDevice
@Override @Override
public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) { public boolean isFilterMatched(CachedBluetoothDevice cachedDevice) {
final BluetoothDevice device = cachedDevice.getDevice(); return cachedDevice.isHearingAidDevice()
final boolean isConnectedHearingAidDevice = (cachedDevice.isConnectedHearingAidDevice() && isDeviceConnected(cachedDevice)
&& (device.getBondState() == BluetoothDevice.BOND_BONDED)); && isDeviceInCachedDevicesList(cachedDevice);
return isConnectedHearingAidDevice && isDeviceInCachedDevicesList(cachedDevice);
} }
@Override @Override

View File

@@ -28,7 +28,8 @@ import com.android.settings.R;
import com.android.settings.bluetooth.BluetoothDevicePairingDetailBase; import com.android.settings.bluetooth.BluetoothDevicePairingDetailBase;
import com.android.settingslib.bluetooth.CachedBluetoothDevice; 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 * 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() { public HearingDevicePairingDetail() {
super(); super();
final ScanFilter filter = new ScanFilter.Builder() final List<ScanFilter> filterList = new ArrayList<>();
.setServiceData(BluetoothUuid.HEARING_AID, new byte[]{0}, new byte[]{0}) // Filters for ASHA hearing aids
.build(); filterList.add(new ScanFilter.Builder().setServiceUuid(BluetoothUuid.HEARING_AID).build());
setFilter(Collections.singletonList(filter)); 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 @Override

View File

@@ -236,6 +236,9 @@ public abstract class BiometricEnrollIntroduction extends BiometricEnrollBase
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
//reset mNextClick to make sure introduction page would be closed correctly
mNextClicked = false;
final int errorMsg = checkMaxEnrolled(); final int errorMsg = checkMaxEnrolled();
if (errorMsg == 0) { if (errorMsg == 0) {
mErrorText.setText(null); mErrorText.setText(null);

View File

@@ -191,10 +191,11 @@ abstract class DeviceListPreferenceFragment(restrictedKey: String?) :
private suspend fun addDevice(cachedDevice: CachedBluetoothDevice) = private suspend fun addDevice(cachedDevice: CachedBluetoothDevice) =
withContext(Dispatchers.Default) { 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 // Prevent updates while the list shows one of the state messages
if (mBluetoothAdapter!!.state == BluetoothAdapter.STATE_ON && if (mBluetoothAdapter!!.state == BluetoothAdapter.STATE_ON && filterMatched) {
filter?.matches(cachedDevice.device) == true
) {
createDevicePreference(cachedDevice) 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) { override fun onScanResult(callbackType: Int, result: ScanResult) {
lifecycleScope?.launch { handleLeScanResult(result)
withContext(Dispatchers.Default) { }
if (mBluetoothAdapter!!.state == BluetoothAdapter.STATE_ON) {
val device = result.device override fun onBatchScanResults(results: MutableList<ScanResult>?) {
val cachedDevice = mCachedDeviceManager!!.findDevice(device) for (result in results.orEmpty()) {
?: mCachedDeviceManager!!.addDevice(device) handleLeScanResult(result)
createDevicePreference(cachedDevice)
}
}
} }
} }
@@ -328,12 +326,23 @@ abstract class DeviceListPreferenceFragment(restrictedKey: String?) :
val settings = ScanSettings.Builder() val settings = ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY) .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.build() .build()
scanner.startScan(leScanFilters, settings, scanCallback) scanner.startScan(leScanFilters, settings, leScanCallback)
} }
private fun stopLeScanning() { private fun stopLeScanning() {
val scanner = mBluetoothAdapter!!.bluetoothLeScanner 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 { companion object {

View File

@@ -18,7 +18,6 @@ package com.android.settings.accessibility;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothDevice;
@@ -80,8 +79,9 @@ public class AvailableHearingDeviceUpdaterTest {
@Test @Test
public void isFilterMatch_connectedHearingDevice_returnTrue() { public void isFilterMatch_connectedHearingDevice_returnTrue() {
CachedBluetoothDevice connectedHearingDevice = mCachedBluetoothDevice; CachedBluetoothDevice connectedHearingDevice = mCachedBluetoothDevice;
when(connectedHearingDevice.isConnectedHearingAidDevice()).thenReturn(true); when(connectedHearingDevice.isHearingAidDevice()).thenReturn(true);
doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState(); when(mBluetoothDevice.isConnected()).thenReturn(true);
when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn( when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(
new ArrayList<>(List.of(connectedHearingDevice))); new ArrayList<>(List.of(connectedHearingDevice)));
@@ -91,8 +91,9 @@ public class AvailableHearingDeviceUpdaterTest {
@Test @Test
public void isFilterMatch_nonConnectedHearingDevice_returnFalse() { public void isFilterMatch_nonConnectedHearingDevice_returnFalse() {
CachedBluetoothDevice nonConnectedHearingDevice = mCachedBluetoothDevice; CachedBluetoothDevice nonConnectedHearingDevice = mCachedBluetoothDevice;
when(nonConnectedHearingDevice.isConnectedHearingAidDevice()).thenReturn(false); when(nonConnectedHearingDevice.isHearingAidDevice()).thenReturn(true);
doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState(); when(mBluetoothDevice.isConnected()).thenReturn(false);
when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn( when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(
new ArrayList<>(List.of(nonConnectedHearingDevice))); new ArrayList<>(List.of(nonConnectedHearingDevice)));
@@ -103,7 +104,8 @@ public class AvailableHearingDeviceUpdaterTest {
public void isFilterMatch_connectedBondingHearingDevice_returnFalse() { public void isFilterMatch_connectedBondingHearingDevice_returnFalse() {
CachedBluetoothDevice connectedBondingHearingDevice = mCachedBluetoothDevice; CachedBluetoothDevice connectedBondingHearingDevice = mCachedBluetoothDevice;
when(connectedBondingHearingDevice.isHearingAidDevice()).thenReturn(true); 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( when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(
new ArrayList<>(List.of(connectedBondingHearingDevice))); new ArrayList<>(List.of(connectedBondingHearingDevice)));
@@ -114,8 +116,8 @@ public class AvailableHearingDeviceUpdaterTest {
public void isFilterMatch_hearingDeviceNotInCachedDevicesList_returnFalse() { public void isFilterMatch_hearingDeviceNotInCachedDevicesList_returnFalse() {
CachedBluetoothDevice notInCachedDevicesListDevice = mCachedBluetoothDevice; CachedBluetoothDevice notInCachedDevicesListDevice = mCachedBluetoothDevice;
when(notInCachedDevicesListDevice.isHearingAidDevice()).thenReturn(true); when(notInCachedDevicesListDevice.isHearingAidDevice()).thenReturn(true);
doReturn(BluetoothDevice.BOND_BONDED).when(mBluetoothDevice).getBondState(); when(mBluetoothDevice.isConnected()).thenReturn(true);
doReturn(false).when(mBluetoothDevice).isConnected(); when(mBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(new ArrayList<>()); when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(new ArrayList<>());
assertThat(mUpdater.isFilterMatched(notInCachedDevicesListDevice)).isEqualTo(false); assertThat(mUpdater.isFilterMatched(notInCachedDevicesListDevice)).isEqualTo(false);

View File

@@ -85,6 +85,7 @@ public class FingerprintEnrollIntroductionTest {
private Context mContext; private Context mContext;
private TestFingerprintEnrollIntroduction mFingerprintEnrollIntroduction; private TestFingerprintEnrollIntroduction mFingerprintEnrollIntroduction;
private ActivityController<TestFingerprintEnrollIntroduction> mController;
private static final int MAX_ENROLLMENTS = 5; private static final int MAX_ENROLLMENTS = 5;
private static final byte[] EXPECTED_TOKEN = new byte[] { 10, 20, 30, 40 }; private static final byte[] EXPECTED_TOKEN = new byte[] { 10, 20, 30, 40 };
@@ -121,9 +122,8 @@ public class FingerprintEnrollIntroductionTest {
void setupFingerprintEnrollIntroWith(@NonNull Intent intent) { void setupFingerprintEnrollIntroWith(@NonNull Intent intent) {
final ActivityController<TestFingerprintEnrollIntroduction> controller = mController = Robolectric.buildActivity(TestFingerprintEnrollIntroduction.class, intent);
Robolectric.buildActivity(TestFingerprintEnrollIntroduction.class, intent); mFingerprintEnrollIntroduction = mController.get();
mFingerprintEnrollIntroduction = controller.get();
mFingerprintEnrollIntroduction.mMockedFingerprintManager = mFingerprintManager; mFingerprintEnrollIntroduction.mMockedFingerprintManager = mFingerprintManager;
mFingerprintEnrollIntroduction.mMockedGatekeeperPasswordProvider = mFingerprintEnrollIntroduction.mMockedGatekeeperPasswordProvider =
mGatekeeperPasswordProvider; mGatekeeperPasswordProvider;
@@ -137,7 +137,7 @@ public class FingerprintEnrollIntroductionTest {
when(mLockPatternUtils.getActivePasswordQuality(userId)) when(mLockPatternUtils.getActivePasswordQuality(userId))
.thenReturn(PASSWORD_QUALITY_SOMETHING); .thenReturn(PASSWORD_QUALITY_SOMETHING);
controller.create(); mController.create();
} }
void setFingerprintManagerToHave(int numEnrollments) { 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() { private Intent newTokenOnlyIntent() {
return new Intent() return new Intent()
.putExtra(EXTRA_KEY_CHALLENGE_TOKEN, new byte[] { 1 }); .putExtra(EXTRA_KEY_CHALLENGE_TOKEN, new byte[] { 1 });
@@ -362,5 +374,16 @@ public class FingerprintEnrollIntroductionTest {
protected void getChallenge(GenerateChallengeCallback callback) { protected void getChallenge(GenerateChallengeCallback callback) {
callback.onChallengeGenerated(mNewSensorId, mUserId, mNewChallenge); callback.onChallengeGenerated(mNewSensorId, mUserId, mNewChallenge);
} }
@Override
protected boolean shouldFinishWhenBackgrounded() {
return super.shouldFinishWhenBackgrounded();
}
//mock click next btn
public void clickNextBtn() {
super.onNextButtonClick(null);
}
} }
} }