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

Commit 5d113f52 authored by En-Shuo Hsu's avatar En-Shuo Hsu
Browse files

Floss: Add the ResetActiveDevice interface

Also add checks to the SetActiveDevice and SetHfpActiveDevice so that we
print warning when the client tries to set active device when the
profile of the device is not connected.

BUG: 265988575
Tag: #floss
Test: ./build.py and test with a2dp and hfp device

Change-Id: I4ca845ec35c0d85ac464c65dafc2983eab84dc20
parent 452c0114
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -175,6 +175,11 @@ impl IBluetoothMedia for IBluetoothMediaDBus {
        dbus_generated!()
    }

    #[dbus_method("ResetActiveDevice")]
    fn reset_active_device(&mut self) {
        dbus_generated!()
    }

    #[dbus_method("SetHfpActiveDevice")]
    fn set_hfp_active_device(&mut self, address: String) {
        dbus_generated!()
+30 −8
Original line number Diff line number Diff line
@@ -71,6 +71,9 @@ pub trait IBluetoothMedia {
    // Set the device as the active A2DP device
    fn set_active_device(&mut self, address: String);

    // Reset the active A2DP device
    fn reset_active_device(&mut self);

    // Set the device as the active HFP device
    fn set_hfp_active_device(&mut self, address: String);

@@ -1736,11 +1739,26 @@ impl IBluetoothMedia for BluetoothMedia {
            Some(addr) => addr,
        };

        match self.a2dp.as_mut() {
            Some(a2dp) => a2dp.set_active_device(addr),
            None => warn!("Uninitialized A2DP to set active device"),
        }
        match self.a2dp_states.get(&addr) {
            Some(BtavConnectionState::Connected) => {
                if let Some(a2dp) = self.a2dp.as_mut() {
                    a2dp.set_active_device(addr);
                    self.uinput.set_active_device(addr.to_string());
                } else {
                    warn!("Uninitialized A2DP to set active device");
                }
            }
            _ => warn!("[{}] Not connected or disconnected A2DP address", address),
        };
    }

    fn reset_active_device(&mut self) {
        if let Some(a2dp) = self.a2dp.as_mut() {
            a2dp.set_active_device(RawAddress::empty());
        } else {
            warn!("Uninitialized A2DP to set active device");
        }
        self.uinput.set_active_device(RawAddress::empty().to_string());
    }

    fn set_hfp_active_device(&mut self, address: String) {
@@ -1752,11 +1770,15 @@ impl IBluetoothMedia for BluetoothMedia {
            Some(addr) => addr,
        };

        match self.hfp.as_mut() {
            Some(hfp) => {
        match self.hfp_states.get(&addr) {
            Some(BthfConnectionState::SlcConnected) => {
                if let Some(hfp) = self.hfp.as_mut() {
                    hfp.set_active_device(addr);
                } else {
                    warn!("Uninitialized HFP to set active device");
                }
            }
            None => warn!("Uninitialized HFP to set active device"),
            _ => warn!("[{}] Not connected or disconnected HFP address", address),
        }
    }

+4 −0
Original line number Diff line number Diff line
@@ -816,6 +816,10 @@ impl RawAddress {
    pub fn to_byte_arr(&self) -> [u8; 6] {
        self.address.clone()
    }

    pub fn empty() -> RawAddress {
        unsafe { bindings::RawAddress_kEmpty }
    }
}

/// Address that is safe to display in logs.