feat: add AdbTcpConnection::new_with_default method

This commit is contained in:
LIAUD Corentin
2024-07-15 15:25:21 +02:00
parent c6ffa2ff6b
commit 3d3546106e
2 changed files with 11 additions and 2 deletions

View File

@@ -12,6 +12,9 @@ use crate::{
Result, RustADBError,
};
const DEFAULT_SERVER_IP: Ipv4Addr = Ipv4Addr::new(127, 0, 0, 1);
const DEFAULT_SERVER_PORT: u16 = 5037;
/// Represents an ADB-over-TCP connection.
#[derive(Debug)]
pub struct AdbTcpConnection {
@@ -29,6 +32,11 @@ impl AdbTcpConnection {
})
}
/// Instantiates a new instance of [AdbTcpConnection] with default ip/port.
pub fn new_with_default() -> Result<Self> {
Self::new(DEFAULT_SERVER_IP, DEFAULT_SERVER_PORT)
}
/// Creates a new connection to ADB server.
///
/// Can be used after requests that closes connection.
@@ -42,7 +50,7 @@ impl AdbTcpConnection {
&mut self,
adb_command: AdbCommand,
with_response: bool,
fresh_connection: bool
fresh_connection: bool,
) -> Result<Vec<u8>> {
self.send_adb_request(adb_command, fresh_connection)?;

View File

@@ -3,6 +3,7 @@ use crate::{models::AdbCommand, AdbTcpConnection, Result};
impl AdbTcpConnection {
/// Asks the ADB server to quit immediately.
pub fn kill(&mut self) -> Result<()> {
self.proxy_connection(AdbCommand::Kill, false, true).map(|_| ())
self.proxy_connection(AdbCommand::Kill, false, true)
.map(|_| ())
}
}