From fb0d23955d13eefc46a966b22145505caa616879 Mon Sep 17 00:00:00 2001 From: Angela Wang Date: Thu, 11 May 2023 05:14:32 +0000 Subject: [PATCH] Fix non-hearing devices show in pair new hearing devices page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Non-hearing devices are listed in "pair new hearing devices page" if we click the "See more devices" button and go back from "general pair new devices page". Root cause: Two types of Bluetooth scanning happen simultaneously and the scanning results of different scanning methods are handled in the same place. Currently the BLE scanning callback “onScanResult()” directly calls “onDeviceAdded()” method to handle the new scanned devices. This method is mainly called when receiving a broadcast of a new device found in Bluetooth classic scanning. The general pair new devices page uses Bluetooth classic scanning and the pair new hearing devices page uses Bluetooth LE scanning. The life cycle ordering when going back from general pair new devices page to pair new hearing devices page will be "pair new hearing devices page".onStart() -> "general pair new devices page".onStop(). It means the classic scanning is not stopped while the BLE scanning starts and this causes the scanning results from classic scanning unexpectedly added to the list which should only show the scanning results from BLE scanning. Solution: Separates the handling part of two scanning methods. Leaves "onDeviceAdded" handling Bluetooth classic scanning results only, and handles BLE scanning results in the “onScanResult” callback directly. Bug: 279374435 Test: checks the result by switching back from "general pair new devices page" to "pair new hearing devices page" Test: make RunSettingsRoboTests ROBOTEST_FILTER=DeviceListPreferenceFragmentTest Change-Id: Iebdde401ffb3dc0569478730a140a5dd7add115b --- .../bluetooth/DeviceListPreferenceFragment.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java index 522b5cb10b0..a4a98917974 100644 --- a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java +++ b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java @@ -196,10 +196,11 @@ public abstract class DeviceListPreferenceFragment extends } // Prevent updates while the list shows one of the state messages - if (mBluetoothAdapter.getState() != BluetoothAdapter.STATE_ON) return; + if (mBluetoothAdapter.getState() != BluetoothAdapter.STATE_ON) { + return; + } - if (mLeScanFilters != null - || (mFilter != null && mFilter.matches(cachedDevice.getDevice()))) { + if (mFilter != null && mFilter.matches(cachedDevice.getDevice())) { createDevicePreference(cachedDevice); } } @@ -325,7 +326,12 @@ public abstract class DeviceListPreferenceFragment extends if (cachedDevice == null) { cachedDevice = mCachedDeviceManager.addDevice(device); } - onDeviceAdded(cachedDevice); + // Only add device preference when it's not found in the map and there's no other + // state message showing in the list + if (mDevicePreferenceMap.get(cachedDevice) == null + && mBluetoothAdapter.getState() == BluetoothAdapter.STATE_ON) { + createDevicePreference(cachedDevice); + } } @Override