MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / run_android_console_command

Function run_android_console_command

packages/server/src/android.rs:1984–2008  ·  view source on GitHub ↗
(port: u16, command: &str)

Source from the content-addressed store, hash-verified

1982}
1983
1984fn 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
2010fn connect_android_console(port: u16) -> Result<TcpStream, AppError> {
2011 let address = SocketAddr::from(([127, 0, 0, 1], port));

Callers 1

Calls 5

connect_android_consoleFunction · 0.85
insertMethod · 0.80
removeMethod · 0.65

Tested by

no test coverage detected