private String getExternalStoragePath(IDevice device, final String path) throws Exception { CollectingOutputReceiver pathNameOutputReceiver = new CollectingOutputReceiver(); device.executeShellCommand("echo $EXTERNAL_STORAGE", pathNameOutputReceiver); return pathNameOutputReceiver.getOutput().trim() + "/" + path; }
public SpoonAndroidTestRunner(String appPackageName, String packageName, String runnerName, IShellEnabledDevice remoteDevice, boolean clearAppDataBeforeEachTest, boolean debug) { super(packageName, runnerName, remoteDevice); this.remoteDevice = remoteDevice; this.outputReceiver = new CollectingOutputReceiver(); this.clearCommandStr = "pm clear " + appPackageName; this.clearAppDataBeforeEachTest = clearAppDataBeforeEachTest; this.debug = debug; }
@Override public void run(Collection<ITestRunListener> listeners) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException { try { if (clearAppDataBeforeEachTest) { logDebug(debug, String.format("Running adb command: %s", clearCommandStr)); remoteDevice.executeShellCommand(clearCommandStr, outputReceiver, MAX_TIMEOUT_MS, MAX_TIME_TO_OUTPUT_RESPONSE_MILLIS, TimeUnit.MILLISECONDS); String output = outputReceiver.getOutput(); if (output == null || !output.contains("Success")) { logError("adb clear command failed with the following output: " + output); } } } catch (IOException | ShellCommandUnresponsiveException | TimeoutException | AdbCommandRejectedException e) { String exceptionName = e.getClass().getSimpleName(); logError(String.format( "%1$s %2$s when running adb 'pm clear' command %3$s on %4$s", exceptionName, e.toString(), getPackageName(), remoteDevice.getName())); throw e; } super.run(listeners); } }
@Override public void addOutput(byte[] data, int offset, int length) { if (!isCancelled()) { String s; s = new String(data, offset, length, UTF_8); mOutputBuffer.append(s); } }
@Override public void flush() { super.flush(); result[0] = getOutput().trim(); task.run(); } });
private void cleanDirectoryOnDevice(String fullPath, IDevice device) throws Exception { CollectingOutputReceiver deleteDirOutputReceiver = new CollectingOutputReceiver(); device.executeShellCommand("rm -rf " + fullPath, deleteDirOutputReceiver); }
@Override public void run(Collection<ITestRunListener> listeners) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException { try { if (clearAppDataBeforeEachTest) { logDebug(debug, String.format("Running adb command: %s", clearCommandStr)); remoteDevice.executeShellCommand(clearCommandStr, outputReceiver, MAX_TIMEOUT_MS, MAX_TIME_TO_OUTPUT_RESPONSE_MILLIS, TimeUnit.MILLISECONDS); String output = outputReceiver.getOutput(); if (output == null || !output.contains("Success")) { logError("adb clear command failed with the following output: " + output); } } } catch (IOException | ShellCommandUnresponsiveException | TimeoutException | AdbCommandRejectedException e) { String exceptionName = e.getClass().getSimpleName(); logError(String.format( "%1$s %2$s when running adb 'pm clear' command %3$s on %4$s", exceptionName, e.toString(), getPackageName(), remoteDevice.getName())); throw e; } super.run(listeners); } }
@Override public void addOutput(byte[] data, int offset, int length) { if (!isCancelled()) { String s; s = new String(data, offset, length, Charsets.UTF_8); mOutputBuffer.append(s); } }
+ info.activity ); CollectingOutputReceiver shellOutput = new CollectingOutputReceiver(); device.executeShellCommand( command, shellOutput ); if ( shellOutput.getOutput().contains( "Error" ) ) throw new MojoFailureException( shellOutput.getOutput() ); CollectingOutputReceiver processOutput = new CollectingOutputReceiver(); device.executeShellCommand( "ps", processOutput ); BufferedReader r = new BufferedReader( new StringReader( processOutput.getOutput() ) ); int pid = -1; for ( ;; )
private void grantReadWriteExternalStorage(DeviceDetails deviceDetails, IDevice device) throws Exception { // If this is Android Marshmallow or above grant WRITE_EXTERNAL_STORAGE if (deviceDetails.getApiLevel() >= DeviceDetails.MARSHMALLOW_API_LEVEL) { String appPackage = instrumentationInfo.getApplicationPackage(); CollectingOutputReceiver grantOutputReceiver = new CollectingOutputReceiver(); device.executeShellCommand( "pm grant " + appPackage + " android.permission.READ_EXTERNAL_STORAGE", grantOutputReceiver); device.executeShellCommand( "pm grant " + appPackage + " android.permission.WRITE_EXTERNAL_STORAGE", grantOutputReceiver); } }
private String getExternalStoragePath(IDevice device, final String path) throws Exception { CollectingOutputReceiver pathNameOutputReceiver = new CollectingOutputReceiver(); device.executeShellCommand("echo $EXTERNAL_STORAGE", pathNameOutputReceiver); return pathNameOutputReceiver.getOutput().trim() + "/" + path; }
public SpoonAndroidTestRunner(String appPackageName, String packageName, String runnerName, IShellEnabledDevice remoteDevice,boolean clearAppDataBeforeEachTest,boolean debug) { super(packageName, runnerName, remoteDevice); this.remoteDevice = remoteDevice; this.outputReceiver = new CollectingOutputReceiver(); this.clearCommandStr = "pm clear " + appPackageName; this.clearAppDataBeforeEachTest = clearAppDataBeforeEachTest; this.debug = debug; }
@Override public boolean isRoot() throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException { if (mIsRoot) { return true; } CollectingOutputReceiver receiver = new CollectingOutputReceiver(); executeShellCommand("echo $USER_ID", receiver, QUERY_IS_ROOT_TIMEOUT_MS, TimeUnit.MILLISECONDS); String userID = receiver.getOutput().trim(); mIsRoot = userID.equals("0"); return mIsRoot; }
private void cleanDirectoryOnDevice(String fullPath, IDevice device) throws Exception { CollectingOutputReceiver deleteDirOutputReceiver = new CollectingOutputReceiver(); device.executeShellCommand("rm -rf " + fullPath, deleteDirOutputReceiver); }
private boolean hasBinary(String path) { CountDownLatch latch = new CountDownLatch(1); CollectingOutputReceiver receiver = new CollectingOutputReceiver(latch); try { executeShellCommand("ls " + path, receiver, LS_TIMEOUT_SEC, TimeUnit.SECONDS); } catch (Exception e) { return false; } try { latch.await(LS_TIMEOUT_SEC, TimeUnit.SECONDS); } catch (InterruptedException e) { return false; } String value = receiver.getOutput().trim(); return !value.endsWith("No such file or directory"); }
private void grantReadWriteExternalStorage(DeviceDetails deviceDetails, IDevice device) throws Exception { // If this is Android Marshmallow or above grant WRITE_EXTERNAL_STORAGE if (deviceDetails.getApiLevel() >= DeviceDetails.MARSHMALLOW_API_LEVEL) { String appPackage = instrumentationInfo.getApplicationPackage(); CollectingOutputReceiver grantOutputReceiver = new CollectingOutputReceiver(); device.executeShellCommand( "pm grant " + appPackage + " android.permission.READ_EXTERNAL_STORAGE", grantOutputReceiver); device.executeShellCommand( "pm grant " + appPackage + " android.permission.WRITE_EXTERNAL_STORAGE", grantOutputReceiver); } }
private String executeShellCommand(String command) { CollectingOutputReceiver output = new CollectingOutputReceiver(); try { device.executeShellCommand(command, output, 0); } catch (TimeoutException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (AdbCommandRejectedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ShellCommandUnresponsiveException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return output.getOutput(); }