Loading system/gd/rust/linux/client/src/callbacks.rs +12 −12 Original line number Diff line number Diff line Loading @@ -285,7 +285,7 @@ impl IBluetoothCallback for BtCallback { BtBondState::Bonding => (), } let device = BluetoothDevice { address: address, name: String::from("Classic device") }; let device = BluetoothDevice { address, name: String::from("Classic device") }; // If bonded, we should also automatically connect all enabled profiles if BtBondState::Bonded == state.into() { Loading Loading @@ -426,25 +426,25 @@ impl IScannerCallback for ScannerCallback { } fn on_scan_result(&mut self, scan_result: ScanResult) { if self.context.lock().unwrap().active_scanner_ids.len() > 0 { if !self.context.lock().unwrap().active_scanner_ids.is_empty() { print_info!("Scan result: {:#?}", scan_result); } } fn on_advertisement_found(&mut self, scanner_id: u8, scan_result: ScanResult) { if self.context.lock().unwrap().active_scanner_ids.len() > 0 { if !self.context.lock().unwrap().active_scanner_ids.is_empty() { print_info!("Advertisement found for scanner_id {} : {:#?}", scanner_id, scan_result); } } fn on_advertisement_lost(&mut self, scanner_id: u8, scan_result: ScanResult) { if self.context.lock().unwrap().active_scanner_ids.len() > 0 { if !self.context.lock().unwrap().active_scanner_ids.is_empty() { print_info!("Advertisement lost for scanner_id {} : {:#?}", scanner_id, scan_result); } } fn on_suspend_mode_change(&mut self, suspend_mode: SuspendMode) { if self.context.lock().unwrap().active_scanner_ids.len() > 0 { if !self.context.lock().unwrap().active_scanner_ids.is_empty() { print_info!("Scan suspend mode change: {:#?}", suspend_mode); } } Loading Loading @@ -951,7 +951,7 @@ impl IBluetoothGattServerCallback for BtGattServerCallback { return; } self.context.lock().unwrap().pending_gatt_request = Some(GattRequest { address: addr, id: trans_id, offset: offset, value: vec![] }); Some(GattRequest { address: addr, id: trans_id, offset, value: vec![] }); } fn on_descriptor_read_request( Loading @@ -978,7 +978,7 @@ impl IBluetoothGattServerCallback for BtGattServerCallback { return; } self.context.lock().unwrap().pending_gatt_request = Some(GattRequest { address: addr, id: trans_id, offset: offset, value: vec![] }); Some(GattRequest { address: addr, id: trans_id, offset, value: vec![] }); } fn on_characteristic_write_request( Loading Loading @@ -1012,7 +1012,7 @@ impl IBluetoothGattServerCallback for BtGattServerCallback { return; } self.context.lock().unwrap().pending_gatt_request = Some(GattRequest { address: addr, id: trans_id, offset: offset, value: value }); Some(GattRequest { address: addr, id: trans_id, offset, value }); } fn on_descriptor_write_request( Loading Loading @@ -1046,7 +1046,7 @@ impl IBluetoothGattServerCallback for BtGattServerCallback { return; } self.context.lock().unwrap().pending_gatt_request = Some(GattRequest { address: addr, id: trans_id, offset: offset, value: value }); Some(GattRequest { address: addr, id: trans_id, offset, value }); } fn on_execute_write(&mut self, addr: RawAddress, trans_id: i32, exec_write: bool) { Loading Loading @@ -1241,7 +1241,7 @@ impl IBluetoothSocketManagerCallbacks for BtSocketManagerCallback { socket.uuid, ); let callback_id = self.context.lock().unwrap().socket_manager_callback_id.clone().unwrap(); let callback_id = self.context.lock().unwrap().socket_manager_callback_id.unwrap(); self.context.lock().unwrap().run_callback(Box::new(move |context| { let status = context.lock().unwrap().socket_manager_dbus.as_mut().unwrap().accept( Loading Loading @@ -1434,7 +1434,7 @@ impl MediaCallback { fn timestamp_to_string(ts_in_us: u64) -> String { i64::try_from(ts_in_us) .and_then(|ts| Ok(Utc.timestamp_nanos(ts * 1000).to_rfc3339())) .map(|ts| Utc.timestamp_nanos(ts * 1000).to_rfc3339()) .unwrap_or("UNKNOWN".to_string()) } Loading Loading @@ -1625,7 +1625,7 @@ impl IBatteryManagerCallback for BatteryManagerCallback { fn on_battery_info_updated(&mut self, remote_address: RawAddress, battery_set: BatterySet) { let address = remote_address.to_string(); if self.context.lock().unwrap().battery_address_filter.contains(&address) { if battery_set.batteries.len() == 0 { if battery_set.batteries.is_empty() { print_info!( "Battery info for address '{}' updated with empty battery set. \ The batteries for this device may have been removed.", Loading system/gd/rust/linux/client/src/command_handler.rs +31 −40 Original line number Diff line number Diff line Loading @@ -101,9 +101,9 @@ struct DisplayList<T>(Vec<T>); impl<T: Display> Display for DisplayList<T> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let _ = write!(f, "[\n"); let _ = writeln!(f, "["); for item in self.0.iter() { let _ = write!(f, " {}\n", item); let _ = writeln!(f, " {}", item); } write!(f, "]") Loading Loading @@ -429,7 +429,7 @@ impl CommandHandler { _ => match self.command_options.get(command) { Some(cmd) => { let rules = cmd.rules.clone(); match (cmd.function_pointer)(self, &args) { match (cmd.function_pointer)(self, args) { Ok(()) => true, Err(CommandError::InvalidArgs) => { print_error!("Invalid arguments. Usage:\n{}", rules.join("\n")); Loading @@ -443,7 +443,7 @@ impl CommandHandler { } None => { println!("'{}' is an invalid command!", command); self.cmd_help(&args).ok(); self.cmd_help(args).ok(); false } }, Loading @@ -464,7 +464,7 @@ impl CommandHandler { } fn cmd_help(&mut self, args: &Vec<String>) -> CommandResult { if let Some(command) = args.get(0) { if let Some(command) = args.first() { match self.command_options.get(command) { Some(cmd) => { println!( Loading Loading @@ -501,7 +501,7 @@ impl CommandHandler { for (key, val) in self.command_options.iter() { println!( "{}\n{}\n{}", wrap_help_text(&key, MAX_MENU_CHAR_WIDTH, 4), wrap_help_text(key, MAX_MENU_CHAR_WIDTH, 4), wrap_help_text(&val.description, MAX_MENU_CHAR_WIDTH, 8), empty_bar ); Loading Loading @@ -715,7 +715,7 @@ impl CommandHandler { { None => println!("Battery status for device {} could not be fetched", address), Some(set) => { if set.batteries.len() == 0 { if set.batteries.is_empty() { println!("Battery set for device {} is empty", set.address.to_string()); return Ok(()); } Loading Loading @@ -751,7 +751,7 @@ impl CommandHandler { } println!("Stopped tracking {}", address); if self.lock_context().battery_address_filter.len() == 0 { if self.lock_context().battery_address_filter.is_empty() { println!("No longer tracking any addresses for battery status updates"); return Ok(()); } Loading Loading @@ -1001,7 +1001,7 @@ impl CommandHandler { let (accept, pin) = match (&pin[..], pin) { ("reject", _) => (false, vec![]), (_, p) => (true, p.as_bytes().iter().cloned().collect::<Vec<u8>>()), (_, p) => (true, p.as_bytes().to_vec()), }; self.lock_context().adapter_dbus.as_mut().unwrap().set_pin( Loading Loading @@ -1252,7 +1252,7 @@ impl CommandHandler { } }; let value = hex::decode(&get_arg(args, 4)?).or(Err("Failed to parse value"))?; let value = hex::decode(get_arg(args, 4)?).or(Err("Failed to parse value"))?; let client_id = self .lock_context() Loading Loading @@ -1503,7 +1503,7 @@ impl CommandHandler { }; self.lock_context().gatt_dbus.as_mut().unwrap().send_response( server_id, request.address.clone(), request.address, request.id, status, request.offset, Loading Loading @@ -1607,11 +1607,11 @@ impl CommandHandler { return Err(self.adapter_not_ready()); } if self.lock_context().advertiser_callback_id == None { if self.lock_context().advertiser_callback_id.is_none() { return Err("No advertiser callback registered".into()); } let callback_id = self.lock_context().advertiser_callback_id.clone().unwrap(); let callback_id = self.lock_context().advertiser_callback_id.unwrap(); let command = get_arg(args, 0)?; Loading @@ -1631,7 +1631,7 @@ impl CommandHandler { } "set-interval" => { let ms = String::from(get_arg(args, 1)?).parse::<i32>(); if !ms.is_ok() { if ms.is_err() { return Err("Failed parsing interval".into()); } let interval = ms.unwrap() * 8 / 5; // in 0.625 ms. Loading @@ -1645,7 +1645,7 @@ impl CommandHandler { let advs: Vec<(_, _)> = context .adv_sets .iter() .filter_map(|(_, s)| s.adv_id.map(|adv_id| (adv_id.clone(), s.params.clone()))) .filter_map(|(_, s)| s.adv_id.map(|adv_id| (adv_id, s.params.clone()))) .collect(); for (adv_id, params) in advs { print_info!("Setting advertising parameters for {}", adv_id); Loading Loading @@ -1700,8 +1700,7 @@ impl CommandHandler { .adv_sets .iter() .filter_map(|(_, s)| { s.adv_id .map(|adv_id| (adv_id.clone(), s.params.clone(), s.scan_rsp.clone())) s.adv_id.map(|adv_id| (adv_id, s.params.clone(), s.scan_rsp.clone())) }) .collect(); for (adv_id, params, scan_rsp) in advs { Loading @@ -1719,11 +1718,7 @@ impl CommandHandler { .or(Err("Failed parsing adv_id"))?; let mut context = self.context.lock().unwrap(); if context .adv_sets .iter() .find(|(_, s)| s.adv_id.map_or(false, |id| id == adv_id)) .is_none() if !context.adv_sets.iter().any(|(_, s)| s.adv_id.map_or(false, |id| id == adv_id)) { return Err("Failed to find advertising set".into()); } Loading Loading @@ -1767,7 +1762,7 @@ impl CommandHandler { return Err(self.adapter_not_ready()); } let callback_id = match self.lock_context().socket_manager_callback_id.clone() { let callback_id = match self.lock_context().socket_manager_callback_id { Some(id) => id, None => { return Err("No socket manager callback registered.".into()); Loading Loading @@ -1849,13 +1844,11 @@ impl CommandHandler { } else { proxy.listen_using_l2cap_channel(callback_id) } } else { if is_le { } else if is_le { proxy.listen_using_insecure_l2cap_le_channel(callback_id) } else { proxy.listen_using_insecure_l2cap_channel(callback_id) } } }; if status != BtStatus::Success { Loading Loading @@ -1909,21 +1902,19 @@ impl CommandHandler { } else { proxy.create_l2cap_channel(callback_id, device, psm) } } else { if is_le { } else if is_le { proxy.create_insecure_l2cap_le_channel(callback_id, device, psm) } else { proxy.create_insecure_l2cap_channel(callback_id, device, psm) } } } "rfcomm" => { let uuid = match Uuid::from_string(*psm_or_uuid) { Some(uu) => uu, None => { return Err(CommandError::Failed(format!( "Could not parse given uuid." ))); return Err(CommandError::Failed( "Could not parse given uuid.".to_string(), )); } }; Loading Loading @@ -2122,7 +2113,7 @@ impl CommandHandler { let strength = String::from(get_arg(args, 1)?) .parse::<i32>() .or(Err("Failed parsing signal strength"))?; if strength < 0 || strength > 5 { if !(0..=5).contains(&strength) { return Err( format!("Invalid signal strength, got {}, want 0 to 5", strength).into() ); Loading @@ -2139,7 +2130,7 @@ impl CommandHandler { let level = String::from(get_arg(args, 1)?) .parse::<i32>() .or(Err("Failed parsing battery level"))?; if level < 0 || level > 5 { if !(0..=5).contains(&level) { return Err(format!("Invalid battery level, got {}, want 0 to 5", level).into()); } self.context Loading @@ -2160,7 +2151,7 @@ impl CommandHandler { .unwrap() .create_sdp_record(BtSdpRecord::Mps(BtSdpMpsRecord::default())); if !success { return Err(format!("Failed to create SDP record").into()); return Err("Failed to create SDP record".to_string().into()); } } } Loading @@ -2170,7 +2161,7 @@ impl CommandHandler { if let Some(handle) = context.mps_sdp_handle.take() { let success = context.adapter_dbus.as_mut().unwrap().remove_sdp_record(handle); if !success { return Err(format!("Failed to remove SDP record").into()); return Err("Failed to remove SDP record".to_string().into()); } } } Loading system/gd/rust/linux/client/src/dbus_iface.rs +5 −5 Original line number Diff line number Diff line Loading @@ -235,7 +235,7 @@ where key, stringify!(T), ))))?, format!("{}", stringify!(T)), stringify!(T).to_string(), )?; let output = T::from_dbus(output, None, None, None)?; Ok(output) Loading Loading @@ -509,11 +509,11 @@ impl DBusArg for ScanFilterCondition { let patterns = <<Vec<ScanFilterPattern> as DBusArg>::DBusType as RefArgToRust>::ref_arg_to_rust( variant.as_static_inner(0).unwrap(), format!("ScanFilterCondition::Patterns"), "ScanFilterCondition::Patterns".to_string(), )?; let patterns = Vec::<ScanFilterPattern>::from_dbus(patterns, None, None, None)?; return Ok(ScanFilterCondition::Patterns(patterns)); Ok(ScanFilterCondition::Patterns(patterns)) } fn to_dbus( Loading @@ -529,7 +529,7 @@ impl DBusArg for ScanFilterCondition { } _ => {} } return Ok(map); Ok(map) } // We don't log in btclient. Loading Loading @@ -1146,7 +1146,7 @@ impl BluetoothManagerDBus { pub(crate) fn is_valid(&self) -> bool { let result: Result<(bool,), _> = self.client_proxy.method_withresult("GetFlossEnabled", ()); return result.is_ok(); result.is_ok() } } Loading system/gd/rust/linux/client/src/editor.rs +6 −6 Original line number Diff line number Diff line Loading @@ -84,19 +84,19 @@ impl BtHelper { let mut result = HashSet::<CommandCandidate>::new(); for rule in self.command_rules.iter() { let n_splits = cmd.split(" ").count(); let n_splits = cmd.split(' ').count(); // The tokens should have empty strings removed from them, except the last one. let tokens = cmd .split(" ") .split(' ') .enumerate() .filter_map(|(i, token)| (i == n_splits - 1 || token != "").then(|| token)); .filter_map(|(i, token)| (i == n_splits - 1 || !token.is_empty()).then_some(token)); let n_cmd = tokens.clone().count(); for (i, (rule_token, cmd_token)) in rule.split(" ").zip(tokens).enumerate() { for (i, (rule_token, cmd_token)) in rule.split(' ').zip(tokens).enumerate() { let mut candidates = Vec::<String>::new(); let mut match_some = false; for opt in rule_token.replace("<", "").replace(">", "").split("|") { for opt in rule_token.replace(['<', '>'], "").split('|') { if opt.eq("address") { let devices = self.client_context.lock().unwrap().get_devices(); candidates.extend(devices); Loading @@ -105,7 +105,7 @@ impl BtHelper { } } if cmd_token.len() == 0 { if cmd_token.is_empty() { candidates.iter().for_each(|s| { result.insert(CommandCandidate { suggest_word: s.clone(), matched_len: 0 }); }); Loading system/gd/rust/linux/client/src/main.rs +8 −10 Original line number Diff line number Diff line Loading @@ -283,7 +283,7 @@ impl ClientContext { // Foreground-only: Updates the adapter address. fn update_adapter_address(&mut self) -> RawAddress { let address = self.adapter_dbus.as_ref().unwrap().get_address(); self.adapter_address = Some(address.clone()); self.adapter_address = Some(address); address } Loading Loading @@ -314,14 +314,12 @@ impl ClientContext { fn get_devices(&self) -> Vec<String> { let mut result: Vec<String> = vec![]; result.extend( self.found_devices.keys().map(|key| String::from(key)).collect::<Vec<String>>(), ); result.extend(self.found_devices.keys().map(String::from).collect::<Vec<String>>()); result.extend( self.bonded_devices .keys() .filter(|key| !self.found_devices.contains_key(&String::from(*key))) .map(|key| String::from(key)) .map(String::from) .collect::<Vec<String>>(), ); Loading Loading @@ -450,7 +448,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { } let handler = CommandHandler::new(context.clone()); if let Ok(_) = command { if command.is_ok() { // Timeout applies only to non-interactive commands. if let Ok(timeout_secs) = timeout_secs { let timeout_duration = Duration::from_secs(timeout_secs); Loading @@ -473,7 +471,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { // - Interactive commands: none of these commands require a timeout. // - Non-interactive commands that have not specified a timeout. handle_client_command(handler, tx, rx, context, command).await?; return Result::Ok(()); Result::Ok(()) }) } Loading @@ -496,7 +494,7 @@ async fn handle_client_command( let semaphore_fg = Arc::new(tokio::sync::Semaphore::new(1)); // If there are no command arguments, start the interactive shell. if let Err(_) = command { if command.is_err() { let command_rule_list = handler.get_command_rule_list().clone(); let context_for_closure = context.clone(); Loading Loading @@ -546,7 +544,7 @@ async fn handle_client_command( callback(context.clone()); // Break the loop as a non-interactive command is completed. if let Ok(_) = command { if command.is_ok() { break; } } Loading Loading @@ -763,7 +761,7 @@ async fn handle_client_command( // Run the command with the command arguments as the client is // non-interactive. if let Some(command) = command.as_ref().ok() { if let Ok(command) = command.as_ref() { let mut iter = command.split(' ').map(String::from); let first = iter.next().unwrap_or(String::from("")); if !handler.process_cmd_line(&first, &iter.collect::<Vec<String>>()) { Loading Loading
system/gd/rust/linux/client/src/callbacks.rs +12 −12 Original line number Diff line number Diff line Loading @@ -285,7 +285,7 @@ impl IBluetoothCallback for BtCallback { BtBondState::Bonding => (), } let device = BluetoothDevice { address: address, name: String::from("Classic device") }; let device = BluetoothDevice { address, name: String::from("Classic device") }; // If bonded, we should also automatically connect all enabled profiles if BtBondState::Bonded == state.into() { Loading Loading @@ -426,25 +426,25 @@ impl IScannerCallback for ScannerCallback { } fn on_scan_result(&mut self, scan_result: ScanResult) { if self.context.lock().unwrap().active_scanner_ids.len() > 0 { if !self.context.lock().unwrap().active_scanner_ids.is_empty() { print_info!("Scan result: {:#?}", scan_result); } } fn on_advertisement_found(&mut self, scanner_id: u8, scan_result: ScanResult) { if self.context.lock().unwrap().active_scanner_ids.len() > 0 { if !self.context.lock().unwrap().active_scanner_ids.is_empty() { print_info!("Advertisement found for scanner_id {} : {:#?}", scanner_id, scan_result); } } fn on_advertisement_lost(&mut self, scanner_id: u8, scan_result: ScanResult) { if self.context.lock().unwrap().active_scanner_ids.len() > 0 { if !self.context.lock().unwrap().active_scanner_ids.is_empty() { print_info!("Advertisement lost for scanner_id {} : {:#?}", scanner_id, scan_result); } } fn on_suspend_mode_change(&mut self, suspend_mode: SuspendMode) { if self.context.lock().unwrap().active_scanner_ids.len() > 0 { if !self.context.lock().unwrap().active_scanner_ids.is_empty() { print_info!("Scan suspend mode change: {:#?}", suspend_mode); } } Loading Loading @@ -951,7 +951,7 @@ impl IBluetoothGattServerCallback for BtGattServerCallback { return; } self.context.lock().unwrap().pending_gatt_request = Some(GattRequest { address: addr, id: trans_id, offset: offset, value: vec![] }); Some(GattRequest { address: addr, id: trans_id, offset, value: vec![] }); } fn on_descriptor_read_request( Loading @@ -978,7 +978,7 @@ impl IBluetoothGattServerCallback for BtGattServerCallback { return; } self.context.lock().unwrap().pending_gatt_request = Some(GattRequest { address: addr, id: trans_id, offset: offset, value: vec![] }); Some(GattRequest { address: addr, id: trans_id, offset, value: vec![] }); } fn on_characteristic_write_request( Loading Loading @@ -1012,7 +1012,7 @@ impl IBluetoothGattServerCallback for BtGattServerCallback { return; } self.context.lock().unwrap().pending_gatt_request = Some(GattRequest { address: addr, id: trans_id, offset: offset, value: value }); Some(GattRequest { address: addr, id: trans_id, offset, value }); } fn on_descriptor_write_request( Loading Loading @@ -1046,7 +1046,7 @@ impl IBluetoothGattServerCallback for BtGattServerCallback { return; } self.context.lock().unwrap().pending_gatt_request = Some(GattRequest { address: addr, id: trans_id, offset: offset, value: value }); Some(GattRequest { address: addr, id: trans_id, offset, value }); } fn on_execute_write(&mut self, addr: RawAddress, trans_id: i32, exec_write: bool) { Loading Loading @@ -1241,7 +1241,7 @@ impl IBluetoothSocketManagerCallbacks for BtSocketManagerCallback { socket.uuid, ); let callback_id = self.context.lock().unwrap().socket_manager_callback_id.clone().unwrap(); let callback_id = self.context.lock().unwrap().socket_manager_callback_id.unwrap(); self.context.lock().unwrap().run_callback(Box::new(move |context| { let status = context.lock().unwrap().socket_manager_dbus.as_mut().unwrap().accept( Loading Loading @@ -1434,7 +1434,7 @@ impl MediaCallback { fn timestamp_to_string(ts_in_us: u64) -> String { i64::try_from(ts_in_us) .and_then(|ts| Ok(Utc.timestamp_nanos(ts * 1000).to_rfc3339())) .map(|ts| Utc.timestamp_nanos(ts * 1000).to_rfc3339()) .unwrap_or("UNKNOWN".to_string()) } Loading Loading @@ -1625,7 +1625,7 @@ impl IBatteryManagerCallback for BatteryManagerCallback { fn on_battery_info_updated(&mut self, remote_address: RawAddress, battery_set: BatterySet) { let address = remote_address.to_string(); if self.context.lock().unwrap().battery_address_filter.contains(&address) { if battery_set.batteries.len() == 0 { if battery_set.batteries.is_empty() { print_info!( "Battery info for address '{}' updated with empty battery set. \ The batteries for this device may have been removed.", Loading
system/gd/rust/linux/client/src/command_handler.rs +31 −40 Original line number Diff line number Diff line Loading @@ -101,9 +101,9 @@ struct DisplayList<T>(Vec<T>); impl<T: Display> Display for DisplayList<T> { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { let _ = write!(f, "[\n"); let _ = writeln!(f, "["); for item in self.0.iter() { let _ = write!(f, " {}\n", item); let _ = writeln!(f, " {}", item); } write!(f, "]") Loading Loading @@ -429,7 +429,7 @@ impl CommandHandler { _ => match self.command_options.get(command) { Some(cmd) => { let rules = cmd.rules.clone(); match (cmd.function_pointer)(self, &args) { match (cmd.function_pointer)(self, args) { Ok(()) => true, Err(CommandError::InvalidArgs) => { print_error!("Invalid arguments. Usage:\n{}", rules.join("\n")); Loading @@ -443,7 +443,7 @@ impl CommandHandler { } None => { println!("'{}' is an invalid command!", command); self.cmd_help(&args).ok(); self.cmd_help(args).ok(); false } }, Loading @@ -464,7 +464,7 @@ impl CommandHandler { } fn cmd_help(&mut self, args: &Vec<String>) -> CommandResult { if let Some(command) = args.get(0) { if let Some(command) = args.first() { match self.command_options.get(command) { Some(cmd) => { println!( Loading Loading @@ -501,7 +501,7 @@ impl CommandHandler { for (key, val) in self.command_options.iter() { println!( "{}\n{}\n{}", wrap_help_text(&key, MAX_MENU_CHAR_WIDTH, 4), wrap_help_text(key, MAX_MENU_CHAR_WIDTH, 4), wrap_help_text(&val.description, MAX_MENU_CHAR_WIDTH, 8), empty_bar ); Loading Loading @@ -715,7 +715,7 @@ impl CommandHandler { { None => println!("Battery status for device {} could not be fetched", address), Some(set) => { if set.batteries.len() == 0 { if set.batteries.is_empty() { println!("Battery set for device {} is empty", set.address.to_string()); return Ok(()); } Loading Loading @@ -751,7 +751,7 @@ impl CommandHandler { } println!("Stopped tracking {}", address); if self.lock_context().battery_address_filter.len() == 0 { if self.lock_context().battery_address_filter.is_empty() { println!("No longer tracking any addresses for battery status updates"); return Ok(()); } Loading Loading @@ -1001,7 +1001,7 @@ impl CommandHandler { let (accept, pin) = match (&pin[..], pin) { ("reject", _) => (false, vec![]), (_, p) => (true, p.as_bytes().iter().cloned().collect::<Vec<u8>>()), (_, p) => (true, p.as_bytes().to_vec()), }; self.lock_context().adapter_dbus.as_mut().unwrap().set_pin( Loading Loading @@ -1252,7 +1252,7 @@ impl CommandHandler { } }; let value = hex::decode(&get_arg(args, 4)?).or(Err("Failed to parse value"))?; let value = hex::decode(get_arg(args, 4)?).or(Err("Failed to parse value"))?; let client_id = self .lock_context() Loading Loading @@ -1503,7 +1503,7 @@ impl CommandHandler { }; self.lock_context().gatt_dbus.as_mut().unwrap().send_response( server_id, request.address.clone(), request.address, request.id, status, request.offset, Loading Loading @@ -1607,11 +1607,11 @@ impl CommandHandler { return Err(self.adapter_not_ready()); } if self.lock_context().advertiser_callback_id == None { if self.lock_context().advertiser_callback_id.is_none() { return Err("No advertiser callback registered".into()); } let callback_id = self.lock_context().advertiser_callback_id.clone().unwrap(); let callback_id = self.lock_context().advertiser_callback_id.unwrap(); let command = get_arg(args, 0)?; Loading @@ -1631,7 +1631,7 @@ impl CommandHandler { } "set-interval" => { let ms = String::from(get_arg(args, 1)?).parse::<i32>(); if !ms.is_ok() { if ms.is_err() { return Err("Failed parsing interval".into()); } let interval = ms.unwrap() * 8 / 5; // in 0.625 ms. Loading @@ -1645,7 +1645,7 @@ impl CommandHandler { let advs: Vec<(_, _)> = context .adv_sets .iter() .filter_map(|(_, s)| s.adv_id.map(|adv_id| (adv_id.clone(), s.params.clone()))) .filter_map(|(_, s)| s.adv_id.map(|adv_id| (adv_id, s.params.clone()))) .collect(); for (adv_id, params) in advs { print_info!("Setting advertising parameters for {}", adv_id); Loading Loading @@ -1700,8 +1700,7 @@ impl CommandHandler { .adv_sets .iter() .filter_map(|(_, s)| { s.adv_id .map(|adv_id| (adv_id.clone(), s.params.clone(), s.scan_rsp.clone())) s.adv_id.map(|adv_id| (adv_id, s.params.clone(), s.scan_rsp.clone())) }) .collect(); for (adv_id, params, scan_rsp) in advs { Loading @@ -1719,11 +1718,7 @@ impl CommandHandler { .or(Err("Failed parsing adv_id"))?; let mut context = self.context.lock().unwrap(); if context .adv_sets .iter() .find(|(_, s)| s.adv_id.map_or(false, |id| id == adv_id)) .is_none() if !context.adv_sets.iter().any(|(_, s)| s.adv_id.map_or(false, |id| id == adv_id)) { return Err("Failed to find advertising set".into()); } Loading Loading @@ -1767,7 +1762,7 @@ impl CommandHandler { return Err(self.adapter_not_ready()); } let callback_id = match self.lock_context().socket_manager_callback_id.clone() { let callback_id = match self.lock_context().socket_manager_callback_id { Some(id) => id, None => { return Err("No socket manager callback registered.".into()); Loading Loading @@ -1849,13 +1844,11 @@ impl CommandHandler { } else { proxy.listen_using_l2cap_channel(callback_id) } } else { if is_le { } else if is_le { proxy.listen_using_insecure_l2cap_le_channel(callback_id) } else { proxy.listen_using_insecure_l2cap_channel(callback_id) } } }; if status != BtStatus::Success { Loading Loading @@ -1909,21 +1902,19 @@ impl CommandHandler { } else { proxy.create_l2cap_channel(callback_id, device, psm) } } else { if is_le { } else if is_le { proxy.create_insecure_l2cap_le_channel(callback_id, device, psm) } else { proxy.create_insecure_l2cap_channel(callback_id, device, psm) } } } "rfcomm" => { let uuid = match Uuid::from_string(*psm_or_uuid) { Some(uu) => uu, None => { return Err(CommandError::Failed(format!( "Could not parse given uuid." ))); return Err(CommandError::Failed( "Could not parse given uuid.".to_string(), )); } }; Loading Loading @@ -2122,7 +2113,7 @@ impl CommandHandler { let strength = String::from(get_arg(args, 1)?) .parse::<i32>() .or(Err("Failed parsing signal strength"))?; if strength < 0 || strength > 5 { if !(0..=5).contains(&strength) { return Err( format!("Invalid signal strength, got {}, want 0 to 5", strength).into() ); Loading @@ -2139,7 +2130,7 @@ impl CommandHandler { let level = String::from(get_arg(args, 1)?) .parse::<i32>() .or(Err("Failed parsing battery level"))?; if level < 0 || level > 5 { if !(0..=5).contains(&level) { return Err(format!("Invalid battery level, got {}, want 0 to 5", level).into()); } self.context Loading @@ -2160,7 +2151,7 @@ impl CommandHandler { .unwrap() .create_sdp_record(BtSdpRecord::Mps(BtSdpMpsRecord::default())); if !success { return Err(format!("Failed to create SDP record").into()); return Err("Failed to create SDP record".to_string().into()); } } } Loading @@ -2170,7 +2161,7 @@ impl CommandHandler { if let Some(handle) = context.mps_sdp_handle.take() { let success = context.adapter_dbus.as_mut().unwrap().remove_sdp_record(handle); if !success { return Err(format!("Failed to remove SDP record").into()); return Err("Failed to remove SDP record".to_string().into()); } } } Loading
system/gd/rust/linux/client/src/dbus_iface.rs +5 −5 Original line number Diff line number Diff line Loading @@ -235,7 +235,7 @@ where key, stringify!(T), ))))?, format!("{}", stringify!(T)), stringify!(T).to_string(), )?; let output = T::from_dbus(output, None, None, None)?; Ok(output) Loading Loading @@ -509,11 +509,11 @@ impl DBusArg for ScanFilterCondition { let patterns = <<Vec<ScanFilterPattern> as DBusArg>::DBusType as RefArgToRust>::ref_arg_to_rust( variant.as_static_inner(0).unwrap(), format!("ScanFilterCondition::Patterns"), "ScanFilterCondition::Patterns".to_string(), )?; let patterns = Vec::<ScanFilterPattern>::from_dbus(patterns, None, None, None)?; return Ok(ScanFilterCondition::Patterns(patterns)); Ok(ScanFilterCondition::Patterns(patterns)) } fn to_dbus( Loading @@ -529,7 +529,7 @@ impl DBusArg for ScanFilterCondition { } _ => {} } return Ok(map); Ok(map) } // We don't log in btclient. Loading Loading @@ -1146,7 +1146,7 @@ impl BluetoothManagerDBus { pub(crate) fn is_valid(&self) -> bool { let result: Result<(bool,), _> = self.client_proxy.method_withresult("GetFlossEnabled", ()); return result.is_ok(); result.is_ok() } } Loading
system/gd/rust/linux/client/src/editor.rs +6 −6 Original line number Diff line number Diff line Loading @@ -84,19 +84,19 @@ impl BtHelper { let mut result = HashSet::<CommandCandidate>::new(); for rule in self.command_rules.iter() { let n_splits = cmd.split(" ").count(); let n_splits = cmd.split(' ').count(); // The tokens should have empty strings removed from them, except the last one. let tokens = cmd .split(" ") .split(' ') .enumerate() .filter_map(|(i, token)| (i == n_splits - 1 || token != "").then(|| token)); .filter_map(|(i, token)| (i == n_splits - 1 || !token.is_empty()).then_some(token)); let n_cmd = tokens.clone().count(); for (i, (rule_token, cmd_token)) in rule.split(" ").zip(tokens).enumerate() { for (i, (rule_token, cmd_token)) in rule.split(' ').zip(tokens).enumerate() { let mut candidates = Vec::<String>::new(); let mut match_some = false; for opt in rule_token.replace("<", "").replace(">", "").split("|") { for opt in rule_token.replace(['<', '>'], "").split('|') { if opt.eq("address") { let devices = self.client_context.lock().unwrap().get_devices(); candidates.extend(devices); Loading @@ -105,7 +105,7 @@ impl BtHelper { } } if cmd_token.len() == 0 { if cmd_token.is_empty() { candidates.iter().for_each(|s| { result.insert(CommandCandidate { suggest_word: s.clone(), matched_len: 0 }); }); Loading
system/gd/rust/linux/client/src/main.rs +8 −10 Original line number Diff line number Diff line Loading @@ -283,7 +283,7 @@ impl ClientContext { // Foreground-only: Updates the adapter address. fn update_adapter_address(&mut self) -> RawAddress { let address = self.adapter_dbus.as_ref().unwrap().get_address(); self.adapter_address = Some(address.clone()); self.adapter_address = Some(address); address } Loading Loading @@ -314,14 +314,12 @@ impl ClientContext { fn get_devices(&self) -> Vec<String> { let mut result: Vec<String> = vec![]; result.extend( self.found_devices.keys().map(|key| String::from(key)).collect::<Vec<String>>(), ); result.extend(self.found_devices.keys().map(String::from).collect::<Vec<String>>()); result.extend( self.bonded_devices .keys() .filter(|key| !self.found_devices.contains_key(&String::from(*key))) .map(|key| String::from(key)) .map(String::from) .collect::<Vec<String>>(), ); Loading Loading @@ -450,7 +448,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { } let handler = CommandHandler::new(context.clone()); if let Ok(_) = command { if command.is_ok() { // Timeout applies only to non-interactive commands. if let Ok(timeout_secs) = timeout_secs { let timeout_duration = Duration::from_secs(timeout_secs); Loading @@ -473,7 +471,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { // - Interactive commands: none of these commands require a timeout. // - Non-interactive commands that have not specified a timeout. handle_client_command(handler, tx, rx, context, command).await?; return Result::Ok(()); Result::Ok(()) }) } Loading @@ -496,7 +494,7 @@ async fn handle_client_command( let semaphore_fg = Arc::new(tokio::sync::Semaphore::new(1)); // If there are no command arguments, start the interactive shell. if let Err(_) = command { if command.is_err() { let command_rule_list = handler.get_command_rule_list().clone(); let context_for_closure = context.clone(); Loading Loading @@ -546,7 +544,7 @@ async fn handle_client_command( callback(context.clone()); // Break the loop as a non-interactive command is completed. if let Ok(_) = command { if command.is_ok() { break; } } Loading Loading @@ -763,7 +761,7 @@ async fn handle_client_command( // Run the command with the command arguments as the client is // non-interactive. if let Some(command) = command.as_ref().ok() { if let Ok(command) = command.as_ref() { let mut iter = command.split(' ').map(String::from); let first = iter.next().unwrap_or(String::from("")); if !handler.process_cmd_line(&first, &iter.collect::<Vec<String>>()) { Loading