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

Commit ad24d916 authored by Zhengping Jiang's avatar Zhengping Jiang
Browse files

floss: Do not allow hid wakeup when tablet mode is enabled

The power manager policy prevents wakeup from tablet mode by bluetooth
hid devices. Add the dbus call to receive updates from powerd and change
suspend type according to the tablet mode.

Bug: 286575709
Test: powerd_dbus_suspend in tablet mode
Test: mma -j32

Change-Id: Iaf1e5a8a6f7b9f9eb9ab3feec6ed4773ebc4e0a8
parent 12e4368b
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1150,6 +1150,11 @@ impl IBluetoothManager for BluetoothManagerDBus {
    fn get_floss_api_version(&mut self) -> u32 {
        dbus_generated!()
    }

    #[dbus_method("SetTabletMode")]
    fn set_tablet_mode(&mut self, tablet_mode: bool) {
        dbus_generated!()
    }
}

struct IBluetoothManagerCallbackDBus {}
+16 −1
Original line number Diff line number Diff line
@@ -2,6 +2,9 @@ use log::{error, info, warn};

use std::collections::HashMap;
use std::process::Command;
use std::sync::{Arc, Mutex};

use crate::powerd_suspend_manager::SuspendManagerContext;

use crate::iface_bluetooth_experimental::IBluetoothExperimental;
use crate::iface_bluetooth_manager::{
@@ -19,11 +22,16 @@ const INVALID_VER: u16 = 0xffff;
pub struct BluetoothManager {
    proxy: StateMachineProxy,
    callbacks: HashMap<u32, Box<dyn IBluetoothManagerCallback + Send>>,
    suspend_manager_context: Option<Arc<Mutex<SuspendManagerContext>>>,
}

impl BluetoothManager {
    pub fn new(proxy: StateMachineProxy) -> BluetoothManager {
        BluetoothManager { proxy, callbacks: HashMap::new() }
        BluetoothManager { proxy, callbacks: HashMap::new(), suspend_manager_context: None }
    }

    pub fn set_suspend_manager_context(&mut self, context: Arc<Mutex<SuspendManagerContext>>) {
        self.suspend_manager_context = Some(context);
    }

    fn is_adapter_enabled(&self, hci_device: VirtualHciIndex) -> bool {
@@ -190,6 +198,13 @@ impl IBluetoothManager for BluetoothManager {
        let minor = env!("CARGO_PKG_VERSION_MINOR").parse::<u16>().unwrap_or(INVALID_VER);
        ((major as u32) << 16) | (minor as u32)
    }

    fn set_tablet_mode(&mut self, tablet_mode: bool) {
        match &self.suspend_manager_context {
            Some(ctx) => ctx.lock().unwrap().tablet_mode = tablet_mode,
            None => warn!("Context not available to set tablet mode."),
        }
    }
}

/// Implementation of IBluetoothExperimental
+5 −0
Original line number Diff line number Diff line
@@ -76,6 +76,11 @@ impl IBluetoothManager for BluetoothManagerDBus {
    fn get_floss_api_version(&mut self) -> u32 {
        dbus_generated!()
    }

    #[dbus_method("SetTabletMode")]
    fn set_tablet_mode(&mut self, tablet_mode: bool) {
        dbus_generated!()
    }
}

/// D-Bus projection of IBluetoothManagerCallback.
+4 −0
Original line number Diff line number Diff line
@@ -51,6 +51,10 @@ pub trait IBluetoothManager {
    /// Returns Floss API verion.The MSB 16-bit is the major version and
    /// LSB 16-bit is the minor version
    fn get_floss_api_version(&mut self) -> u32;

    /// Set the tablet mode of the device. The device that is in tablet mode does not allow
    /// wakeup by the HID devices.
    fn set_tablet_mode(&mut self, tablet_mode: bool);
}

/// Interface of Bluetooth Manager callbacks.
+5 −0
Original line number Diff line number Diff line
@@ -152,6 +152,11 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {

    let mut powerd_suspend_manager = PowerdSuspendManager::new(conn.clone(), cr);

    bluetooth_manager
        .lock()
        .unwrap()
        .set_suspend_manager_context(powerd_suspend_manager.get_suspend_manager_context());

    tokio::spawn(async move {
        powerd_suspend_manager.init().await;
        powerd_suspend_manager.mainloop().await;
Loading