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

Commit 046b4c72 authored by Hsin-chen Chuang's avatar Hsin-chen Chuang Committed by Automerger Merge Worker
Browse files

Merge "floss: Construct DisplayAddress by borrowing" am: 0782e9a6 am: d2060015 am: e8b285bc

parents 555f7b4f e8b285bc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1934,7 +1934,7 @@ impl IBluetooth for Bluetooth {
        // If SDP isn't completed yet, we wait for it to complete and retry the connection again.
        // Otherwise, this connection request is done, no retry is required.
        if !has_enabled_uuids {
            warn!("[{}] SDP hasn't completed for device, wait to connect.", DisplayAddress(addr));
            warn!("[{}] SDP hasn't completed for device, wait to connect.", DisplayAddress(&addr));
            if let Some(d) = self.get_remote_device_if_found_mut(&device.address) {
                if uuids.len() == 0 || !d.services_resolved {
                    d.wait_to_connect = true;
+53 −53
Original line number Diff line number Diff line
@@ -310,7 +310,7 @@ impl BluetoothMedia {

    fn add_connected_profile(&mut self, addr: RawAddress, profile: uuid::Profile) {
        if self.is_profile_connected(&addr, &profile) {
            warn!("[{}]: profile is already connected", DisplayAddress(addr));
            warn!("[{}]: profile is already connected", DisplayAddress(&addr));
            return;
        }

@@ -326,7 +326,7 @@ impl BluetoothMedia {
        is_profile_critical: bool,
    ) {
        if !self.is_profile_connected(&addr, &profile) {
            warn!("[{}]: profile is already disconnected", DisplayAddress(addr));
            warn!("[{}]: profile is already disconnected", DisplayAddress(&addr));
            return;
        }

@@ -431,12 +431,12 @@ impl BluetoothMedia {
                );
                match state {
                    BtavConnectionState::Connected => {
                        info!("[{}]: a2dp connected.", DisplayAddress(addr));
                        info!("[{}]: a2dp connected.", DisplayAddress(&addr));
                        self.a2dp_states.insert(addr, state);
                        self.add_connected_profile(addr, uuid::Profile::A2dpSink);
                    }
                    BtavConnectionState::Disconnected => {
                        info!("[{}]: a2dp disconnected.", DisplayAddress(addr));
                        info!("[{}]: a2dp disconnected.", DisplayAddress(&addr));
                        self.a2dp_states.remove(&addr);
                        self.a2dp_caps.remove(&addr);
                        self.a2dp_audio_state.remove(&addr);
@@ -453,7 +453,7 @@ impl BluetoothMedia {
            }
            A2dpCallbacks::AudioConfig(addr, _config, _local_caps, a2dp_caps) => {
                // TODO(b/254808917): revert to debug log once fixed
                info!("[{}]: a2dp updated audio config: {:?}", DisplayAddress(addr), a2dp_caps);
                info!("[{}]: a2dp updated audio config: {:?}", DisplayAddress(&addr), a2dp_caps);
                self.a2dp_caps.insert(addr, a2dp_caps);
            }
            A2dpCallbacks::MandatoryCodecPreferred(_addr) => {}
@@ -465,12 +465,12 @@ impl BluetoothMedia {
            AvrcpCallbacks::AvrcpDeviceConnected(addr, supported) => {
                info!(
                    "[{}]: avrcp connected. Absolute volume support: {}.",
                    DisplayAddress(addr),
                    DisplayAddress(&addr),
                    supported
                );

                match self.uinput.create(self.adapter_get_remote_name(addr), addr.to_string()) {
                    Ok(()) => info!("uinput device created for: {}", DisplayAddress(addr)),
                    Ok(()) => info!("uinput device created for: {}", DisplayAddress(&addr)),
                    Err(e) => warn!("{}", e),
                }

@@ -510,7 +510,7 @@ impl BluetoothMedia {
                self.add_connected_profile(addr, uuid::Profile::AvrcpController);
            }
            AvrcpCallbacks::AvrcpDeviceDisconnected(addr) => {
                info!("[{}]: avrcp disconnected.", DisplayAddress(addr));
                info!("[{}]: avrcp disconnected.", DisplayAddress(&addr));

                self.uinput.close(addr.to_string());

@@ -589,10 +589,10 @@ impl BluetoothMedia {
                );
                match state {
                    BthfConnectionState::Connected => {
                        info!("[{}]: hfp connected.", DisplayAddress(addr));
                        info!("[{}]: hfp connected.", DisplayAddress(&addr));
                    }
                    BthfConnectionState::SlcConnected => {
                        info!("[{}]: hfp slc connected.", DisplayAddress(addr));
                        info!("[{}]: hfp slc connected.", DisplayAddress(&addr));
                        // The device may not support codec-negotiation,
                        // in which case we shall assume it supports CVSD at this point.
                        if !self.hfp_cap.contains_key(&addr) {
@@ -603,12 +603,12 @@ impl BluetoothMedia {
                        // Connect SCO if phone operations are enabled and an active call exists.
                        // This is only used for Bluetooth HFP qualification.
                        if self.phone_ops_enabled && self.phone_state.num_active > 0 {
                            debug!("[{}]: Connect SCO due to active call.", DisplayAddress(addr));
                            debug!("[{}]: Connect SCO due to active call.", DisplayAddress(&addr));
                            self.start_sco_call_impl(addr.to_string(), false, false);
                        }
                    }
                    BthfConnectionState::Disconnected => {
                        info!("[{}]: hfp disconnected.", DisplayAddress(addr));
                        info!("[{}]: hfp disconnected.", DisplayAddress(&addr));
                        self.hfp_states.remove(&addr);
                        self.hfp_cap.remove(&addr);
                        self.hfp_audio_state.remove(&addr);
@@ -616,10 +616,10 @@ impl BluetoothMedia {
                        self.disconnect(addr.to_string());
                    }
                    BthfConnectionState::Connecting => {
                        info!("[{}]: hfp connecting.", DisplayAddress(addr));
                        info!("[{}]: hfp connecting.", DisplayAddress(&addr));
                    }
                    BthfConnectionState::Disconnecting => {
                        info!("[{}]: hfp disconnecting.", DisplayAddress(addr));
                        info!("[{}]: hfp disconnecting.", DisplayAddress(&addr));
                    }
                }

@@ -629,13 +629,13 @@ impl BluetoothMedia {
                if self.hfp_states.get(&addr).is_none()
                    || BthfConnectionState::SlcConnected != *self.hfp_states.get(&addr).unwrap()
                {
                    warn!("[{}]: Unknown address hfp or slc not ready", DisplayAddress(addr));
                    warn!("[{}]: Unknown address hfp or slc not ready", DisplayAddress(&addr));
                    return;
                }

                match state {
                    BthfAudioState::Connected => {
                        info!("[{}]: hfp audio connected.", DisplayAddress(addr));
                        info!("[{}]: hfp audio connected.", DisplayAddress(&addr));

                        self.hfp_audio_state.insert(addr, state);

@@ -655,7 +655,7 @@ impl BluetoothMedia {
                        }
                    }
                    BthfAudioState::Disconnected => {
                        info!("[{}]: hfp audio disconnected.", DisplayAddress(addr));
                        info!("[{}]: hfp audio disconnected.", DisplayAddress(&addr));

                        // Ignore disconnected -> disconnected
                        if let Some(BthfAudioState::Connected) =
@@ -675,10 +675,10 @@ impl BluetoothMedia {
                        }
                    }
                    BthfAudioState::Connecting => {
                        info!("[{}]: hfp audio connecting.", DisplayAddress(addr));
                        info!("[{}]: hfp audio connecting.", DisplayAddress(&addr));
                    }
                    BthfAudioState::Disconnecting => {
                        info!("[{}]: hfp audio disconnecting.", DisplayAddress(addr));
                        info!("[{}]: hfp audio disconnecting.", DisplayAddress(&addr));
                    }
                }
            }
@@ -712,7 +712,7 @@ impl BluetoothMedia {
                    Some(hfp) => {
                        debug!(
                            "[{}]: Responding CIND query with device={:?} phone={:?}",
                            DisplayAddress(addr),
                            DisplayAddress(&addr),
                            self.telephony_device_status,
                            self.phone_state,
                        );
@@ -724,7 +724,7 @@ impl BluetoothMedia {
                        if status != BtStatus::Success {
                            warn!(
                                "[{}]: CIND response failed, status={:?}",
                                DisplayAddress(addr),
                                DisplayAddress(&addr),
                                status
                            );
                        }
@@ -737,14 +737,14 @@ impl BluetoothMedia {
                    Some(hfp) => {
                        debug!(
                            "[{}]: Responding CLCC query with call_list={:?}",
                            DisplayAddress(addr),
                            DisplayAddress(&addr),
                            self.call_list,
                        );
                        let status = hfp.current_calls_query_response(&self.call_list, addr);
                        if status != BtStatus::Success {
                            warn!(
                                "[{}]: CLCC response failed, status={:?}",
                                DisplayAddress(addr),
                                DisplayAddress(&addr),
                                status
                            );
                        }
@@ -754,17 +754,17 @@ impl BluetoothMedia {
            }
            HfpCallbacks::AnswerCall(addr) => {
                if !self.answer_call_impl() {
                    warn!("[{}]: answer_call triggered by ATA failed", DisplayAddress(addr));
                    warn!("[{}]: answer_call triggered by ATA failed", DisplayAddress(&addr));
                    return;
                }
                self.phone_state_change("".into());

                debug!("[{}]: Start SCO call due to ATA", DisplayAddress(addr));
                debug!("[{}]: Start SCO call due to ATA", DisplayAddress(&addr));
                self.start_sco_call_impl(addr.to_string(), false, false);
            }
            HfpCallbacks::HangupCall(addr) => {
                if !self.hangup_call_impl() {
                    warn!("[{}]: hangup_call triggered by AT+CHUP failed", DisplayAddress(addr));
                    warn!("[{}]: hangup_call triggered by AT+CHUP failed", DisplayAddress(&addr));
                    return;
                }
                self.phone_state_change("".into());
@@ -787,7 +787,7 @@ impl BluetoothMedia {
                    // Success means the call state has changed. Inform the LibBluetooth stack.
                    self.phone_state_change("".into());
                } else {
                    warn!("[{}]: Unexpected dialing command from HF", DisplayAddress(addr));
                    warn!("[{}]: Unexpected dialing command from HF", DisplayAddress(&addr));
                }
            }
            HfpCallbacks::CallHold(command, addr) => {
@@ -808,7 +808,7 @@ impl BluetoothMedia {
                } else {
                    warn!(
                        "[{}]: Unexpected or unsupported CHLD command {:?} from HF",
                        DisplayAddress(addr),
                        DisplayAddress(&addr),
                        command
                    );
                }
@@ -823,7 +823,7 @@ impl BluetoothMedia {
    fn notify_critical_profile_disconnected(&mut self, addr: RawAddress) {
        info!(
            "[{}]: Device connection state: {:?}.",
            DisplayAddress(addr),
            DisplayAddress(&addr),
            DeviceConnectionStates::Disconnecting
        );

@@ -837,7 +837,7 @@ impl BluetoothMedia {
                    Some((handler, _ts)) => {
                        warn!(
                            "[{}]: Device disconnected a critical profile before it was added.",
                            DisplayAddress(addr)
                            DisplayAddress(&addr)
                        );
                        handler.abort();
                        guard.insert(addr, None);
@@ -846,7 +846,7 @@ impl BluetoothMedia {
                    None => {
                        info!(
                            "[{}]: Device disconnected a critical profile, removing the device.",
                            DisplayAddress(addr)
                            DisplayAddress(&addr)
                        );
                        self.callbacks.lock().unwrap().for_all_callbacks(|callback| {
                            callback.on_bluetooth_audio_device_removed(addr.to_string());
@@ -882,7 +882,7 @@ impl BluetoothMedia {

        // Cleanup if transitioning to empty set.
        if is_profile_cleared {
            info!("[{}]: Device connection state: Disconnected.", DisplayAddress(addr));
            info!("[{}]: Device connection state: Disconnected.", DisplayAddress(&addr));
            self.connected_profiles.remove(&addr);
            states.remove(&addr);
            guard.remove(&addr);
@@ -906,7 +906,7 @@ impl BluetoothMedia {

        info!(
            "[{}]: Device connection state: {:?}.",
            DisplayAddress(addr),
            DisplayAddress(&addr),
            states.get(&addr).unwrap()
        );

@@ -930,7 +930,7 @@ impl BluetoothMedia {

                    info!(
                        "[{}]: Device connection state: {:?}.",
                        DisplayAddress(addr),
                        DisplayAddress(&addr),
                        DeviceConnectionStates::ConnectingAfterRetry
                    );

@@ -951,7 +951,7 @@ impl BluetoothMedia {

                    info!(
                        "[{}]: Device connection state: {:?}.",
                        DisplayAddress(addr),
                        DisplayAddress(&addr),
                        DeviceConnectionStates::Disconnecting
                    );

@@ -980,7 +980,7 @@ impl BluetoothMedia {

                    info!(
                        "[{}]: Device connection state: {:?}.",
                        DisplayAddress(addr),
                        DisplayAddress(&addr),
                        DeviceConnectionStates::Disconnecting
                    );

@@ -1141,7 +1141,7 @@ impl BluetoothMedia {
        match (|| -> Result<(), &str> {
            let addr = RawAddress::from_string(address.clone())
                .ok_or("Can't start sco call with bad address")?;
            info!("Start sco call for {}", DisplayAddress(addr));
            info!("Start sco call for {}", DisplayAddress(&addr));

            let hfp = self.hfp.as_mut().ok_or("Uninitialized HFP to start the sco call")?;
            if hfp.connect_audio(addr, sco_offload, force_cvsd) != 0 {
@@ -1162,7 +1162,7 @@ impl BluetoothMedia {
        match (|| -> Result<(), &str> {
            let addr = RawAddress::from_string(address.clone())
                .ok_or("Can't stop sco call with bad address")?;
            info!("Stop sco call for {}", DisplayAddress(addr));
            info!("Stop sco call for {}", DisplayAddress(&addr));
            let hfp = self.hfp.as_mut().ok_or("Uninitialized HFP to stop the sco call")?;
            hfp.disconnect_audio(addr);
            Ok(())
@@ -1181,7 +1181,7 @@ impl BluetoothMedia {
                    }
                    debug!(
                        "[{}]: Device status notification {:?}",
                        DisplayAddress(*addr),
                        DisplayAddress(addr),
                        self.telephony_device_status
                    );
                    let status =
@@ -1189,7 +1189,7 @@ impl BluetoothMedia {
                    if status != BtStatus::Success {
                        warn!(
                            "[{}]: Device status notification failed, status={:?}",
                            DisplayAddress(*addr),
                            DisplayAddress(addr),
                            status
                        );
                    }
@@ -1208,7 +1208,7 @@ impl BluetoothMedia {
                    }
                    debug!(
                        "[{}]: Phone state change state={:?} number={}",
                        DisplayAddress(*addr),
                        DisplayAddress(addr),
                        self.phone_state,
                        number
                    );
@@ -1216,7 +1216,7 @@ impl BluetoothMedia {
                    if status != BtStatus::Success {
                        warn!(
                            "[{}]: Device status notification failed, status={:?}",
                            DisplayAddress(*addr),
                            DisplayAddress(addr),
                            status
                        );
                    }
@@ -1238,7 +1238,7 @@ impl BluetoothMedia {
            Some(hfp) => {
                let status = hfp.simple_at_response(ok, addr.clone());
                if status != BtStatus::Success {
                    warn!("[{}]: AT response failed, status={:?}", DisplayAddress(addr), status);
                    warn!("[{}]: AT response failed, status={:?}", DisplayAddress(&addr), status);
                }
            }
            None => warn!("Uninitialized HFP to send AT response"),
@@ -1438,7 +1438,7 @@ impl IBluetoothMedia for BluetoothMedia {

        info!(
            "[{}]: Connecting to device, available profiles: {:?}.",
            DisplayAddress(addr),
            DisplayAddress(&addr),
            available_profiles
        );

@@ -1469,7 +1469,7 @@ impl IBluetoothMedia for BluetoothMedia {
                            }
                        }
                        None => {
                            warn!("Uninitialized A2DP to connect {}", DisplayAddress(addr));
                            warn!("Uninitialized A2DP to connect {}", DisplayAddress(&addr));
                            metrics::profile_connection_state_changed(
                                addr,
                                Profile::A2dpSink as u32,
@@ -1499,7 +1499,7 @@ impl IBluetoothMedia for BluetoothMedia {
                            }
                        }
                        None => {
                            warn!("Uninitialized HFP to connect {}", DisplayAddress(addr));
                            warn!("Uninitialized HFP to connect {}", DisplayAddress(&addr));
                            metrics::profile_connection_state_changed(
                                addr,
                                Profile::Hfp as u32,
@@ -1540,7 +1540,7 @@ impl IBluetoothMedia for BluetoothMedia {
                        }

                        None => {
                            warn!("Uninitialized AVRCP to connect {}", DisplayAddress(addr));
                            warn!("Uninitialized AVRCP to connect {}", DisplayAddress(&addr));
                            metrics::profile_connection_state_changed(
                                addr,
                                Profile::AvrcpController as u32,
@@ -1576,7 +1576,7 @@ impl IBluetoothMedia for BluetoothMedia {
            None => {
                warn!(
                    "[{}]: Ignoring disconnection request since there is no connected profile.",
                    DisplayAddress(addr)
                    DisplayAddress(&addr)
                );
                return;
            }
@@ -1609,7 +1609,7 @@ impl IBluetoothMedia for BluetoothMedia {
                            }
                        }
                        None => {
                            warn!("Uninitialized A2DP to disconnect {}", DisplayAddress(addr));
                            warn!("Uninitialized A2DP to disconnect {}", DisplayAddress(&addr));
                            metrics::profile_connection_state_changed(
                                addr,
                                Profile::A2dpSource as u32,
@@ -1639,7 +1639,7 @@ impl IBluetoothMedia for BluetoothMedia {
                            }
                        }
                        None => {
                            warn!("Uninitialized HFP to disconnect {}", DisplayAddress(addr));
                            warn!("Uninitialized HFP to disconnect {}", DisplayAddress(&addr));
                            metrics::profile_connection_state_changed(
                                addr,
                                Profile::Hfp as u32,
@@ -1676,7 +1676,7 @@ impl IBluetoothMedia for BluetoothMedia {
                        }

                        None => {
                            warn!("Uninitialized AVRCP to disconnect {}", DisplayAddress(addr));
                            warn!("Uninitialized AVRCP to disconnect {}", DisplayAddress(&addr));
                            metrics::profile_connection_state_changed(
                                addr,
                                Profile::AvrcpController as u32,
@@ -1777,7 +1777,7 @@ impl IBluetoothMedia for BluetoothMedia {
        let vol = match i8::try_from(volume) {
            Ok(val) if val <= 15 => val,
            _ => {
                warn!("[{}]: Ignore invalid volume {}", DisplayAddress(addr), volume);
                warn!("[{}]: Ignore invalid volume {}", DisplayAddress(&addr), volume);
                return;
            }
        };
@@ -1785,7 +1785,7 @@ impl IBluetoothMedia for BluetoothMedia {
        if self.hfp_states.get(&addr).is_none() {
            warn!(
                "[{}]: Ignore volume event for unconnected or disconnected HFP device",
                DisplayAddress(addr)
                DisplayAddress(&addr)
            );
            return;
        }
+2 −2
Original line number Diff line number Diff line
@@ -819,8 +819,8 @@ impl RawAddress {
}

/// Address that is safe to display in logs.
pub struct DisplayAddress(pub RawAddress);
impl Display for DisplayAddress {
pub struct DisplayAddress<'a>(pub &'a RawAddress);
impl<'a> Display for DisplayAddress<'a> {
    fn fmt(&self, f: &mut Formatter) -> Result {
        write!(f, "xx:xx:xx:xx:{:2X}:{:2X}", &self.0.address[4], &self.0.address[5])
    }