@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); } }
@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 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 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); } }
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 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 + "."); }
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 + "."); }
@Override public boolean isPackageInstalled(String packageName) throws AndroidExecutionException { try { String command = "pm list packages -f"; PackageInstalledMonkey monkey = new PackageInstalledMonkey(packageName); executeShellCommand(command, monkey); return monkey.isInstalled(); } catch (Exception e) { throw new AndroidExecutionException("Unable to decide if package " + packageName + " is installed or nor", e); } }
@Override public boolean isPackageInstalled(String packageName) throws AndroidExecutionException { try { String command = "pm list packages -f"; PackageInstalledMonkey monkey = new PackageInstalledMonkey(packageName); executeShellCommand(command, monkey); return monkey.isInstalled(); } catch (Exception e) { throw new AndroidExecutionException("Unable to decide if package " + packageName + " is installed or nor", e); } }
private Process constructDeleteProcess(ProcessExecutor executor, AndroidSDK androidSDK, String avdName) throws AndroidExecutionException { Command command = new Command(); command.add(androidSDK.getAndroidPath()).add("delete").add("avd").add("-n").add(avdName); try { return executor.spawn(command.getAsList()); } catch (InterruptedException e) { throw new AndroidExecutionException(e, "Unable to delete AVD {0}.", avdName); } catch (ExecutionException e) { throw new AndroidExecutionException(e, "Unable to delete AVD {0}.", avdName); } }
private List<String> getAndroidListAVDOutput(boolean compact) { try { CommandBuilder cb = new CommandBuilder(androidSDK.get().getAndroidPath()) .parameter("list") .parameter("avd"); if (compact) { cb.parameter("-c"); } Command command = cb.build(); return Spacelift.task(CommandTool.class) .addEnvironment(androidSDK.get().getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .command(command).execute().await().output(); } catch (ExecutionException ex) { throw new AndroidExecutionException(ex, "Unable to get list of AVDs"); } }