(&self)
| 856 | } |
| 857 | |
| 858 | fn running_emulators(&self) -> Result<HashMap<String, String>, AppError> { |
| 859 | static CACHE: OnceLock<Mutex<TimedMap<String>>> = OnceLock::new(); |
| 860 | let cache = CACHE.get_or_init(|| Mutex::new(None)); |
| 861 | if let Some((updated_at, running)) = cache.lock().unwrap().as_ref() { |
| 862 | if updated_at.elapsed() < RUNNING_EMULATOR_CACHE_TTL { |
| 863 | return Ok(running.clone()); |
| 864 | } |
| 865 | } |
| 866 | if !self.adb_path().exists() { |
| 867 | return Ok(HashMap::new()); |
| 868 | } |
| 869 | let mut result = HashMap::new(); |
| 870 | for serial in self.online_emulator_serials()? { |
| 871 | if let Some(name) = self.avd_name_for_serial(&serial) { |
| 872 | result.insert(name, serial); |
| 873 | } |
| 874 | } |
| 875 | *cache.lock().unwrap() = Some((Instant::now(), result.clone())); |
| 876 | Ok(result) |
| 877 | } |
| 878 | |
| 879 | fn online_emulator_serials(&self) -> Result<Vec<String>, AppError> { |
| 880 | Ok(parse_online_emulator_serials(&self.run_adb(["devices"])?)) |
no test coverage detected