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

Commit 9bf54293 authored by Abhishek Pandit-Subedi's avatar Abhishek Pandit-Subedi Committed by Abhishek Pandit-Subedi
Browse files

floss: Change manager GetState to GetAdapterEnabled

btmanagerd has 4 internal states (on, off, turning on, turning off) but
these aren't useful to the manager clients. Thus, replace the GetState
api with a GetAdapterEnabled api which returns True only when an adapter
is fully on.

Bug: 194420996
Tag: #floss
Test: Verified on ChromeOS device
Change-Id: I69391699c64590cb93cc028100b9003b2f96d181
parent dbc63f79
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -216,8 +216,8 @@ impl IBluetoothManager for BluetoothManagerDBus {
        self.client_proxy.method_noreturn("Stop", (hci_interface,))
    }

    fn get_state(&mut self) -> i32 {
        self.client_proxy.method("GetState", ())
    fn get_adapter_enabled(&mut self, hci_interface: i32) -> bool {
        self.client_proxy.method("GetAdapterEnabled", (hci_interface,))
    }

    fn register_callback(&mut self, callback: Box<dyn IBluetoothManagerCallback + Send>) {
+4 −2
Original line number Diff line number Diff line
@@ -55,10 +55,12 @@ impl IBluetoothManager for BluetoothManager {
        self.manager_context.proxy.stop_bluetooth(hci_interface);
    }

    fn get_state(&mut self) -> i32 {
    fn get_adapter_enabled(&mut self, _hci_interface: i32) -> bool {
        let proxy = self.manager_context.proxy.clone();

        // TODO(b/189501676) - State should depend on given adapter.
        let state = proxy.get_state();
        let result = state_machine::state_to_i32(state);
        let result = state_machine::state_to_enabled(state);
        result
    }

+3 −3
Original line number Diff line number Diff line
@@ -21,9 +21,9 @@ impl IBluetoothManager for BluetoothManagerDBus {
    #[dbus_method("Stop")]
    fn stop(&mut self, _hci_interface: i32) {}

    #[dbus_method("GetState")]
    fn get_state(&mut self) -> i32 {
        0
    #[dbus_method("GetAdapterEnabled")]
    fn get_adapter_enabled(&mut self, _hci_interface: i32) -> bool {
        false
    }

    #[dbus_method("RegisterCallback")]
+5 −7
Original line number Diff line number Diff line
@@ -22,14 +22,12 @@ pub enum State {
    TurningOff = 3, // We are not notified that the Bluetooth is stopped
}

impl From<State> for i32 {
    fn from(item: State) -> i32 {
        item as i32
    }
/// Check whether adapter is enabled by checking internal state.
pub fn state_to_enabled(state: State) -> bool {
    match state {
        State::On => true,
        _ => false,
    }

pub fn state_to_i32(state: State) -> i32 {
    i32::from(state)
}

/// Adapter state actions
+2 −3
Original line number Diff line number Diff line
@@ -8,9 +8,8 @@ pub trait IBluetoothManager {
    /// Stops the Bluetooth stack.
    fn stop(&mut self, hci_interface: i32);

    /// Returns the state of Bluetooth manager.
    /// TODO: Should return an enum.
    fn get_state(&mut self) -> i32;
    /// Returns whether an adapter is enabled.
    fn get_adapter_enabled(&mut self, hci_interface: i32) -> bool;

    /// Registers a callback to the Bluetooth manager state.
    fn register_callback(&mut self, callback: Box<dyn IBluetoothManagerCallback + Send>);