(port: u16, command: &str)
| 1982 | } |
| 1983 | |
| 1984 | fn run_android_console_command(port: u16, command: &str) -> Result<(), AppError> { |
| 1985 | let mut cache = android_console_connection_cache().lock().unwrap(); |
| 1986 | for attempt in 0..2 { |
| 1987 | if let std::collections::hash_map::Entry::Vacant(entry) = cache.entry(port) { |
| 1988 | entry.insert(connect_android_console(port)?); |
| 1989 | } |
| 1990 | let stream = cache |
| 1991 | .get_mut(&port) |
| 1992 | .ok_or_else(|| AppError::native("Android emulator console connection was missing."))?; |
| 1993 | match write_android_console_command(stream, command) { |
| 1994 | Ok(()) => return Ok(()), |
| 1995 | Err(error) if attempt == 0 => { |
| 1996 | cache.remove(&port); |
| 1997 | tracing::debug!("Android emulator console command retry on {port}: {error}"); |
| 1998 | } |
| 1999 | Err(error) => { |
| 2000 | cache.remove(&port); |
| 2001 | return Err(error); |
| 2002 | } |
| 2003 | } |
| 2004 | } |
| 2005 | Err(AppError::native( |
| 2006 | "Android emulator console command failed unexpectedly.", |
| 2007 | )) |
| 2008 | } |
| 2009 | |
| 2010 | fn connect_android_console(port: u16) -> Result<TcpStream, AppError> { |
| 2011 | let address = SocketAddr::from(([127, 0, 0, 1], port)); |
no test coverage detected