Sync desktop daily logs and fix emulator ADB upstream connections

This commit is contained in:
tongtong committed 2026-11-13 11:57:07 +08:00
1 parent 87e1fff59b
commit 0d269f3ded
15 files changed
+139 -12

No files matched your search

+37 -1
View File
@@ -243,8 +243,24 @@ async fn adb_request(stream: &mut TcpStream, service: &str) -> Result<()> {
}
}
/// Requires TCP adbd on the phone, even when selecting a USB transport.
/// Uses host-side adbd for emulators; other transports require TCP adbd on the phone.
pub async fn adb_tcp_connect(server: &str, serial: &str, port: u16) -> Result<TcpStream> {
// Emulator console serials identify a host-side raw adbd socket, not a
// device-internal TCP adbd listener. No tcpip restart is needed.
if let Some(console) = serial
.strip_prefix("emulator-")
.and_then(|v| v.parse::<u16>().ok())
{
if console >= 1024 && console % 2 == 0 {
let host = server
.rsplit_once(':')
.context("ADB server requires host:port")?
.0;
return tcp_connect(&format!("{host}:{}", console + 1))
.await
.context("cannot reach emulator host adbd");
}
}
let mut stream = tcp_connect(server).await?;
timeout(CONNECT_TIMEOUT, async {
adb_request(&mut stream, &format!("host:transport:{serial}")).await?;
@@ -268,6 +284,26 @@ pub fn init_logging() {
mod tests {
use super::*;
#[tokio::test]
async fn emulator_uses_host_adbd_socket() {
let listener = loop {
let socket = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
if socket.local_addr().unwrap().port() % 2 == 1 {
break socket;
}
};
let serial = format!("emulator-{}", listener.local_addr().unwrap().port() - 1);
let peer = tokio::spawn(async move {
let (mut stream, _) = listener.accept().await.unwrap();
stream.write_all(b"raw-adbd").await.unwrap();
});
let mut stream = adb_tcp_connect("127.0.0.1:1", &serial, 5555).await.unwrap();
let mut bytes = [0; 8];
stream.read_exact(&mut bytes).await.unwrap();
assert_eq!(&bytes, b"raw-adbd");
peer.await.unwrap();
}
#[test]
fn rejects_unsafe_configuration() {
let network = NetworkArgs {