private void queryNewDeviceForMountingPoint(final Device device, final String name) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException { device.executeShellCommand("echo $" + name, new MultiLineReceiver() { //$NON-NLS-1$ public boolean isCancelled() { return false; } @Override public void processNewLines(String[] lines) { for (String line : lines) { if (line.length() > 0) { // this should be the only one. device.setMountingPoint(name, line); } } } }); }
public static void shell(Device device, String cmd, IShellOutputReceiver outputReceiver) { try { device.executeShellCommand(cmd, outputReceiver, 60, TimeUnit.SECONDS); } catch (TimeoutException | AdbCommandRejectedException | ShellCommandUnresponsiveException | IOException ex) { if (device.logError) LLog.ex(ex); } }
@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"); }
@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); } } };
mDevice.executeShellCommand(command, receiver);
@Nullable private String queryMountPoint(@NonNull final String name) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException { final AtomicReference<String> ref = Atomics.newReference(); executeShellCommand("echo $" + name, new MultiLineReceiver() { //$NON-NLS-1$ @Override public boolean isCancelled() { return false; } @Override public void processNewLines(String[] lines) { for (String line : lines) { if (!line.isEmpty()) { // this should be the only one. ref.set(line); } } } }); return ref.get(); }
mDevice.executeShellCommand(command, new MultiLineReceiver() { @Override public void processNewLines(String[] lines) {
@Override public void installRemotePackage(String remoteFilePath, boolean reinstall, String... extraArgs) throws InstallException { try { InstallReceiver receiver = new InstallReceiver(); StringBuilder optionString = new StringBuilder(); if (reinstall) { optionString.append("-r "); } if (extraArgs != null) { optionString.append(Joiner.on(' ').join(extraArgs)); } String cmd = String.format("pm install %1$s \"%2$s\"", optionString.toString(), remoteFilePath); executeShellCommand(cmd, receiver, INSTALL_TIMEOUT_MINUTES, TimeUnit.MINUTES); String error = receiver.getErrorMessage(); if (error != null) { throw new InstallException(error); } } catch (TimeoutException e) { throw new InstallException(e); } catch (AdbCommandRejectedException e) { throw new InstallException(e); } catch (ShellCommandUnresponsiveException e) { throw new InstallException(e); } catch (IOException e) { throw new InstallException(e); } }
@Override public void startScreenRecorder( @NonNull String remoteFilePath, @NonNull ScreenRecorderOptions options, @NonNull IShellOutputReceiver receiver) throws TimeoutException, AdbCommandRejectedException, IOException, ShellCommandUnresponsiveException { executeShellCommand(getScreenRecorderCommand(remoteFilePath, options), receiver, 0, null); }
private void doLsAndThrow(FileEntry entry) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException { // create a list that will receive the list of the entries ArrayList<FileEntry> entryList = new ArrayList<FileEntry>(); // create a list that will receive the link to compute post ls; ArrayList<String> linkList = new ArrayList<String>(); try { // create the command String command = "ls -l " + entry.getFullEscapedPath(); //$NON-NLS-1$ if (entry.isDirectory()) { // If we expect a file to behave like a directory, we should stick a "/" at the end. // This is a good habit, and is mandatory for symlinks-to-directories, which will // otherwise behave like symlinks. command += FILE_SEPARATOR; } // create the receiver object that will parse the result from ls LsReceiver receiver = new LsReceiver(entry, entryList, linkList); // call ls. mDevice.executeShellCommand(command, receiver); // finish the process of the receiver to handle links receiver.finishLinks(mDevice, entryList); } finally { // at this point we need to refresh the viewer entry.fetchTime = System.currentTimeMillis(); // sort the children and set them as the new children Collections.sort(entryList, FileEntry.sEntryComparator); entry.setChildren(entryList); } }
mDevice.executeShellCommand(command, new MultiLineReceiver() { @Override public void processNewLines(String[] lines) {
@Override public void removeRemotePackage(String remoteFilePath) throws InstallException { try { executeShellCommand(String.format("rm \"%1$s\"", remoteFilePath), new NullOutputReceiver(), INSTALL_TIMEOUT_MINUTES, TimeUnit.MINUTES); } catch (IOException e) { throw new InstallException(e); } catch (TimeoutException e) { throw new InstallException(e); } catch (AdbCommandRejectedException e) { throw new InstallException(e); } catch (ShellCommandUnresponsiveException e) { throw new InstallException(e); } }
device.executeShellCommand(GetPropReceiver.GETPROP_COMMAND, new GetPropReceiver(device));
public String installRemotePackage(String remoteFilePath, boolean reinstall) throws InstallException { try { InstallReceiver receiver = new InstallReceiver(); String cmd = String.format(reinstall ? "pm install -r \"%1$s\"" : "pm install \"%1$s\"", remoteFilePath); executeShellCommand(cmd, receiver, INSTALL_TIMEOUT); return receiver.getErrorMessage(); } catch (TimeoutException e) { throw new InstallException(e); } catch (AdbCommandRejectedException e) { throw new InstallException(e); } catch (ShellCommandUnresponsiveException e) { throw new InstallException(e); } catch (IOException e) { throw new InstallException(e); } }
public void removeRemotePackage(String remoteFilePath) throws InstallException { try { executeShellCommand("rm " + remoteFilePath, new NullOutputReceiver(), INSTALL_TIMEOUT); } catch (IOException e) { throw new InstallException(e); } catch (TimeoutException e) { throw new InstallException(e); } catch (AdbCommandRejectedException e) { throw new InstallException(e); } catch (ShellCommandUnresponsiveException e) { throw new InstallException(e); } }
public String uninstallPackage(String packageName) throws InstallException { try { InstallReceiver receiver = new InstallReceiver(); executeShellCommand("pm uninstall " + packageName, receiver, INSTALL_TIMEOUT); return receiver.getErrorMessage(); } catch (TimeoutException e) { throw new InstallException(e); } catch (AdbCommandRejectedException e) { throw new InstallException(e); } catch (ShellCommandUnresponsiveException e) { throw new InstallException(e); } catch (IOException e) { throw new InstallException(e); } }
@Override public String uninstallPackage(String packageName) throws InstallException { try { InstallReceiver receiver = new InstallReceiver(); executeShellCommand("pm uninstall " + packageName, receiver, INSTALL_TIMEOUT_MINUTES, TimeUnit.MINUTES); return receiver.getErrorMessage(); } catch (TimeoutException e) { throw new InstallException(e); } catch (AdbCommandRejectedException e) { throw new InstallException(e); } catch (ShellCommandUnresponsiveException e) { throw new InstallException(e); } catch (IOException e) { throw new InstallException(e); } }
device.executeShellCommand(GetPropReceiver.GETPROP_COMMAND, new GetPropReceiver(device));