Loading system/gd/rust/linux/stack/src/bluetooth.rs +75 −1 Original line number Diff line number Diff line Loading @@ -40,7 +40,7 @@ use crate::bluetooth_admin::{BluetoothAdmin, IBluetoothAdmin}; use crate::bluetooth_media::{BluetoothMedia, IBluetoothMedia, MediaActions}; use crate::callbacks::Callbacks; use crate::uuid::{Profile, UuidHelper, HOGP}; use crate::{Message, RPCProxy}; use crate::{Message, RPCProxy, SuspendMode}; const DEFAULT_DISCOVERY_TIMEOUT_MS: u64 = 12800; const MIN_ADV_INSTANCES_FOR_MULTI_ADV: u8 = 5; Loading Loading @@ -428,6 +428,8 @@ pub struct Bluetooth { hh: Option<HidHost>, is_connectable: bool, is_discovering: bool, is_discovering_before_suspend: bool, discovery_suspend_mode: SuspendMode, local_address: Option<RawAddress>, properties: HashMap<BtPropertyType, BluetoothProperty>, profiles_ready: bool, Loading Loading @@ -468,6 +470,8 @@ impl Bluetooth { intf, is_connectable: false, is_discovering: false, is_discovering_before_suspend: false, discovery_suspend_mode: SuspendMode::Normal, local_address: None, properties: HashMap::new(), profiles_ready: false, Loading Loading @@ -782,6 +786,50 @@ impl Bluetooth { std::fs::remove_file(&file_name)?; Ok(()) } /// Set the suspend mode. pub fn set_discovery_suspend_mode(&mut self, suspend_mode: SuspendMode) { if suspend_mode != self.discovery_suspend_mode { self.discovery_suspend_mode = suspend_mode; } } /// Gets current suspend mode. pub fn get_discovery_suspend_mode(&self) -> SuspendMode { self.discovery_suspend_mode.clone() } /// Enters the suspend mode for discovery. pub fn discovery_enter_suspend(&mut self) -> BtStatus { if self.get_discovery_suspend_mode() != SuspendMode::Normal { return BtStatus::Busy; } self.set_discovery_suspend_mode(SuspendMode::Suspending); if self.is_discovering { self.is_discovering_before_suspend = true; self.cancel_discovery(); } self.set_discovery_suspend_mode(SuspendMode::Suspended); return BtStatus::Success; } /// Exits the suspend mode for discovery. pub fn discovery_exit_suspend(&mut self) -> BtStatus { if self.get_discovery_suspend_mode() != SuspendMode::Suspended { return BtStatus::Busy; } self.set_discovery_suspend_mode(SuspendMode::Resuming); if self.is_discovering_before_suspend { self.is_discovering_before_suspend = false; self.start_discovery(); } self.set_discovery_suspend_mode(SuspendMode::Normal); return BtStatus::Success; } } #[btif_callbacks_dispatcher(dispatch_base_callbacks, BaseCallbacks)] Loading Loading @@ -1041,6 +1089,16 @@ impl BtifBluetoothCallbacks for Bluetooth { self.discovering_started = Instant::now(); } // Prevent sending out discovering changes or freshness checks when // suspending. Clients don't need to be notified of discovery pausing // during suspend. They will probably try to restore it and fail. let discovery_suspend_mode = self.get_discovery_suspend_mode(); if discovery_suspend_mode != SuspendMode::Normal && discovery_suspend_mode != SuspendMode::Resuming { return; } self.callbacks.for_all_callbacks(|callback| { callback.on_discovering_changed(state == BtDiscoveryState::Started); }); Loading Loading @@ -1465,6 +1523,14 @@ impl IBluetooth for Bluetooth { return true; } let discovery_suspend_mode = self.get_discovery_suspend_mode(); if discovery_suspend_mode != SuspendMode::Normal && discovery_suspend_mode != SuspendMode::Resuming { log::warn!("start_discovery is not allowed when suspending or suspended."); return false; } self.intf.lock().unwrap().start_discovery() == 0 } Loading @@ -1476,6 +1542,14 @@ impl IBluetooth for Bluetooth { return false; } let discovery_suspend_mode = self.get_discovery_suspend_mode(); if discovery_suspend_mode != SuspendMode::Normal && discovery_suspend_mode != SuspendMode::Suspending { log::warn!("cancel_discovery is not allowed when resuming or suspended."); return false; } self.intf.lock().unwrap().cancel_discovery() == 0 } Loading system/gd/rust/linux/stack/src/suspend.rs +2 −0 Original line number Diff line number Diff line Loading @@ -188,6 +188,7 @@ impl ISuspend for Suspend { self.intf.lock().unwrap().clear_event_filter(); self.intf.lock().unwrap().clear_filter_accept_list(); self.bt.lock().unwrap().discovery_enter_suspend(); self.gatt.lock().unwrap().advertising_enter_suspend(); self.gatt.lock().unwrap().scan_enter_suspend(); Loading Loading @@ -280,6 +281,7 @@ impl ISuspend for Suspend { })); } self.bt.lock().unwrap().discovery_exit_suspend(); self.gatt.lock().unwrap().advertising_exit_suspend(); self.gatt.lock().unwrap().scan_exit_suspend(); Loading Loading
system/gd/rust/linux/stack/src/bluetooth.rs +75 −1 Original line number Diff line number Diff line Loading @@ -40,7 +40,7 @@ use crate::bluetooth_admin::{BluetoothAdmin, IBluetoothAdmin}; use crate::bluetooth_media::{BluetoothMedia, IBluetoothMedia, MediaActions}; use crate::callbacks::Callbacks; use crate::uuid::{Profile, UuidHelper, HOGP}; use crate::{Message, RPCProxy}; use crate::{Message, RPCProxy, SuspendMode}; const DEFAULT_DISCOVERY_TIMEOUT_MS: u64 = 12800; const MIN_ADV_INSTANCES_FOR_MULTI_ADV: u8 = 5; Loading Loading @@ -428,6 +428,8 @@ pub struct Bluetooth { hh: Option<HidHost>, is_connectable: bool, is_discovering: bool, is_discovering_before_suspend: bool, discovery_suspend_mode: SuspendMode, local_address: Option<RawAddress>, properties: HashMap<BtPropertyType, BluetoothProperty>, profiles_ready: bool, Loading Loading @@ -468,6 +470,8 @@ impl Bluetooth { intf, is_connectable: false, is_discovering: false, is_discovering_before_suspend: false, discovery_suspend_mode: SuspendMode::Normal, local_address: None, properties: HashMap::new(), profiles_ready: false, Loading Loading @@ -782,6 +786,50 @@ impl Bluetooth { std::fs::remove_file(&file_name)?; Ok(()) } /// Set the suspend mode. pub fn set_discovery_suspend_mode(&mut self, suspend_mode: SuspendMode) { if suspend_mode != self.discovery_suspend_mode { self.discovery_suspend_mode = suspend_mode; } } /// Gets current suspend mode. pub fn get_discovery_suspend_mode(&self) -> SuspendMode { self.discovery_suspend_mode.clone() } /// Enters the suspend mode for discovery. pub fn discovery_enter_suspend(&mut self) -> BtStatus { if self.get_discovery_suspend_mode() != SuspendMode::Normal { return BtStatus::Busy; } self.set_discovery_suspend_mode(SuspendMode::Suspending); if self.is_discovering { self.is_discovering_before_suspend = true; self.cancel_discovery(); } self.set_discovery_suspend_mode(SuspendMode::Suspended); return BtStatus::Success; } /// Exits the suspend mode for discovery. pub fn discovery_exit_suspend(&mut self) -> BtStatus { if self.get_discovery_suspend_mode() != SuspendMode::Suspended { return BtStatus::Busy; } self.set_discovery_suspend_mode(SuspendMode::Resuming); if self.is_discovering_before_suspend { self.is_discovering_before_suspend = false; self.start_discovery(); } self.set_discovery_suspend_mode(SuspendMode::Normal); return BtStatus::Success; } } #[btif_callbacks_dispatcher(dispatch_base_callbacks, BaseCallbacks)] Loading Loading @@ -1041,6 +1089,16 @@ impl BtifBluetoothCallbacks for Bluetooth { self.discovering_started = Instant::now(); } // Prevent sending out discovering changes or freshness checks when // suspending. Clients don't need to be notified of discovery pausing // during suspend. They will probably try to restore it and fail. let discovery_suspend_mode = self.get_discovery_suspend_mode(); if discovery_suspend_mode != SuspendMode::Normal && discovery_suspend_mode != SuspendMode::Resuming { return; } self.callbacks.for_all_callbacks(|callback| { callback.on_discovering_changed(state == BtDiscoveryState::Started); }); Loading Loading @@ -1465,6 +1523,14 @@ impl IBluetooth for Bluetooth { return true; } let discovery_suspend_mode = self.get_discovery_suspend_mode(); if discovery_suspend_mode != SuspendMode::Normal && discovery_suspend_mode != SuspendMode::Resuming { log::warn!("start_discovery is not allowed when suspending or suspended."); return false; } self.intf.lock().unwrap().start_discovery() == 0 } Loading @@ -1476,6 +1542,14 @@ impl IBluetooth for Bluetooth { return false; } let discovery_suspend_mode = self.get_discovery_suspend_mode(); if discovery_suspend_mode != SuspendMode::Normal && discovery_suspend_mode != SuspendMode::Suspending { log::warn!("cancel_discovery is not allowed when resuming or suspended."); return false; } self.intf.lock().unwrap().cancel_discovery() == 0 } Loading
system/gd/rust/linux/stack/src/suspend.rs +2 −0 Original line number Diff line number Diff line Loading @@ -188,6 +188,7 @@ impl ISuspend for Suspend { self.intf.lock().unwrap().clear_event_filter(); self.intf.lock().unwrap().clear_filter_accept_list(); self.bt.lock().unwrap().discovery_enter_suspend(); self.gatt.lock().unwrap().advertising_enter_suspend(); self.gatt.lock().unwrap().scan_enter_suspend(); Loading Loading @@ -280,6 +281,7 @@ impl ISuspend for Suspend { })); } self.bt.lock().unwrap().discovery_exit_suspend(); self.gatt.lock().unwrap().advertising_exit_suspend(); self.gatt.lock().unwrap().scan_exit_suspend(); Loading