public void shutdownEmulator(@Observes AndroidContainerStop event) throws AndroidExecutionException { AndroidDevice device = androidDevice.get(); AndroidContainerConfiguration configuration = this.configuration.get(); androidDeviceRegister.get().remove(device); if (device != null && device.isEmulator() && !device.getAlreadyRuns()) { logger.log(Level.INFO, "Stopping Android emulator of AVD name {0}.", configuration.getAvdName()); CountDownWatch countdown = new CountDownWatch(configuration.getEmulatorShutdownTimeoutInSeconds(), TimeUnit.SECONDS); logger.info("Waiting " + countdown.timeout() + " seconds for emulator " + device.getAvdName() + " to be disconnected and shutdown."); Spacelift.task(device, EmulatorShutdownTask.class).countdown(countdown).execute().await(); logger.info("Device " + device.getAvdName() + " on port " + device.getConsolePort() + " was disconnected in " + countdown.timeElapsed() + " seconds."); if (configuration.isAVDGenerated()) { androidVirtualDeviceDelete.fire(new AndroidVirtualDeviceDelete()); } androidEmulatorShuttedDown.fire(new AndroidEmulatorShuttedDown(device)); } }