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

Commit 7f3f7769 authored by Hsin-chen Chuang's avatar Hsin-chen Chuang
Browse files

floss: Fix race between adapter prop change and device prop change

AdapterBondedDevices event would insert the remote device addresses
into the bonded list. This event usually comes first and the device prop
change event would update the list afterwards. However, it's found that
they could come in the reversed order and Floss would "miss" the updated
device prop.

Bug: 331561532
Tag: #floss
Test: mmm packages/modules/Bluetooth
Test: Stress tested cl_HID_reports_restart_test.floss, no failure
Flag: EXEMPT, Floss-only changes
Change-Id: Id37b1adcbd3184a948d8dd2068274e8a0cb3bfea
parent 1c8c9402
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -1468,18 +1468,24 @@ impl BtifBluetoothCallbacks for Bluetooth {
                    for addr in bondlist.iter() {
                        let address = addr.to_string();

                        // Update bonded state if already in the list. Otherwise create a new
                        // context with empty properties and name.
                        self.bonded_devices
                            .entry(address.clone())
                            .and_modify(|d| d.bond_state = BtBondState::Bonded)
                            .or_insert(BluetoothDeviceContext::new(
                        // On BT started, the |remote_device_properties_changed| event from BTIF
                        // could comes earlier then this |AdapterBondedDevices| prop. In that case
                        // the updated remote device properties would be stored in |found_devices|,
                        // so we need to move out and reuse them, otherwise those properties
                        // (usually the device name) would be lost.
                        // If the device doesn't exist in both map, create a new context with
                        // empty properties and name.
                        let device = self.found_devices.remove(&address).unwrap_or(
                            BluetoothDeviceContext::new(
                                BtBondState::Bonded,
                                BtAclState::Disconnected,
                                BluetoothDevice::new(address.clone(), "".to_string()),
                                Instant::now(),
                                vec![],
                            ));
                            ),
                        );
                        self.bonded_devices.entry(address.clone()).or_insert(device).bond_state =
                            BtBondState::Bonded;
                    }
                }
                BluetoothProperty::BdName(bdname) => {