Loading src/com/android/settings/accessibility/HearingDevicePairingFragment.java +12 −1 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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(); Loading Loading @@ -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; } } tests/robotests/src/com/android/settings/accessibility/HearingDevicePairingFragmentTest.java +12 −12 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading Loading @@ -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); Loading Loading
src/com/android/settings/accessibility/HearingDevicePairingFragment.java +12 −1 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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(); Loading Loading @@ -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; } }
tests/robotests/src/com/android/settings/accessibility/HearingDevicePairingFragmentTest.java +12 −12 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading Loading @@ -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); Loading