private AndroidDevice getVirtualDeviceByConsolePort(String consolePort) throws AndroidExecutionException { Validate.notNullOrEmpty(consolePort, "Console port 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 deviceConsolePort = device.getConsolePort(); if (deviceConsolePort != null && deviceConsolePort.equals(consolePort)) { logger.log(Level.INFO, "Connecting to virtual device running on console port {0}.", consolePort); return device; } } throw new AndroidExecutionException("Unable to get Android emulator running on the console port " + consolePort); }
private AndroidDevice getVirtualDeviceByConsolePort(String consolePort) throws AndroidExecutionException { Validate.notNullOrEmpty(consolePort, "Console port 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 deviceConsolePort = device.getConsolePort(); if (deviceConsolePort != null && deviceConsolePort.equals(consolePort)) { return device; } } throw new AndroidExecutionException("Unable to get Android emulator running on the console port " + consolePort); }
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; }
logger.info("Device " + device.getAvdName() + " on port " + device.getConsolePort() + " was disconnected in " + countdown.timeElapsed() + " seconds."); } catch (InterruptedException e) {
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)); } }