@Override public void deviceDisconnected(IDevice device) { if (device.getAvdName().equals(connectedDevice.getAvdName())) { this.offline = true; } logger.fine("Discovered an emulator device id=" + device.getSerialNumber() + " disconnected from ADB bus"); }
@Override public void deviceDisconnected(IDevice delegate) { if (delegate.isEmulator()) { if (delegate.getAvdName().equals(this.device.getAvdName())) { offline = true; logger.fine("Device id=" + delegate.getAvdName() + " disconnected from ADB bus."); } } else { if (delegate.getSerialNumber().equals(this.device.getSerialNumber())) { offline = true; logger.fine("Device id=" + delegate.getSerialNumber() + " disconnected from ADB bus."); } } }
private AndroidDevice getVirtualDeviceByAvdName(String avdName) throws AndroidExecutionException { Validate.notNullOrEmpty(avdName, "AVD name to get emulator of is a null object or an empty string"); List<AndroidDevice> devices = androidBridge.get().getEmulators(); if (devices == null || devices.size() == 0) { throw new AndroidExecutionException("There are no emulators on the Android bridge."); } for (AndroidDevice device : devices) { String deviceAvdName = device.getAvdName(); if (deviceAvdName != null && deviceAvdName.equals(avdName)) { logger.log(Level.INFO, "Connecting to virtual device running on AVD of name {0}.", avdName); return device; } } throw new AndroidExecutionException("No running emulator of AVD name " + avdName + "."); }
private AndroidDevice getVirtualDeviceByAvdName(String avdName) throws AndroidExecutionException { Validate.notNullOrEmpty(avdName, "AVD name to get emulator of is a null object or an empty string"); List<AndroidDevice> devices = androidBridge.get().getEmulators(); if (devices == null || devices.size() == 0) { throw new AndroidExecutionException("There are no emulators on the Android bridge."); } for (AndroidDevice device : devices) { String deviceAvdName = device.getAvdName(); if (deviceAvdName != null && deviceAvdName.equals(avdName)) { return device; } } throw new AndroidExecutionException("No running emulator of AVD name " + avdName + "."); }
private AndroidDevice getVirtualDevice(String consolePort, String avdName) throws AndroidExecutionException { Validate.notNullOrEmpty(consolePort, "Console port to get emulator of is a null object or an empty string."); Validate.notNullOrEmpty(avdName, "AVD name to get emulator of is a null object or an empty string."); List<AndroidDevice> devices = androidBridge.get().getEmulators(); if (devices == null || devices.size() == 0) { throw new AndroidExecutionException("There are no emulators on the Android bridge."); } for (AndroidDevice device : devices) { try { if (device.getConsolePort().equals(consolePort) && device.getAvdName().equals(avdName)) { logger.log(Level.INFO, "Connecting to virtual device running on console port {0} with AVD name {1}.", new Object[] { consolePort, avdName }); return device; } } catch (NullPointerException ex) { logger.severe("Unable to connect to the emulator. Please be sure you are running adb server."); } } return null; }
private AndroidDevice getVirtualDevice(String consolePort, String avdName) throws AndroidExecutionException { Validate.notNullOrEmpty(consolePort, "Console port to get emulator of is a null object or an empty string."); Validate.notNullOrEmpty(avdName, "AVD name to get emulator of is a null object or an empty string."); List<AndroidDevice> devices = androidBridge.get().getEmulators(); if (devices == null || devices.size() == 0) { throw new AndroidExecutionException("There are no emulators on the Android bridge."); } for (AndroidDevice device : devices) { try { if (device.getConsolePort().equals(consolePort) && device.getAvdName().equals(avdName)) { return device; } } catch (NullPointerException ex) { logger.severe("Unable to connect to the emulator. Please be sure you are running adb server."); } } return null; }
device.getAvdName(), countdown.timeout()); logger.info("Device " + device.getAvdName() + " on port " + device.getConsolePort() + " was disconnected in " + countdown.timeElapsed() + " seconds."); } catch (InterruptedException e) { throw new AndroidExecutionException(e, "Unable to disconnect AVD device {0}", device.getAvdName()); } catch (ExecutionException e) { throw new AndroidExecutionException(e, "Unable to disconnect AVD device {0}", device.getAvdName());
} catch (InterruptedException e) { p.destroy(); throw new AndroidExecutionException(e, "Unable to stop emulator {0}", device.getAvdName()); } catch (ExecutionException e) { p.destroy(); throw new AndroidExecutionException(e, "Unable to stop emulator {0}", device.getAvdName());
connectedDevice.getAvdName(), countdown.timeElapsed() });
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)); } }
public void shutdownEmulator(@Observes AndroidContainerStop event) throws AndroidExecutionException { AndroidEmulator emulator = androidEmulator.get(); AndroidDevice device = androidDevice.get(); AndroidContainerConfiguration configuration = this.configuration.get(); if (emulator != null && device.isEmulator()) { final ProcessExecutor executor = this.executor.get(); final Process p = emulator.getProcess(); CountDownWatch countdown = new CountDownWatch(configuration.getEmulatorShutdownTimeoutInSeconds(), TimeUnit.SECONDS); logger.info("Waiting " + countdown.timeout() + " seconds for emulator " + device.getAvdName() + " to be disconnected and shutdown."); try { final DeviceDisconnectDiscovery listener = new DeviceDisconnectDiscovery(device); AndroidDebugBridge.addDeviceChangeListener(listener); stopEmulator(p, executor, device, countdown); waitUntilShutDownIsComplete(device, listener, executor, countdown); AndroidDebugBridge.removeDeviceChangeListener(listener); if (configuration.isAVDGenerated()) { androidVirtualDeviceDelete.fire(new AndroidVirtualDeviceDelete()); } androidEmulatorShuttedDown.fire(new AndroidEmulatorShuttedDown(device)); } finally { executor.removeShutdownHook(p); } } }