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

Commit fe803047 authored by Sonny Sasaka's avatar Sonny Sasaka Committed by Automerger Merge Worker
Browse files

Merge changes I744d2ba5,Ieae1a882,Id7604ce3,If99a05bd,I27190251, ... am:...

Merge changes I744d2ba5,Ieae1a882,Id7604ce3,If99a05bd,I27190251, ... am: 5464529f am: 24c3430c am: 7c3dce85 am: f31374c7

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2058063



Change-Id: I77a8704678d2a1f0e59c8b04397ea917cf31ac61
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 562d1091 f31374c7
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -248,6 +248,7 @@ class HostBuild():
        self.env['CARGO_HOME'] = os.path.join(self.output_dir, 'cargo_home')
        self.env['RUSTFLAGS'] = self._generate_rustflags()
        self.env['CXX_ROOT_PATH'] = os.path.join(self.platform_dir, 'bt')
        self.env['CROS_SYSTEM_API_ROOT'] = os.path.join(self.platform_dir, 'system_api')

    def run_command(self, target, args, cwd=None, env=None):
        """ Run command and stream the output.
@@ -608,6 +609,7 @@ class Bootstrap():
        # Symlink things
        symlinks = [
            (os.path.join(self.git_dir, 'platform2', 'common-mk'), os.path.join(self.staging_dir, 'common-mk')),
            (os.path.join(self.git_dir, 'platform2', 'system_api'), os.path.join(self.staging_dir, 'system_api')),
            (os.path.join(self.git_dir, 'platform2', '.gn'), os.path.join(self.staging_dir, '.gn')),
            (os.path.join(self.bt_dir), os.path.join(self.staging_dir, 'bt')),
            (os.path.join(self.git_dir, 'rust_crates'), os.path.join(self.external_dir, 'rust')),
+1 −1
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ impl IBluetoothManagerCallback for BtManagerCallback {
    }
}

impl manager_service::RPCProxy for BtManagerCallback {
impl RPCProxy for BtManagerCallback {
    fn register_disconnect(&mut self, _f: Box<dyn Fn(u32) + Send>) -> u32 {
        0
    }
+32 −80
Original line number Diff line number Diff line
@@ -11,14 +11,15 @@ use btstack::bluetooth_gatt::{
    GattWriteRequestStatus, GattWriteType, IBluetoothGatt, IBluetoothGattCallback,
    IScannerCallback, LePhy, ScanFilter, ScanSettings,
};
use btstack::RPCProxy;

use btstack::suspend::{ISuspend, ISuspendCallback, SuspendType};

use btstack::uuid::Profile;
use dbus::arg::{AppendAll, RefArg};
use dbus::arg::RefArg;
use dbus::nonblock::SyncConnection;

use dbus_projection::{impl_dbus_arg_enum, DisconnectWatcher};
use dbus_projection::{impl_dbus_arg_enum, ClientDBusProxy, DisconnectWatcher};

use dbus_macros::{
    dbus_method, dbus_propmap, generate_dbus_exporter, generate_dbus_interface_client,
@@ -100,59 +101,10 @@ pub struct BluetoothDeviceDBus {
    name: String,
}

struct ClientDBusProxy {
    conn: Arc<SyncConnection>,
    bus_name: String,
    objpath: dbus::Path<'static>,
    interface: String,
}

impl ClientDBusProxy {
    fn create_proxy(&self) -> dbus::nonblock::Proxy<Arc<SyncConnection>> {
        let conn = self.conn.clone();
        dbus::nonblock::Proxy::new(
            self.bus_name.clone(),
            self.objpath.clone(),
            std::time::Duration::from_secs(2),
            conn,
        )
    }

    /// Calls a method and returns the dbus result.
    fn method_withresult<A: AppendAll, T: 'static + dbus::arg::Arg + for<'z> dbus::arg::Get<'z>>(
        &self,
        member: &str,
        args: A,
    ) -> Result<(T,), dbus::Error> {
        let proxy = self.create_proxy();
        // We know that all APIs return immediately, so we can block on it for simplicity.
        return futures::executor::block_on(async {
            proxy.method_call(self.interface.clone(), member, args).await
        });
    }

    fn method<A: AppendAll, T: 'static + dbus::arg::Arg + for<'z> dbus::arg::Get<'z>>(
        &self,
        member: &str,
        args: A,
    ) -> T {
        let (ret,): (T,) = self.method_withresult(member, args).unwrap();
        return ret;
    }

    fn method_noreturn<A: AppendAll>(&self, member: &str, args: A) {
        // The real type should be Result<((),), _> since there is no return value. However, to
        // meet trait constraints, we just use bool and never unwrap the result. This calls the
        // method, waits for the response but doesn't actually attempt to parse the result (on
        // unwrap).
        let _: Result<(bool,), _> = self.method_withresult(member, args);
    }
}

#[allow(dead_code)]
struct IBluetoothCallbackDBus {}

impl btstack::RPCProxy for IBluetoothCallbackDBus {
impl RPCProxy for IBluetoothCallbackDBus {
    // Dummy implementations just to satisfy impl RPCProxy requirements.
    fn register_disconnect(&mut self, _f: Box<dyn Fn(u32) + Send>) -> u32 {
        0
@@ -206,7 +158,7 @@ impl IBluetoothCallback for IBluetoothCallbackDBus {
#[allow(dead_code)]
struct IBluetoothConnectionCallbackDBus {}

impl btstack::RPCProxy for IBluetoothConnectionCallbackDBus {
impl RPCProxy for IBluetoothConnectionCallbackDBus {
    // Dummy implementations just to satisfy impl RPCProxy requirements.
    fn register_disconnect(&mut self, _f: Box<dyn Fn(u32) + Send>) -> u32 {
        0
@@ -239,12 +191,12 @@ pub(crate) struct BluetoothDBus {
impl BluetoothDBus {
    pub(crate) fn new(conn: Arc<SyncConnection>, index: i32) -> BluetoothDBus {
        BluetoothDBus {
            client_proxy: ClientDBusProxy {
                conn: conn.clone(),
                bus_name: String::from("org.chromium.bluetooth"),
                objpath: make_object_path(index, "adapter"),
                interface: String::from("org.chromium.bluetooth.Bluetooth"),
            },
            client_proxy: ClientDBusProxy::new(
                conn.clone(),
                String::from("org.chromium.bluetooth"),
                make_object_path(index, "adapter"),
                String::from("org.chromium.bluetooth.Bluetooth"),
            ),
        }
    }
}
@@ -468,12 +420,12 @@ pub(crate) struct BluetoothManagerDBus {
impl BluetoothManagerDBus {
    pub(crate) fn new(conn: Arc<SyncConnection>) -> BluetoothManagerDBus {
        BluetoothManagerDBus {
            client_proxy: ClientDBusProxy {
                conn: conn.clone(),
                bus_name: String::from("org.chromium.bluetooth.Manager"),
                objpath: dbus::Path::new("/org/chromium/bluetooth/Manager").unwrap(),
                interface: String::from("org.chromium.bluetooth.Manager"),
            },
            client_proxy: ClientDBusProxy::new(
                conn.clone(),
                String::from("org.chromium.bluetooth.Manager"),
                dbus::Path::new("/org/chromium/bluetooth/Manager").unwrap(),
                String::from("org.chromium.bluetooth.Manager"),
            ),
        }
    }

@@ -524,7 +476,7 @@ impl IBluetoothManager for BluetoothManagerDBus {
#[allow(dead_code)]
struct IBluetoothManagerCallbackDBus {}

impl manager_service::RPCProxy for IBluetoothManagerCallbackDBus {
impl RPCProxy for IBluetoothManagerCallbackDBus {
    // Placeholder implementations just to satisfy impl RPCProxy requirements.
    fn register_disconnect(&mut self, _f: Box<dyn Fn(u32) + Send>) -> u32 {
        0
@@ -557,12 +509,12 @@ pub(crate) struct BluetoothGattDBus {
impl BluetoothGattDBus {
    pub(crate) fn new(conn: Arc<SyncConnection>, index: i32) -> BluetoothGattDBus {
        BluetoothGattDBus {
            client_proxy: ClientDBusProxy {
                conn: conn.clone(),
                bus_name: String::from("org.chromium.bluetooth"),
                objpath: make_object_path(index, "gatt"),
                interface: String::from("org.chromium.bluetooth.BluetoothGatt"),
            },
            client_proxy: ClientDBusProxy::new(
                conn.clone(),
                String::from("org.chromium.bluetooth"),
                make_object_path(index, "gatt"),
                String::from("org.chromium.bluetooth.BluetoothGatt"),
            ),
        }
    }
}
@@ -742,7 +694,7 @@ impl IBluetoothGatt for BluetoothGattDBus {
#[allow(dead_code)]
struct IBluetoothGattCallbackDBus {}

impl btstack::RPCProxy for IBluetoothGattCallbackDBus {
impl RPCProxy for IBluetoothGattCallbackDBus {
    // Placeholder implementations just to satisfy impl RPCProxy requirements.
    fn register_disconnect(&mut self, _f: Box<dyn Fn(u32) + Send>) -> u32 {
        0
@@ -829,12 +781,12 @@ pub(crate) struct SuspendDBus {
impl SuspendDBus {
    pub(crate) fn new(conn: Arc<SyncConnection>, index: i32) -> SuspendDBus {
        SuspendDBus {
            client_proxy: ClientDBusProxy {
                conn: conn.clone(),
                bus_name: String::from("org.chromium.bluetooth"),
                objpath: make_object_path(index, "suspend"),
                interface: String::from("org.chromium.bluetooth.Suspend"),
            },
            client_proxy: ClientDBusProxy::new(
                conn.clone(),
                String::from("org.chromium.bluetooth"),
                make_object_path(index, "suspend"),
                String::from("org.chromium.bluetooth.Suspend"),
            ),
        }
    }
}
@@ -865,7 +817,7 @@ impl ISuspend for SuspendDBus {
#[allow(dead_code)]
struct ISuspendCallbackDBus {}

impl btstack::RPCProxy for ISuspendCallbackDBus {
impl RPCProxy for ISuspendCallbackDBus {
    // Placeholder implementations just to satisfy impl RPCProxy requirements.
    fn register_disconnect(&mut self, _f: Box<dyn Fn(u32) + Send>) -> u32 {
        0
+1 −0
Original line number Diff line number Diff line
@@ -7,3 +7,4 @@ edition = "2018"
dbus_macros = { path = "dbus_macros" }
dbus = "0.9.2"
dbus-tokio = "0.7.3"
futures = "0.3.13"
+66 −0
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@
//!   passing in the object path, D-Bus connection, Crossroads object, the Rust object to be
//!   projected, and a [`DisconnectWatcher`](DisconnectWatcher) object.

use dbus::arg::AppendAll;
use dbus::channel::MatchingReceiver;
use dbus::message::MatchRule;
use dbus::nonblock::SyncConnection;
@@ -155,6 +156,71 @@ impl DisconnectWatcher {
    }
}

/// A client proxy to conveniently call API methods generated with the
/// [`generate_dbus_interface_client`](dbus_macros::generate_dbus_interface_client) macro.
pub struct ClientDBusProxy {
    conn: Arc<SyncConnection>,
    bus_name: String,
    objpath: dbus::Path<'static>,
    interface: String,
}

impl ClientDBusProxy {
    pub fn new(
        conn: Arc<SyncConnection>,
        bus_name: String,
        objpath: dbus::Path<'static>,
        interface: String,
    ) -> Self {
        Self { conn, bus_name, objpath, interface }
    }

    fn create_proxy(&self) -> dbus::nonblock::Proxy<Arc<SyncConnection>> {
        let conn = self.conn.clone();
        dbus::nonblock::Proxy::new(
            self.bus_name.clone(),
            self.objpath.clone(),
            std::time::Duration::from_secs(2),
            conn,
        )
    }

    /// Calls the method and returns the D-Bus result and lets the caller unwrap.
    pub fn method_withresult<
        A: AppendAll,
        T: 'static + dbus::arg::Arg + for<'z> dbus::arg::Get<'z>,
    >(
        &self,
        member: &str,
        args: A,
    ) -> Result<(T,), dbus::Error> {
        let proxy = self.create_proxy();
        // We know that all APIs return immediately, so we can block on it for simplicity.
        return futures::executor::block_on(async {
            proxy.method_call(self.interface.clone(), member, args).await
        });
    }

    /// Calls the method and unwrap the returned D-Bus result.
    pub fn method<A: AppendAll, T: 'static + dbus::arg::Arg + for<'z> dbus::arg::Get<'z>>(
        &self,
        member: &str,
        args: A,
    ) -> T {
        let (ret,): (T,) = self.method_withresult(member, args).unwrap();
        return ret;
    }

    /// Calls the void method and does not need to unwrap the result.
    pub fn method_noreturn<A: AppendAll>(&self, member: &str, args: A) {
        // The real type should be Result<((),), _> since there is no return value. However, to
        // meet trait constraints, we just use bool and never unwrap the result. This calls the
        // method, waits for the response but doesn't actually attempt to parse the result (on
        // unwrap).
        let _: Result<(bool,), _> = self.method_withresult(member, args);
    }
}

/// Implements `DBusArg` for an enum.
///
/// A Rust enum is converted to D-Bus INT32 type.
Loading