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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<ScanResult>?) {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user