/** * Destroys Android Debug Bridge and fires {@link AndroidBridgeTerminated} event. * * @param event * @throws AndroidExecutionException */ public void terminateAndroidDebugBridge(@Observes AndroidEmulatorShuttedDown event) throws AndroidExecutionException { logger.info("Disconnecting Android Debug Bridge."); androidBridge.get().disconnect(); adbTerminated.fire(new AndroidBridgeTerminated()); }
private List<AndroidDevice> getDevices() { return androidBridge.get().getDevices(); }
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); }
/** * Initializes Android Debug Bridge and fires {@link AndroidBridgeInitialized} event. * * @param event * @throws AndroidExecutionException */ public void initAndroidDebugBridge(@Observes AndroidContainerStart event) throws AndroidExecutionException { logger.info("Initializing Android Debug Bridge."); long start = System.currentTimeMillis(); AndroidBridge bridge = new AndroidBridgeImpl(new File(androidSDK.get().getAdbPath()), configuration.get() .isForceNewBridge()); bridge.connect(); long delta = System.currentTimeMillis() - start; logger.info("Android Debug Bridge was initialized in " + delta + "ms."); androidBridge.set(bridge); adbInitialized.fire(new AndroidBridgeInitialized()); }
public void createAndroidEmulator(@Observes AndroidVirtualDeviceAvailable event) throws AndroidExecutionException { if (!androidBridge.get().isConnected()) { throw new IllegalStateException("Android debug bridge must be connected in order to spawn the emulator"); } AndroidContainerConfiguration configuration = this.configuration.get(); AndroidDevice emulator = null; CountDownWatch countdown = new CountDownWatch(configuration.getEmulatorBootupTimeoutInSeconds(), TimeUnit.SECONDS); logger.log(Level.INFO, "Waiting {0} seconds for emulator {1} to be started and connected.", new Object[] { countdown.timeout(), configuration.getAvdName() }); ProcessExecutor emulatorProcessExecutor = this.executor.get(); DeviceConnectDiscovery deviceDiscovery = new DeviceConnectDiscovery(); AndroidDebugBridge.addDeviceChangeListener(deviceDiscovery); Process emulatorProcess = startEmulator(emulatorProcessExecutor); androidEmulator.set(new AndroidEmulator(emulatorProcess)); logger.log(Level.INFO, "Emulator process started, {0} seconds remaining to start the device {1}", new Object[] { countdown.timeLeft(), configuration.getAvdName() }); waitUntilBootUpIsComplete(deviceDiscovery, emulatorProcessExecutor, countdown); unlockEmulator(deviceDiscovery, emulatorProcessExecutor); emulator = deviceDiscovery.getDiscoveredDevice(); setDronePorts(emulator); AndroidDebugBridge.removeDeviceChangeListener(deviceDiscovery); androidDevice.set(emulator); screenshooter.set(new AndroidScreenshooter(emulator)); androidDeviceReady.fire(new AndroidDeviceReady(emulator)); }
/** * Initializes Android Debug Bridge and fires {@link AndroidBridgeInitialized} event. * * @param event * @throws AndroidExecutionException */ public void initAndroidDebugBridge(@Observes AndroidContainerStart event) throws AndroidExecutionException { logger.info("Initializing Android Debug Bridge."); long start = System.currentTimeMillis(); AndroidBridge bridge = new AndroidBridgeImpl( androidSDK.get(), new File(androidSDK.get().getAdbPath()), configuration.get().isForceNewBridge(), Integer.parseInt(configuration.get().getDdmlibCommandTimeout())); bridge.connect(); long delta = System.currentTimeMillis() - start; logger.info("Android Debug Bridge was initialized in " + delta + "ms."); androidBridge.set(bridge); adbInitialized.fire(new AndroidBridgeInitialized()); }
public void startAndroidEmulator(@Observes AndroidVirtualDeviceAvailable event) throws AndroidExecutionException { if (!androidBridge.get().isConnected()) { throw new IllegalStateException("Android debug bridge must be connected in order to spawn an emulator");
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 getPhysicalDevice() throws AndroidExecutionException { String serialId = configuration.get().getSerialId(); List<AndroidDevice> devices = androidBridge.get().getDevices(); if (devices == null || devices.size() == 0) { throw new AndroidExecutionException("There are no devices on the Android bridge."); } for (AndroidDevice device : devices) { if (!device.isEmulator() && serialId.equals(device.getSerialNumber())) { logger.info("Detected physical device with serial ID " + serialId + "."); return device; } } throw new AndroidExecutionException("Unable to get device with serial ID " + serialId + "."); }
/** * Destroys Android Debug Bridge and fires {@link AndroidBridgeTerminated} event. * * @param event * @throws AndroidExecutionException */ public void terminateAndroidDebugBridge(@Observes AndroidEmulatorShuttedDown event) throws AndroidExecutionException { logger.info("Disconnecting Android Debug Bridge."); androidBridge.get().disconnect(); adbTerminated.fire(new AndroidBridgeTerminated()); }
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 getPhysicalDevice() throws AndroidExecutionException { String serialId = configuration.get().getSerialId(); List<AndroidDevice> devices = androidBridge.get().getDevices(); if (devices == null || devices.size() == 0) { throw new AndroidExecutionException("There are no physical devices on the Android bridge."); } for (AndroidDevice device : devices) { if (!device.isEmulator() && serialId.equals(device.getSerialNumber())) { logger.log(Level.INFO, "Connecting to physical device with serial ID {0}", serialId); return device; } } throw new AndroidExecutionException("Unable to get device with serial ID " + serialId + "."); }
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; }