(port: u16)
| 2008 | } |
| 2009 | |
| 2010 | fn connect_android_console(port: u16) -> Result<TcpStream, AppError> { |
| 2011 | let address = SocketAddr::from(([127, 0, 0, 1], port)); |
| 2012 | let mut stream = |
| 2013 | TcpStream::connect_timeout(&address, ANDROID_CONSOLE_TIMEOUT).map_err(|error| { |
| 2014 | AppError::native(format!( |
| 2015 | "Unable to connect to Android emulator console on port {port}: {error}" |
| 2016 | )) |
| 2017 | })?; |
| 2018 | stream |
| 2019 | .set_read_timeout(Some(ANDROID_CONSOLE_TIMEOUT)) |
| 2020 | .map_err(|error| { |
| 2021 | AppError::native(format!("Unable to configure console timeout: {error}")) |
| 2022 | })?; |
| 2023 | stream |
| 2024 | .set_write_timeout(Some(ANDROID_CONSOLE_TIMEOUT)) |
| 2025 | .map_err(|error| { |
| 2026 | AppError::native(format!("Unable to configure console timeout: {error}")) |
| 2027 | })?; |
| 2028 | let greeting = read_android_console_response(&mut stream)?; |
| 2029 | if greeting.contains("Authentication required") { |
| 2030 | let token_path = home_dir().join(".emulator_console_auth_token"); |
| 2031 | let token = std::fs::read_to_string(&token_path).map_err(|error| { |
| 2032 | AppError::native(format!( |
| 2033 | "Unable to read Android emulator console auth token at {}: {error}", |
| 2034 | token_path.display() |
| 2035 | )) |
| 2036 | })?; |
| 2037 | write_android_console_command(&mut stream, &format!("auth {}", token.trim()))?; |
| 2038 | } |
| 2039 | Ok(stream) |
| 2040 | } |
| 2041 | |
| 2042 | fn write_android_console_command(stream: &mut TcpStream, command: &str) -> Result<(), AppError> { |
| 2043 | stream |
no test coverage detected