Skip to content

Commit

Permalink
add tcpip and usb command for device services
Browse files Browse the repository at this point in the history
  • Loading branch information
JinkeJ committed Nov 13, 2024
1 parent bbba179 commit 95f925d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
10 changes: 8 additions & 2 deletions adb_client/src/models/adb_server_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub(crate) enum AdbServerCommand {
MDNSServices,
ServerStatus,
ReconnectOffline,
TcpIP(u16),
USB,
}

impl Display for AdbServerCommand {
Expand Down Expand Up @@ -77,8 +79,12 @@ impl Display for AdbServerCommand {
AdbServerCommand::ReconnectOffline => {
write!(f, "host:reconnect-offline")
}
// TODO: tcpip tcpip:%d/usb usb:
// killforward-all
AdbServerCommand::TcpIP(port) => {
write!(f, "tcpip:{port}")
}
AdbServerCommand::USB => {
write!(f, "usb:")
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions adb_client/src/server/device_commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ mod reverse;
mod send;
mod stat;
mod transport;
mod tcpip;
mod usb;
17 changes: 17 additions & 0 deletions adb_client/src/server/device_commands/tcpip.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use crate::{
models::AdbServerCommand,
ADBServerDevice, Result,
};

impl ADBServerDevice {
/// Set adb daemon to tcpip mode
pub fn tcpip(&mut self, port: u16) -> Result<()> {
let serial = self.identifier.clone();
self.connect()?
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;

self.get_transport_mut()
.proxy_connection(AdbServerCommand::TcpIP(port), false)
.map(|_| ())
}
}
17 changes: 17 additions & 0 deletions adb_client/src/server/device_commands/usb.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use crate::{
models::AdbServerCommand,
ADBServerDevice, Result,
};

impl ADBServerDevice {
/// Set adb daemon to usb mode
pub fn usb(&mut self) -> Result<()> {
let serial = self.identifier.clone();
self.connect()?
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;

self.get_transport_mut()
.proxy_connection(AdbServerCommand::USB, false)
.map(|_| ())
}
}

0 comments on commit 95f925d

Please sign in to comment.