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

Method console_port_for_avd

packages/server/src/android.rs:911–936  ·  view source on GitHub ↗
(&self, avd_name: &str)

Source from the content-addressed store, hash-verified

909 }
910
911 fn console_port_for_avd(&self, avd_name: &str) -> Result<u16, AppError> {
912 static CACHE: OnceLock<Mutex<TimedMap<u16>>> = OnceLock::new();
913 let cache = CACHE.get_or_init(|| Mutex::new(None));
914 if let Some((updated_at, ports)) = cache.lock().unwrap().as_ref() {
915 if updated_at.elapsed() < AVD_CONSOLE_PORT_CACHE_TTL {
916 if let Some(port) = ports.get(avd_name) {
917 return Ok(*port);
918 }
919 }
920 }
921
922 let ports = self
923 .run_emulator(["-list-avds"])?
924 .lines()
925 .map(str::trim)
926 .filter(|line| !line.is_empty())
927 .enumerate()
928 .map(|(index, name)| Ok((name.to_owned(), console_port_for_avd_index(index)?)))
929 .collect::<Result<HashMap<_, _>, AppError>>()?;
930 let port = ports
931 .get(avd_name)
932 .copied()
933 .ok_or_else(|| AppError::not_found(format!("Unknown Android AVD `{avd_name}`.")))?;
934 *cache.lock().unwrap() = Some((Instant::now(), ports));
935 Ok(port)
936 }
937
938 fn screen_size_for_serial(&self, serial: &str) -> Result<(f64, f64), AppError> {
939 let metrics = self.display_metrics_for_serial(serial)?;

Callers 1

bootMethod · 0.80

Calls 4

run_emulatorMethod · 0.80
is_emptyMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected