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

Commit 004616eb authored by Michael Sun's avatar Michael Sun
Browse files

floss: metrics: HFP/AVRCP connection state handling

Route the HFP/AVRCP profiles connection events route to the metrics
processing unit. Then, parse the event into structured metrics
compatible format.

BUG: 240781725
Tag: #floss
Test: emerge-${BOARD} floss
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: Ide9664f6e333a39a5ff74b409a38b284357474cb
parent 1ed5f88b
Loading
Loading
Loading
Loading
+126 −8
Original line number Diff line number Diff line
@@ -286,6 +286,13 @@ impl BluetoothMedia {
                    .insert(uuid::Profile::AvrcpController);

                self.notify_media_capability_updated(addr);

                metrics::profile_connection_state_changed(
                    addr,
                    Profile::AvrcpController as u32,
                    BtStatus::Success,
                    BtavConnectionState::Connected as u32,
                );
            }
            AvrcpCallbacks::AvrcpDeviceDisconnected(addr) => {
                info!("[{}]: avrcp disconnected.", addr.to_string());
@@ -307,6 +314,13 @@ impl BluetoothMedia {
                }

                self.notify_media_capability_updated(addr);

                metrics::profile_connection_state_changed(
                    addr,
                    Profile::AvrcpController as u32,
                    BtStatus::Success,
                    BtavConnectionState::Disconnected as u32,
                );
            }
            AvrcpCallbacks::AvrcpAbsoluteVolumeUpdate(volume) => {
                self.callbacks.lock().unwrap().for_all_callbacks(|callback| {
@@ -340,6 +354,12 @@ impl BluetoothMedia {
                {
                    return;
                }
                metrics::profile_connection_state_changed(
                    addr,
                    Profile::Hfp as u32,
                    BtStatus::Success,
                    state.clone() as u32,
                );
                match state {
                    BthfConnectionState::Connected => {
                        info!("[{}]: hfp connected.", addr.to_string());
@@ -762,15 +782,64 @@ impl IBluetoothMedia for BluetoothMedia {
                    };
                }
                uuid::Profile::Hfp => {
                    metrics::profile_connection_state_changed(
                        addr,
                        Profile::Hfp as u32,
                        BtStatus::Success,
                        BtavConnectionState::Connecting as u32,
                    );
                    match self.hfp.as_mut() {
                        Some(hfp) => hfp.connect(addr),
                        None => warn!("Uninitialized HFP to connect {}", address),
                        Some(hfp) => {
                            let status: BtStatus = hfp.connect(addr);
                            if BtStatus::Success != status {
                                metrics::profile_connection_state_changed(
                                    addr,
                                    Profile::Hfp as u32,
                                    status,
                                    BthfConnectionState::Disconnected as u32,
                                );
                            }
                        }
                        None => {
                            warn!("Uninitialized HFP to connect {}", address);
                            metrics::profile_connection_state_changed(
                                addr,
                                Profile::Hfp as u32,
                                BtStatus::NotReady,
                                BthfConnectionState::Disconnected as u32,
                            );
                        }
                    };
                }
                uuid::Profile::AvrcpController => {
                    metrics::profile_connection_state_changed(
                        addr,
                        Profile::AvrcpController as u32,
                        BtStatus::Success,
                        BtavConnectionState::Connecting as u32,
                    );
                    match self.avrcp.as_mut() {
                        Some(avrcp) => avrcp.connect(addr),
                        None => warn!("Uninitialized AVRCP to connect {}", address),
                        Some(avrcp) => {
                            let status: BtStatus = avrcp.connect(addr);
                            if BtStatus::Success != status {
                                metrics::profile_connection_state_changed(
                                    addr,
                                    Profile::AvrcpController as u32,
                                    status,
                                    BtavConnectionState::Disconnected as u32,
                                );
                            }
                        }

                        None => {
                            warn!("Uninitialized AVRCP to connect {}", address);
                            metrics::profile_connection_state_changed(
                                addr,
                                Profile::AvrcpController as u32,
                                BtStatus::NotReady,
                                BtavConnectionState::Disconnected as u32,
                            );
                        }
                    };
                }
                _ => warn!("Unknown profile: {:?}", profile),
@@ -835,15 +904,64 @@ impl IBluetoothMedia for BluetoothMedia {
                    };
                }
                uuid::Profile::Hfp => {
                    metrics::profile_connection_state_changed(
                        addr,
                        Profile::Hfp as u32,
                        BtStatus::Success,
                        BthfConnectionState::Disconnecting as u32,
                    );
                    match self.hfp.as_mut() {
                        Some(hfp) => hfp.disconnect(addr),
                        None => warn!("Uninitialized HFP to disconnect {}", address),
                        Some(hfp) => {
                            let status: BtStatus = hfp.disconnect(addr);
                            if BtStatus::Success != status {
                                metrics::profile_connection_state_changed(
                                    addr,
                                    Profile::Hfp as u32,
                                    status,
                                    BthfConnectionState::Disconnected as u32,
                                );
                            }
                        }
                        None => {
                            warn!("Uninitialized HFP to disconnect {}", address);
                            metrics::profile_connection_state_changed(
                                addr,
                                Profile::Hfp as u32,
                                BtStatus::NotReady,
                                BthfConnectionState::Disconnected as u32,
                            );
                        }
                    };
                }
                uuid::Profile::AvrcpController => {
                    metrics::profile_connection_state_changed(
                        addr,
                        Profile::AvrcpController as u32,
                        BtStatus::Success,
                        BtavConnectionState::Disconnecting as u32,
                    );
                    match self.avrcp.as_mut() {
                        Some(avrcp) => avrcp.disconnect(addr),
                        None => warn!("Uninitialized AVRCP to disconnect {}", address),
                        Some(avrcp) => {
                            let status: BtStatus = avrcp.disconnect(addr);
                            if BtStatus::Success != status {
                                metrics::profile_connection_state_changed(
                                    addr,
                                    Profile::AvrcpController as u32,
                                    status,
                                    BtavConnectionState::Disconnected as u32,
                                );
                            }
                        }

                        None => {
                            warn!("Uninitialized AVRCP to disconnect {}", address);
                            metrics::profile_connection_state_changed(
                                addr,
                                Profile::AvrcpController as u32,
                                BtStatus::NotReady,
                                BtavConnectionState::Disconnected as u32,
                            );
                        }
                    };
                }
                _ => warn!("Unknown profile: {:?}", profile),
+2 −2
Original line number Diff line number Diff line
@@ -295,11 +295,11 @@ void AvrcpIntf::cleanup() {
  intf_->Cleanup();
}

int AvrcpIntf::connect(RustRawAddress bt_addr) {
uint32_t AvrcpIntf::connect(RustRawAddress bt_addr) {
  RawAddress addr = rusty::CopyFromRustAddress(bt_addr);
  return intf_->ConnectDevice(addr);
}
int AvrcpIntf::disconnect(RustRawAddress bt_addr) {
uint32_t AvrcpIntf::disconnect(RustRawAddress bt_addr) {
  RawAddress addr = rusty::CopyFromRustAddress(bt_addr);
  return intf_->DisconnectDevice(addr);
}
+2 −2
Original line number Diff line number Diff line
@@ -65,8 +65,8 @@ class AvrcpIntf {

  void init();
  void cleanup();
  int connect(RustRawAddress bt_addr);
  int disconnect(RustRawAddress bt_addr);
  uint32_t connect(RustRawAddress bt_addr);
  uint32_t disconnect(RustRawAddress bt_addr);

  // interface for Audio server
  void set_volume(int8_t volume);
+2 −2
Original line number Diff line number Diff line
@@ -210,7 +210,7 @@ int HfpIntf::init() {
  return intf_->Init(DBusHeadsetCallbacks::GetInstance(intf_), 1, false);
}

int HfpIntf::connect(RustRawAddress bt_addr) {
uint32_t HfpIntf::connect(RustRawAddress bt_addr) {
  RawAddress addr = rusty::CopyFromRustAddress(bt_addr);
  return intf_->Connect(&addr);
}
@@ -231,7 +231,7 @@ int HfpIntf::set_volume(int8_t volume, RustRawAddress bt_addr) {
  return intf_->VolumeControl(headset::bthf_volume_type_t::BTHF_VOLUME_TYPE_SPK, volume, &addr);
}

int HfpIntf::disconnect(RustRawAddress bt_addr) {
uint32_t HfpIntf::disconnect(RustRawAddress bt_addr) {
  RawAddress addr = rusty::CopyFromRustAddress(bt_addr);
  return intf_->Disconnect(&addr);
}
+2 −2
Original line number Diff line number Diff line
@@ -33,11 +33,11 @@ class HfpIntf {
  HfpIntf(headset::Interface* intf) : intf_(intf){};

  int init();
  int connect(RustRawAddress bt_addr);
  uint32_t connect(RustRawAddress bt_addr);
  int connect_audio(RustRawAddress bt_addr, bool sco_offload, bool force_cvsd);
  int set_active_device(RustRawAddress bt_addr);
  int set_volume(int8_t volume, RustRawAddress bt_addr);
  int disconnect(RustRawAddress bt_addr);
  uint32_t disconnect(RustRawAddress bt_addr);
  int disconnect_audio(RustRawAddress bt_addr);
  void cleanup();

Loading