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

Commit 621155a0 authored by Abhishek Pandit-Subedi's avatar Abhishek Pandit-Subedi
Browse files

floss: Delay socket profile init

In order for the socket profile to init correctly, the stack must be
initialized first.

Bug: 233123287
Tag: #floss
Test: chrome-btclient creates listening socket
Change-Id: I934f7646e29a3fb0e4956996012d6cd90929ba99
parent 37dee534
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -114,8 +114,7 @@ fn main() -> Result<(), Box<dyn Error>> {
        tx.clone(),
    ))));

    let bt_sock_mgr =
        Arc::new(Mutex::new(Box::new(BluetoothSocketManager::new(intf.clone(), tx.clone()))));
    let bt_sock_mgr = Arc::new(Mutex::new(Box::new(BluetoothSocketManager::new(tx.clone()))));

    topstack::get_runtime().block_on(async {
        // Connect to D-Bus system bus.
@@ -244,6 +243,7 @@ fn main() -> Result<(), Box<dyn Error>> {
            bluetooth.enable();

            bluetooth_gatt.lock().unwrap().init_profiles(tx.clone());
            bt_sock_mgr.lock().unwrap().initialize(intf.clone());
        }

        // Serve clients forever.
+49 −33
Original line number Diff line number Diff line
@@ -423,8 +423,8 @@ pub struct BluetoothSocketManager {
    /// same runtime as RPC).
    runtime: Arc<Runtime>,

    /// Topshim interface for socket.
    sock: socket::BtSocket,
    /// Topshim interface for socket. Must call initialize for this to be valid.
    sock: Option<socket::BtSocket>,

    /// Monotonically increasing counter for socket id. Always access using
    /// `next_socket_id`.
@@ -436,8 +436,7 @@ pub struct BluetoothSocketManager {

impl BluetoothSocketManager {
    /// Constructs the IBluetooth implementation.
    pub fn new(intf: Arc<Mutex<BluetoothInterface>>, tx: Sender<Message>) -> Self {
        let sock = socket::BtSocket::new(&intf.lock().unwrap());
    pub fn new(tx: Sender<Message>) -> Self {
        let callbacks = Callbacks::new(tx.clone(), Message::SocketManagerCallbackDisconnected);
        let socket_counter: u64 = 1000;
        let futures = HashMap::new();
@@ -451,7 +450,22 @@ impl BluetoothSocketManager {
                .expect("Failed to make socket runtime."),
        );

        BluetoothSocketManager { callbacks, futures, listening, runtime, sock, socket_counter, tx }
        BluetoothSocketManager {
            callbacks,
            futures,
            listening,
            runtime,
            sock: None,
            socket_counter,
            tx,
        }
    }

    /// In order to access the underlying socket apis, we must initialize after
    /// the btif layer has initialized. Thus, this must be called after intf is
    /// init.
    pub fn initialize(&mut self, intf: Arc<Mutex<BluetoothInterface>>) {
        self.sock = Some(socket::BtSocket::new(&intf.lock().unwrap()));
    }

    // TODO(abps) - We need to save information about who the caller is so that
@@ -476,7 +490,8 @@ impl BluetoothSocketManager {
        cbid: CallbackId,
    ) -> SocketResult {
        // Create listener socket pair
        let (mut status, result) = self.sock.listen(
        let (mut status, result) =
            self.sock.as_ref().expect("Socket Manager not initialized").listen(
                socket_info.sock_type.clone(),
                socket_info.name.as_ref().unwrap_or(&String::new()).clone(),
                match socket_info.uuid {
@@ -582,7 +597,8 @@ impl BluetoothSocketManager {
        };

        // Create connecting socket pair.
        let (mut status, result) = self.sock.connect(
        let (mut status, result) =
            self.sock.as_ref().expect("Socket manager not initialized").connect(
                addr,
                socket_info.sock_type.clone(),
                match socket_info.uuid {