Skip to content

Commit

Permalink
Add Forward and Reverse commands
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitsangwan01 authored and cocool97 committed Nov 4, 2024
1 parent e60ae74 commit d932e93
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions adb_client/src/models/adb_server_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub(crate) enum AdbServerCommand {
FrameBuffer,
Sync,
Reboot(RebootType),
Forward(String, String, String),
Reverse(String, String),
}

impl Display for AdbServerCommand {
Expand Down Expand Up @@ -53,6 +55,12 @@ impl Display for AdbServerCommand {
write!(f, "host:pair:{code}:{addr}")
}
AdbServerCommand::FrameBuffer => write!(f, "framebuffer:"),
AdbServerCommand::Forward(serial, remote, local) => {
write!(f, "host-serial:{serial}:forward:{local};{remote}")
}
AdbServerCommand::Reverse(remote, local) => {
write!(f, "reverse:forward:{remote};{local}")
}
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions adb_client/src/server/device_commands/forward.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use crate::{models::AdbServerCommand, ADBServerDevice, Result};

impl ADBServerDevice {
/// Forward socket connection
pub fn forward(&mut self, remote: String, local: String) -> Result<()> {
let serial = self.identifier.clone();
self.connect()?
.send_adb_request(AdbServerCommand::TransportSerial(serial.clone()))?;

self.get_transport_mut()
.proxy_connection(AdbServerCommand::Forward(serial, remote, local), false)
.map(|_| ())
}
}
2 changes: 2 additions & 0 deletions adb_client/src/server/device_commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
mod forward;
mod framebuffer;
mod host_features;
mod list;
mod logcat;
mod reboot;
mod recv;
mod reverse;
mod send;
mod stat;
mod transport;
14 changes: 14 additions & 0 deletions adb_client/src/server/device_commands/reverse.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use crate::{models::AdbServerCommand, ADBServerDevice, Result};

impl ADBServerDevice {
/// Reverse socket connection
pub fn reverse(&mut self, remote: String, local: String) -> Result<()> {
let serial = self.identifier.clone();
self.connect()?
.send_adb_request(AdbServerCommand::TransportSerial(serial))?;

self.get_transport_mut()
.proxy_connection(AdbServerCommand::Reverse(remote, local), false)
.map(|_| ())
}
}

0 comments on commit d932e93

Please sign in to comment.