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); } }
private void executeOnAdbShell( String command ) { try { device.executeShellCommand( command, new IShellOutputReceiver() { @Override public boolean isCancelled() { return false; } @Override public void flush() { } @Override public void addOutput( byte[] data, int offset, int length ) { } } ); } catch ( TimeoutException | AdbCommandRejectedException | IOException | ShellCommandUnresponsiveException e ) { getLog().error( e ); } }
device.executeShellCommand( command, shellOutput ); if ( shellOutput.getOutput().contains( "Error" ) ) device.executeShellCommand( "ps", processOutput ); BufferedReader r = new BufferedReader( new StringReader( processOutput.getOutput() ) ); int pid = -1;
mRemoteDevice.executeShellCommand( runCaseCommandStr, mParser, mMaxTimeToOutputResponse );
mRemoteDevice.executeShellCommand( runCaseCommandStr, mParser, mMaxTimeToOutputResponse );
@Override public void executeShellCommand( String command, IShellOutputReceiver receiver, long maxTimeToOutputResponse, TimeUnit maxTimeUnits) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException { device.executeShellCommand(command, receiver, maxTimeToOutputResponse, maxTimeUnits); }
@Override public void run() { try { device.executeShellCommand(LOGCAT_COMMAND, logListenerCommandShell, 0); } catch (Exception e) { // log.error("Exception launching screenshot-request-listening logcat.", e); } } }
@Override public void executeShellCommand(String command, IShellOutputReceiver receiver, long maxTimeToOutputResponse, TimeUnit maxTimeUnits) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException { iDevice.executeShellCommand(command, receiver, maxTimeToOutputResponse, maxTimeUnits); }
@Override public void run() { try { device.executeShellCommand(LOGCAT_COMMAND, logListenerCommandShell, 0); } catch (Exception e) { // log.error("Exception launching screenshot-request-listening logcat.", e); } } }
@Override public void executeShellCommand(String command, IShellOutputReceiver receiver, long maxTimeToOutputResponse, TimeUnit maxTimeUnits) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException { iDevice.executeShellCommand(command, receiver, maxTimeToOutputResponse, maxTimeUnits); }
/** * @deprecated */ @Deprecated @Override public void executeShellCommand(String command, IShellOutputReceiver receiver, int maxTimeToOutputResponse) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException { device.executeShellCommand(command, receiver, maxTimeToOutputResponse); }
private static void executeCommand(IDevice device, String command, String errorMessage) { try { device.executeShellCommand(command, NO_OP_RECEIVER); } catch (TimeoutException | AdbCommandRejectedException | ShellCommandUnresponsiveException | IOException e) { logger.error(errorMessage, e); } }
private void cleanDirectoryOnDevice(String fullPath, IDevice device) throws Exception { CollectingOutputReceiver deleteDirOutputReceiver = new CollectingOutputReceiver(); device.executeShellCommand("rm -rf " + fullPath, deleteDirOutputReceiver); }
@Override public void execute(Command command) { LOGGER.debug("execute(Command command={}) - start", command); try { device.executeShellCommand(command.getFormattedCommand(), shellOutputReceiver, adbCommandTimeout, TimeUnit.SECONDS); } catch (TimeoutException | AdbCommandRejectedException | ShellCommandUnresponsiveException | IOException e) { LOGGER.error("execute(Command command={})", command, e); throw new AdbShellCommandExecutionException(command, e); } LOGGER.debug("execute(Command command={}) - end", command); }
private void clearLogcat(final IDevice device) { try { device.executeShellCommand("logcat -c", new NullOutputReceiver()); } catch (TimeoutException | AdbCommandRejectedException | ShellCommandUnresponsiveException | IOException e) { logger.warn("Could not clear logcat on device: " + device.getSerialNumber(), e); } } }
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() { try { GetPropReceiver propReceiver = new GetPropReceiver(); mDevice.executeShellCommand(GETPROP_COMMAND, propReceiver, GETPROP_TIMEOUT_SEC, TimeUnit.SECONDS); populateCache(propReceiver.getCollectedProperties()); } catch (Exception e) { handleException(e); } } };
private void grantMockLocationInMarshmallow(final IDevice device, final String appPackage) { if (isMarshmallowOrMore(device)) { CollectingShellOutputReceiver receiver = new CollectingShellOutputReceiver(); String command = " appops set " + appPackage + " android:mock_location allow"; try { device.executeShellCommand(command, receiver); logger.debug("When mock location granted for " + appPackage + " :" + receiver.getOutput()); } catch (Exception e) { logger.warn("Error when executing " + command + " on " + device.getSerialNumber(), e); } } } }