/** * @return random name for APK file name (ends with .apk suffix) */ public static String getRandomAPKFileName() { return aig.getIdentifier(FileType.APK); }
@Override public void processNewLines(String[] lines) { delegate.processNewLines(lines); }
@Override public boolean isCancelled() { return delegate.isCancelled(); }
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 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)) { return device; } } throw new AndroidExecutionException("No running emulator of AVD name " + avdName + "."); }
@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); } }
private void installServerAPK(AndroidDevice device, File apk) throws AndroidExecutionException { if (device.isPackageInstalled(APK_APP_NAME)) { log.info("Package " + APK_APP_NAME + " is installed, trying to uninstall it."); device.uninstallPackage(APK_APP_NAME); } device.installPackage(apk, true); }
@Override public String getIdentifier(FileType identifierType) { String uuid = UUID.randomUUID().toString(); switch (identifierType) { case AVD: return uuid; case SD_CARD: return uuid + sdCardSuffix; case SD_CARD_LABEL: return uuid; case FILE: return uuid; case APK: return uuid + apkSuffix; } throw new IdentifierGeneratorException("Not possible to generate any identifier of type " + identifierType.name()); }
@Override public void deviceChanged(IDevice delegate, int changeMask) { if (this.delegate.equals(delegate) && (changeMask & IDevice.CHANGE_STATE) == 1) { if (device.isOnline()) { online = true; } } }
private List<AndroidDevice> getDevices() { return androidBridge.get().getDevices(); }
public ScreenrecordOptions build() { return new ScreenrecordOptions(this); } }
/** * Gets deployment which is backed by specified archive. * * @param archive archive to get the deployment of * @return deployment bean of {@code archive} or null if there is no such mapping */ public T get(Archive<?> archive) { for (T deployment : deployments) { if (deployment.getDeployment() == archive) { return deployment; } } return null; }
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); }
@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 processNewLines(String[] lines) { delegate.processNewLines(lines); }
@Override public boolean isCancelled() { return delegate.isCancelled(); }
@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 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); } }