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

Commit 7d8e58e9 authored by Hsin-chen Chuang's avatar Hsin-chen Chuang
Browse files

floss client: Fix clippy warnings

- warning: this `MutexGuard` is held across an `await` point
- warning: this function has too many arguments (9/7)
- warning: you seem to be trying to use `match` for destructuring a
           single pattern. Consider using `if let`
- warning: use of a disallowed/placeholder name `foo`
- warning: writing `&Vec` instead of `&[_]` involves a new object where
           a slice will do
- warning: `format!` in `println!` args
- warning: name `NONE` contains a capitalized acronym

Bug: 343315863
Tag: #floss
Test: mmm packages/modules/Bluetooth
Test: ./build.py --target test
Test: Deploy to Guybrush, played with btclient command
Flag: EXEMPT, Floss-only changes
Change-Id: Ieffd57244636ced2da057555c2de4a0ef8f4a839
parent 8076aa18
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -5,7 +5,7 @@ use bt_topshim::profiles::gatt::LePhy;
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone)]
pub enum AuthReq {
pub enum AuthReq {
    // reference to system/stack/include/gatt_api.h
    // reference to system/stack/include/gatt_api.h
    NONE = 0,
    NoEnc = 0,
    EncNoMitm = 1,
    EncNoMitm = 1,
    EncMitm = 2,
    EncMitm = 2,
    SignedNoMitm = 3,
    SignedNoMitm = 3,
@@ -38,7 +38,7 @@ impl GattClientContext {
    pub(crate) fn new() -> Self {
    pub(crate) fn new() -> Self {
        GattClientContext {
        GattClientContext {
            client_id: None,
            client_id: None,
            auth_req: AuthReq::NONE,
            auth_req: AuthReq::NoEnc,
            is_connect_direct: false,
            is_connect_direct: false,
            connect_transport: BtTransport::Le,
            connect_transport: BtTransport::Le,
            connect_opportunistic: false,
            connect_opportunistic: false,
+22 −23
Original line number Original line Diff line number Diff line
@@ -176,15 +176,20 @@ impl IBluetoothCallback for BtCallback {
    }
    }


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


        self.context.lock().unwrap().bonded_devices.remove(&remote_device.address.to_string());
        self.context.lock().unwrap().bonded_devices.remove(&remote_device.address.to_string());
    }
    }
@@ -217,8 +222,7 @@ impl IBluetoothCallback for BtCallback {
                    // Auto-confirm bonding attempts that were locally initiated.
                    // Auto-confirm bonding attempts that were locally initiated.
                    // Ignore all other bonding attempts.
                    // Ignore all other bonding attempts.
                    let bonding_device = context.lock().unwrap().bonding_attempt.as_ref().cloned();
                    let bonding_device = context.lock().unwrap().bonding_attempt.as_ref().cloned();
                    match bonding_device {
                    if let Some(bd) = bonding_device {
                        Some(bd) => {
                        if bd.address == rd.address {
                        if bd.address == rd.address {
                            context
                            context
                                .lock()
                                .lock()
@@ -229,8 +233,6 @@ impl IBluetoothCallback for BtCallback {
                                .set_pairing_confirmation(rd.clone(), true);
                                .set_pairing_confirmation(rd.clone(), true);
                        }
                        }
                    }
                    }
                        None => (),
                    }
                }));
                }));
            }
            }
            BtSspVariant::PasskeyEntry => {
            BtSspVariant::PasskeyEntry => {
@@ -273,14 +275,11 @@ impl IBluetoothCallback for BtCallback {
            BtBondState::NotBonded | BtBondState::Bonded => {
            BtBondState::NotBonded | BtBondState::Bonded => {
                let bonding_attempt =
                let bonding_attempt =
                    self.context.lock().unwrap().bonding_attempt.as_ref().cloned();
                    self.context.lock().unwrap().bonding_attempt.as_ref().cloned();
                match bonding_attempt {
                if let Some(bd) = bonding_attempt {
                    Some(bd) => {
                    if address == bd.address {
                    if address == bd.address {
                        self.context.lock().unwrap().bonding_attempt = None;
                        self.context.lock().unwrap().bonding_attempt = None;
                    }
                    }
                }
                }
                    None => (),
                }
            }
            }
            BtBondState::Bonding => (),
            BtBondState::Bonding => (),
        }
        }
+27 −27
Original line number Original line Diff line number Diff line
@@ -62,9 +62,9 @@ impl From<String> for CommandError {


type CommandResult = Result<(), CommandError>;
type CommandResult = Result<(), CommandError>;


type CommandFunction = fn(&mut CommandHandler, &Vec<String>) -> CommandResult;
type CommandFunction = fn(&mut CommandHandler, &[String]) -> CommandResult;


fn _noop(_handler: &mut CommandHandler, _args: &Vec<String>) -> CommandResult {
fn _noop(_handler: &mut CommandHandler, _args: &[String]) -> CommandResult {
    // Used so we can add options with no direct function
    // Used so we can add options with no direct function
    // e.g. help and quit
    // e.g. help and quit
    Ok(())
    Ok(())
@@ -406,7 +406,7 @@ fn build_commands() -> HashMap<String, CommandOption> {
// Use this to safely index an argument and conveniently return the error if the argument does not
// Use this to safely index an argument and conveniently return the error if the argument does not
// exist.
// exist.
fn get_arg<I>(
fn get_arg<I>(
    args: &Vec<String>,
    args: &[String],
    index: I,
    index: I,
) -> Result<&<I as SliceIndex<[String]>>::Output, CommandError>
) -> Result<&<I as SliceIndex<[String]>>::Output, CommandError>
where
where
@@ -422,7 +422,7 @@ impl CommandHandler {
    }
    }


    /// Entry point for command and arguments
    /// Entry point for command and arguments
    pub fn process_cmd_line(&mut self, command: &str, args: &Vec<String>) -> bool {
    pub fn process_cmd_line(&mut self, command: &str, args: &[String]) -> bool {
        // Ignore empty line
        // Ignore empty line
        match command {
        match command {
            "" => false,
            "" => false,
@@ -463,7 +463,7 @@ impl CommandHandler {
        .into()
        .into()
    }
    }


    fn cmd_help(&mut self, args: &Vec<String>) -> CommandResult {
    fn cmd_help(&mut self, args: &[String]) -> CommandResult {
        if let Some(command) = args.first() {
        if let Some(command) = args.first() {
            match self.command_options.get(command) {
            match self.command_options.get(command) {
                Some(cmd) => {
                Some(cmd) => {
@@ -477,7 +477,7 @@ impl CommandHandler {
                }
                }
                None => {
                None => {
                    println!("'{}' is an invalid command!", command);
                    println!("'{}' is an invalid command!", command);
                    self.cmd_help(&vec![]).ok();
                    self.cmd_help(&[]).ok();
                }
                }
            }
            }
        } else {
        } else {
@@ -489,11 +489,11 @@ impl CommandHandler {


            // Header
            // Header
            println!(
            println!(
                "\n{}\n{}\n{}\n{}",
                "\n{}\n{}\n+{}+\n{}",
                equal_bar,
                equal_bar,
                wrap_help_text("Help Menu", MAX_MENU_CHAR_WIDTH, 2),
                wrap_help_text("Help Menu", MAX_MENU_CHAR_WIDTH, 2),
                // Minus bar
                // Minus bar
                format!("+{}+", BAR2_CHAR.repeat(MAX_MENU_CHAR_WIDTH)),
                BAR2_CHAR.repeat(MAX_MENU_CHAR_WIDTH),
                empty_bar
                empty_bar
            );
            );


@@ -514,7 +514,7 @@ impl CommandHandler {
        Ok(())
        Ok(())
    }
    }


    fn cmd_adapter(&mut self, args: &Vec<String>) -> CommandResult {
    fn cmd_adapter(&mut self, args: &[String]) -> CommandResult {
        if !self.lock_context().manager_dbus.get_floss_enabled() {
        if !self.lock_context().manager_dbus.get_floss_enabled() {
            return Err("Floss is not enabled. First run, `floss enable`".into());
            return Err("Floss is not enabled. First run, `floss enable`".into());
        }
        }
@@ -665,7 +665,7 @@ impl CommandHandler {
        Ok(())
        Ok(())
    }
    }


    fn cmd_get_address(&mut self, _args: &Vec<String>) -> CommandResult {
    fn cmd_get_address(&mut self, _args: &[String]) -> CommandResult {
        if !self.lock_context().adapter_ready {
        if !self.lock_context().adapter_ready {
            return Err(self.adapter_not_ready());
            return Err(self.adapter_not_ready());
        }
        }
@@ -675,7 +675,7 @@ impl CommandHandler {
        Ok(())
        Ok(())
    }
    }


    fn cmd_discovery(&mut self, args: &Vec<String>) -> CommandResult {
    fn cmd_discovery(&mut self, args: &[String]) -> CommandResult {
        if !self.lock_context().adapter_ready {
        if !self.lock_context().adapter_ready {
            return Err(self.adapter_not_ready());
            return Err(self.adapter_not_ready());
        }
        }
@@ -695,7 +695,7 @@ impl CommandHandler {
        Ok(())
        Ok(())
    }
    }


    fn cmd_battery(&mut self, args: &Vec<String>) -> CommandResult {
    fn cmd_battery(&mut self, args: &[String]) -> CommandResult {
        if !self.lock_context().adapter_ready {
        if !self.lock_context().adapter_ready {
            return Err(self.adapter_not_ready());
            return Err(self.adapter_not_ready());
        }
        }
@@ -766,7 +766,7 @@ impl CommandHandler {
        Ok(())
        Ok(())
    }
    }


    fn cmd_bond(&mut self, args: &Vec<String>) -> CommandResult {
    fn cmd_bond(&mut self, args: &[String]) -> CommandResult {
        if !self.lock_context().adapter_ready {
        if !self.lock_context().adapter_ready {
            return Err(self.adapter_not_ready());
            return Err(self.adapter_not_ready());
        }
        }
@@ -825,7 +825,7 @@ impl CommandHandler {
        Ok(())
        Ok(())
    }
    }


    fn cmd_device(&mut self, args: &Vec<String>) -> CommandResult {
    fn cmd_device(&mut self, args: &[String]) -> CommandResult {
        if !self.lock_context().adapter_ready {
        if !self.lock_context().adapter_ready {
            return Err(self.adapter_not_ready());
            return Err(self.adapter_not_ready());
        }
        }
@@ -1059,7 +1059,7 @@ impl CommandHandler {
        Ok(())
        Ok(())
    }
    }


    fn cmd_floss(&mut self, args: &Vec<String>) -> CommandResult {
    fn cmd_floss(&mut self, args: &[String]) -> CommandResult {
        let command = get_arg(args, 0)?;
        let command = get_arg(args, 0)?;


        match &command[..] {
        match &command[..] {
@@ -1083,7 +1083,7 @@ impl CommandHandler {
        Ok(())
        Ok(())
    }
    }


    fn cmd_gatt(&mut self, args: &Vec<String>) -> CommandResult {
    fn cmd_gatt(&mut self, args: &[String]) -> CommandResult {
        if !self.lock_context().adapter_ready {
        if !self.lock_context().adapter_ready {
            return Err(self.adapter_not_ready());
            return Err(self.adapter_not_ready());
        }
        }
@@ -1224,7 +1224,7 @@ impl CommandHandler {
            }
            }
            "set-auth-req" => {
            "set-auth-req" => {
                let flag = match &get_arg(args, 1)?[..] {
                let flag = match &get_arg(args, 1)?[..] {
                    "NONE" => AuthReq::NONE,
                    "NONE" => AuthReq::NoEnc,
                    "EncNoMitm" => AuthReq::EncNoMitm,
                    "EncNoMitm" => AuthReq::EncNoMitm,
                    "EncMitm" => AuthReq::EncMitm,
                    "EncMitm" => AuthReq::EncMitm,
                    "SignedNoMitm" => AuthReq::SignedNoMitm,
                    "SignedNoMitm" => AuthReq::SignedNoMitm,
@@ -1535,7 +1535,7 @@ impl CommandHandler {
        Ok(())
        Ok(())
    }
    }


    fn cmd_le_scan(&mut self, args: &Vec<String>) -> CommandResult {
    fn cmd_le_scan(&mut self, args: &[String]) -> CommandResult {
        if !self.lock_context().adapter_ready {
        if !self.lock_context().adapter_ready {
            return Err(self.adapter_not_ready());
            return Err(self.adapter_not_ready());
        }
        }
@@ -1602,7 +1602,7 @@ impl CommandHandler {


    // TODO(b/233128828): More options will be implemented to test BLE advertising.
    // TODO(b/233128828): More options will be implemented to test BLE advertising.
    // Such as setting advertising parameters, starting multiple advertising sets, etc.
    // Such as setting advertising parameters, starting multiple advertising sets, etc.
    fn cmd_advertise(&mut self, args: &Vec<String>) -> CommandResult {
    fn cmd_advertise(&mut self, args: &[String]) -> CommandResult {
        if !self.lock_context().adapter_ready {
        if !self.lock_context().adapter_ready {
            return Err(self.adapter_not_ready());
            return Err(self.adapter_not_ready());
        }
        }
@@ -1732,7 +1732,7 @@ impl CommandHandler {
        Ok(())
        Ok(())
    }
    }


    fn cmd_sdp(&mut self, args: &Vec<String>) -> CommandResult {
    fn cmd_sdp(&mut self, args: &[String]) -> CommandResult {
        if !self.lock_context().adapter_ready {
        if !self.lock_context().adapter_ready {
            return Err(self.adapter_not_ready());
            return Err(self.adapter_not_ready());
        }
        }
@@ -1757,7 +1757,7 @@ impl CommandHandler {
        Ok(())
        Ok(())
    }
    }


    fn cmd_socket(&mut self, args: &Vec<String>) -> CommandResult {
    fn cmd_socket(&mut self, args: &[String]) -> CommandResult {
        if !self.lock_context().adapter_ready {
        if !self.lock_context().adapter_ready {
            return Err(self.adapter_not_ready());
            return Err(self.adapter_not_ready());
        }
        }
@@ -1976,7 +1976,7 @@ impl CommandHandler {
        Ok(())
        Ok(())
    }
    }


    fn cmd_hid(&mut self, args: &Vec<String>) -> CommandResult {
    fn cmd_hid(&mut self, args: &[String]) -> CommandResult {
        if !self.context.lock().unwrap().adapter_ready {
        if !self.context.lock().unwrap().adapter_ready {
            return Err(self.adapter_not_ready());
            return Err(self.adapter_not_ready());
        }
        }
@@ -2039,7 +2039,7 @@ impl CommandHandler {
        self.command_options.values().flat_map(|cmd| cmd.rules.clone()).collect()
        self.command_options.values().flat_map(|cmd| cmd.rules.clone()).collect()
    }
    }


    fn cmd_list_devices(&mut self, args: &Vec<String>) -> CommandResult {
    fn cmd_list_devices(&mut self, args: &[String]) -> CommandResult {
        if !self.lock_context().adapter_ready {
        if !self.lock_context().adapter_ready {
            return Err(self.adapter_not_ready());
            return Err(self.adapter_not_ready());
        }
        }
@@ -2077,7 +2077,7 @@ impl CommandHandler {
        Ok(())
        Ok(())
    }
    }


    fn cmd_telephony(&mut self, args: &Vec<String>) -> CommandResult {
    fn cmd_telephony(&mut self, args: &[String]) -> CommandResult {
        if !self.context.lock().unwrap().adapter_ready {
        if !self.context.lock().unwrap().adapter_ready {
            return Err(self.adapter_not_ready());
            return Err(self.adapter_not_ready());
        }
        }
@@ -2301,7 +2301,7 @@ impl CommandHandler {
        Ok(())
        Ok(())
    }
    }


    fn cmd_qa(&mut self, args: &Vec<String>) -> CommandResult {
    fn cmd_qa(&mut self, args: &[String]) -> CommandResult {
        if !self.context.lock().unwrap().adapter_ready {
        if !self.context.lock().unwrap().adapter_ready {
            return Err(self.adapter_not_ready());
            return Err(self.adapter_not_ready());
        }
        }
@@ -2328,7 +2328,7 @@ impl CommandHandler {
        Ok(())
        Ok(())
    }
    }


    fn cmd_media(&mut self, args: &Vec<String>) -> CommandResult {
    fn cmd_media(&mut self, args: &[String]) -> CommandResult {
        if !self.context.lock().unwrap().adapter_ready {
        if !self.context.lock().unwrap().adapter_ready {
            return Err(self.adapter_not_ready());
            return Err(self.adapter_not_ready());
        }
        }
@@ -2345,7 +2345,7 @@ impl CommandHandler {
        Ok(())
        Ok(())
    }
    }


    fn cmd_dumpsys(&mut self, _args: &Vec<String>) -> CommandResult {
    fn cmd_dumpsys(&mut self, _args: &[String]) -> CommandResult {
        if !self.lock_context().adapter_ready {
        if !self.lock_context().adapter_ready {
            return Err(self.adapter_not_ready());
            return Err(self.adapter_not_ready());
        }
        }
+16 −8
Original line number Original line Diff line number Diff line
@@ -520,15 +520,12 @@ impl DBusArg for ScanFilterCondition {
        condition: ScanFilterCondition,
        condition: ScanFilterCondition,
    ) -> Result<dbus::arg::PropMap, Box<dyn std::error::Error>> {
    ) -> Result<dbus::arg::PropMap, Box<dyn std::error::Error>> {
        let mut map: dbus::arg::PropMap = std::collections::HashMap::new();
        let mut map: dbus::arg::PropMap = std::collections::HashMap::new();
        match condition {
        if let ScanFilterCondition::Patterns(patterns) = condition {
            ScanFilterCondition::Patterns(patterns) => {
            map.insert(
            map.insert(
                String::from("patterns"),
                String::from("patterns"),
                dbus::arg::Variant(Box::new(DBusArg::to_dbus(patterns)?)),
                dbus::arg::Variant(Box::new(DBusArg::to_dbus(patterns)?)),
            );
            );
        }
        }
            _ => {}
        }
        Ok(map)
        Ok(map)
    }
    }


@@ -715,6 +712,7 @@ impl_dbus_arg_enum!(BtDiscMode);


// Implements RPC-friendly wrapper methods for calling IBluetooth, generated by
// Implements RPC-friendly wrapper methods for calling IBluetooth, generated by
// `generate_dbus_interface_client` below.
// `generate_dbus_interface_client` below.
#[derive(Clone)]
pub(crate) struct BluetoothDBusRPC {
pub(crate) struct BluetoothDBusRPC {
    client_proxy: ClientDBusProxy,
    client_proxy: ClientDBusProxy,
}
}
@@ -1118,6 +1116,7 @@ pub struct AdapterWithEnabledDbus {


// Implements RPC-friendly wrapper methods for calling IBluetoothManager, generated by
// Implements RPC-friendly wrapper methods for calling IBluetoothManager, generated by
// `generate_dbus_interface_client` below.
// `generate_dbus_interface_client` below.
#[derive(Clone)]
pub(crate) struct BluetoothManagerDBusRPC {
pub(crate) struct BluetoothManagerDBusRPC {
    client_proxy: ClientDBusProxy,
    client_proxy: ClientDBusProxy,
}
}
@@ -1333,6 +1332,7 @@ pub struct PeriodicAdvertisingParametersDBus {
    pub interval: i32,
    pub interval: i32,
}
}


#[derive(Clone)]
pub(crate) struct BluetoothAdminDBusRPC {
pub(crate) struct BluetoothAdminDBusRPC {
    client_proxy: ClientDBusProxy,
    client_proxy: ClientDBusProxy,
}
}
@@ -1428,6 +1428,7 @@ impl IBluetoothAdminPolicyCallback for IBluetoothAdminPolicyCallbackDBus {
    }
    }
}
}


#[derive(Clone)]
pub(crate) struct BluetoothGattDBusRPC {
pub(crate) struct BluetoothGattDBusRPC {
    client_proxy: ClientDBusProxy,
    client_proxy: ClientDBusProxy,
}
}
@@ -1521,6 +1522,7 @@ impl IBluetoothGatt for BluetoothGattDBus {
    }
    }


    #[dbus_method("StartAdvertisingSet")]
    #[dbus_method("StartAdvertisingSet")]
    #[allow(clippy::too_many_arguments)]
    fn start_advertising_set(
    fn start_advertising_set(
        &mut self,
        &mut self,
        parameters: AdvertisingSetParameters,
        parameters: AdvertisingSetParameters,
@@ -1757,6 +1759,7 @@ impl IBluetoothGatt for BluetoothGattDBus {
    }
    }


    #[dbus_method("ConnectionParameterUpdate")]
    #[dbus_method("ConnectionParameterUpdate")]
    #[allow(clippy::too_many_arguments)]
    fn connection_parameter_update(
    fn connection_parameter_update(
        &self,
        &self,
        client_id: i32,
        client_id: i32,
@@ -2102,6 +2105,7 @@ pub struct SocketResultDBus {
    id: u64,
    id: u64,
}
}


#[derive(Clone)]
pub(crate) struct BluetoothSocketManagerDBusRPC {
pub(crate) struct BluetoothSocketManagerDBusRPC {
    client_proxy: ClientDBusProxy,
    client_proxy: ClientDBusProxy,
}
}
@@ -2365,6 +2369,7 @@ impl ISuspendCallback for ISuspendCallbackDBus {
    fn on_resumed(&mut self, suspend_id: i32) {}
    fn on_resumed(&mut self, suspend_id: i32) {}
}
}


#[derive(Clone)]
pub(crate) struct BluetoothTelephonyDBusRPC {
pub(crate) struct BluetoothTelephonyDBusRPC {
    client_proxy: ClientDBusProxy,
    client_proxy: ClientDBusProxy,
}
}
@@ -2489,6 +2494,7 @@ impl IBluetoothTelephonyCallback for IBluetoothTelephonyCallbackDBus {
    }
    }
}
}


#[derive(Clone)]
pub(crate) struct BluetoothQADBusRPC {
pub(crate) struct BluetoothQADBusRPC {
    client_proxy: ClientDBusProxy,
    client_proxy: ClientDBusProxy,
}
}
@@ -2608,6 +2614,7 @@ impl IBluetoothQACallback for IBluetoothQACallbackDBus {
    }
    }
}
}


#[derive(Clone)]
pub(crate) struct BluetoothMediaDBusRPC {
pub(crate) struct BluetoothMediaDBusRPC {
    client_proxy: ClientDBusProxy,
    client_proxy: ClientDBusProxy,
}
}
@@ -2976,6 +2983,7 @@ impl IBluetoothMediaCallback for IBluetoothMediaCallbackDBus {
    fn on_lea_group_volume_changed(&mut self, group_id: i32, volume: u8) {}
    fn on_lea_group_volume_changed(&mut self, group_id: i32, volume: u8) {}
}
}


#[derive(Clone)]
pub(crate) struct BatteryManagerDBusRPC {
pub(crate) struct BatteryManagerDBusRPC {
    client_proxy: ClientDBusProxy,
    client_proxy: ClientDBusProxy,
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -804,7 +804,7 @@ async fn handle_client_command(
                            break 'foreground_actions;
                            break 'foreground_actions;
                        }
                        }


                        handler.process_cmd_line(cmd, &rest.to_vec());
                        handler.process_cmd_line(cmd, rest);
                        break 'readline;
                        break 'readline;
                    }
                    }


Loading