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

Commit e8d86283 authored by Henri Chataing's avatar Henri Chataing
Browse files

rust/gatt: Suppress rust panics on LE disconnection events received

after rust module unloading

Disconnection events received after the rust module is unloaded
(from shutting down the stack) cause the rust module to raise
a panic because the arbiter is no longer initialized.

This change silences LE disconnection events received in this
context.

Bug: 289280004
Test: atest avatar
Change-Id: Iec122a42feed059f6fa1826b625df10e92ad64bb
parent e429133e
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -52,6 +52,11 @@ pub fn with_arbiter<T>(f: impl FnOnce(&mut IsolationManager) -> T) -> T {
    f(ARBITER.read().unwrap().as_ref().expect("Rust stack is not started").lock().as_mut().unwrap())
}

/// Check if the Arbiter is initialized.
pub fn has_arbiter() -> bool {
    ARBITER.read().unwrap().is_some()
}

/// Test to see if a buffer contains a valid ATT packet with an opcode we
/// are interested in intercepting (those intended for servers that are isolated)
fn try_parse_att_server_packet(
@@ -89,6 +94,13 @@ fn on_le_connect(tcb_idx: u8, advertiser: u8) {
}

fn on_le_disconnect(tcb_idx: u8) {
    // Disconnection events may be received after a FactoryReset
    // is initiated for Bluetooth and the rust arbiter is taken
    // down.
    if !has_arbiter() {
        return;
    }

    let tcb_idx = TransportIndex(tcb_idx);
    let was_isolated = with_arbiter(|arbiter| arbiter.is_connection_isolated(tcb_idx));
    if was_isolated {