-
-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integrate adb port forwarding (#2451)
- Loading branch information
Showing
20 changed files
with
874 additions
and
75 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "alvr_adb" | ||
version.workspace = true | ||
edition.workspace = true | ||
rust-version.workspace = true | ||
authors.workspace = true | ||
license.workspace = true | ||
|
||
[dependencies] | ||
alvr_common.workspace = true | ||
alvr_filesystem.workspace = true | ||
alvr_server_io.workspace = true | ||
|
||
anyhow = "1" | ||
ureq = "2.10" | ||
zip = "2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// https://cs.android.com/android/platform/superproject/main/+/7dbe542b9a93fb3cee6c528e16e2d02a26da7cc0:packages/modules/adb/adb.h;l=104-122 | ||
#[derive(Debug)] | ||
pub enum ConnectionState { | ||
Authorizing, | ||
Bootloader, | ||
Connecting, | ||
Detached, | ||
Device, | ||
Host, | ||
NoPermissions, // https://cs.android.com/android/platform/superproject/main/+/main:system/core/diagnose_usb/diagnose_usb.cpp;l=83-90 | ||
Offline, | ||
Recovery, | ||
Rescue, | ||
Sideload, | ||
Unauthorized, | ||
} | ||
|
||
pub fn parse(value: &str) -> Option<ConnectionState> { | ||
match value { | ||
"authorizing" => Some(ConnectionState::Authorizing), | ||
"bootloader" => Some(ConnectionState::Bootloader), | ||
"connecting" => Some(ConnectionState::Connecting), | ||
"detached" => Some(ConnectionState::Detached), | ||
"device" => Some(ConnectionState::Device), | ||
"host" => Some(ConnectionState::Host), | ||
"offline" => Some(ConnectionState::Offline), | ||
"recovery" => Some(ConnectionState::Recovery), | ||
"rescue" => Some(ConnectionState::Rescue), | ||
"sideload" => Some(ConnectionState::Sideload), | ||
"unauthorized" => Some(ConnectionState::Unauthorized), | ||
_ => None, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use crate::{ | ||
connection_state::{self, ConnectionState}, | ||
transport_type::{self, TransportType}, | ||
}; | ||
|
||
// https://cs.android.com/android/platform/superproject/main/+/7dbe542b9a93fb3cee6c528e16e2d02a26da7cc0:packages/modules/adb/transport.cpp;l=1409 | ||
// The serial number is printed with a "%-22s" format, meaning that it's a left-aligned space-padded string of 22 characters. | ||
const SERIAL_NUMBER_COLUMN_LENGTH: usize = 22; | ||
|
||
// https://cs.android.com/android/platform/superproject/main/+/7dbe542b9a93fb3cee6c528e16e2d02a26da7cc0:packages/modules/adb/transport.cpp;l=1398 | ||
#[derive(Debug)] | ||
pub struct Device { | ||
pub connection_state: Option<ConnectionState>, | ||
pub device: Option<String>, | ||
pub model: Option<String>, | ||
pub product: Option<String>, | ||
pub serial: Option<String>, | ||
pub transport_type: Option<TransportType>, | ||
} | ||
|
||
pub fn parse(line: &str) -> Option<Device> { | ||
if line.len() < SERIAL_NUMBER_COLUMN_LENGTH { | ||
return None; | ||
} | ||
let (left, right) = line.split_at(SERIAL_NUMBER_COLUMN_LENGTH); | ||
let serial = left | ||
.contains("(no serial number)") | ||
.then(|| left.trim().to_owned()); | ||
let mut remaining = right.trim(); | ||
|
||
let connection_state = if remaining.starts_with("no permissions") { | ||
// Since the current user's name can be printed in the error message, | ||
// we are gambling that there's not a "]" in it. | ||
if let Some((_, right)) = remaining.split_once(']') { | ||
remaining = right; | ||
Some(ConnectionState::NoPermissions) | ||
} else { | ||
None | ||
} | ||
} else if let Some((left, right)) = remaining.split_once(' ') { | ||
remaining = right; | ||
connection_state::parse(left) | ||
} else { | ||
None | ||
}; | ||
|
||
let mut slices = remaining.split_whitespace(); | ||
let product = slices.next().and_then(parse_pair); | ||
let model = slices.next().and_then(parse_pair); | ||
let device = slices.next().and_then(parse_pair); | ||
let transport_type = slices.next().and_then(transport_type::parse); | ||
|
||
Some(Device { | ||
connection_state, | ||
device, | ||
model, | ||
product, | ||
serial, | ||
transport_type, | ||
}) | ||
} | ||
|
||
fn parse_pair(pair: &str) -> Option<String> { | ||
let mut slice = pair.split(':'); | ||
let _key = slice.next(); | ||
|
||
slice.next().map(|value| value.to_string()) | ||
} |
Oops, something went wrong.