Compare commits
13 Commits
v2.1.19
...
151-pyadb_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e111d03e4d | ||
|
|
0e24117678 | ||
|
|
8e89aa0d6e | ||
|
|
f0ed96cbd5 | ||
|
|
e2e1ae1202 | ||
|
|
4f26ebfe29 | ||
|
|
2a7c9bdc57 | ||
|
|
d06b157255 | ||
|
|
947964163b | ||
|
|
5075e09d0e | ||
|
|
f1d3f8d5f2 | ||
|
|
9016b7fab4 | ||
|
|
558ef4df7f |
45
.github/workflows/python-build.yml
vendored
45
.github/workflows/python-build.yml
vendored
@@ -9,8 +9,17 @@ on:
|
|||||||
types: [created]
|
types: [created]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
# ============================
|
||||||
|
# BUILD (multi-architecture)
|
||||||
|
# ============================
|
||||||
build-python-packages:
|
build-python-packages:
|
||||||
runs-on: ubuntu-latest
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
arch: [x86_64, arm64]
|
||||||
|
|
||||||
|
runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -23,16 +32,34 @@ jobs:
|
|||||||
- name: Build Python packages
|
- name: Build Python packages
|
||||||
run: maturin build --sdist --release -m pyadb_client/Cargo.toml
|
run: maturin build --sdist --release -m pyadb_client/Cargo.toml
|
||||||
|
|
||||||
- name: Publish Python packages
|
- name: Upload wheels as artifacts
|
||||||
if: github.event_name == 'release' && github.event.action == 'created'
|
uses: actions/upload-artifact@v4
|
||||||
run: maturin publish -m pyadb_client/Cargo.toml --non-interactive
|
with:
|
||||||
|
name: wheels-${{ matrix.arch }}
|
||||||
|
path: target/wheels/*
|
||||||
|
if-no-files-found: error
|
||||||
|
|
||||||
|
# ================================
|
||||||
|
# PUBLISH (release creation only)
|
||||||
|
# ================================
|
||||||
|
publish:
|
||||||
|
name: Publish to PyPI & GitHub Release
|
||||||
|
if: github.event_name == 'release' && github.event.action == 'created'
|
||||||
|
needs: build-python-packages
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Download all wheels
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
path: wheels
|
||||||
|
|
||||||
|
- name: Publish Python packages to PyPI
|
||||||
|
run: maturin publish wheels/**/*.whl --non-interactive
|
||||||
env:
|
env:
|
||||||
MATURIN_PYPI_TOKEN: ${{ secrets.MATURIN_PYPI_TOKEN }}
|
MATURIN_PYPI_TOKEN: ${{ secrets.MATURIN_PYPI_TOKEN }}
|
||||||
|
|
||||||
- name: "Publish GitHub artefacts"
|
- name: Publish GitHub release artifacts
|
||||||
if: github.event_name == 'release' && github.event.action == 'created'
|
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
files: |
|
files: wheels/**/*.*
|
||||||
target/wheels/pyadb_client*.whl
|
|
||||||
target/wheels/pyadb_client*.tar.gz
|
|
||||||
|
|||||||
22
.github/workflows/rust-build.yml
vendored
22
.github/workflows/rust-build.yml
vendored
@@ -6,24 +6,6 @@ on:
|
|||||||
- main
|
- main
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
env:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build-release:
|
||||||
name: "Build on ${{ matrix.os }}"
|
uses: cocool97/action_templates/.github/workflows/rust-build.yml@main
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: "3.10"
|
|
||||||
|
|
||||||
- name: Build project
|
|
||||||
run: cargo build --release --all-features
|
|
||||||
|
|||||||
39
.github/workflows/rust-quality.yml
vendored
39
.github/workflows/rust-quality.yml
vendored
@@ -6,41 +6,6 @@ on:
|
|||||||
- main
|
- main
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
env:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
clippy:
|
quality:
|
||||||
name: "clippy"
|
uses: cocool97/action_templates/.github/workflows/rust-quality.yml@main
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- run: rustup component add clippy
|
|
||||||
- name: Run clippy
|
|
||||||
run: cargo clippy --all-features -- -Dwarnings
|
|
||||||
|
|
||||||
fmt:
|
|
||||||
name: "fmt"
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Run formatter
|
|
||||||
run: cargo fmt --all --check
|
|
||||||
|
|
||||||
doc:
|
|
||||||
name: "doc"
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Run doc
|
|
||||||
run: cargo doc --all-features --no-deps
|
|
||||||
env:
|
|
||||||
RUSTDOCFLAGS: "-D warnings"
|
|
||||||
|
|
||||||
tests:
|
|
||||||
name: "tests"
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Run tests
|
|
||||||
run: cargo test --verbose --all-features
|
|
||||||
|
|||||||
10
.github/workflows/rust-release.yml
vendored
10
.github/workflows/rust-release.yml
vendored
@@ -36,10 +36,10 @@ jobs:
|
|||||||
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
|
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
|
||||||
|
|
||||||
- name: Build release
|
- name: Build release
|
||||||
run: cargo build --all-features --release
|
run: cargo build -p adb_cli --release
|
||||||
|
|
||||||
- name: Rename binary
|
- name: Rename binary
|
||||||
run: mv target/release/adb_cli target/release/adb_cli-linux
|
run: cp target/release/adb_cli target/release/adb_cli-linux
|
||||||
|
|
||||||
- name: Build DEB package
|
- name: Build DEB package
|
||||||
run: cargo deb -p adb_cli
|
run: cargo deb -p adb_cli
|
||||||
@@ -69,10 +69,10 @@ jobs:
|
|||||||
override: true
|
override: true
|
||||||
|
|
||||||
- name: Build release
|
- name: Build release
|
||||||
run: cargo build --all-features --release
|
run: cargo build -p adb_cli --release
|
||||||
|
|
||||||
- name: Rename binary
|
- name: Rename binary
|
||||||
run: mv target/release/adb_cli target/release/adb_cli-macos
|
run: cp target/release/adb_cli target/release/adb_cli-macos
|
||||||
|
|
||||||
- name: Upload macOS binary
|
- name: Upload macOS binary
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
@@ -98,7 +98,7 @@ jobs:
|
|||||||
python-version: "3.10"
|
python-version: "3.10"
|
||||||
|
|
||||||
- name: Build release
|
- name: Build release
|
||||||
run: cargo build --all-features --release
|
run: cargo build -p adb_cli --release
|
||||||
|
|
||||||
- name: Rename binary
|
- name: Rename binary
|
||||||
run: Rename-Item -Path target/release/adb_cli.exe -NewName adb_cli-windows.exe
|
run: Rename-Item -Path target/release/adb_cli.exe -NewName adb_cli-windows.exe
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = ["adb_cli", "adb_client", "pyadb_client"]
|
members = ["adb_cli", "adb_client", "pyadb_client", "examples/mdns"]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
|
|||||||
@@ -42,6 +42,12 @@ Rust library implementing both ADB protocols (server and end-devices) and provid
|
|||||||
|
|
||||||
Improved documentation available [here](./adb_client/README.md).
|
Improved documentation available [here](./adb_client/README.md).
|
||||||
|
|
||||||
|
## examples
|
||||||
|
|
||||||
|
Some examples showing of to use this library are available in the `examples` directory:
|
||||||
|
|
||||||
|
- `examples/mdns`: mDNS device discovery
|
||||||
|
|
||||||
## adb_cli
|
## adb_cli
|
||||||
|
|
||||||
Rust binary providing an improved version of Google's official `adb` CLI, by using `adb_client` library.
|
Rust binary providing an improved version of Google's official `adb` CLI, by using `adb_client` library.
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ rust-version.workspace = true
|
|||||||
version.workspace = true
|
version.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
adb_client = { version = "^2.1.18" }
|
adb_client = { version = "^2.1.19", features = ["mdns"] }
|
||||||
clap = { version = "4.5.53", features = ["derive"] }
|
clap = { version = "4.5.53", features = ["derive"] }
|
||||||
env_logger = { version = "0.11.8" }
|
env_logger = { version = "0.11.8" }
|
||||||
log = { version = "0.4.29" }
|
log = { version = "0.4.29" }
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ mod utils;
|
|||||||
|
|
||||||
use adb_client::{
|
use adb_client::{
|
||||||
ADBDeviceExt, ADBListItemType, ADBServer, ADBServerDevice, ADBTcpDevice, ADBUSBDevice,
|
ADBDeviceExt, ADBListItemType, ADBServer, ADBServerDevice, ADBTcpDevice, ADBUSBDevice,
|
||||||
MDNSDiscoveryService,
|
mdns::MDNSDiscoveryService,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||||
@@ -22,6 +22,7 @@ use std::collections::HashMap;
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use std::process::ExitCode;
|
||||||
use utils::setup_logger;
|
use utils::setup_logger;
|
||||||
|
|
||||||
use crate::models::{ADBCliError, ADBCliResult};
|
use crate::models::{ADBCliError, ADBCliResult};
|
||||||
@@ -108,7 +109,16 @@ fn run_command(mut device: Box<dyn ADBDeviceExt>, command: DeviceCommands) -> AD
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> ADBCliResult<()> {
|
fn main() -> ExitCode {
|
||||||
|
if let Err(err) = inner_main() {
|
||||||
|
log::error!("{err}");
|
||||||
|
return ExitCode::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ExitCode::SUCCESS
|
||||||
|
}
|
||||||
|
|
||||||
|
fn inner_main() -> ADBCliResult<()> {
|
||||||
// This depends on `clap`
|
// This depends on `clap`
|
||||||
let opts = Opts::parse();
|
let opts = Opts::parse();
|
||||||
|
|
||||||
@@ -174,9 +184,10 @@ fn main() -> ADBCliResult<()> {
|
|||||||
log::info!("Starting mdns discovery...");
|
log::info!("Starting mdns discovery...");
|
||||||
while let Ok(device) = rx.recv() {
|
while let Ok(device) = rx.recv() {
|
||||||
log::info!(
|
log::info!(
|
||||||
"Found device {} with addresses {:?}",
|
"Found device fullname='{}' with ipv4 addresses={:?} and ipv6 addresses={:?}",
|
||||||
device.fullname,
|
device.fullname,
|
||||||
device.addresses
|
device.ipv4_addresses(),
|
||||||
|
device.ipv6_addresses()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::fmt::Debug;
|
use std::fmt::Display;
|
||||||
|
|
||||||
use adb_client::RustADBError;
|
use adb_client::RustADBError;
|
||||||
|
|
||||||
@@ -9,19 +9,18 @@ pub enum ADBCliError {
|
|||||||
MayNeedAnIssue(Box<dyn std::error::Error>),
|
MayNeedAnIssue(Box<dyn std::error::Error>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Debug for ADBCliError {
|
impl Display for ADBCliError {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
ADBCliError::Standard(error) => write!(f, "{error}"),
|
ADBCliError::Standard(error) => write!(f, "{error}"),
|
||||||
ADBCliError::MayNeedAnIssue(error) => write!(
|
ADBCliError::MayNeedAnIssue(error) => {
|
||||||
f,
|
write!(
|
||||||
r"
|
f,
|
||||||
This error is abnormal and may need to fill an issue.
|
r"Error: {error}
|
||||||
Please submit it to this project's repository here: https://github.com/cocool97/adb_client/issues.
|
An unexpected error occurred and may indicate a bug.
|
||||||
Error source:
|
Please report this issue on the project repository (including steps to reproduce if possible): https://github.com/cocool97/adb_client/issues.",
|
||||||
{error}
|
)
|
||||||
",
|
}
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -68,7 +67,7 @@ impl From<adb_client::RustADBError> for ADBCliError {
|
|||||||
| RustADBError::PoisonError
|
| RustADBError::PoisonError
|
||||||
| RustADBError::UpgradeError(_)
|
| RustADBError::UpgradeError(_)
|
||||||
| RustADBError::MDNSError(_)
|
| RustADBError::MDNSError(_)
|
||||||
| RustADBError::SendError(_)
|
| RustADBError::SendError
|
||||||
| RustADBError::UnknownFileMode(_)
|
| RustADBError::UnknownFileMode(_)
|
||||||
| RustADBError::UnknownTransport(_) => Self::MayNeedAnIssue(value),
|
| RustADBError::UnknownTransport(_) => Self::MayNeedAnIssue(value),
|
||||||
// List of [`RustADBError`] that may occur in standard contexts and therefore do not require for issues
|
// List of [`RustADBError`] that may occur in standard contexts and therefore do not require for issues
|
||||||
|
|||||||
@@ -10,16 +10,21 @@ repository.workspace = true
|
|||||||
rust-version.workspace = true
|
rust-version.workspace = true
|
||||||
version.workspace = true
|
version.workspace = true
|
||||||
|
|
||||||
|
[package.metadata.docs.rs]
|
||||||
|
all-features = true
|
||||||
|
rustdoc-args = ["--cfg", "docsrs"]
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
mdns = ["dep:mdns-sd"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
base64 = { version = "0.22.1" }
|
base64 = { version = "0.22.1" }
|
||||||
bincode = { version = "2.0.1", features = ["serde"] }
|
bincode = { version = "2.0.1", features = ["serde"] }
|
||||||
byteorder = { version = "1.5.0" }
|
byteorder = { version = "1.5.0" }
|
||||||
chrono = { version = "0.4.42", default-features = false, features = ["std"] }
|
chrono = { version = "0.4.42", default-features = false, features = ["std"] }
|
||||||
image = { version = "0.25.9", default-features = false }
|
image = { version = "0.25.9", default-features = false, features = ["png"] }
|
||||||
log = { version = "0.4.29" }
|
log = { version = "0.4.29" }
|
||||||
mdns-sd = { version = "0.17.1", default-features = false, features = [
|
|
||||||
"logging",
|
|
||||||
] }
|
|
||||||
num-bigint = { version = "0.8.6", package = "num-bigint-dig" }
|
num-bigint = { version = "0.8.6", package = "num-bigint-dig" }
|
||||||
num-traits = { version = "0.2.19" }
|
num-traits = { version = "0.2.19" }
|
||||||
quick-protobuf = { version = "0.8.1" }
|
quick-protobuf = { version = "0.8.1" }
|
||||||
@@ -35,6 +40,13 @@ serde_repr = { version = "0.1.20" }
|
|||||||
sha1 = { version = "0.10.6", features = ["oid"] }
|
sha1 = { version = "0.10.6", features = ["oid"] }
|
||||||
thiserror = { version = "2.0.17" }
|
thiserror = { version = "2.0.17" }
|
||||||
|
|
||||||
|
#########
|
||||||
|
# `mdns` feature-specific dependencies
|
||||||
|
mdns-sd = { version = "0.17.1", default-features = false, features = [
|
||||||
|
"logging",
|
||||||
|
], optional = true }
|
||||||
|
#########
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
anyhow = { version = "1.0.100" }
|
anyhow = { version = "1.0.100" }
|
||||||
criterion = { version = "0.7.0" } # Used for benchmarks
|
criterion = { version = "0.7.0" } # Used for benchmarks
|
||||||
|
|||||||
@@ -16,6 +16,19 @@ Add `adb_client` crate as a dependency by simply adding it to your `Cargo.toml`:
|
|||||||
adb_client = "*"
|
adb_client = "*"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Crate features
|
||||||
|
|
||||||
|
| Feature | Description | Default? |
|
||||||
|
| :-----: | :---------------------------------------------: | :------: |
|
||||||
|
| `mdns` | Enables mDNS device discovery on local network. | No |
|
||||||
|
|
||||||
|
To deactivate some default features you can use the `default-features = false` option in your `Cargo.toml` file and manually specify the features you want to activate:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[dependencies]
|
||||||
|
adb_client = { version = "*", default-features = false, features = ["mdns"] }
|
||||||
|
```
|
||||||
|
|
||||||
## Benchmarks
|
## Benchmarks
|
||||||
|
|
||||||
Benchmarks run on `v2.0.6`, on a **Samsung S10 SM-G973F** device and an **Intel i7-1265U** CPU laptop
|
Benchmarks run on `v2.0.6`, on a **Samsung S10 SM-G973F** device and an **Intel i7-1265U** CPU laptop
|
||||||
@@ -24,11 +37,11 @@ Benchmarks run on `v2.0.6`, on a **Samsung S10 SM-G973F** device and an **Intel
|
|||||||
|
|
||||||
`ADBServerDevice` performs all operations by using adb server as a bridge.
|
`ADBServerDevice` performs all operations by using adb server as a bridge.
|
||||||
|
|
||||||
|File size|Sample size|`ADBServerDevice`|`adb`|Difference|
|
| File size | Sample size | `ADBServerDevice` | `adb` | Difference |
|
||||||
|:-------:|:---------:|:----------:|:---:|:-----:|
|
| :-------: | :---------: | :---------------: | :-------: | :------------------------------------: |
|
||||||
|10 MB|100|350,79 ms|356,30 ms|<div style="color:green">-1,57 %</div>|
|
| 10 MB | 100 | 350,79 ms | 356,30 ms | <div style="color:green">-1,57 %</div> |
|
||||||
|500 MB|50|15,60 s|15,64 s|<div style="color:green">-0,25 %</div>|
|
| 500 MB | 50 | 15,60 s | 15,64 s | <div style="color:green">-0,25 %</div> |
|
||||||
|1 GB|20|31,09 s|31,12 s|<div style="color:green">-0,10 %</div>|
|
| 1 GB | 20 | 31,09 s | 31,12 s | <div style="color:green">-0,10 %</div> |
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,9 @@ pub trait ADBDeviceExt {
|
|||||||
/// Inner method requesting framebuffer from an Android device
|
/// Inner method requesting framebuffer from an Android device
|
||||||
fn framebuffer_inner(&mut self) -> Result<ImageBuffer<Rgba<u8>, Vec<u8>>>;
|
fn framebuffer_inner(&mut self) -> Result<ImageBuffer<Rgba<u8>, Vec<u8>>>;
|
||||||
|
|
||||||
/// Dump framebuffer of this device into given path
|
/// Dump framebuffer of this device into given path.
|
||||||
|
///
|
||||||
|
/// Output data format is currently only `PNG`.
|
||||||
fn framebuffer(&mut self, path: &dyn AsRef<Path>) -> Result<()> {
|
fn framebuffer(&mut self, path: &dyn AsRef<Path>) -> Result<()> {
|
||||||
// Big help from AOSP source code (<https://android.googlesource.com/platform/system/adb/+/refs/heads/main/framebuffer_service.cpp>)
|
// Big help from AOSP source code (<https://android.googlesource.com/platform/system/adb/+/refs/heads/main/framebuffer_service.cpp>)
|
||||||
let img = self.framebuffer_inner()?;
|
let img = self.framebuffer_inner()?;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use super::{ADBRsaKey, ADBTransportMessage, MessageCommand, models::MessageSubcommand};
|
use super::{ADBRsaKey, ADBTransportMessage, MessageCommand, models::MessageSubcommand};
|
||||||
use crate::device::adb_transport_message::{AUTH_RSAPUBLICKEY, AUTH_SIGNATURE, AUTH_TOKEN};
|
use crate::device::adb_transport_message::{AUTH_RSAPUBLICKEY, AUTH_SIGNATURE, AUTH_TOKEN};
|
||||||
|
use crate::device::models::ADBSession;
|
||||||
use crate::{ADBMessageTransport, AdbStatResponse, Result, RustADBError, constants::BUFFER_SIZE};
|
use crate::{ADBMessageTransport, AdbStatResponse, Result, RustADBError, constants::BUFFER_SIZE};
|
||||||
use bincode::config::{Configuration, Fixint, LittleEndian, NoLimit};
|
use bincode::config::{Configuration, Fixint, LittleEndian, NoLimit};
|
||||||
use byteorder::ReadBytesExt;
|
use byteorder::ReadBytesExt;
|
||||||
@@ -27,18 +28,12 @@ pub(crate) fn bincode_deserialize_from_slice<D: DeserializeOwned>(data: &[u8]) -
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ADBMessageDevice<T: ADBMessageTransport> {
|
pub struct ADBMessageDevice<T: ADBMessageTransport> {
|
||||||
transport: T,
|
transport: T,
|
||||||
local_id: Option<u32>,
|
|
||||||
remote_id: Option<u32>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||||
/// Instantiate a new [`ADBMessageTransport`]
|
/// Instantiate a new [`ADBMessageTransport`]
|
||||||
pub fn new(transport: T) -> Self {
|
pub fn new(transport: T) -> Self {
|
||||||
Self {
|
Self { transport }
|
||||||
transport,
|
|
||||||
local_id: None,
|
|
||||||
remote_id: None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_transport(&mut self) -> &T {
|
pub(crate) fn get_transport(&mut self) -> &T {
|
||||||
@@ -110,12 +105,15 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Receive a message and acknowledge it by replying with an `OKAY` command
|
/// Receive a message and acknowledge it by replying with an `OKAY` command
|
||||||
pub(crate) fn recv_and_reply_okay(&mut self) -> Result<ADBTransportMessage> {
|
pub(crate) fn recv_and_reply_okay(
|
||||||
|
&mut self,
|
||||||
|
session: ADBSession,
|
||||||
|
) -> Result<ADBTransportMessage> {
|
||||||
let message = self.transport.read_message()?;
|
let message = self.transport.read_message()?;
|
||||||
self.transport.write_message(ADBTransportMessage::new(
|
self.transport.write_message(ADBTransportMessage::new(
|
||||||
MessageCommand::Okay,
|
MessageCommand::Okay,
|
||||||
self.get_local_id()?,
|
session.local_id(),
|
||||||
self.get_remote_id()?,
|
session.remote_id(),
|
||||||
&[],
|
&[],
|
||||||
))?;
|
))?;
|
||||||
Ok(message)
|
Ok(message)
|
||||||
@@ -136,11 +134,12 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
|
|
||||||
pub(crate) fn recv_file<W: std::io::Write>(
|
pub(crate) fn recv_file<W: std::io::Write>(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
session: ADBSession,
|
||||||
mut output: W,
|
mut output: W,
|
||||||
) -> std::result::Result<(), RustADBError> {
|
) -> std::result::Result<(), RustADBError> {
|
||||||
let mut len: Option<u64> = None;
|
let mut len: Option<u64> = None;
|
||||||
loop {
|
loop {
|
||||||
let payload = self.recv_and_reply_okay()?.into_payload();
|
let payload = self.recv_and_reply_okay(session)?.into_payload();
|
||||||
let mut rdr = Cursor::new(&payload);
|
let mut rdr = Cursor::new(&payload);
|
||||||
while rdr.position() != payload.len() as u64 {
|
while rdr.position() != payload.len() as u64 {
|
||||||
match len.take() {
|
match len.take() {
|
||||||
@@ -173,8 +172,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
|
|
||||||
pub(crate) fn push_file<R: std::io::Read>(
|
pub(crate) fn push_file<R: std::io::Read>(
|
||||||
&mut self,
|
&mut self,
|
||||||
local_id: u32,
|
session: ADBSession,
|
||||||
remote_id: u32,
|
|
||||||
mut reader: R,
|
mut reader: R,
|
||||||
) -> std::result::Result<(), RustADBError> {
|
) -> std::result::Result<(), RustADBError> {
|
||||||
let mut buffer = vec![0; BUFFER_SIZE].into_boxed_slice();
|
let mut buffer = vec![0; BUFFER_SIZE].into_boxed_slice();
|
||||||
@@ -186,8 +184,8 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
|
|
||||||
let message = ADBTransportMessage::new(
|
let message = ADBTransportMessage::new(
|
||||||
MessageCommand::Write,
|
MessageCommand::Write,
|
||||||
local_id,
|
session.local_id(),
|
||||||
remote_id,
|
session.remote_id(),
|
||||||
&serialized_message,
|
&serialized_message,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -204,8 +202,8 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
let serialized_message = bincode_serialize_to_vec(&subcommand_data)?;
|
let serialized_message = bincode_serialize_to_vec(&subcommand_data)?;
|
||||||
let message = ADBTransportMessage::new(
|
let message = ADBTransportMessage::new(
|
||||||
MessageCommand::Write,
|
MessageCommand::Write,
|
||||||
local_id,
|
session.local_id(),
|
||||||
remote_id,
|
session.remote_id(),
|
||||||
&serialized_message,
|
&serialized_message,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -230,8 +228,8 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
|
|
||||||
let message = ADBTransportMessage::new(
|
let message = ADBTransportMessage::new(
|
||||||
MessageCommand::Write,
|
MessageCommand::Write,
|
||||||
local_id,
|
session.local_id(),
|
||||||
remote_id,
|
session.remote_id(),
|
||||||
&serialized_message,
|
&serialized_message,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -244,24 +242,27 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn begin_synchronization(&mut self) -> Result<()> {
|
pub(crate) fn begin_synchronization(&mut self) -> Result<ADBSession> {
|
||||||
self.open_session(b"sync:\0")?;
|
self.open_session(b"sync:\0")
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn stat_with_explicit_ids(&mut self, remote_path: &str) -> Result<AdbStatResponse> {
|
pub(crate) fn stat_with_explicit_ids(
|
||||||
|
&mut self,
|
||||||
|
session: ADBSession,
|
||||||
|
remote_path: &str,
|
||||||
|
) -> Result<AdbStatResponse> {
|
||||||
let stat_buffer = MessageSubcommand::Stat.with_arg(u32::try_from(remote_path.len())?);
|
let stat_buffer = MessageSubcommand::Stat.with_arg(u32::try_from(remote_path.len())?);
|
||||||
let message = ADBTransportMessage::new(
|
let message = ADBTransportMessage::new(
|
||||||
MessageCommand::Write,
|
MessageCommand::Write,
|
||||||
self.get_local_id()?,
|
session.local_id(),
|
||||||
self.get_remote_id()?,
|
session.remote_id(),
|
||||||
&bincode_serialize_to_vec(&stat_buffer)?,
|
&bincode_serialize_to_vec(&stat_buffer)?,
|
||||||
);
|
);
|
||||||
self.send_and_expect_okay(message)?;
|
self.send_and_expect_okay(message)?;
|
||||||
self.send_and_expect_okay(ADBTransportMessage::new(
|
self.send_and_expect_okay(ADBTransportMessage::new(
|
||||||
MessageCommand::Write,
|
MessageCommand::Write,
|
||||||
self.get_local_id()?,
|
session.local_id(),
|
||||||
self.get_remote_id()?,
|
session.remote_id(),
|
||||||
remote_path.as_bytes(),
|
remote_path.as_bytes(),
|
||||||
))?;
|
))?;
|
||||||
let response = self.transport.read_message()?;
|
let response = self.transport.read_message()?;
|
||||||
@@ -271,24 +272,25 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
bincode_deserialize_from_slice(&response.into_payload()[4..])
|
bincode_deserialize_from_slice(&response.into_payload()[4..])
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn end_transaction(&mut self) -> Result<()> {
|
pub(crate) fn end_transaction(&mut self, session: ADBSession) -> Result<()> {
|
||||||
let quit_buffer = MessageSubcommand::Quit.with_arg(0u32);
|
let quit_buffer = MessageSubcommand::Quit.with_arg(0u32);
|
||||||
self.send_and_expect_okay(ADBTransportMessage::new(
|
self.send_and_expect_okay(ADBTransportMessage::new(
|
||||||
MessageCommand::Write,
|
MessageCommand::Write,
|
||||||
self.get_local_id()?,
|
session.local_id(),
|
||||||
self.get_remote_id()?,
|
session.remote_id(),
|
||||||
&bincode_serialize_to_vec(&quit_buffer)?,
|
&bincode_serialize_to_vec(&quit_buffer)?,
|
||||||
))?;
|
))?;
|
||||||
let _discard_close = self.transport.read_message()?;
|
let _discard_close = self.transport.read_message()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn open_session(&mut self, data: &[u8]) -> Result<ADBTransportMessage> {
|
pub(crate) fn open_session(&mut self, data: &[u8]) -> Result<ADBSession> {
|
||||||
let mut rng = rand::rng();
|
let mut rng = rand::rng();
|
||||||
|
let local_id: u32 = rng.random();
|
||||||
|
|
||||||
let message = ADBTransportMessage::new(
|
let message = ADBTransportMessage::new(
|
||||||
MessageCommand::Open,
|
MessageCommand::Open,
|
||||||
rng.random(), // Our 'local-id'
|
local_id, // Our 'local-id'
|
||||||
0,
|
0,
|
||||||
data,
|
data,
|
||||||
);
|
);
|
||||||
@@ -296,21 +298,20 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
|
|
||||||
let response = self.get_transport_mut().read_message()?;
|
let response = self.get_transport_mut().read_message()?;
|
||||||
|
|
||||||
self.local_id = Some(response.header().arg1());
|
if response.header().command() != MessageCommand::Okay {
|
||||||
self.remote_id = Some(response.header().arg0());
|
return Err(RustADBError::ADBRequestFailed(format!(
|
||||||
|
"Open session failed: got {} in respone instead of OKAY",
|
||||||
|
response.header().command()
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(response)
|
if response.header().arg1() != local_id {
|
||||||
}
|
return Err(RustADBError::ADBRequestFailed(format!(
|
||||||
|
"Open session failed: respones used {} for our local_id instead of {local_id}",
|
||||||
|
response.header().arg1()
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn get_local_id(&self) -> Result<u32> {
|
Ok(ADBSession::new(local_id, response.header().arg0()))
|
||||||
self.local_id.ok_or(RustADBError::ADBRequestFailed(
|
|
||||||
"connection not opened, no local_id".into(),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_remote_id(&self) -> Result<u32> {
|
|
||||||
self.remote_id.ok_or(RustADBError::ADBRequestFailed(
|
|
||||||
"connection not opened, no remote_id".into(),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ use crate::{
|
|||||||
|
|
||||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||||
pub(crate) fn framebuffer_inner(&mut self) -> Result<ImageBuffer<Rgba<u8>, Vec<u8>>> {
|
pub(crate) fn framebuffer_inner(&mut self) -> Result<ImageBuffer<Rgba<u8>, Vec<u8>>> {
|
||||||
self.open_session(b"framebuffer:\0")?;
|
let session = self.open_session(b"framebuffer:\0")?;
|
||||||
|
|
||||||
let response = self.recv_and_reply_okay()?;
|
let response = self.recv_and_reply_okay(session)?;
|
||||||
|
|
||||||
let mut payload_cursor = Cursor::new(response.payload());
|
let mut payload_cursor = Cursor::new(response.payload());
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let response = self.recv_and_reply_okay()?;
|
let response = self.recv_and_reply_okay(session)?;
|
||||||
|
|
||||||
framebuffer_data.extend_from_slice(&response.into_payload());
|
framebuffer_data.extend_from_slice(&response.into_payload());
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let response = self.recv_and_reply_okay()?;
|
let response = self.recv_and_reply_okay(session)?;
|
||||||
|
|
||||||
framebuffer_data.extend_from_slice(&response.into_payload());
|
framebuffer_data.extend_from_slice(&response.into_payload());
|
||||||
|
|
||||||
|
|||||||
@@ -14,11 +14,12 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
|
|
||||||
let file_size = apk_file.metadata()?.len();
|
let file_size = apk_file.metadata()?.len();
|
||||||
|
|
||||||
self.open_session(format!("exec:cmd package 'install' -S {file_size}\0").as_bytes())?;
|
let session =
|
||||||
|
self.open_session(format!("exec:cmd package 'install' -S {file_size}\0").as_bytes())?;
|
||||||
|
|
||||||
let transport = self.get_transport().clone();
|
let transport = self.get_transport().clone();
|
||||||
|
|
||||||
let mut writer = MessageWriter::new(transport, self.get_local_id()?, self.get_remote_id()?);
|
let mut writer = MessageWriter::new(transport, session.local_id(), session.remote_id());
|
||||||
|
|
||||||
std::io::copy(&mut apk_file, &mut writer)?;
|
std::io::copy(&mut apk_file, &mut writer)?;
|
||||||
|
|
||||||
|
|||||||
@@ -13,11 +13,11 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
/// List the entries in the given directory on the device.
|
/// List the entries in the given directory on the device.
|
||||||
/// note: path uses internal file paths, so Documents is at /storage/emulated/0/Documents
|
/// note: path uses internal file paths, so Documents is at /storage/emulated/0/Documents
|
||||||
pub(crate) fn list<A: AsRef<str>>(&mut self, path: A) -> Result<Vec<ADBListItem>> {
|
pub(crate) fn list<A: AsRef<str>>(&mut self, path: A) -> Result<Vec<ADBListItem>> {
|
||||||
self.begin_synchronization()?;
|
let session = self.begin_synchronization()?;
|
||||||
|
|
||||||
let output = self.handle_list(path);
|
let output = self.handle_list(path, session.local_id(), session.remote_id());
|
||||||
|
|
||||||
self.end_transaction()?;
|
self.end_transaction(session)?;
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,12 +36,12 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
/// payload Wanted in
|
/// payload Wanted in
|
||||||
/// Next payload
|
/// Next payload
|
||||||
fn read_bytes_from_transport(
|
fn read_bytes_from_transport(
|
||||||
requested_bytes: &usize,
|
requested_bytes: usize,
|
||||||
current_index: &mut usize,
|
current_index: &mut usize,
|
||||||
transport: &mut T,
|
transport: &mut T,
|
||||||
payload: &mut Vec<u8>,
|
payload: &mut Vec<u8>,
|
||||||
local_id: &u32,
|
local_id: u32,
|
||||||
remote_id: &u32,
|
remote_id: u32,
|
||||||
) -> Result<Vec<u8>> {
|
) -> Result<Vec<u8>> {
|
||||||
if *current_index + requested_bytes <= payload.len() {
|
if *current_index + requested_bytes <= payload.len() {
|
||||||
// if there is enough bytes in this payload
|
// if there is enough bytes in this payload
|
||||||
@@ -59,7 +59,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
|
|
||||||
// Request the next message
|
// Request the next message
|
||||||
let send_message =
|
let send_message =
|
||||||
ADBTransportMessage::new(MessageCommand::Okay, *local_id, *remote_id, &[]);
|
ADBTransportMessage::new(MessageCommand::Okay, local_id, remote_id, &[]);
|
||||||
transport.write_message(send_message)?;
|
transport.write_message(send_message)?;
|
||||||
// Read the new message
|
// Read the new message
|
||||||
*payload = transport.read_message()?.into_payload();
|
*payload = transport.read_message()?.into_payload();
|
||||||
@@ -70,14 +70,17 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_list<A: AsRef<str>>(&mut self, path: A) -> Result<Vec<ADBListItem>> {
|
fn handle_list<A: AsRef<str>>(
|
||||||
|
&mut self,
|
||||||
|
path: A,
|
||||||
|
local_id: u32,
|
||||||
|
remote_id: u32,
|
||||||
|
) -> Result<Vec<ADBListItem>> {
|
||||||
// TODO: use LIS2 to support files over 2.14 GB in size.
|
// TODO: use LIS2 to support files over 2.14 GB in size.
|
||||||
// SEE: https://github.com/cstyan/adbDocumentation?tab=readme-ov-file#adb-list
|
// SEE: https://github.com/cstyan/adbDocumentation?tab=readme-ov-file#adb-list
|
||||||
let local_id = self.get_local_id()?;
|
|
||||||
let remote_id = self.get_remote_id()?;
|
|
||||||
{
|
{
|
||||||
let mut len_buf = Vec::from([0_u8; 4]);
|
let mut len_buf = Vec::from([0_u8; 4]);
|
||||||
LittleEndian::write_u32(&mut len_buf, path.as_ref().len() as u32);
|
LittleEndian::write_u32(&mut len_buf, u32::try_from(path.as_ref().len())?);
|
||||||
|
|
||||||
let subcommand_data = MessageSubcommand::List;
|
let subcommand_data = MessageSubcommand::List;
|
||||||
|
|
||||||
@@ -106,12 +109,12 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
// Loop though the response for all the entries
|
// Loop though the response for all the entries
|
||||||
const STATUS_CODE_LENGTH_IN_BYTES: usize = 4;
|
const STATUS_CODE_LENGTH_IN_BYTES: usize = 4;
|
||||||
let status_code = Self::read_bytes_from_transport(
|
let status_code = Self::read_bytes_from_transport(
|
||||||
&STATUS_CODE_LENGTH_IN_BYTES,
|
STATUS_CODE_LENGTH_IN_BYTES,
|
||||||
&mut current_index,
|
&mut current_index,
|
||||||
transport,
|
transport,
|
||||||
&mut payload,
|
&mut payload,
|
||||||
&local_id,
|
local_id,
|
||||||
&remote_id,
|
remote_id,
|
||||||
)?;
|
)?;
|
||||||
match str::from_utf8(&status_code)? {
|
match str::from_utf8(&status_code)? {
|
||||||
"DENT" => {
|
"DENT" => {
|
||||||
@@ -119,12 +122,12 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
const U32_SIZE_IN_BYTES: usize = 4;
|
const U32_SIZE_IN_BYTES: usize = 4;
|
||||||
const SIZE_OF_METADATA: usize = U32_SIZE_IN_BYTES * 4;
|
const SIZE_OF_METADATA: usize = U32_SIZE_IN_BYTES * 4;
|
||||||
let metadata = Self::read_bytes_from_transport(
|
let metadata = Self::read_bytes_from_transport(
|
||||||
&SIZE_OF_METADATA,
|
SIZE_OF_METADATA,
|
||||||
&mut current_index,
|
&mut current_index,
|
||||||
transport,
|
transport,
|
||||||
&mut payload,
|
&mut payload,
|
||||||
&local_id,
|
local_id,
|
||||||
&remote_id,
|
remote_id,
|
||||||
)?;
|
)?;
|
||||||
let mode = metadata[..U32_SIZE_IN_BYTES].to_vec();
|
let mode = metadata[..U32_SIZE_IN_BYTES].to_vec();
|
||||||
let size = metadata[U32_SIZE_IN_BYTES..2 * U32_SIZE_IN_BYTES].to_vec();
|
let size = metadata[U32_SIZE_IN_BYTES..2 * U32_SIZE_IN_BYTES].to_vec();
|
||||||
@@ -137,12 +140,12 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
let name_len = LittleEndian::read_u32(&name_len) as usize;
|
let name_len = LittleEndian::read_u32(&name_len) as usize;
|
||||||
// Read the file name, since it requires the length from the name_len
|
// Read the file name, since it requires the length from the name_len
|
||||||
let name_buf = Self::read_bytes_from_transport(
|
let name_buf = Self::read_bytes_from_transport(
|
||||||
&name_len,
|
name_len,
|
||||||
&mut current_index,
|
&mut current_index,
|
||||||
transport,
|
transport,
|
||||||
&mut payload,
|
&mut payload,
|
||||||
&local_id,
|
local_id,
|
||||||
&remote_id,
|
remote_id,
|
||||||
)?;
|
)?;
|
||||||
let name = String::from_utf8(name_buf)?;
|
let name = String::from_utf8(name_buf)?;
|
||||||
|
|
||||||
@@ -167,7 +170,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
"DONE" => {
|
"DONE" => {
|
||||||
return Ok(list_items);
|
return Ok(list_items);
|
||||||
}
|
}
|
||||||
x => log::error!("Got an unknown response {}", x),
|
x => log::error!("Got an unknown response {x}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ use crate::{
|
|||||||
|
|
||||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||||
pub(crate) fn pull<A: AsRef<str>, W: Write>(&mut self, source: A, output: W) -> Result<()> {
|
pub(crate) fn pull<A: AsRef<str>, W: Write>(&mut self, source: A, output: W) -> Result<()> {
|
||||||
self.begin_synchronization()?;
|
let session = self.begin_synchronization()?;
|
||||||
let source = source.as_ref();
|
let source = source.as_ref();
|
||||||
|
|
||||||
let adb_stat_response = self.stat_with_explicit_ids(source)?;
|
let adb_stat_response = self.stat_with_explicit_ids(session, source)?;
|
||||||
|
|
||||||
if adb_stat_response.file_perm == 0 {
|
if adb_stat_response.file_perm == 0 {
|
||||||
return Err(RustADBError::UnknownResponseType(
|
return Err(RustADBError::UnknownResponseType(
|
||||||
@@ -22,11 +22,13 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let local_id = self.get_local_id()?;
|
|
||||||
let remote_id = self.get_remote_id()?;
|
|
||||||
|
|
||||||
self.get_transport_mut().write_message_with_timeout(
|
self.get_transport_mut().write_message_with_timeout(
|
||||||
ADBTransportMessage::new(MessageCommand::Okay, local_id, remote_id, &[]),
|
ADBTransportMessage::new(
|
||||||
|
MessageCommand::Okay,
|
||||||
|
session.local_id(),
|
||||||
|
session.remote_id(),
|
||||||
|
&[],
|
||||||
|
),
|
||||||
std::time::Duration::from_secs(4),
|
std::time::Duration::from_secs(4),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@@ -34,19 +36,19 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
let recv_buffer = adb_message_device::bincode_serialize_to_vec(&recv_buffer)?;
|
let recv_buffer = adb_message_device::bincode_serialize_to_vec(&recv_buffer)?;
|
||||||
self.send_and_expect_okay(ADBTransportMessage::new(
|
self.send_and_expect_okay(ADBTransportMessage::new(
|
||||||
MessageCommand::Write,
|
MessageCommand::Write,
|
||||||
self.get_local_id()?,
|
session.local_id(),
|
||||||
self.get_remote_id()?,
|
session.remote_id(),
|
||||||
&recv_buffer,
|
&recv_buffer,
|
||||||
))?;
|
))?;
|
||||||
self.send_and_expect_okay(ADBTransportMessage::new(
|
self.send_and_expect_okay(ADBTransportMessage::new(
|
||||||
MessageCommand::Write,
|
MessageCommand::Write,
|
||||||
self.get_local_id()?,
|
session.local_id(),
|
||||||
self.get_remote_id()?,
|
session.remote_id(),
|
||||||
source.as_bytes(),
|
source.as_bytes(),
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
self.recv_file(output)?;
|
self.recv_file(session, output)?;
|
||||||
self.end_transaction()?;
|
self.end_transaction(session)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use crate::{
|
|||||||
|
|
||||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||||
pub(crate) fn push<R: Read, A: AsRef<str>>(&mut self, stream: R, path: A) -> Result<()> {
|
pub(crate) fn push<R: Read, A: AsRef<str>>(&mut self, stream: R, path: A) -> Result<()> {
|
||||||
self.begin_synchronization()?;
|
let session = self.begin_synchronization()?;
|
||||||
|
|
||||||
let path_header = format!("{},0777", path.as_ref());
|
let path_header = format!("{},0777", path.as_ref());
|
||||||
|
|
||||||
@@ -20,14 +20,13 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
|
|
||||||
self.send_and_expect_okay(ADBTransportMessage::new(
|
self.send_and_expect_okay(ADBTransportMessage::new(
|
||||||
MessageCommand::Write,
|
MessageCommand::Write,
|
||||||
self.get_local_id()?,
|
session.local_id(),
|
||||||
self.get_remote_id()?,
|
session.remote_id(),
|
||||||
&send_buffer,
|
&send_buffer,
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
self.push_file(self.get_local_id()?, self.get_remote_id()?, stream)?;
|
self.push_file(session, stream)?;
|
||||||
|
self.end_transaction(session)?;
|
||||||
self.end_transaction()?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,20 +11,10 @@ use crate::{
|
|||||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||||
/// Runs 'command' in a shell on the device, and write its output and error streams into output.
|
/// Runs 'command' in a shell on the device, and write its output and error streams into output.
|
||||||
pub(crate) fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()> {
|
pub(crate) fn shell_command(&mut self, command: &[&str], output: &mut dyn Write) -> Result<()> {
|
||||||
let response = self.open_session(format!("shell:{}\0", command.join(" "),).as_bytes())?;
|
let session = self.open_session(format!("shell:{}\0", command.join(" "),).as_bytes())?;
|
||||||
|
|
||||||
let mut transport = self.get_transport().clone();
|
let mut transport = self.get_transport().clone();
|
||||||
|
|
||||||
let local_id = self.get_local_id()?;
|
|
||||||
let remote_id = self.get_remote_id()?;
|
|
||||||
|
|
||||||
if response.header().command() != MessageCommand::Okay {
|
|
||||||
return Err(RustADBError::ADBRequestFailed(format!(
|
|
||||||
"wrong command {}",
|
|
||||||
response.header().command()
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let message = transport.read_message()?;
|
let message = transport.read_message()?;
|
||||||
let command = message.header().command();
|
let command = message.header().command();
|
||||||
@@ -36,8 +26,8 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
self.get_transport_mut()
|
self.get_transport_mut()
|
||||||
.write_message(ADBTransportMessage::new(
|
.write_message(ADBTransportMessage::new(
|
||||||
MessageCommand::Okay,
|
MessageCommand::Okay,
|
||||||
local_id,
|
session.local_id(),
|
||||||
remote_id,
|
session.remote_id(),
|
||||||
&[],
|
&[],
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
@@ -48,9 +38,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
// the client has acknowledged it. Read them quickly if present.
|
// the client has acknowledged it. Read them quickly if present.
|
||||||
while let Ok(_discard_close_message) =
|
while let Ok(_discard_close_message) =
|
||||||
transport.read_message_with_timeout(Duration::from_millis(20))
|
transport.read_message_with_timeout(Duration::from_millis(20))
|
||||||
{
|
{}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -62,21 +50,22 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
mut reader: &mut dyn Read,
|
mut reader: &mut dyn Read,
|
||||||
mut writer: Box<dyn Write + Send>,
|
mut writer: Box<dyn Write + Send>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
self.open_session(b"shell:\0")?;
|
let session = self.open_session(b"shell:\0")?;
|
||||||
|
|
||||||
let mut transport = self.get_transport().clone();
|
let mut transport = self.get_transport().clone();
|
||||||
|
|
||||||
let local_id = self.get_local_id()?;
|
|
||||||
let remote_id = self.get_remote_id()?;
|
|
||||||
|
|
||||||
// Reading thread, reads response from adbd
|
// Reading thread, reads response from adbd
|
||||||
std::thread::spawn(move || -> Result<()> {
|
std::thread::spawn(move || -> Result<()> {
|
||||||
loop {
|
loop {
|
||||||
let message = transport.read_message()?;
|
let message = transport.read_message()?;
|
||||||
|
|
||||||
// Acknowledge for more data
|
// Acknowledge for more data
|
||||||
let response =
|
let response = ADBTransportMessage::new(
|
||||||
ADBTransportMessage::new(MessageCommand::Okay, local_id, remote_id, &[]);
|
MessageCommand::Okay,
|
||||||
|
session.local_id(),
|
||||||
|
session.remote_id(),
|
||||||
|
&[],
|
||||||
|
);
|
||||||
transport.write_message(response)?;
|
transport.write_message(response)?;
|
||||||
|
|
||||||
match message.header().command() {
|
match message.header().command() {
|
||||||
@@ -91,7 +80,8 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let transport = self.get_transport().clone();
|
let transport = self.get_transport().clone();
|
||||||
let mut shell_writer = ShellMessageWriter::new(transport, local_id, remote_id);
|
let mut shell_writer =
|
||||||
|
ShellMessageWriter::new(transport, session.local_id(), session.remote_id());
|
||||||
|
|
||||||
// Read from given reader (that could be stdin e.g), and write content to device adbd
|
// Read from given reader (that could be stdin e.g), and write content to device adbd
|
||||||
if let Err(e) = std::io::copy(&mut reader, &mut shell_writer) {
|
if let Err(e) = std::io::copy(&mut reader, &mut shell_writer) {
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ use crate::{
|
|||||||
|
|
||||||
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||||
pub(crate) fn stat(&mut self, remote_path: &str) -> Result<AdbStatResponse> {
|
pub(crate) fn stat(&mut self, remote_path: &str) -> Result<AdbStatResponse> {
|
||||||
self.begin_synchronization()?;
|
let session = self.begin_synchronization()?;
|
||||||
let adb_stat_response = self.stat_with_explicit_ids(remote_path)?;
|
let adb_stat_response = self.stat_with_explicit_ids(session, remote_path)?;
|
||||||
self.end_transaction()?;
|
self.end_transaction(session)?;
|
||||||
Ok(adb_stat_response)
|
Ok(adb_stat_response)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ fn set_bit(n: usize) -> Result<BigUint> {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pubkey_gen() {
|
fn test_pubkey_gen() {
|
||||||
const DEFAULT_PRIV_KEY: &'static str = r"-----BEGIN PRIVATE KEY-----
|
const DEFAULT_PRIV_KEY: &str = r"-----BEGIN PRIVATE KEY-----
|
||||||
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC4Dyn85cxDJnjM
|
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC4Dyn85cxDJnjM
|
||||||
uYXQl/w469MDKdlGdviLfmFMWeYLVfL2Mz1AVyvKqscrtlhbbgMQ/M+3lDvEdHS0
|
uYXQl/w469MDKdlGdviLfmFMWeYLVfL2Mz1AVyvKqscrtlhbbgMQ/M+3lDvEdHS0
|
||||||
14RIGAwWRtrlTTmhLvM2/IO+eSKSYeCrCVc4KLG3E3WRryUXbs2ynA29xjTJVw+Z
|
14RIGAwWRtrlTTmhLvM2/IO+eSKSYeCrCVc4KLG3E3WRryUXbs2ynA29xjTJVw+Z
|
||||||
|
|||||||
23
adb_client/src/device/models/adb_session.rs
Normal file
23
adb_client/src/device/models/adb_session.rs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/// Represent a session between an `ADBDevice` and remote `adbd`.
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub(crate) struct ADBSession {
|
||||||
|
local_id: u32,
|
||||||
|
remote_id: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ADBSession {
|
||||||
|
pub fn new(local_id: u32, remote_id: u32) -> Self {
|
||||||
|
Self {
|
||||||
|
local_id,
|
||||||
|
remote_id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn local_id(self) -> u32 {
|
||||||
|
self.local_id
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn remote_id(self) -> u32 {
|
||||||
|
self.remote_id
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
mod adb_rsa_key;
|
mod adb_rsa_key;
|
||||||
|
mod adb_session;
|
||||||
mod message_commands;
|
mod message_commands;
|
||||||
|
|
||||||
pub use adb_rsa_key::ADBRsaKey;
|
pub use adb_rsa_key::ADBRsaKey;
|
||||||
|
pub(crate) use adb_session::ADBSession;
|
||||||
pub use message_commands::{MessageCommand, MessageSubcommand};
|
pub use message_commands::{MessageCommand, MessageSubcommand};
|
||||||
|
|||||||
@@ -115,11 +115,13 @@ pub enum RustADBError {
|
|||||||
#[error("upgrade error: {0}")]
|
#[error("upgrade error: {0}")]
|
||||||
UpgradeError(String),
|
UpgradeError(String),
|
||||||
/// An error occurred while getting mdns devices
|
/// An error occurred while getting mdns devices
|
||||||
|
#[cfg(feature = "mdns")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "mdns")))]
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
MDNSError(#[from] mdns_sd::Error),
|
MDNSError(#[from] mdns_sd::Error),
|
||||||
/// An error occurred while sending data to channel
|
/// An error occurred while sending data to channel
|
||||||
#[error(transparent)]
|
#[error("error sending data to channel")]
|
||||||
SendError(#[from] std::sync::mpsc::SendError<crate::MDNSDevice>),
|
SendError,
|
||||||
/// An unknown transport has been provided
|
/// An unknown transport has been provided
|
||||||
#[error("unknown transport: {0}")]
|
#[error("unknown transport: {0}")]
|
||||||
UnknownTransport(String),
|
UnknownTransport(String),
|
||||||
|
|||||||
@@ -3,13 +3,23 @@
|
|||||||
#![forbid(missing_debug_implementations)]
|
#![forbid(missing_debug_implementations)]
|
||||||
#![forbid(missing_docs)]
|
#![forbid(missing_docs)]
|
||||||
#![doc = include_str!("../README.md")]
|
#![doc = include_str!("../README.md")]
|
||||||
|
// Feature `doc_cfg` is currently only available on nightly builds.
|
||||||
|
// It is activated when cfg `docsrs` is enabled.
|
||||||
|
// Documentation can be build locally using:
|
||||||
|
// `RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --no-deps --all-features`
|
||||||
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
||||||
|
|
||||||
mod adb_device_ext;
|
mod adb_device_ext;
|
||||||
mod constants;
|
mod constants;
|
||||||
mod device;
|
mod device;
|
||||||
mod emulator_device;
|
mod emulator_device;
|
||||||
mod error;
|
mod error;
|
||||||
mod mdns;
|
|
||||||
|
/// MDNS-related definitions
|
||||||
|
#[cfg(feature = "mdns")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "mdns")))]
|
||||||
|
pub mod mdns;
|
||||||
|
|
||||||
mod models;
|
mod models;
|
||||||
mod server;
|
mod server;
|
||||||
mod server_device;
|
mod server_device;
|
||||||
@@ -20,7 +30,6 @@ pub use adb_device_ext::ADBDeviceExt;
|
|||||||
pub use device::{ADBTcpDevice, ADBUSBDevice, is_adb_device, search_adb_devices};
|
pub use device::{ADBTcpDevice, ADBUSBDevice, is_adb_device, search_adb_devices};
|
||||||
pub use emulator_device::ADBEmulatorDevice;
|
pub use emulator_device::ADBEmulatorDevice;
|
||||||
pub use error::{Result, RustADBError};
|
pub use error::{Result, RustADBError};
|
||||||
pub use mdns::*;
|
|
||||||
pub use models::{ADBListItem, ADBListItemType, AdbStatResponse, RebootType};
|
pub use models::{ADBListItem, ADBListItemType, AdbStatResponse, RebootType};
|
||||||
pub use server::*;
|
pub use server::*;
|
||||||
pub use server_device::ADBServerDevice;
|
pub use server_device::ADBServerDevice;
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
use std::{collections::HashSet, net::IpAddr};
|
use std::{
|
||||||
|
collections::HashSet,
|
||||||
|
fmt::Display,
|
||||||
|
net::{IpAddr, Ipv4Addr, Ipv6Addr},
|
||||||
|
};
|
||||||
|
|
||||||
use mdns_sd::{ResolvedService, ScopedIp};
|
use mdns_sd::{ResolvedService, ScopedIp};
|
||||||
|
|
||||||
@@ -8,7 +12,41 @@ pub struct MDNSDevice {
|
|||||||
/// Full device address when resolved
|
/// Full device address when resolved
|
||||||
pub fullname: String,
|
pub fullname: String,
|
||||||
/// Device IP addresses
|
/// Device IP addresses
|
||||||
pub addresses: HashSet<IpAddr>,
|
addresses: HashSet<IpAddr>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MDNSDevice {
|
||||||
|
/// Return all adresses linked to this device
|
||||||
|
#[must_use]
|
||||||
|
pub fn addresses(&self) -> HashSet<IpAddr> {
|
||||||
|
self.addresses.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return all IPv4 addresses linked to this device
|
||||||
|
#[must_use]
|
||||||
|
pub fn ipv4_addresses(&self) -> HashSet<Ipv4Addr> {
|
||||||
|
self.addresses
|
||||||
|
.iter()
|
||||||
|
.filter_map(|addr| match addr {
|
||||||
|
IpAddr::V4(addr) => Some(addr),
|
||||||
|
IpAddr::V6(_) => None,
|
||||||
|
})
|
||||||
|
.copied()
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return all IPv6 addresses linked to this device
|
||||||
|
#[must_use]
|
||||||
|
pub fn ipv6_addresses(&self) -> HashSet<Ipv6Addr> {
|
||||||
|
self.addresses
|
||||||
|
.iter()
|
||||||
|
.filter_map(|addr| match addr {
|
||||||
|
IpAddr::V4(_) => None,
|
||||||
|
IpAddr::V6(addr) => Some(addr),
|
||||||
|
})
|
||||||
|
.copied()
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Box<ResolvedService>> for MDNSDevice {
|
impl From<Box<ResolvedService>> for MDNSDevice {
|
||||||
@@ -19,3 +57,13 @@ impl From<Box<ResolvedService>> for MDNSDevice {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Display for MDNSDevice {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
writeln!(f, "Device fullname: {}", self.fullname)?;
|
||||||
|
writeln!(f, "IPv4 Addresses: {:?}", self.ipv4_addresses())?;
|
||||||
|
write!(f, "IPv6 Addresses: {:?}", self.ipv6_addresses())?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
use mdns_sd::{ServiceDaemon, ServiceEvent};
|
use mdns_sd::{ServiceDaemon, ServiceEvent};
|
||||||
use std::{sync::mpsc::Sender, thread::JoinHandle};
|
use std::{sync::mpsc::Sender, thread::JoinHandle};
|
||||||
|
|
||||||
use crate::{MDNSDevice, Result, RustADBError};
|
use super::MDNSDevice;
|
||||||
|
use crate::{Result, RustADBError};
|
||||||
|
|
||||||
const ADB_SERVICE_NAME: &str = "_adb-tls-connect._tcp.local.";
|
const ADB_SERVICE_NAME: &str = "_adb-tls-connect._tcp.local.";
|
||||||
|
|
||||||
@@ -29,7 +30,7 @@ impl MDNSDiscoveryService {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start discovery by spawning a new thread responsible of getting events.
|
/// Start discovery by spawning a new background thread responsible of getting events.
|
||||||
pub fn start(&mut self, sender: Sender<MDNSDevice>) -> Result<()> {
|
pub fn start(&mut self, sender: Sender<MDNSDevice>) -> Result<()> {
|
||||||
let receiver = self.daemon.browse(ADB_SERVICE_NAME)?;
|
let receiver = self.daemon.browse(ADB_SERVICE_NAME)?;
|
||||||
|
|
||||||
@@ -44,9 +45,9 @@ impl MDNSDiscoveryService {
|
|||||||
// Ignoring these events. We are only interesting in found devices
|
// Ignoring these events. We are only interesting in found devices
|
||||||
}
|
}
|
||||||
ServiceEvent::ServiceResolved(service_info) => {
|
ServiceEvent::ServiceResolved(service_info) => {
|
||||||
if let Err(e) = sender.send(MDNSDevice::from(service_info)) {
|
sender
|
||||||
return Err(e.into());
|
.send(MDNSDevice::from(service_info))
|
||||||
}
|
.map_err(|_| RustADBError::SendError)?;
|
||||||
}
|
}
|
||||||
e => {
|
e => {
|
||||||
log::warn!("received unknown event type {e:?}");
|
log::warn!("received unknown event type {e:?}");
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ pub struct ADBServer {
|
|||||||
|
|
||||||
impl ADBServer {
|
impl ADBServer {
|
||||||
/// Instantiates a new [`ADBServer`]
|
/// Instantiates a new [`ADBServer`]
|
||||||
|
#[must_use]
|
||||||
pub fn new(address: SocketAddrV4) -> Self {
|
pub fn new(address: SocketAddrV4) -> Self {
|
||||||
Self {
|
Self {
|
||||||
transport: None,
|
transport: None,
|
||||||
@@ -32,6 +33,7 @@ impl ADBServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Instantiates a new [`ADBServer`] with a custom adb path
|
/// Instantiates a new [`ADBServer`] with a custom adb path
|
||||||
|
#[must_use]
|
||||||
pub fn new_from_path(address: SocketAddrV4, adb_path: Option<String>) -> Self {
|
pub fn new_from_path(address: SocketAddrV4, adb_path: Option<String>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
transport: None,
|
transport: None,
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ fn test_static_devices_long() {
|
|||||||
"QQ20131020250511 device 20-4 product:NOH-AN00 model:NOH_AN00 device:HWNOH transport_id:3",
|
"QQ20131020250511 device 20-4 product:NOH-AN00 model:NOH_AN00 device:HWNOH transport_id:3",
|
||||||
];
|
];
|
||||||
for input in inputs {
|
for input in inputs {
|
||||||
DeviceLong::try_from(input.as_bytes()).expect(&format!("cannot parse input: '{input}'"));
|
DeviceLong::try_from(input.as_bytes())
|
||||||
|
.unwrap_or_else(|_| panic!("cannot parse input: '{input}'"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ pub struct ADBServerDevice {
|
|||||||
|
|
||||||
impl ADBServerDevice {
|
impl ADBServerDevice {
|
||||||
/// Instantiates a new [`ADBServerDevice`], knowing its ADB identifier (as returned by `adb devices` command).
|
/// Instantiates a new [`ADBServerDevice`], knowing its ADB identifier (as returned by `adb devices` command).
|
||||||
|
#[must_use]
|
||||||
pub fn new(identifier: String, server_addr: Option<SocketAddrV4>) -> Self {
|
pub fn new(identifier: String, server_addr: Option<SocketAddrV4>) -> Self {
|
||||||
let transport = TCPServerTransport::new_or_default(server_addr);
|
let transport = TCPServerTransport::new_or_default(server_addr);
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ impl ADBServerDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Instantiates a new [`ADBServerDevice`], assuming only one is currently connected.
|
/// Instantiates a new [`ADBServerDevice`], assuming only one is currently connected.
|
||||||
|
#[must_use]
|
||||||
pub fn autodetect(server_addr: Option<SocketAddrV4>) -> Self {
|
pub fn autodetect(server_addr: Option<SocketAddrV4>) -> Self {
|
||||||
let transport = TCPServerTransport::new_or_default(server_addr);
|
let transport = TCPServerTransport::new_or_default(server_addr);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
convert::TryInto,
|
convert::TryInto,
|
||||||
io::{BufReader, BufWriter, Read, Write},
|
io::{self, BufReader, BufWriter, Read, Write},
|
||||||
str::{self, FromStr},
|
str::{self, FromStr},
|
||||||
time::SystemTime,
|
time::SystemTime,
|
||||||
};
|
};
|
||||||
@@ -22,7 +22,7 @@ impl<W: Write> ADBSendCommandWriter<W> {
|
|||||||
|
|
||||||
impl<W: Write> Write for ADBSendCommandWriter<W> {
|
impl<W: Write> Write for ADBSendCommandWriter<W> {
|
||||||
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
||||||
let chunk_len = buf.len() as u32;
|
let chunk_len = u32::try_from(buf.len()).map_err(io::Error::other)?;
|
||||||
|
|
||||||
// 8 = "DATA".len() + sizeof(u32)
|
// 8 = "DATA".len() + sizeof(u32)
|
||||||
let mut buffer = Vec::with_capacity(8 + buf.len());
|
let mut buffer = Vec::with_capacity(8 + buf.len());
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ impl Default for TCPServerTransport {
|
|||||||
|
|
||||||
impl TCPServerTransport {
|
impl TCPServerTransport {
|
||||||
/// Instantiates a new instance of [`TCPServerTransport`]
|
/// Instantiates a new instance of [`TCPServerTransport`]
|
||||||
|
#[must_use]
|
||||||
pub fn new(socket_addr: SocketAddrV4) -> Self {
|
pub fn new(socket_addr: SocketAddrV4) -> Self {
|
||||||
Self {
|
Self {
|
||||||
socket_addr,
|
socket_addr,
|
||||||
|
|||||||
19
examples/mdns/Cargo.toml
Normal file
19
examples/mdns/Cargo.toml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
[package]
|
||||||
|
name = "mdns"
|
||||||
|
authors.workspace = true
|
||||||
|
edition.workspace = true
|
||||||
|
homepage.workspace = true
|
||||||
|
keywords.workspace = true
|
||||||
|
license.workspace = true
|
||||||
|
repository.workspace = true
|
||||||
|
version.workspace = true
|
||||||
|
rust-version.workspace = true
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "mdns"
|
||||||
|
path = "main.rs"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
adb_client = { path = "../../adb_client", default-features = false, features = [
|
||||||
|
"mdns",
|
||||||
|
] }
|
||||||
19
examples/mdns/main.rs
Normal file
19
examples/mdns/main.rs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
use std::sync::mpsc;
|
||||||
|
|
||||||
|
use adb_client::mdns::{MDNSDevice, MDNSDiscoveryService};
|
||||||
|
|
||||||
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
println!("Starting mDNS device discovery...");
|
||||||
|
|
||||||
|
// Create a channel to receive discovered devices information
|
||||||
|
let (sender, receiver) = mpsc::channel::<MDNSDevice>();
|
||||||
|
|
||||||
|
// Create and start the discovery service
|
||||||
|
let mut discovery = MDNSDiscoveryService::new()?;
|
||||||
|
discovery.start(sender)?;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let device = receiver.recv()?;
|
||||||
|
println!("{device}");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# pyadb_client
|
# `pyadb_client`
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<p align="center">Python library to communicate with ADB devices. Built on top of Rust adb_client library.</p>
|
<p align="center">Python library to communicate with ADB devices. Built on top of Rust adb_client library.</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user