Loading system/gd/rust/linux/stack/src/bluetooth_adv.rs +21 −0 Original line number Diff line number Diff line Loading @@ -396,6 +396,11 @@ pub(crate) struct AdvertisingSetInfo { /// Whether the advertising set has been paused. paused: bool, /// Whether the stop of advertising set is held. /// This happens when an advertising set is stopped when the system is suspending. /// The advertising set will be stopped on system resumed. stopped: bool, /// Advertising duration, in 10 ms unit. adv_timeout: u16, Loading Loading @@ -424,6 +429,7 @@ impl AdvertisingSetInfo { reg_id, enabled: false, paused: false, stopped: false, adv_timeout, adv_events, legacy, Loading Loading @@ -471,6 +477,16 @@ impl AdvertisingSetInfo { self.paused } /// Marks the advertising set as stopped. pub(crate) fn set_stopped(&mut self) { self.stopped = true; } /// Returns true if the advertising set has been stopped, false otherwise. pub(crate) fn is_stopped(&self) -> bool { self.stopped } /// Gets adv_timeout. pub(crate) fn adv_timeout(&self) -> u16 { self.adv_timeout Loading Loading @@ -535,6 +551,11 @@ impl Advertisers { self.valid_sets_mut().filter(|s| s.is_paused()) } /// Returns an iterator of stopped advertising sets. pub(crate) fn stopped_sets(&self) -> impl Iterator<Item = &AdvertisingSetInfo> { self.valid_sets().filter(|s| s.is_stopped()) } fn find_reg_id(&self, adv_id: AdvertiserId) -> Option<RegId> { for (_, s) in &self.sets { if s.adv_id == Some(adv_id) { Loading system/gd/rust/linux/stack/src/bluetooth_gatt.rs +17 −7 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ use bt_utils::array_utils; use crate::async_helper::{AsyncHelper, CallbackSender}; use crate::bluetooth::{Bluetooth, IBluetooth}; use crate::bluetooth_adv::{ AdvertiseData, Advertisers, AdvertisingSetInfo, AdvertisingSetParameters, AdvertiseData, AdvertiserId, Advertisers, AdvertisingSetInfo, AdvertisingSetParameters, IAdvertisingSetCallback, PeriodicAdvertisingParameters, INVALID_REG_ID, }; use crate::callbacks::Callbacks; Loading Loading @@ -1736,6 +1736,10 @@ impl BluetoothGatt { /// Exits suspend mode for LE advertising. pub fn advertising_exit_suspend(&mut self) { for id in self.advertisers.stopped_sets().map(|s| s.adv_id()).collect::<Vec<_>>() { self.gatt.as_ref().unwrap().lock().unwrap().advertiser.unregister(id); self.advertisers.remove_by_advertiser_id(id as AdvertiserId); } for s in self.advertisers.paused_sets_mut() { s.set_paused(false); self.gatt.as_ref().unwrap().lock().unwrap().advertiser.enable( Loading Loading @@ -2056,18 +2060,24 @@ impl IBluetoothGatt for BluetoothGatt { } fn stop_advertising_set(&mut self, advertiser_id: i32) { if self.advertisers.suspend_mode() != SuspendMode::Normal { let s = if let Some(s) = self.advertisers.get_by_advertiser_id(advertiser_id) { s.clone() } else { return; } }; let s = self.advertisers.get_by_advertiser_id(advertiser_id); if None == s { if self.advertisers.suspend_mode() != SuspendMode::Normal { if !s.is_stopped() { warn!("Deferred advertisement unregistering due to suspending"); self.advertisers.get_mut_by_advertiser_id(advertiser_id).unwrap().set_stopped(); if let Some(cb) = self.advertisers.get_callback(&s) { cb.on_advertising_set_stopped(advertiser_id); } } return; } let s = s.unwrap().clone(); self.gatt.as_ref().unwrap().lock().unwrap().advertiser.unregister(s.adv_id()); if let Some(cb) = self.advertisers.get_callback(&s) { cb.on_advertising_set_stopped(advertiser_id); } Loading Loading
system/gd/rust/linux/stack/src/bluetooth_adv.rs +21 −0 Original line number Diff line number Diff line Loading @@ -396,6 +396,11 @@ pub(crate) struct AdvertisingSetInfo { /// Whether the advertising set has been paused. paused: bool, /// Whether the stop of advertising set is held. /// This happens when an advertising set is stopped when the system is suspending. /// The advertising set will be stopped on system resumed. stopped: bool, /// Advertising duration, in 10 ms unit. adv_timeout: u16, Loading Loading @@ -424,6 +429,7 @@ impl AdvertisingSetInfo { reg_id, enabled: false, paused: false, stopped: false, adv_timeout, adv_events, legacy, Loading Loading @@ -471,6 +477,16 @@ impl AdvertisingSetInfo { self.paused } /// Marks the advertising set as stopped. pub(crate) fn set_stopped(&mut self) { self.stopped = true; } /// Returns true if the advertising set has been stopped, false otherwise. pub(crate) fn is_stopped(&self) -> bool { self.stopped } /// Gets adv_timeout. pub(crate) fn adv_timeout(&self) -> u16 { self.adv_timeout Loading Loading @@ -535,6 +551,11 @@ impl Advertisers { self.valid_sets_mut().filter(|s| s.is_paused()) } /// Returns an iterator of stopped advertising sets. pub(crate) fn stopped_sets(&self) -> impl Iterator<Item = &AdvertisingSetInfo> { self.valid_sets().filter(|s| s.is_stopped()) } fn find_reg_id(&self, adv_id: AdvertiserId) -> Option<RegId> { for (_, s) in &self.sets { if s.adv_id == Some(adv_id) { Loading
system/gd/rust/linux/stack/src/bluetooth_gatt.rs +17 −7 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ use bt_utils::array_utils; use crate::async_helper::{AsyncHelper, CallbackSender}; use crate::bluetooth::{Bluetooth, IBluetooth}; use crate::bluetooth_adv::{ AdvertiseData, Advertisers, AdvertisingSetInfo, AdvertisingSetParameters, AdvertiseData, AdvertiserId, Advertisers, AdvertisingSetInfo, AdvertisingSetParameters, IAdvertisingSetCallback, PeriodicAdvertisingParameters, INVALID_REG_ID, }; use crate::callbacks::Callbacks; Loading Loading @@ -1736,6 +1736,10 @@ impl BluetoothGatt { /// Exits suspend mode for LE advertising. pub fn advertising_exit_suspend(&mut self) { for id in self.advertisers.stopped_sets().map(|s| s.adv_id()).collect::<Vec<_>>() { self.gatt.as_ref().unwrap().lock().unwrap().advertiser.unregister(id); self.advertisers.remove_by_advertiser_id(id as AdvertiserId); } for s in self.advertisers.paused_sets_mut() { s.set_paused(false); self.gatt.as_ref().unwrap().lock().unwrap().advertiser.enable( Loading Loading @@ -2056,18 +2060,24 @@ impl IBluetoothGatt for BluetoothGatt { } fn stop_advertising_set(&mut self, advertiser_id: i32) { if self.advertisers.suspend_mode() != SuspendMode::Normal { let s = if let Some(s) = self.advertisers.get_by_advertiser_id(advertiser_id) { s.clone() } else { return; } }; let s = self.advertisers.get_by_advertiser_id(advertiser_id); if None == s { if self.advertisers.suspend_mode() != SuspendMode::Normal { if !s.is_stopped() { warn!("Deferred advertisement unregistering due to suspending"); self.advertisers.get_mut_by_advertiser_id(advertiser_id).unwrap().set_stopped(); if let Some(cb) = self.advertisers.get_callback(&s) { cb.on_advertising_set_stopped(advertiser_id); } } return; } let s = s.unwrap().clone(); self.gatt.as_ref().unwrap().lock().unwrap().advertiser.unregister(s.adv_id()); if let Some(cb) = self.advertisers.get_callback(&s) { cb.on_advertising_set_stopped(advertiser_id); } Loading