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; }
private void cleanDirectoryOnDevice(String fullPath, IDevice device) throws Exception { CollectingOutputReceiver deleteDirOutputReceiver = new CollectingOutputReceiver(); device.executeShellCommand("rm -rf " + fullPath, deleteDirOutputReceiver); }
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; }
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); } }
+ info.activity ); CollectingOutputReceiver shellOutput = new CollectingOutputReceiver(); device.executeShellCommand( command, shellOutput ); if ( shellOutput.getOutput().contains( "Error" ) ) CollectingOutputReceiver processOutput = new CollectingOutputReceiver(); device.executeShellCommand( "ps", processOutput ); BufferedReader r = new BufferedReader( new StringReader( processOutput.getOutput() ) );
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; }
private void cleanDirectoryOnDevice(String fullPath, IDevice device) throws Exception { CollectingOutputReceiver deleteDirOutputReceiver = new CollectingOutputReceiver(); device.executeShellCommand("rm -rf " + fullPath, deleteDirOutputReceiver); }
@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; }
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(); }