Fix bluetooth settings pairing page stuck
There is heavy work to do when add device to list in the DeviceListPreferenceFragment, off load these work from main thread to solve the issue. Make devicePreferenceMap a ConcurrentHashMap to avoid potential race condition. Also no longer use getCachedPreference(key) since we not put anything into the cache, the fallback flow is always used. Also in BluetoothDevicePreference.onPreferenceAttributesChanged(), move more heavy work to background thread. Using System.currentTimeMillis() to sort devices could cause flaky because System.currentTimeMillis() could be same for different device, use AtomicInteger instead. Fix: 286628533 Test: Following the step in bug Change-Id: Ia9750adb6b4c1424d084381e9d7c2ca8e7912391
This commit is contained in:
@@ -202,7 +202,7 @@ public class BluetoothDevicePairingDetailBaseTest {
|
||||
new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
||||
true, BluetoothDevicePreference.SortType.TYPE_FIFO);
|
||||
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS);
|
||||
mFragment.mDevicePreferenceMap.put(mCachedBluetoothDevice, preference);
|
||||
mFragment.getDevicePreferenceMap().put(mCachedBluetoothDevice, preference);
|
||||
|
||||
when(mCachedBluetoothDevice.isConnected()).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(device);
|
||||
@@ -210,7 +210,7 @@ public class BluetoothDevicePairingDetailBaseTest {
|
||||
mFragment.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||
BluetoothProfile.A2DP, BluetoothAdapter.STATE_CONNECTED);
|
||||
|
||||
assertThat(mFragment.mDevicePreferenceMap.size()).isEqualTo(0);
|
||||
assertThat(mFragment.getDevicePreferenceMap().size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -221,7 +221,7 @@ public class BluetoothDevicePairingDetailBaseTest {
|
||||
true, BluetoothDevicePreference.SortType.TYPE_FIFO);
|
||||
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS);
|
||||
final BluetoothDevice device2 = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_B);
|
||||
mFragment.mDevicePreferenceMap.put(mCachedBluetoothDevice, preference);
|
||||
mFragment.getDevicePreferenceMap().put(mCachedBluetoothDevice, preference);
|
||||
|
||||
when(mCachedBluetoothDevice.isConnected()).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(device);
|
||||
|
Reference in New Issue
Block a user