Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion adb_cli/src/models/adb_cli_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ impl From<adb_client::RustADBError> for ADBCliError {
| RustADBError::ADBShellNotSupported
| RustADBError::USBDeviceNotFound(_, _)
| RustADBError::WrongFileExtension(_)
| RustADBError::AddrParseError(_) => Self::Standard(value),
| RustADBError::AddrParseError(_)
| RustADBError::DeviceBusy => Self::Standard(value),
}
}
}
5 changes: 5 additions & 0 deletions adb_client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ pub enum RustADBError {
#[cfg_attr(docsrs, doc(cfg(feature = "usb")))]
#[error("USB Error: {0}")]
UsbError(#[from] rusb::Error),
/// Selected device is busy.
#[cfg(feature = "usb")]
#[cfg_attr(docsrs, doc(cfg(feature = "usb")))]
#[error("Device is busy. Is ADB server running?")]
DeviceBusy,
/// USB device not found
#[error("USB Device not found: {0} {1}")]
USBDeviceNotFound(u16, u16),
Expand Down
13 changes: 11 additions & 2 deletions adb_client/src/message_devices/usb/usb_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ impl USBTransport {
}

fn configure_endpoint(handle: &DeviceHandle<GlobalContext>, endpoint: &Endpoint) -> Result<()> {
handle.claim_interface(endpoint.iface)?;
Ok(())
match handle.claim_interface(endpoint.iface) {
Ok(()) => Ok(()),
// busy state likely indicates an ADB server is running and has taken the lock over the device
Err(rusb::Error::Busy) => Err(RustADBError::DeviceBusy),
Err(err) => Err(err.into()),
}
}

fn find_endpoints(handle: &DeviceHandle<GlobalContext>) -> Result<(Endpoint, Endpoint)> {
Expand Down Expand Up @@ -185,6 +189,11 @@ impl ADBTransport for USBTransport {
}

fn disconnect(&mut self) -> crate::Result<()> {
if self.handle.is_none() {
// device has not been initialized, nothing to do
return Ok(());
}

let message = ADBTransportMessage::try_new(MessageCommand::Clse, 0, 0, &[])?;
if let Err(e) = self.write_message(message) {
log::error!("error while sending CLSE message: {e}");
Expand Down
Loading