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; }
@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 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 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 String getExternalStoragePath(IDevice device, final String path) throws Exception { CollectingOutputReceiver pathNameOutputReceiver = new CollectingOutputReceiver(); device.executeShellCommand("echo $EXTERNAL_STORAGE", pathNameOutputReceiver); return pathNameOutputReceiver.getOutput().trim() + "/" + path; }
@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); } }
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(); }