feat: add optional Windows virtual USB ADB device

This commit is contained in:
tongtong committed 2026-11-12 17:34:23 +08:00
1 parent 2abfb63da9
commit 08d60de364
23 files changed
+802 -26

No files matched your search

+2
View File
@@ -22,3 +22,5 @@ $env:ADS_CLIENT_TOKEN = '<本地端令牌>'
- `--status-file <JSON路径>`:输出当前 p2p/relay/mixed/negotiating/idle、通道数和节点 ID,供桌面展示。
节点断线会中断现有 TCP 流;本地 ADB 在重试后创建新通道,重新选择路线,不支持将原 TCP 流无缝迁移。旧中心或旧 agent 会协商回 v1 模式。
可选 `--lease-status-file <路径>` 输出 true/false,供虚拟 USB 启动器等待租约,不包含票据。USB 模式需加 `--no-auto-connect`,由 ads-usb 使用本地原始 adbd 端点,不能把 USB/IP 接到 5037。见 docs/windows-usb.md。
+15
View File
@@ -42,6 +42,9 @@ struct Args {
/// Machine-readable active transport state for desktop clients
#[arg(long)]
status_file: Option<PathBuf>,
/// Optional lease readiness file for virtual USB consumers (no secret tickets)
#[arg(long)]
lease_status_file: Option<PathBuf>,
}
#[derive(Clone)]
@@ -50,6 +53,15 @@ struct LeaseState {
protocol: u8,
}
fn publish_lease(args: &Args, ready: bool) {
if let Some(file) = &args.lease_status_file {
let temp = file.with_extension("tmp");
if std::fs::write(&temp, if ready { "true" } else { "false" }).is_ok() {
let _ = std::fs::rename(temp, file);
}
}
}
async fn lease_once(args: &Args, state: &watch::Sender<Option<LeaseState>>) -> Result<()> {
let mut ws = dial(
args.network
@@ -63,6 +75,7 @@ async fn lease_once(args: &Args, state: &watch::Sender<Option<LeaseState>>) -> R
bail!("expected leased response");
}
let id = response.lease.context("missing lease ticket")?;
publish_lease(args, true);
state.send_replace(Some(LeaseState {
id,
protocol: response.protocol,
@@ -80,6 +93,7 @@ async fn maintain_lease(args: Arc<Args>, state: watch::Sender<Option<LeaseState>
if let Err(error) = lease_once(&args, &state).await {
warn!(%error, "lease unavailable; reconnecting");
}
publish_lease(&args, false);
state.send_replace(None);
if started.elapsed() > Duration::from_secs(30) {
delay = 1;
@@ -164,6 +178,7 @@ async fn accept_connections(
async fn main() -> Result<()> {
init_logging();
let args = Arc::new(Args::parse());
publish_lease(&args, false);
validate_token(&args.token)?;
if !valid_device_id(&args.device) {
bail!("invalid device ID");