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

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

floss: btmanagerd: Send callback only when the presence changed

btmanagerd received an IndexAdded when btadapterd closed the user
channel, and a redundant event is sent.

Bug: 270447662
Tag: #floss
Test: mmm packages/modules/Bluetooth
Test: Toggle BT, verify Chrome log that no redundant event is sent

Change-Id: I5db77ee5e6075e4f0a28a71c25a0e4bd8481ad41
parent eef273d0
Loading
Loading
Loading
Loading
+26 −14
Original line number Diff line number Diff line
@@ -700,6 +700,16 @@ pub async fn mainloop(
                        }

                        prev_state = context.state_machine.get_process_state(hci);

                        // Don't bother the clients if presence is unchanged. But still execute the
                        // state machine here in case there is anything else to be done (e.g.,
                        // verify the next state).
                        let presence_changed = *present
                            != context
                                .state_machine
                                .get_state(hci, |a: &AdapterState| Some(a.present))
                                .unwrap_or(false);

                        let adapter_change_action;
                        let timeout_action;
                        (next_state, adapter_change_action, timeout_action) =
@@ -722,6 +732,7 @@ pub async fn mainloop(
                            AdapterChangeAction::DoNothing => (),
                        };

                        if presence_changed {
                            // If present switched to true and we're turning on the adapter,
                            // defer the callback until the next BluetoothStarted or CommandTimeout
                            // so the clients won't get an unexpected state change after present.
@@ -740,6 +751,7 @@ pub async fn mainloop(
                                    .callback_hci_device_change(hci, *present);
                            }
                        }
                    }
                };

                // All actions and the resulting state changes should be logged for debugging.