Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5097cbe1 authored by Angela Wang's avatar Angela Wang
Browse files

Filter out non-discoverable scan result in hearing device pairing page

Flag: EXEMPT bugfix
Bug: 381027984
Test: atest HearingDevicePairingFragmentTest
Test: check with real device
Change-Id: I7ab70d5508d71472cbd2d0959bb749599d039058
parent 7a9277ca
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -75,6 +75,8 @@ public class HearingDevicePairingFragment extends RestrictedDashboardFragment im
    private static final String BLUETOOTH_SHOW_DEVICES_WITHOUT_NAMES_PROPERTY =
            "persist.bluetooth.showdeviceswithoutnames";
    private static final String KEY_AVAILABLE_HEARING_DEVICES = "available_hearing_devices";
    // Flags data type from CSS 1.3 Flags
    private static final int BT_DISCOVERABLE_MASK = 0x03;

    LocalBluetoothManager mLocalManager;
    @Nullable
@@ -322,7 +324,7 @@ public class HearingDevicePairingFragment extends RestrictedDashboardFragment im
    };

    void handleLeScanResult(ScanResult result) {
        if (mCachedDeviceManager == null) {
        if (mCachedDeviceManager == null || !isDeviceDiscoverable(result)) {
            return;
        }
        final BluetoothDevice device = result.getDevice();
@@ -505,4 +507,13 @@ public class HearingDevicePairingFragment extends RestrictedDashboardFragment im
        Toast.makeText(getContext(), R.string.connected_device_bluetooth_turned_on_toast,
                Toast.LENGTH_SHORT).show();
    }

    boolean isDeviceDiscoverable(ScanResult result) {
        final ScanRecord scanRecord = result.getScanRecord();
        if (scanRecord == null) {
            return false;
        }
        final int flags = scanRecord.getAdvertiseFlags();
        return (flags & BT_DISCOVERABLE_MASK) != 0;
    }
}
+12 −12
Original line number Diff line number Diff line
@@ -156,9 +156,7 @@ public class HearingDevicePairingFragmentTest {

    @Test
    public void handleLeScanResult_markDeviceAsHearingAid() {
        ScanResult scanResult = mock(ScanResult.class);
        doReturn(mDevice).when(scanResult).getDevice();
        doReturn(mCachedDevice).when(mCachedDeviceManager).findDevice(mDevice);
        ScanResult scanResult = createMockScanResult();

        mFragment.handleLeScanResult(scanResult);

@@ -167,9 +165,7 @@ public class HearingDevicePairingFragmentTest {

    @Test
    public void handleLeScanResult_isAndroidCompatible_addDevice() {
        ScanResult scanResult = mock(ScanResult.class);
        doReturn(mDevice).when(scanResult).getDevice();
        doReturn(mCachedDevice).when(mCachedDeviceManager).findDevice(mDevice);
        ScanResult scanResult = createMockScanResult();
        doReturn(true).when(mFragment).isAndroidCompatibleHearingAid(scanResult);

        mFragment.handleLeScanResult(scanResult);
@@ -179,9 +175,7 @@ public class HearingDevicePairingFragmentTest {

    @Test
    public void handleLeScanResult_isNotAndroidCompatible_discoverServices() {
        ScanResult scanResult = mock(ScanResult.class);
        doReturn(mDevice).when(scanResult).getDevice();
        doReturn(mCachedDevice).when(mCachedDeviceManager).findDevice(mDevice);
        ScanResult scanResult = createMockScanResult();
        doReturn(false).when(mFragment).isAndroidCompatibleHearingAid(scanResult);

        mFragment.handleLeScanResult(scanResult);
@@ -191,9 +185,7 @@ public class HearingDevicePairingFragmentTest {

    @Test
    public void handleLeScanResult_alreadyBonded_doNothing() {
        ScanResult scanResult = mock(ScanResult.class);
        doReturn(mDevice).when(scanResult).getDevice();
        doReturn(mCachedDevice).when(mCachedDeviceManager).findDevice(mDevice);
        ScanResult scanResult = createMockScanResult();
        doReturn(BluetoothDevice.BOND_BONDED).when(mCachedDevice).getBondState();

        mFragment.handleLeScanResult(scanResult);
@@ -292,6 +284,14 @@ public class HearingDevicePairingFragmentTest {
        assertThat(isCompatible).isFalse();
    }

    private ScanResult createMockScanResult() {
        ScanResult scanResult = mock(ScanResult.class);
        doReturn(mDevice).when(scanResult).getDevice();
        doReturn(mCachedDevice).when(mCachedDeviceManager).findDevice(mDevice);
        doReturn(true).when(mFragment).isDeviceDiscoverable(scanResult);
        return scanResult;
    }

    private ScanResult createAshaScanResult() {
        ScanResult scanResult = mock(ScanResult.class);
        ScanRecord scanRecord = mock(ScanRecord.class);