@Override protected Void process(Object input) throws Exception { try { CommandTool ct = Spacelift.task(CommandTool.class) .addEnvironment(sdk.getPlatformConfiguration().getAndroidSystemEnvironmentProperties()); ct.command(new CommandBuilder(sdk.getAdbPath()) .parameters("-s", serialNumber, "shell", "input", "keyevent", "82")) .execute() .await(); ct.command(new CommandBuilder(sdk.getAdbPath()) .parameters("-s", serialNumber, "shell", "input", "keyevent", "4")) .execute() .await(); } catch (ExecutionException ex) { logger.log(Level.WARNING, "Unlocking device failed", ex); } return null; }
SeleniumServerExecution execute(Command command) throws InterruptedException { CountDownLatch countDownLatch = new CountDownLatch(1); log.info("Running Selenium server process: " + command.toString()); server = Spacelift .task(CommandTool.class) .command(command) .interaction(new BinaryInteraction() .outputPrefix("[Selenium server] ") .printToOut(".*") .when(".+Selenium.+is up and running$") .thenCountDown(countDownLatch) .build()) .execute(); server.registerShutdownHook(); countDownLatch.await(10, TimeUnit.SECONDS); return this; }
@Override protected Integer process(String androidProcessName) throws Exception { Validate.notNullOrEmpty(androidProcessName, "Android process name to get PID of is a null object or an empty string."); Validate.notNull(androidSdk, "Android SDK is a null object!"); ProcessResult psResult = Spacelift.task(CommandTool.class).programName(androidSdk.getAdbPath()) .addEnvironment(androidSdk.getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .parameter("shell") .parameter("ps") .execute().await(); int pid = -1; for (String psLine : psResult.output()) { if (psLine != null && psLine.trim().endsWith(androidProcessName)) { pid = parsePid(psLine.trim(), androidProcessName); break; } } return pid; }
.programName(androidSdk.getAdbPath()) .addEnvironment(androidSdk.getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .parameter("shell") .parameter("screenrecord"); screenRecorderTool.parameters("--size", options.width + "x" + options.height); screenRecorderTool.parameters("--bit-rate", Long.toString(options.bitrate)); screenRecorderTool.parameters("--time-limit", "180"); // maximum value of screenrecord command screenRecorderTool.parameter(remoteFilePath);
public List<Target> parse() { List<String> output = Spacelift.task(CommandTool.class) .addEnvironment(platformConfiguration.getAndroidSystemEnvironmentProperties()) .programName(androidSdk.getAndroidPath()) .parameters("list", "target") .execute().await() .output(); return parseAndroidListTargetOutput(new LinkedList<String>(output)); }
.addEnvironment(androidSDK.get().getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .command(cb).interaction(interaction).execute().await();
@Override public void startRecording(String remoteFilePath, ScreenrecordOptions options) throws Exception { if (isRecording()) { throw new IllegalStateException("Android device is already recording the video."); } Validate.notNullOrEmpty(remoteFilePath, "remoteFilePath for taken video is a null object"); recordedVideoRemote = remoteFilePath; Validate.notNull(options, "options for recording of a video is a null object"); CommandTool screenRecorderTool = new ScreenRecordToolBuilder() .androidSdk(androidSdk) .options(options) .remoteFilePath(recordedVideoRemote) .build(); screenrecorderExecution = screenRecorderTool.execute(); }
.addEnvironment(sdk.getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .command(command) .interaction(interactions.build()) .execute(); } catch (ExecutionException ex) { throw new AndroidExecutionException(ex, "Unable to start emulator \"{0}\", using {1}",
@Override protected ProcessResult process(Integer pid) throws Exception { Validate.notNull(pid, "PID for process to kill is a null object!"); Validate.notNull(androidSdk, "Android SDK is a null object!"); if (pid <= 0) { throw new IllegalStateException("PID to kill is lower then 0."); } ProcessResult processResult = Spacelift.task(CommandTool.class) .programName(androidSdk.getAdbPath()) .addEnvironment(androidSdk.getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .parameters("shell", "kill", "-" + signum, pid.toString()) .execute().await(); return processResult; } }
private void loadProcessMap() { try { processMap.clear(); Command command = new CommandBuilder(androidSDK.getAdbPath()) .parameter("-s") .parameter(androidDevice.getSerialNumber()) .parameter("shell") .parameter("ps") .build(); List<String> runningProcesses = Spacelift.task(CommandTool.class) .addEnvironment(androidSDK.getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .command(command).execute().await().output(); Pattern pattern = Pattern .compile(".*?\\s+([0-9]+)\\s+[0-9]+\\s+[0-9]+\\s+[0-9]+\\s+[0-9a-f]+\\s+[0-9a-f]+\\s.?\\s(.*)"); for(String line: runningProcesses) { Matcher matcher = pattern.matcher(line); if (!matcher.matches()) { continue; } Integer processId = Integer.valueOf(matcher.group(1)); String processName = matcher.group(2); processMap.put(processId, processName); } } catch (ExecutionException e) { logger.log(Level.SEVERE, "Couldn't load process map!", e); } } }
SeleniumServerExecution execute(Command command) throws InterruptedException { CountDownLatch countDownLatch = new CountDownLatch(1); log.info("Running Selenium server process: " + command.toString()); server = Spacelift .task(CommandTool.class) .command(command) .interaction(new BinaryInteraction() .outputPrefix("[Selenium server] ") .printToOut(".*") .when(".+Selenium.+is up and running$") .thenCountDown(countDownLatch) .build()) .execute(); server.registerShutdownHook(); countDownLatch.await(10, TimeUnit.SECONDS); return this; }
@Override protected Boolean process(String processName) throws Exception { Validate.notNullOrEmpty(processName, "Process name to get running status of is a null object or it is an empty string!"); Validate.notNull(androidSdk, "AndroidSDK is null object!"); List<String> psOutput = Spacelift.task(CommandTool.class) .programName(androidSdk.getAdbPath()) .addEnvironment(androidSdk.getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .parameter("shell") .parameter("ps") .execute().await() .output(); boolean running = false; for (String outputLine : psOutput) { if (outputLine != null) { if (outputLine.trim().endsWith(processName)) { running = true; break; } } } return running; }
private BadgingOutput getAAPTBadgingOutput(File apk) { final Command command = new CommandBuilder(sdk.getAaptPath()) .parameter("dump") .parameter("badging") .parameter(apk.getAbsolutePath()) .build(); return new BadgingOutput(Spacelift.task(CommandTool.class) .addEnvironment(sdk.getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .command(command) .execute() .await() .output()); }
private List<String> getAAPTXmlTreeOutput(File apkFile) { final Command command = new CommandBuilder(sdk.getAaptPath()) .parameter("dump") .parameter("xmltree") .parameter(apkFile.getAbsolutePath()) .parameter("AndroidManifest.xml") .build(); return Spacelift.task(CommandTool.class) .addEnvironment(sdk.getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .command(command) .execute() .await() .output(); }
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"); } }
@Override protected File process(File toSign) throws Exception { if (toSign == null || !toSign.exists()) { throw new IllegalStateException("File to be signed is either null or it does not exists"); } Spacelift.task(CheckKeyStoreTask.class).sdk(androidSDK).execute().await(); File signed = new File(androidSDK.getPlatformConfiguration().getTmpDir(), DroidiumFileUtils.getRandomAPKFileName()); Command jarSignerCommand = new CommandBuilder(androidSDK.getPathForJavaTool("jarsigner")) .parameter("-sigalg").parameter("MD5withRSA") .parameter("-digestalg").parameter("SHA1") .parameter("-signedjar").parameter(signed.getAbsolutePath()) .parameter("-storepass").parameter(androidSDK.getPlatformConfiguration().getStorepass()) .parameter("-keystore").parameter(new File(androidSDK.getPlatformConfiguration().getKeystore()).getAbsolutePath()) .parameter(toSign.getAbsolutePath()) .parameter(androidSDK.getPlatformConfiguration().getAlias()) .build(); Spacelift.task(CommandTool.class) .addEnvironment(androidSDK.getPlatformConfiguration().getAndroidSystemEnvironmentProperties()) .command(jarSignerCommand).execute().await(); return signed; } }