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

Commit 516d800d authored by Hsin-chen Chuang's avatar Hsin-chen Chuang
Browse files

floss: struct BluetoothDevice: Change address type to RawAddress

This brings 2 benefits:
- Make it possible to mask the address in the DBus debugging log
- Don't need to convert the type and handle error in every DBus function

Note that this doesn't really change the DBus API. From the clients'
perspective these DBus args are still String.

Bug: 342337056
Tag: #floss
Test: mmm packages/modules/Bluetooth
Test: Call CreateBond, verified masked address in the log
Test: bluetooth_AdapterQuickHealth.AVL.all_floss
Test: NearbyShare / PhoneHub / FastPair
Flag: EXEMPT, Floss-only changes
Change-Id: I576c09823aa3747a0ae8aabebcaa8293febc2420
parent 12a4317e
Loading
Loading
Loading
Loading
+43 −24
Original line number Diff line number Diff line
@@ -142,7 +142,12 @@ impl IBluetoothCallback for BtCallback {
        remote_device: BluetoothDevice,
        props: Vec<BtPropertyType>,
    ) {
        print_info!("Bluetooth properties {:?} changed for {:?}", props, remote_device);
        print_info!(
            "Bluetooth properties {:?} changed for [{}: {:?}]",
            props,
            remote_device.address.to_string(),
            remote_device.name
        );
    }

    fn on_address_changed(&mut self, addr: RawAddress) {
@@ -163,19 +168,28 @@ impl IBluetoothCallback for BtCallback {
            .lock()
            .unwrap()
            .found_devices
            .entry(remote_device.address.clone())
            .entry(remote_device.address.to_string())
            .or_insert(remote_device.clone());

        print_info!("Found device: {:?}", remote_device);
        print_info!(
            "Found device: [{}: {:?}]",
            remote_device.address.to_string(),
            remote_device.name
        );
    }

    fn on_device_cleared(&mut self, remote_device: BluetoothDevice) {
        match self.context.lock().unwrap().found_devices.remove(&remote_device.address) {
            Some(_) => print_info!("Removed device: {:?}", remote_device),
        match self.context.lock().unwrap().found_devices.remove(&remote_device.address.to_string())
        {
            Some(_) => print_info!(
                "Removed device: [{}: {:?}]",
                remote_device.address.to_string(),
                remote_device.name
            ),
            None => (),
        };

        self.context.lock().unwrap().bonded_devices.remove(&remote_device.address);
        self.context.lock().unwrap().bonded_devices.remove(&remote_device.address.to_string());
    }

    fn on_discovering_changed(&mut self, discovering: bool) {
@@ -194,9 +208,9 @@ impl IBluetoothCallback for BtCallback {
        match variant {
            BtSspVariant::PasskeyNotification | BtSspVariant::PasskeyConfirmation => {
                print_info!(
                    "Device [{}: {}] would like to pair, enter passkey on remote device: {:06}",
                    &remote_device.address,
                    &remote_device.name,
                    "Device [{}: {:?}] would like to pair, enter passkey on remote device: {:06}",
                    remote_device.address.to_string(),
                    remote_device.name,
                    passkey
                );
            }
@@ -230,9 +244,9 @@ impl IBluetoothCallback for BtCallback {

    fn on_pin_request(&mut self, remote_device: BluetoothDevice, _cod: u32, min_16_digit: bool) {
        print_info!(
            "Device [{}: {}] would like to pair, enter pin code {}",
            &remote_device.address,
            &remote_device.name,
            "Device [{}: {:?}] would like to pair, enter pin code {}",
            remote_device.address.to_string(),
            remote_device.name,
            match min_16_digit {
                true => "with at least 16 digits",
                false => "",
@@ -242,9 +256,9 @@ impl IBluetoothCallback for BtCallback {

    fn on_pin_display(&mut self, remote_device: BluetoothDevice, pincode: String) {
        print_info!(
            "Device [{}: {}] would like to pair, enter pin code {} on the remote",
            &remote_device.address,
            &remote_device.name,
            "Device [{}: {:?}] would like to pair, enter pin code {} on the remote",
            remote_device.address.to_string(),
            remote_device.name,
            pincode
        );
    }
@@ -264,7 +278,7 @@ impl IBluetoothCallback for BtCallback {
                    self.context.lock().unwrap().bonding_attempt.as_ref().cloned();
                match bonding_attempt {
                    Some(bd) => {
                        if address.to_string() == bd.address {
                        if address == bd.address {
                            self.context.lock().unwrap().bonding_attempt = None;
                        }
                    }
@@ -274,8 +288,7 @@ impl IBluetoothCallback for BtCallback {
            BtBondState::Bonding => (),
        }

        let device =
            BluetoothDevice { address: address.to_string(), name: String::from("Classic device") };
        let device = BluetoothDevice { address: address, name: String::from("Classic device") };

        // If bonded, we should also automatically connect all enabled profiles
        if BtBondState::Bonded == state.into() {
@@ -295,8 +308,9 @@ impl IBluetoothCallback for BtCallback {
        sdp_records: Vec<BtSdpRecord>,
    ) {
        print_info!(
            "SDP search of {} for UUID {} returned {} results",
            remote_device.address,
            "SDP search of [{}: {:?}] for UUID {} returned {} results",
            remote_device.address.to_string(),
            remote_device.name,
            UuidWrapper(&searched_uuid),
            sdp_records.len()
        );
@@ -357,11 +371,15 @@ impl BtConnectionCallback {

impl IBluetoothConnectionCallback for BtConnectionCallback {
    fn on_device_connected(&mut self, remote_device: BluetoothDevice) {
        print_info!("Connected: [{}]: {}", remote_device.address, remote_device.name);
        print_info!("Connected: [{}: {:?}]", remote_device.address.to_string(), remote_device.name);
    }

    fn on_device_disconnected(&mut self, remote_device: BluetoothDevice) {
        print_info!("Disconnected: [{}]: {}", remote_device.address, remote_device.name);
        print_info!(
            "Disconnected: [{}: {:?}]",
            remote_device.address.to_string(),
            remote_device.name
        );
    }
}

@@ -483,8 +501,9 @@ impl IBluetoothAdminPolicyCallback for AdminCallback {
        new_policy_effect: Option<PolicyEffect>,
    ) {
        print_info!(
            "new device policy effect. Device: {:?}. New Effect: {:?}",
            device,
            "new device policy effect. Device: [{}: {:?}]. New Effect: {:?}",
            device.address.to_string(),
            device.name,
            new_policy_effect
        );
    }
+21 −21
Original line number Diff line number Diff line
@@ -768,7 +768,7 @@ impl CommandHandler {
        match &command[..] {
            "add" => {
                let device = BluetoothDevice {
                    address: String::from(get_arg(args, 1)?),
                    address: RawAddress::from_string(get_arg(args, 1)?).ok_or("Invalid Address")?,
                    name: String::from("Classic Device"),
                };

@@ -777,7 +777,7 @@ impl CommandHandler {
                if bonding_attempt.is_some() {
                    return Err(format!(
                        "Already bonding [{}]. Cancel bonding first.",
                        bonding_attempt.as_ref().unwrap().address,
                        bonding_attempt.as_ref().unwrap().address.to_string(),
                    )
                    .into());
                }
@@ -795,7 +795,7 @@ impl CommandHandler {
            }
            "remove" => {
                let device = BluetoothDevice {
                    address: String::from(get_arg(args, 1)?),
                    address: RawAddress::from_string(get_arg(args, 1)?).ok_or("Invalid Address")?,
                    name: String::from("Classic Device"),
                };

@@ -803,7 +803,7 @@ impl CommandHandler {
            }
            "cancel" => {
                let device = BluetoothDevice {
                    address: String::from(get_arg(args, 1)?),
                    address: RawAddress::from_string(get_arg(args, 1)?).ok_or("Invalid Address")?,
                    name: String::from("Classic Device"),
                };

@@ -827,7 +827,7 @@ impl CommandHandler {
        match &command[..] {
            "connect" => {
                let device = BluetoothDevice {
                    address: String::from(get_arg(args, 1)?),
                    address: RawAddress::from_string(get_arg(args, 1)?).ok_or("Invalid Address")?,
                    name: String::from("Classic Device"),
                };

@@ -839,14 +839,14 @@ impl CommandHandler {
                    .connect_all_enabled_profiles(device.clone());

                if status == BtStatus::Success {
                    println!("Connecting to {}", &device.address);
                    println!("Connecting to {}", &device.address.to_string());
                } else {
                    println!("Can't connect to {}", &device.address);
                    println!("Can't connect to {}", &device.address.to_string());
                }
            }
            "disconnect" => {
                let device = BluetoothDevice {
                    address: String::from(get_arg(args, 1)?),
                    address: RawAddress::from_string(get_arg(args, 1)?).ok_or("Invalid Address")?,
                    name: String::from("Classic Device"),
                };

@@ -858,14 +858,14 @@ impl CommandHandler {
                    .disconnect_all_enabled_profiles(device.clone());

                if success {
                    println!("Disconnecting from {}", &device.address);
                    println!("Disconnecting from {}", &device.address.to_string());
                } else {
                    println!("Can't disconnect from {}", &device.address);
                    println!("Can't disconnect from {}", &device.address.to_string());
                }
            }
            "info" => {
                let device = BluetoothDevice {
                    address: String::from(get_arg(args, 1)?),
                    address: RawAddress::from_string(get_arg(args, 1)?).ok_or("Invalid Address")?,
                    name: String::from("Classic Device"),
                };

@@ -913,7 +913,7 @@ impl CommandHandler {
                    )
                };

                print_info!("Address: {}", &device.address);
                print_info!("Address: {}", &device.address.to_string());
                print_info!("Name: {}", name);
                print_info!("Alias: {}", alias);
                print_info!("Device Type: {:?}", device_type);
@@ -936,7 +936,7 @@ impl CommandHandler {
            "set-alias" => {
                let new_alias = get_arg(args, 2)?;
                let device = BluetoothDevice {
                    address: String::from(get_arg(args, 1)?),
                    address: RawAddress::from_string(get_arg(args, 1)?).ok_or("Invalid Address")?,
                    name: String::from(""),
                };
                let old_alias = self
@@ -959,7 +959,7 @@ impl CommandHandler {
            }
            "set-pairing-confirmation" => {
                let device = BluetoothDevice {
                    address: String::from(get_arg(args, 1)?),
                    address: RawAddress::from_string(get_arg(args, 1)?).ok_or("Invalid Address")?,
                    name: String::from(""),
                };
                let accept = match &get_arg(args, 2)?[..] {
@@ -978,7 +978,7 @@ impl CommandHandler {
            }
            "set-pairing-pin" => {
                let device = BluetoothDevice {
                    address: String::from(get_arg(args, 1)?),
                    address: RawAddress::from_string(get_arg(args, 1)?).ok_or("Invalid Address")?,
                    name: String::from(""),
                };
                let pin = get_arg(args, 2)?;
@@ -996,7 +996,7 @@ impl CommandHandler {
            }
            "set-pairing-passkey" => {
                let device = BluetoothDevice {
                    address: String::from(get_arg(args, 1)?),
                    address: RawAddress::from_string(get_arg(args, 1)?).ok_or("Invalid Address")?,
                    name: String::from(""),
                };
                let passkey = get_arg(args, 2)?;
@@ -1016,7 +1016,7 @@ impl CommandHandler {
            }
            "get-rssi" => {
                let device = BluetoothDevice {
                    address: String::from(get_arg(args, 1)?),
                    address: RawAddress::from_string(get_arg(args, 1)?).ok_or("Invalid Address")?,
                    name: String::from(""),
                };

@@ -1734,7 +1734,7 @@ impl CommandHandler {
        match &command[..] {
            "search" => {
                let device = BluetoothDevice {
                    address: String::from(get_arg(args, 1)?),
                    address: RawAddress::from_string(get_arg(args, 1)?).ok_or("Invalid Address")?,
                    name: String::from(""),
                };
                let uuid = match UuidHelper::parse_string(get_arg(args, 2)?) {
@@ -1861,7 +1861,7 @@ impl CommandHandler {
                let (addr, sock_type, psm_or_uuid) =
                    (&get_arg(args, 1)?, &get_arg(args, 2)?, &get_arg(args, 3)?);
                let device = BluetoothDevice {
                    address: String::from(*addr),
                    address: RawAddress::from_string(*addr).ok_or("Invalid Address")?,
                    name: String::from("Socket Connect Device"),
                };

@@ -2051,7 +2051,7 @@ impl CommandHandler {
                let devices =
                    self.lock_context().adapter_dbus.as_ref().unwrap().get_bonded_devices();
                for device in devices.iter() {
                    print_info!("[{:17}] {}", device.address, device.name);
                    print_info!("[{}] {}", device.address.to_string(), device.name);
                }
            }
            "found" => {
@@ -2065,7 +2065,7 @@ impl CommandHandler {
                let devices =
                    self.lock_context().adapter_dbus.as_ref().unwrap().get_connected_devices();
                for device in devices.iter() {
                    print_info!("[{:17}] {}", device.address, device.name);
                    print_info!("[{}] {}", device.address.to_string(), device.name);
                }
            }
            other => {
+1 −1
Original line number Diff line number Diff line
@@ -441,7 +441,7 @@ pub struct BluetoothGattServiceDBus {

#[dbus_propmap(BluetoothDevice)]
pub struct BluetoothDeviceDBus {
    address: String,
    address: RawAddress,
    name: String,
}

+1 −1
Original line number Diff line number Diff line
@@ -293,7 +293,7 @@ impl ClientContext {
        let bonded_devices = self.adapter_dbus.as_ref().unwrap().get_bonded_devices();

        for device in bonded_devices {
            self.bonded_devices.insert(device.address.clone(), device.clone());
            self.bonded_devices.insert(device.address.to_string(), device.clone());
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ pub struct BluetoothMixin {

#[dbus_propmap(BluetoothDevice)]
pub struct BluetoothDeviceDBus {
    address: String,
    address: RawAddress,
    name: String,
}

Loading