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

Commit feee6874 authored by David Duarte's avatar David Duarte Committed by Gerrit Code Review
Browse files

Merge changes Ic995239d,I434d863d into main

* changes:
  Remove private_gatt flag
  Remove rust_event_loop flag
parents c22a2b0b 92e8fe6c
Loading
Loading
Loading
Loading
+4 −33
Original line number Diff line number Diff line
@@ -89,15 +89,13 @@ trait FlagHolder: Default {
    fn get_defaults_for_test() -> Self;
    fn parse(flags: Vec<String>) -> Self;
    fn dump(&self) -> BTreeMap<&'static str, String>;
    fn reconcile(self) -> Self;
}

macro_rules! init_flags_struct {
    (
     name: $name:ident
     flags: { $($flag:ident $(: $type:ty)? $(= $default:tt)?,)* }
     extra_parsed_flags: { $($extra_flag:tt => $extra_flag_fn:ident(_, _ $(,$extra_args:tt)*),)*}
     dependencies: { $($parent:ident => $child:ident),* }) => {
     extra_parsed_flags: { $($extra_flag:tt => $extra_flag_fn:ident(_, _ $(,$extra_args:tt)*),)*}) => {

        struct $name {
            $($flag : type_expand!($($type)?),)*
@@ -144,20 +142,7 @@ macro_rules! init_flags_struct {
                    }
                }

                init_flags.reconcile()
            }

            #[allow(unused_mut)]
            fn reconcile(mut self) -> Self {
                loop {
                    // dependencies can be specified in any order
                    $(if self.$parent && !self.$child {
                        self.$child = true;
                        continue;
                    })*
                    break;
                }
                self
                init_flags
            }
        }

@@ -175,8 +160,7 @@ macro_rules! init_flags_struct {
macro_rules! init_flags_getters {
    (
     flags: { $($flag:ident $(: $type:ty)? $(= $default:tt)?,)* }
     extra_parsed_flags: { $($extra_flag:tt => $extra_flag_fn:ident(_, _ $(,$extra_args:tt)*),)*}
     dependencies: { $($parent:ident => $child:ident),* }) => {
     extra_parsed_flags: { $($extra_flag:tt => $extra_flag_fn:ident(_, _ $(,$extra_args:tt)*),)*}) => {

        $(create_getter_fn!($flag $($type)?);)*

@@ -239,9 +223,7 @@ init_flags!(
        irk_rotation,
        leaudio_targeted_announcement_reconnection_mode = true,
        pbap_pse_dynamic_version_upgrade = false,
        private_gatt = true,
        redact_log = true,
        rust_event_loop = true,
        sco_codec_select_lc3 = true,
        sco_codec_timeout_clear,
        sdp_serialization = true,
@@ -258,10 +240,6 @@ init_flags!(
    extra_parsed_flags: {
        "--hci" => parse_hci_adapter(_, _),
    }
    dependencies: {
        always_use_private_gatt_for_debugging => private_gatt,
        private_gatt => rust_event_loop
    }
);

lazy_static! {
@@ -304,11 +282,7 @@ mod tests {
    #[test]
    fn simple_flag() {
        let _guard = ASYNC_LOCK.lock().unwrap();
        test_load(vec![
            "INIT_private_gatt=false", //override a default flag
            "INIT_gatt_robust_caching_server=true",
        ]);
        assert!(!private_gatt_is_enabled());
        test_load(vec!["INIT_gatt_robust_caching_server=true"]);
        assert!(gatt_robust_caching_server_is_enabled());
    }
    #[test]
@@ -317,10 +291,8 @@ mod tests {
        test_load(vec![
            "foo=bar=?",                                // vec length
            "foo=bar",                                  // flag not save
            "INIT_private_gatt=not_false",              // parse error but has default value
            "INIT_gatt_robust_caching_server=not_true", // parse error
        ]);
        assert!(private_gatt_is_enabled());
        assert!(!gatt_robust_caching_server_is_enabled());
    }
    #[test]
@@ -347,7 +319,6 @@ mod tests {
            cat,
        }
        extra_parsed_flags: {}
        dependencies: {}
    );

    #[test]
+0 −2
Original line number Diff line number Diff line
@@ -28,9 +28,7 @@ mod ffi {
        fn irk_rotation_is_enabled() -> bool;
        fn leaudio_targeted_announcement_reconnection_mode_is_enabled() -> bool;
        fn pbap_pse_dynamic_version_upgrade_is_enabled() -> bool;
        fn private_gatt_is_enabled() -> bool;
        fn redact_log_is_enabled() -> bool;
        fn rust_event_loop_is_enabled() -> bool;
        fn sco_codec_select_lc3_is_enabled() -> bool;
        fn sco_codec_timeout_clear_is_enabled() -> bool;
        fn sdp_serialization_is_enabled() -> bool;
+10 −13
Original line number Diff line number Diff line
@@ -8,7 +8,6 @@ pub mod uuid;

use std::{pin::Pin, rc::Rc, thread};

use bt_common::init_flags::rust_event_loop_is_enabled;
use cxx::UniquePtr;

use crate::{
@@ -24,7 +23,6 @@ fn start(
    le_acl_manager: UniquePtr<LeAclManagerShim>,
    on_started: Pin<&'static mut Future>,
) {
    if rust_event_loop_is_enabled() {
    thread::spawn(move || {
        GlobalModuleRegistry::start(
            Rc::new(GattCallbacksImpl(gatt_server_callbacks)),
@@ -36,7 +34,6 @@ fn start(
        );
    });
}
}

fn stop() {
    let _ = GLOBAL_MODULE_REGISTRY
+4 −40
Original line number Diff line number Diff line
@@ -4,9 +4,7 @@
use std::iter::Peekable;

use anyhow::{bail, Result};
use bt_common::init_flags::{
    always_use_private_gatt_for_debugging_is_enabled, rust_event_loop_is_enabled,
};
use bt_common::init_flags::always_use_private_gatt_for_debugging_is_enabled;
use cxx::UniquePtr;
pub use inner::*;
use log::{error, info, trace, warn};
@@ -283,10 +281,6 @@ impl AttTransport for AttTransportImpl {
}

fn open_server(server_id: u8) {
    if !rust_event_loop_is_enabled() {
        return;
    }

    let server_id = ServerId(server_id);

    do_in_rust_thread(move |modules| {
@@ -303,10 +297,6 @@ fn open_server(server_id: u8) {
}

fn close_server(server_id: u8) {
    if !rust_event_loop_is_enabled() {
        return;
    }

    let server_id = ServerId(server_id);

    do_in_rust_thread(move |modules| {
@@ -368,17 +358,15 @@ fn records_to_service(service_records: &[GattRecord]) -> Result<GattServiceWithH
    }

    let Some((handle, uuid)) = service_handle_uuid else {
        bail!("got service registration but with no primary service! {characteristics:?}".to_string())
        bail!(
            "got service registration but with no primary service! {characteristics:?}".to_string()
        )
    };

    Ok(GattServiceWithHandle { handle: AttHandle(handle), type_: uuid, characteristics })
}

fn add_service(server_id: u8, service_records: Vec<GattRecord>) {
    if !rust_event_loop_is_enabled() {
        return;
    }

    // marshal into the form expected by GattModule
    let server_id = ServerId(server_id);

@@ -408,10 +396,6 @@ fn add_service(server_id: u8, service_records: Vec<GattRecord>) {
}

fn remove_service(server_id: u8, service_handle: u16) {
    if !rust_event_loop_is_enabled() {
        return;
    }

    let server_id = ServerId(server_id);
    let service_handle = AttHandle(service_handle);
    do_in_rust_thread(move |modules| {
@@ -428,18 +412,10 @@ fn remove_service(server_id: u8, service_handle: u16) {
}

fn is_connection_isolated(conn_id: u16) -> bool {
    if !rust_event_loop_is_enabled() {
        return false;
    }

    with_arbiter(|arbiter| arbiter.is_connection_isolated(ConnectionId(conn_id).get_tcb_idx()))
}

fn send_response(_server_id: u8, conn_id: u16, trans_id: u32, status: u8, value: &[u8]) {
    if !rust_event_loop_is_enabled() {
        return;
    }

    // TODO(aryarahul): fixup error codes to allow app-specific values (i.e. don't
    // make it an enum in PDL)
    let value = if status == 0 {
@@ -463,10 +439,6 @@ fn send_response(_server_id: u8, conn_id: u16, trans_id: u32, status: u8, value:
}

fn send_indication(_server_id: u8, handle: u16, conn_id: u16, value: &[u8]) {
    if !rust_event_loop_is_enabled() {
        return;
    }

    let handle = AttHandle(handle);
    let conn_id = ConnectionId(conn_id);
    let value = AttAttributeDataChild::RawData(value.into());
@@ -488,10 +460,6 @@ fn send_indication(_server_id: u8, handle: u16, conn_id: u16, value: &[u8]) {
}

fn associate_server_with_advertiser(server_id: u8, advertiser_id: u8) {
    if !rust_event_loop_is_enabled() {
        return;
    }

    let server_id = ServerId(server_id);
    let advertiser_id = AdvertiserId(advertiser_id);
    do_in_rust_thread(move |modules| {
@@ -503,10 +471,6 @@ fn associate_server_with_advertiser(server_id: u8, advertiser_id: u8) {
}

fn clear_advertiser(advertiser_id: u8) {
    if !rust_event_loop_is_enabled() {
        return;
    }

    let advertiser_id = AdvertiserId(advertiser_id);

    do_in_rust_thread(move |modules| {
+0 −5
Original line number Diff line number Diff line
@@ -15,7 +15,6 @@
//! The core event loop for Rust modules. Here Rust modules are started in
//! dependency order.

use bt_common::init_flags::rust_event_loop_is_enabled;
use connection::le_manager::InactiveLeAclManager;
use gatt::{channel::AttTransport, GattCallbacks};
use log::{info, warn};
@@ -160,10 +159,6 @@ pub fn do_in_rust_thread<F>(f: F)
where
    F: for<'a> FnOnce(&'a mut ModuleViews) + Send + 'static,
{
    if !rust_event_loop_is_enabled() {
        warn!("ignoring do_in_rust_thread() invocation since Rust loop is inactive");
        return;
    }
    let ret = MAIN_THREAD_TX.with(|tx| tx.send(MainThreadTxMessage::Callback(Box::new(f))));
    if ret.is_err() {
        panic!("Rust call failed");
Loading