Skip to content

Commit

Permalink
add reconnect and forware remove all
Browse files Browse the repository at this point in the history
  • Loading branch information
JinkeJ committed Nov 13, 2024
1 parent 95f925d commit 4268383
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
24 changes: 9 additions & 15 deletions adb_client/src/models/adb_server_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ pub(crate) enum AdbServerCommand {
Sync,
Reboot(RebootType),
Forward(String, String, String),
ForwardRemoveAll,
Reverse(String, String),
MDNSCheck,
MDNSServices,
ServerStatus,
Reconnect,
ReconnectOffline,
TcpIP(u16),
USB,
Expand Down Expand Up @@ -61,30 +63,22 @@ impl Display for AdbServerCommand {
write!(f, "host:pair:{code}:{addr}")
}
AdbServerCommand::FrameBuffer => write!(f, "framebuffer:"),
AdbServerCommand::ForwardRemoveAll => write!(f, "host:killforward-all"),
AdbServerCommand::Forward(serial, remote, local) => {
write!(f, "host-serial:{serial}:forward:{local};{remote}")
}
AdbServerCommand::Reverse(remote, local) => {
write!(f, "reverse:forward:{remote};{local}")
}
AdbServerCommand::MDNSCheck => {
write!(f, "host:mdns:check")
}
AdbServerCommand::MDNSServices => {
write!(f, "host:mdns:services")
}
AdbServerCommand::ServerStatus => {
write!(f, "host:server-status")
}
AdbServerCommand::ReconnectOffline => {
write!(f, "host:reconnect-offline")
}
AdbServerCommand::MDNSCheck => write!(f, "host:mdns:check"),
AdbServerCommand::MDNSServices => write!(f, "host:mdns:services"),
AdbServerCommand::ServerStatus => write!(f, "host:server-status"),
AdbServerCommand::Reconnect => write!(f, "reconnect"),
AdbServerCommand::ReconnectOffline => write!(f, "host:reconnect-offline"),
AdbServerCommand::TcpIP(port) => {
write!(f, "tcpip:{port}")
}
AdbServerCommand::USB => {
write!(f, "usb:")
}
AdbServerCommand::USB => write!(f, "usb:"),
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions adb_client/src/server/device_commands/forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,15 @@ impl ADBServerDevice {
.proxy_connection(AdbServerCommand::Forward(serial, remote, local), false)
.map(|_| ())
}

/// remove all forward rules
pub fn forward_remove_all(&mut self) -> Result<()> {
let serial = self.identifier.clone();
self.connect()?
.send_adb_request(AdbServerCommand::TransportSerial(serial.clone()))?;

self.get_transport_mut()
.proxy_connection(AdbServerCommand::ForwardRemoveAll, false)
.map(|_| ())
}
}
1 change: 1 addition & 0 deletions adb_client/src/server/device_commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ mod stat;
mod transport;
mod tcpip;
mod usb;
mod reconnect;
17 changes: 17 additions & 0 deletions adb_client/src/server/device_commands/reconnect.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use crate::{
models::AdbServerCommand,
ADBServerDevice, Result,
};

impl ADBServerDevice {
/// reconnect device
pub fn reconnect(&mut self) -> Result<()> {
let serial = self.identifier.clone();
self.connect()?
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;

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

0 comments on commit 4268383

Please sign in to comment.