Compare commits
1 Commits
wasm-suppo
...
108-instal
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14d4888d41 |
@@ -9,7 +9,7 @@ homepage = "https://github.com/cocool97/adb_client"
|
|||||||
keywords = ["adb", "android", "tcp", "usb"]
|
keywords = ["adb", "android", "tcp", "usb"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://github.com/cocool97/adb_client"
|
repository = "https://github.com/cocool97/adb_client"
|
||||||
version = "2.1.13"
|
version = "2.1.12"
|
||||||
|
|
||||||
# To build locally when working on a new release
|
# To build locally when working on a new release
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ pub enum RebootTypeCommand {
|
|||||||
Recovery,
|
Recovery,
|
||||||
Sideload,
|
Sideload,
|
||||||
SideloadAutoReboot,
|
SideloadAutoReboot,
|
||||||
Fastboot,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<RebootTypeCommand> for RebootType {
|
impl From<RebootTypeCommand> for RebootType {
|
||||||
@@ -19,7 +18,6 @@ impl From<RebootTypeCommand> for RebootType {
|
|||||||
RebootTypeCommand::Recovery => RebootType::Recovery,
|
RebootTypeCommand::Recovery => RebootType::Recovery,
|
||||||
RebootTypeCommand::Sideload => RebootType::Sideload,
|
RebootTypeCommand::Sideload => RebootType::Sideload,
|
||||||
RebootTypeCommand::SideloadAutoReboot => RebootType::SideloadAutoReboot,
|
RebootTypeCommand::SideloadAutoReboot => RebootType::SideloadAutoReboot,
|
||||||
RebootTypeCommand::Fastboot => RebootType::Fastboot,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,44 +10,33 @@ repository.workspace = true
|
|||||||
version.workspace = true
|
version.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
getrandom = { version = "*", features = ["js"] }
|
base64 = { version = "0.22.1" }
|
||||||
ring = { version = "*", features = ["wasm32_unknown_unknown_js"] }
|
|
||||||
|
|
||||||
bincode = { version = "1.3.3" }
|
bincode = { version = "1.3.3" }
|
||||||
base64 = { version = "0.22.1", optional = true }
|
byteorder = { version = "1.5.0" }
|
||||||
byteorder = { version = "1.5.0", optional = true }
|
chrono = { version = "0.4.40" }
|
||||||
chrono = { version = "0.4.40", default-features = false, features = ["std"] }
|
homedir = { version = "0.3.4" }
|
||||||
homedir = { version = "0.3.4", optional = true }
|
image = { version = "0.25.5" }
|
||||||
image = { version = "0.25.5", default-features = false }
|
lazy_static = { version = "1.5.0" }
|
||||||
log = { version = "0.4.26" }
|
log = { version = "0.4.26" }
|
||||||
mdns-sd = { version = "0.13.9", default-features = false, features = [
|
mdns-sd = { version = "0.13.2" }
|
||||||
"logging",
|
num-bigint = { version = "0.8.4", package = "num-bigint-dig" }
|
||||||
], optional = true }
|
num-traits = { version = "0.2.19" }
|
||||||
num-bigint = { version = "0.8.4", package = "num-bigint-dig", optional = true }
|
quick-protobuf = { version = "0.8.1" }
|
||||||
num-traits = { version = "0.2.19", optional = true }
|
rand = { version = "0.9.0" }
|
||||||
quick-protobuf = { version = "0.8.1", optional = true }
|
rcgen = { version = "0.13.1" }
|
||||||
rand = { version = "0.8.5", optional = true }
|
regex = { version = "1.11.1", features = ["perf", "std", "unicode"] }
|
||||||
rcgen = { version = "0.13.1", default-features = false, features = [
|
rsa = { version = "0.9.7" }
|
||||||
"aws_lc_rs",
|
rusb = { version = "0.9.4", features = ["vendored"] }
|
||||||
"pem",
|
rustls = { version = "0.23.22" }
|
||||||
], optional = true }
|
rustls-pki-types = "1.11.0"
|
||||||
regex = { version = "1.11.1", features = [
|
|
||||||
"perf",
|
|
||||||
"std",
|
|
||||||
"unicode",
|
|
||||||
], optional = true }
|
|
||||||
rsa = { version = "0.9.7", optional = true }
|
|
||||||
rusb = { version = "0.9.4", features = ["vendored"], optional = true }
|
|
||||||
rustls = { version = "0.23.27", optional = true }
|
|
||||||
rustls-pki-types = { version = "1.11.0", optional = true }
|
|
||||||
serde = { version = "1.0.216", features = ["derive"] }
|
serde = { version = "1.0.216", features = ["derive"] }
|
||||||
serde_repr = { version = "0.1.19", optional = true }
|
serde_repr = { version = "0.1.19" }
|
||||||
sha1 = { version = "0.10.6", features = ["oid"], optional = true }
|
sha1 = { version = "0.10.6", features = ["oid"] }
|
||||||
thiserror = { version = "2.0.7" }
|
thiserror = { version = "2.0.7" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
anyhow = { version = "1.0.93" }
|
anyhow = { version = "1.0.93" }
|
||||||
criterion = { version = "0.6.0" } # Used for benchmarks
|
criterion = { version = "0.5.1" } # Used for benchmarks
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
harness = false
|
harness = false
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::{fs::File, path::Path};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ADBMessageTransport, Result,
|
ADBMessageTransport, Result,
|
||||||
device::{MessageWriter, adb_message_device::ADBMessageDevice},
|
device::{MessageCommand, MessageWriter, adb_message_device::ADBMessageDevice},
|
||||||
utils::check_extension_is_apk,
|
utils::check_extension_is_apk,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -30,6 +30,9 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
"APK file {} successfully installed",
|
"APK file {} successfully installed",
|
||||||
apk_path.as_ref().display()
|
apk_path.as_ref().display()
|
||||||
);
|
);
|
||||||
|
self.get_transport_mut()
|
||||||
|
.read_message()?
|
||||||
|
.assert_command(MessageCommand::Clse)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
d => Err(crate::RustADBError::ADBRequestFailed(String::from_utf8(
|
d => Err(crate::RustADBError::ADBRequestFailed(String::from_utf8(
|
||||||
|
|||||||
@@ -7,37 +7,21 @@
|
|||||||
mod adb_device_ext;
|
mod adb_device_ext;
|
||||||
mod constants;
|
mod constants;
|
||||||
mod device;
|
mod device;
|
||||||
mod error;
|
|
||||||
mod models;
|
|
||||||
mod transports;
|
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
mod emulator_device;
|
mod emulator_device;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
mod error;
|
||||||
mod mdns;
|
mod mdns;
|
||||||
|
mod models;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
mod server;
|
mod server;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
mod server_device;
|
mod server_device;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
mod transports;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
pub use adb_device_ext::ADBDeviceExt;
|
pub use adb_device_ext::ADBDeviceExt;
|
||||||
pub use device::ADBUSBDevice;
|
pub use device::{ADBTcpDevice, ADBUSBDevice};
|
||||||
pub use error::{Result, RustADBError};
|
|
||||||
pub use models::{AdbStatResponse, RebootType};
|
|
||||||
pub use transports::{ADBMessageTransport, ADBTransport};
|
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub use device::ADBTcpDevice;
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub use emulator_device::ADBEmulatorDevice;
|
pub use emulator_device::ADBEmulatorDevice;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
pub use error::{Result, RustADBError};
|
||||||
pub use mdns::*;
|
pub use mdns::*;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
pub use models::{AdbStatResponse, RebootType};
|
||||||
pub use server::*;
|
pub use server::*;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub use server_device::ADBServerDevice;
|
pub use server_device::ADBServerDevice;
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
|
||||||
pub use transports::*;
|
pub use transports::*;
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ pub enum RebootType {
|
|||||||
Sideload,
|
Sideload,
|
||||||
/// Same as `Sideload` but reboots after sideloading
|
/// Same as `Sideload` but reboots after sideloading
|
||||||
SideloadAutoReboot,
|
SideloadAutoReboot,
|
||||||
/// Reboots to fastboot
|
|
||||||
Fastboot,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for RebootType {
|
impl Display for RebootType {
|
||||||
@@ -25,7 +23,6 @@ impl Display for RebootType {
|
|||||||
RebootType::Recovery => write!(f, "recovery"),
|
RebootType::Recovery => write!(f, "recovery"),
|
||||||
RebootType::Sideload => write!(f, "sideload"),
|
RebootType::Sideload => write!(f, "sideload"),
|
||||||
RebootType::SideloadAutoReboot => write!(f, "sideload-auto-reboot"),
|
RebootType::SideloadAutoReboot => write!(f, "sideload-auto-reboot"),
|
||||||
RebootType::Fastboot => write!(f, "fastboot"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ impl ADBServer {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec_devices.push(DeviceLong::try_from(device)?);
|
vec_devices.push(DeviceLong::try_from(device.to_vec())?);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(vec_devices)
|
Ok(vec_devices)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use crate::{DeviceState, RustADBError};
|
|||||||
use regex::bytes::Regex;
|
use regex::bytes::Regex;
|
||||||
|
|
||||||
static DEVICES_LONG_REGEX: LazyLock<Regex> = LazyLock::new(|| {
|
static DEVICES_LONG_REGEX: LazyLock<Regex> = LazyLock::new(|| {
|
||||||
Regex::new(r"^(?P<identifier>\S+)\s+(?P<state>\w+)\s+(usb:(?P<usb1>\S+)|(?P<usb2>\S+))?\s*(product:(?P<product>\S+)\s+model:(?P<model>\w+)\s+device:(?P<device>\S+)\s+)?transport_id:(?P<transport_id>\d+)$").expect("cannot build devices long regex")
|
Regex::new(r"^(?P<identifier>\S+)\s+(?P<state>\w+)\s+(usb:(?P<usb1>\S+)|(?P<usb2>\S+))?\s*(product:(?P<product>\w+)\s+model:(?P<model>\w+)\s+device:(?P<device>\w+)\s+)?transport_id:(?P<transport_id>\d+)$").expect("cannot build devices long regex")
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Represents a new device with more informations.
|
/// Represents a new device with more informations.
|
||||||
@@ -44,12 +44,12 @@ impl Display for DeviceLong {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<&[u8]> for DeviceLong {
|
impl TryFrom<Vec<u8>> for DeviceLong {
|
||||||
type Error = RustADBError;
|
type Error = RustADBError;
|
||||||
|
|
||||||
fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
|
fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
|
||||||
let groups = DEVICES_LONG_REGEX
|
let groups = DEVICES_LONG_REGEX
|
||||||
.captures(value)
|
.captures(&value)
|
||||||
.ok_or(RustADBError::RegexParsingError)?;
|
.ok_or(RustADBError::RegexParsingError)?;
|
||||||
|
|
||||||
Ok(DeviceLong {
|
Ok(DeviceLong {
|
||||||
@@ -98,17 +98,3 @@ impl TryFrom<&[u8]> for DeviceLong {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_static_devices_long() {
|
|
||||||
let inputs = [
|
|
||||||
"7a5158f05122195aa device 1-5 product:gts210vewifixx model:SM_T813 device:gts210vewifi transport_id:4",
|
|
||||||
"n311r05e device usb:0-1.5 product:alioth model:M2012K11AC device:alioth transport_id:58",
|
|
||||||
"192.168.100.192:5555 device product:alioth model:M2012K11AC device:alioth transport_id:97",
|
|
||||||
"emulator-5554 device product:sdk_gphone64_arm64 model:sdk_gphone64_arm64 device:emu64a transport_id:101",
|
|
||||||
"QQ20131020250511 device 20-4 product:NOH-AN00 model:NOH_AN00 device:HWNOH transport_id:3",
|
|
||||||
];
|
|
||||||
for input in inputs {
|
|
||||||
DeviceLong::try_from(input.as_bytes()).expect(&format!("cannot parse input: '{input}'"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -21,6 +21,6 @@ name = "stub_gen"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
adb_client = { path = "../adb_client" }
|
adb_client = { path = "../adb_client" }
|
||||||
anyhow = { version = "1.0.95" }
|
anyhow = { version = "1.0.95" }
|
||||||
pyo3 = { version = "0.25.0", features = ["abi3-py37", "anyhow"] }
|
pyo3 = { version = "0.24.1", features = ["abi3-py37", "anyhow"] }
|
||||||
pyo3-stub-gen = "0.7.0"
|
pyo3-stub-gen = "0.7.0"
|
||||||
pyo3-stub-gen-derive = "0.7.0"
|
pyo3-stub-gen-derive = "0.7.0"
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ usb_device.push("file.txt", "/data/local/tmp/file.txt")
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Create Python virtual environment
|
# Create Python virtual environment
|
||||||
|
cd pyadb_client
|
||||||
python3 -m venv .venv
|
python3 -m venv .venv
|
||||||
source .venv/bin/activate
|
source .venv/bin/activate
|
||||||
|
|
||||||
|
|||||||
101
tests/tests.rs
Normal file
101
tests/tests.rs
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use std::io::Cursor;
|
||||||
|
|
||||||
|
use adb_client::{ADBServer, ADBServerDevice, DeviceLong};
|
||||||
|
use rand::Rng;
|
||||||
|
|
||||||
|
fn new_client() -> ADBServer {
|
||||||
|
ADBServer::default()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new_device() -> ADBServerDevice {
|
||||||
|
let mut client = new_client();
|
||||||
|
return client.get_device().expect("cannot get device");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_version() {
|
||||||
|
let mut adb = new_client();
|
||||||
|
adb.version().expect("cannot get adb version");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_shell_commands() {
|
||||||
|
let mut device = new_device();
|
||||||
|
|
||||||
|
device.shell_command(["ls"]).expect("error while executing `ls` command");
|
||||||
|
device.shell_command(["pwd"]).expect("error while executing `pwd` command");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_devices() {
|
||||||
|
let mut adb = new_client();
|
||||||
|
adb.devices().expect("cannot list devices");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_devices_long() {
|
||||||
|
let mut adb = new_client();
|
||||||
|
adb.devices_long().expect("cannot list devices long");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_static_devices_long() {
|
||||||
|
let inputs = ["7a5158f05122195aa device 1-5 product:gts210vewifixx model:SM_T813 device:gts210vewifi transport_id:4",
|
||||||
|
"n311r05e device usb:0-1.5 product:alioth model:M2012K11AC device:alioth transport_id:58",
|
||||||
|
"192.168.100.192:5555 device product:alioth model:M2012K11AC device:alioth transport_id:97",
|
||||||
|
"emulator-5554 device product:sdk_gphone64_arm64 model:sdk_gphone64_arm64 device:emu64a transport_id:101"];
|
||||||
|
for input in inputs {
|
||||||
|
DeviceLong::try_from(input.as_bytes().to_vec())
|
||||||
|
.expect(&format!("cannot parse input: '{input}'"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_send_recv() {
|
||||||
|
// Create random "Reader" in memory
|
||||||
|
let mut key = [0u8; 1000];
|
||||||
|
rand::thread_rng().fill(&mut key[..]);
|
||||||
|
let mut c: Cursor<Vec<u8>> = Cursor::new(key.to_vec());
|
||||||
|
|
||||||
|
let mut device = new_device();
|
||||||
|
|
||||||
|
const TEST_FILENAME: &'static str = "/data/local/tmp/test_file";
|
||||||
|
// Send it
|
||||||
|
device
|
||||||
|
.send(&mut c, TEST_FILENAME)
|
||||||
|
.expect("cannot send file");
|
||||||
|
|
||||||
|
// Pull it to memory
|
||||||
|
let mut res = vec![];
|
||||||
|
device
|
||||||
|
.recv(TEST_FILENAME, &mut res)
|
||||||
|
.expect("cannot recv file");
|
||||||
|
|
||||||
|
// diff
|
||||||
|
assert_eq!(c.get_ref(), &res);
|
||||||
|
|
||||||
|
device
|
||||||
|
.shell_command::<&str>([format!("rm {TEST_FILENAME}").as_str()])
|
||||||
|
.expect("cannot remove test file");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn multiple_connexions() {
|
||||||
|
let mut connection = new_client();
|
||||||
|
|
||||||
|
for _ in 0..2 {
|
||||||
|
let _ = connection.devices().expect("cannot get version");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn command_emulator() {
|
||||||
|
let mut connection = new_client();
|
||||||
|
let mut emulator = connection
|
||||||
|
.get_emulator_device()
|
||||||
|
.expect("no emulator running");
|
||||||
|
emulator.hello().expect("cannot hello");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user