Loading system/gd/rust/linux/stack/src/bluetooth_media.rs +58 −6 Original line number Diff line number Diff line Loading @@ -255,6 +255,7 @@ pub struct BluetoothMedia { delay_enable_profiles: HashSet<uuid::Profile>, connected_profiles: HashMap<RawAddress, HashSet<uuid::Profile>>, device_states: Arc<Mutex<HashMap<RawAddress, DeviceConnectionStates>>>, delay_volume_update: HashMap<uuid::Profile, u8>, telephony_device_status: TelephonyDeviceStatus, phone_state: PhoneState, call_list: Vec<CallInfo>, Loading Loading @@ -301,6 +302,7 @@ impl BluetoothMedia { delay_enable_profiles: HashSet::new(), connected_profiles: HashMap::new(), device_states: Arc::new(Mutex::new(HashMap::new())), delay_volume_update: HashMap::new(), telephony_device_status: TelephonyDeviceStatus::new(), phone_state: PhoneState { num_active: 0, num_held: 0, state: CallState::Idle }, call_list: vec![], Loading Loading @@ -345,6 +347,7 @@ impl BluetoothMedia { } self.connected_profiles.entry(addr).or_insert_with(HashSet::new).remove(&profile); self.delay_volume_update.remove(&profile); if is_profile_critical && self.is_complete_profiles_required() { self.notify_critical_profile_disconnected(addr); Loading Loading @@ -566,9 +569,23 @@ impl BluetoothMedia { ); } AvrcpCallbacks::AvrcpAbsoluteVolumeUpdate(volume) => { for (addr, state) in self.device_states.lock().unwrap().iter() { info!("[{}]: state {:?}", DisplayAddress(&addr), state); match state { DeviceConnectionStates::ConnectingBeforeRetry | DeviceConnectionStates::ConnectingAfterRetry => { self.delay_volume_update.insert(Profile::AvrcpController, volume); } DeviceConnectionStates::FullyConnected => { self.delay_volume_update.remove(&Profile::AvrcpController); self.callbacks.lock().unwrap().for_all_callbacks(|callback| { callback.on_absolute_volume_changed(volume); }); return; } _ => {} } } } AvrcpCallbacks::AvrcpSendKeyEvent(key, value) => { match self.uinput.send_key(key, value) { Loading Loading @@ -714,10 +731,32 @@ impl BluetoothMedia { } } HfpCallbacks::VolumeUpdate(volume, addr) => { if self.hfp_states.get(&addr).is_none() || BthfConnectionState::SlcConnected != *self.hfp_states.get(&addr).unwrap() { warn!("[{}]: Unknown address hfp or slc not ready", addr.to_string()); return; } let states = self.device_states.lock().unwrap(); info!( "[{}]: VolumeUpdate state: {:?}", DisplayAddress(&addr), states.get(&addr).unwrap() ); match states.get(&addr).unwrap() { DeviceConnectionStates::ConnectingBeforeRetry | DeviceConnectionStates::ConnectingAfterRetry => { self.delay_volume_update.insert(Profile::Hfp, volume); } DeviceConnectionStates::FullyConnected => { self.callbacks.lock().unwrap().for_all_callbacks(|callback| { callback.on_hfp_volume_changed(volume, addr.to_string()); }); } _ => {} } } HfpCallbacks::BatteryLevelUpdate(battery_level, addr) => { let battery_set = BatterySet::new( addr.to_string(), Loading Loading @@ -895,6 +934,7 @@ impl BluetoothMedia { } }; } self.delay_volume_update.clear(); } } Loading Loading @@ -1107,8 +1147,20 @@ impl BluetoothMedia { absolute_volume, ); let hfp_volume = self.delay_volume_update.remove(&Profile::Hfp); let avrcp_volume = self.delay_volume_update.remove(&Profile::AvrcpController); self.callbacks.lock().unwrap().for_all_callbacks(|callback| { callback.on_bluetooth_audio_device_added(device.clone()); if let Some(volume) = hfp_volume { info!("Trigger HFP volume update to {}", DisplayAddress(&addr)); callback.on_hfp_volume_changed(volume, addr.to_string()); } if let Some(volume) = avrcp_volume { info!("Trigger avrcp volume update"); callback.on_absolute_volume_changed(volume); } }); guard.insert(addr, None); Loading Loading
system/gd/rust/linux/stack/src/bluetooth_media.rs +58 −6 Original line number Diff line number Diff line Loading @@ -255,6 +255,7 @@ pub struct BluetoothMedia { delay_enable_profiles: HashSet<uuid::Profile>, connected_profiles: HashMap<RawAddress, HashSet<uuid::Profile>>, device_states: Arc<Mutex<HashMap<RawAddress, DeviceConnectionStates>>>, delay_volume_update: HashMap<uuid::Profile, u8>, telephony_device_status: TelephonyDeviceStatus, phone_state: PhoneState, call_list: Vec<CallInfo>, Loading Loading @@ -301,6 +302,7 @@ impl BluetoothMedia { delay_enable_profiles: HashSet::new(), connected_profiles: HashMap::new(), device_states: Arc::new(Mutex::new(HashMap::new())), delay_volume_update: HashMap::new(), telephony_device_status: TelephonyDeviceStatus::new(), phone_state: PhoneState { num_active: 0, num_held: 0, state: CallState::Idle }, call_list: vec![], Loading Loading @@ -345,6 +347,7 @@ impl BluetoothMedia { } self.connected_profiles.entry(addr).or_insert_with(HashSet::new).remove(&profile); self.delay_volume_update.remove(&profile); if is_profile_critical && self.is_complete_profiles_required() { self.notify_critical_profile_disconnected(addr); Loading Loading @@ -566,9 +569,23 @@ impl BluetoothMedia { ); } AvrcpCallbacks::AvrcpAbsoluteVolumeUpdate(volume) => { for (addr, state) in self.device_states.lock().unwrap().iter() { info!("[{}]: state {:?}", DisplayAddress(&addr), state); match state { DeviceConnectionStates::ConnectingBeforeRetry | DeviceConnectionStates::ConnectingAfterRetry => { self.delay_volume_update.insert(Profile::AvrcpController, volume); } DeviceConnectionStates::FullyConnected => { self.delay_volume_update.remove(&Profile::AvrcpController); self.callbacks.lock().unwrap().for_all_callbacks(|callback| { callback.on_absolute_volume_changed(volume); }); return; } _ => {} } } } AvrcpCallbacks::AvrcpSendKeyEvent(key, value) => { match self.uinput.send_key(key, value) { Loading Loading @@ -714,10 +731,32 @@ impl BluetoothMedia { } } HfpCallbacks::VolumeUpdate(volume, addr) => { if self.hfp_states.get(&addr).is_none() || BthfConnectionState::SlcConnected != *self.hfp_states.get(&addr).unwrap() { warn!("[{}]: Unknown address hfp or slc not ready", addr.to_string()); return; } let states = self.device_states.lock().unwrap(); info!( "[{}]: VolumeUpdate state: {:?}", DisplayAddress(&addr), states.get(&addr).unwrap() ); match states.get(&addr).unwrap() { DeviceConnectionStates::ConnectingBeforeRetry | DeviceConnectionStates::ConnectingAfterRetry => { self.delay_volume_update.insert(Profile::Hfp, volume); } DeviceConnectionStates::FullyConnected => { self.callbacks.lock().unwrap().for_all_callbacks(|callback| { callback.on_hfp_volume_changed(volume, addr.to_string()); }); } _ => {} } } HfpCallbacks::BatteryLevelUpdate(battery_level, addr) => { let battery_set = BatterySet::new( addr.to_string(), Loading Loading @@ -895,6 +934,7 @@ impl BluetoothMedia { } }; } self.delay_volume_update.clear(); } } Loading Loading @@ -1107,8 +1147,20 @@ impl BluetoothMedia { absolute_volume, ); let hfp_volume = self.delay_volume_update.remove(&Profile::Hfp); let avrcp_volume = self.delay_volume_update.remove(&Profile::AvrcpController); self.callbacks.lock().unwrap().for_all_callbacks(|callback| { callback.on_bluetooth_audio_device_added(device.clone()); if let Some(volume) = hfp_volume { info!("Trigger HFP volume update to {}", DisplayAddress(&addr)); callback.on_hfp_volume_changed(volume, addr.to_string()); } if let Some(volume) = avrcp_volume { info!("Trigger avrcp volume update"); callback.on_absolute_volume_changed(volume); } }); guard.insert(addr, None); Loading