@Override public String getProperty(String name) throws IOException, AndroidExecutionException { try { return delegate.getPropertyCacheOrSync(name); } catch (TimeoutException e) { throw new AndroidExecutionException("Unable to get property '" + name + "' value in given timeout", e); } catch (AdbCommandRejectedException e) { throw new AndroidExecutionException("Unable to get property '" + name + "' value, command was rejected", e); } catch (ShellCommandUnresponsiveException e) { throw new AndroidExecutionException("Unable to get property '" + name + "' value, shell is not responsive", e); } }
public void deleteAndroidVirtualDevice(@Observes AndroidVirtualDeviceDelete event) { AndroidContainerConfiguration configuration = this.configuration.get(); try { ProcessExecutor executor = this.executor.get(); Process android = constructDeleteProcess(executor, androidSDK.get(), configuration.getAvdName()); if (deleteAVD(android, executor) == 0) { logger.info("Android Virtual Device " + configuration.getAvdName() + " deleted."); } else { logger.info("Unable to delete Android Virtual Device " + configuration.getAvdName() + "."); } } catch (AndroidExecutionException ex) { logger.info("Unable to delete AVD - " + ex.getMessage()); } androidSDCardDelete.fire(new AndroidSDCardDelete()); androidVirtualDeviceDeleted.fire(new AndroidVirtualDeviceDeleted(configuration.getAvdName())); }
@Override public void createPortForwarding(int localPort, int remotePort) throws AndroidExecutionException { try { delegate.createForward(localPort, remotePort); } catch (TimeoutException e) { throw new AndroidExecutionException("Unable to forward port (" + localPort + " to " + remotePort + ") within given timeout", e); } catch (AdbCommandRejectedException e) { throw new AndroidExecutionException("Unable to forward port (" + localPort + " to " + remotePort + "), command was rejected", e); } catch (IOException e) { throw new AndroidExecutionException("Unable to forward port (" + localPort + " to " + remotePort + ").", e); } }
@Override public void removePortForwarding(int localPort, int remotePort) throws AndroidExecutionException { try { delegate.removeForward(localPort, remotePort); } catch (TimeoutException e) { throw new AndroidExecutionException("Unable to remove port forwarding (" + localPort + " to " + remotePort + ") within given timeout", e); } catch (AdbCommandRejectedException e) { throw new AndroidExecutionException("Unable to remove port forwarding (" + localPort + " to " + remotePort + "), command was rejected", e); } catch (IOException e) { throw new AndroidExecutionException("Unable to remove port forwarding (" + localPort + " to " + remotePort + ").", e); } }
@Override public void createPortForwarding(int localPort, int remotePort) throws AndroidExecutionException { try { delegate.createForward(localPort, remotePort); } catch (TimeoutException e) { throw new AndroidExecutionException("Unable to forward port (" + localPort + " to " + remotePort + ") within given timeout", e); } catch (AdbCommandRejectedException e) { throw new AndroidExecutionException("Unable to forward port (" + localPort + " to " + remotePort + "), command was rejected", e); } catch (IOException e) { throw new AndroidExecutionException("Unable to forward port (" + localPort + " to " + remotePort + ").", e); } }
@Override public void removePortForwarding(int localPort, int remotePort) throws AndroidExecutionException { try { delegate.removeForward(localPort, remotePort); } catch (TimeoutException e) { throw new AndroidExecutionException("Unable to remove port forwarding (" + localPort + " to " + remotePort + ") within given timeout", e); } catch (AdbCommandRejectedException e) { throw new AndroidExecutionException("Unable to remove port forwarding (" + localPort + " to " + remotePort + "), command was rejected", e); } catch (IOException e) { throw new AndroidExecutionException("Unable to remove port forwarding (" + localPort + " to " + remotePort + ").", e); } }
@Override public String getProperty(String name) throws IOException, AndroidExecutionException { try { return delegate.getSystemProperty(name).get(); } catch (ExecutionException e) { throw new AndroidExecutionException("Unable to get property '" + name + "' value, not responsive", e); } catch (InterruptedException e) { throw new AndroidExecutionException("Unable to get property '" + name + "' value, not responsive", e); } }
@Override public void executeShellCommand(String command, AndroidDeviceOutputReciever reciever) throws AndroidExecutionException { try { delegate.executeShellCommand(command, new AndroidRecieverDelegate(reciever)); } catch (TimeoutException e) { throw new AndroidExecutionException("Unable to execute command '" + command + "' within given timeout", e); } catch (AdbCommandRejectedException e) { throw new AndroidExecutionException("Unable to execute command '" + command + "', command was rejected", e); } catch (ShellCommandUnresponsiveException e) { throw new AndroidExecutionException("Unable to execute command '" + command + "', shell is not responsive", e); } catch (IOException e) { throw new AndroidExecutionException("Unable to execute command '" + command + "'", e); } }
@Override public void executeShellCommand(String command, AndroidDeviceOutputReciever reciever) throws AndroidExecutionException { try { delegate.executeShellCommand(command, new AndroidRecieverDelegate(reciever)); } catch (TimeoutException e) { throw new AndroidExecutionException("Unable to execute command '" + command + "' within given timeout", e); } catch (AdbCommandRejectedException e) { throw new AndroidExecutionException("Unable to execute command '" + command + "', command was rejected", e); } catch (ShellCommandUnresponsiveException e) { throw new AndroidExecutionException("Unable to execute command '" + command + "', shell is not responsive", e); } catch (IOException e) { throw new AndroidExecutionException("Unable to execute command '" + command + "'", e); } }
@Override public void uninstallPackage(String packageName) throws AndroidExecutionException { try { delegate.uninstallPackage(packageName); } catch (InstallException e) { throw new AndroidExecutionException("Unable to uninstall APK named " + packageName, e); } }
@Override public void uninstallPackage(String packageName) throws AndroidExecutionException { try { delegate.uninstallPackage(packageName); } catch (InstallException e) { throw new AndroidExecutionException("Unable to uninstall APK named " + packageName, e); } }
private int createSDCard(final Process sdCardProcess, final ProcessExecutor executor) throws AndroidExecutionException { try { int created = executor.submit(new Callable<Integer>() { @Override public Integer call() throws Exception { return sdCardProcess.waitFor(); } }).get(); return created; } catch (Exception ex) { throw new AndroidExecutionException(ex); } }
private int deleteAVD(final Process android, final ProcessExecutor executor) throws AndroidExecutionException { try { int deleted = executor.submit(new Callable<Integer>() { @Override public Integer call() throws Exception { return android.waitFor(); } }).get(); return deleted; } catch (Exception ex) { throw new AndroidExecutionException(ex); } }
@Override public void installPackage(File packageFilePath, boolean reinstall, String... extraArgs) throws AndroidExecutionException { Validate.isReadable(packageFilePath.getAbsoluteFile(), "File " + packageFilePath.getAbsoluteFile() + " must represent a readable APK file"); try { String retval = delegate.installPackage(packageFilePath.getAbsolutePath(), reinstall, extraArgs); if (retval != null) { throw new AndroidExecutionException("Unable to install APK from " + packageFilePath.getAbsolutePath() + ". Command failed with status code: " + retval); } } catch (InstallException e) { throw new AndroidExecutionException("Unable to install APK from " + packageFilePath.getAbsolutePath(), e); } }
@Override public void installPackage(File packageFilePath, boolean reinstall, String... extraArgs) throws AndroidExecutionException { if (!Validate.isReadable(packageFilePath.getAbsoluteFile())) { throw new IllegalArgumentException("File " + packageFilePath.getAbsoluteFile() + " must represent a readable APK file"); } try { delegate.installPackage(packageFilePath.getAbsolutePath(), reinstall, extraArgs); } catch (InstallException e) { throw new AndroidExecutionException("Unable to install APK from " + packageFilePath.getAbsolutePath(), e); } }
public static void wait(AndroidDevice device, Monkey monkey, String command) { final int retries = 5; for (int i = 0; i < retries; i++) { device.executeShellCommand(command, monkey); if (monkey.isActive()) { return; } try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } throw new AndroidExecutionException(String.format("Waiting for monkey executing command \"%s\" timeouted in %d seconds.", command, retries)); } }
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 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 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 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 + "."); }