Search in sources :

Example 1 with AdbCommandRejectedException

use of com.android.ddmlib.AdbCommandRejectedException in project buck by facebook.

the class AdbHelper method deviceUninstallPackage.

/**
   * Modified version of <a href="http://fburl.com/8840769">Device.uninstallPackage()</a>.
   *
   * @param device an {@link IDevice}
   * @param packageName application package name
   * @param keepData  true if user data is to be kept
   * @return error message or null if successful
   * @throws InstallException
   */
@Nullable
private String deviceUninstallPackage(IDevice device, String packageName, boolean keepData) throws InstallException {
    try {
        AdbHelper.ErrorParsingReceiver receiver = new AdbHelper.ErrorParsingReceiver() {

            @Override
            @Nullable
            protected String matchForError(String line) {
                return line.toLowerCase(Locale.US).contains("failure") ? line : null;
            }
        };
        device.executeShellCommand("pm uninstall " + (keepData ? "-k " : "") + packageName, receiver, AdbHelper.INSTALL_TIMEOUT, TimeUnit.MILLISECONDS);
        return receiver.getErrorMessage();
    } catch (AdbCommandRejectedException | IOException | ShellCommandUnresponsiveException | TimeoutException e) {
        throw new InstallException(e);
    }
}
Also used : ShellCommandUnresponsiveException(com.android.ddmlib.ShellCommandUnresponsiveException) AdbCommandRejectedException(com.android.ddmlib.AdbCommandRejectedException) IOException(java.io.IOException) InstallException(com.android.ddmlib.InstallException) TimeoutException(com.android.ddmlib.TimeoutException) Nullable(javax.annotation.Nullable)

Example 2 with AdbCommandRejectedException

use of com.android.ddmlib.AdbCommandRejectedException in project android by JetBrains.

the class InstantRunBuilderTest method setUp.

@Before
public void setUp() throws Exception {
    myDevice = mock(IDevice.class);
    when(myDevice.getSerialNumber()).thenReturn("device1-serial");
    myInstalledPatchCache = new InstalledPatchCache();
    myInstantRunContext = mock(InstantRunContext.class);
    when(myInstantRunContext.getInstantRunBuildInfo()).thenReturn(InstantRunBuildInfo.get(BUILD_INFO)).thenReturn(InstantRunBuildInfo.get(BUILD_INFO_RELOAD_DEX));
    when(myInstantRunContext.getApplicationId()).thenReturn(APPLICATION_ID);
    when(myInstantRunContext.getInstalledPatchCache()).thenReturn(myInstalledPatchCache);
    myRunConfigContext = new AndroidRunConfigContext();
    myRunConfigContext.setTargetDevices(DeviceFutures.forDevices(Collections.singletonList(myDevice)));
    myTasksProvider = mock(InstantRunTasksProvider.class);
    when(myTasksProvider.getFullBuildTasks()).thenReturn(ASSEMBLE_TASKS);
    when(myTasksProvider.getCleanAndGenerateSourcesTasks()).thenReturn(CLEAN_TASKS);
    myInstalledApkCache = new InstalledApkCache() {

        @Override
        protected String executeShellCommand(@NotNull IDevice device, @NotNull String cmd, long timeout, @NotNull TimeUnit timeUnit) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException, InterruptedException {
            return myDumpsysPackageOutput;
        }
    };
    myApk = FileUtil.createTempFile("foo", "apk");
    myTaskRunner = new RecordingTaskRunner();
    myInstantRunClientDelegate = createInstantRunClientDelegate();
    myBuilder = new InstantRunBuilder(myDevice, myInstantRunContext, myRunConfigContext, myTasksProvider, false, myInstalledApkCache, myInstantRunClientDelegate);
}
Also used : AndroidRunConfigContext(com.android.tools.idea.run.AndroidRunConfigContext) IDevice(com.android.ddmlib.IDevice) IOException(java.io.IOException) InstalledPatchCache(com.android.tools.idea.run.InstalledPatchCache) InstalledApkCache(com.android.tools.idea.run.InstalledApkCache) ShellCommandUnresponsiveException(com.android.ddmlib.ShellCommandUnresponsiveException) AdbCommandRejectedException(com.android.ddmlib.AdbCommandRejectedException) TimeUnit(java.util.concurrent.TimeUnit) TimeoutException(com.android.ddmlib.TimeoutException) Before(org.junit.Before)

Example 3 with AdbCommandRejectedException

use of com.android.ddmlib.AdbCommandRejectedException in project buck by facebook.

the class AdbHelper method isDeviceTempWritable.

@VisibleForTesting
@SuppressForbidden
protected boolean isDeviceTempWritable(IDevice device, String name) {
    StringBuilder loggingInfo = new StringBuilder();
    try {
        String output;
        try {
            output = executeCommandWithErrorChecking(device, "ls -l -d /data/local/tmp");
            if (!(// Pattern for Android's "toolbox" version of ls
            output.matches("\\Adrwx....-x +shell +shell.* tmp[\\r\\n]*\\z") || // Pattern for CyanogenMod's busybox version of ls
            output.matches("\\Adrwx....-x +[0-9]+ +shell +shell.* /data/local/tmp[\\r\\n]*\\z"))) {
                loggingInfo.append(String.format(Locale.ENGLISH, "Bad ls output for /data/local/tmp: '%s'\n", output));
            }
            executeCommandWithErrorChecking(device, "echo exo > /data/local/tmp/buck-experiment");
            output = executeCommandWithErrorChecking(device, "cat /data/local/tmp/buck-experiment");
            if (!output.matches("\\Aexo[\\r\\n]*\\z")) {
                loggingInfo.append(String.format(Locale.ENGLISH, "Bad echo/cat output for /data/local/tmp: '%s'\n", output));
            }
            executeCommandWithErrorChecking(device, "rm /data/local/tmp/buck-experiment");
        } catch (CommandFailedException e) {
            loggingInfo.append(String.format(Locale.ENGLISH, "Failed (%d) '%s':\n%s\n", e.exitCode, e.command, e.output));
        }
        if (!loggingInfo.toString().isEmpty()) {
            CollectingOutputReceiver receiver = new CollectingOutputReceiver();
            device.executeShellCommand("getprop", receiver);
            for (String line : com.google.common.base.Splitter.on('\n').split(receiver.getOutput())) {
                if (line.contains("ro.product.model") || line.contains("ro.build.description")) {
                    loggingInfo.append(line).append('\n');
                }
            }
        }
    } catch (AdbCommandRejectedException | ShellCommandUnresponsiveException | TimeoutException | IOException e) {
        console.printBuildFailure(String.format("Failed to test /data/local/tmp on %s.", name));
        e.printStackTrace(console.getStdErr());
        return false;
    }
    String logMessage = loggingInfo.toString();
    if (!logMessage.isEmpty()) {
        StringBuilder fullMessage = new StringBuilder();
        fullMessage.append("============================================================\n");
        fullMessage.append('\n');
        fullMessage.append("HEY! LISTEN!\n");
        fullMessage.append('\n');
        fullMessage.append("The /data/local/tmp directory on your device isn't fully-functional.\n");
        fullMessage.append("Here's some extra info:\n");
        fullMessage.append(logMessage);
        fullMessage.append("============================================================\n");
        console.getStdErr().println(fullMessage.toString());
    }
    return true;
}
Also used : ShellCommandUnresponsiveException(com.android.ddmlib.ShellCommandUnresponsiveException) CollectingOutputReceiver(com.android.ddmlib.CollectingOutputReceiver) AdbCommandRejectedException(com.android.ddmlib.AdbCommandRejectedException) IOException(java.io.IOException) TimeoutException(com.android.ddmlib.TimeoutException) VisibleForTesting(com.google.common.annotations.VisibleForTesting) SuppressForbidden(com.facebook.buck.annotations.SuppressForbidden)

Example 4 with AdbCommandRejectedException

use of com.android.ddmlib.AdbCommandRejectedException in project android by JetBrains.

the class HttpDataCache method getFile.

public File getFile(String path) {
    File tempFile = myFiles.get(path);
    if (tempFile == null) {
        int fileNameStartIndex = path.lastIndexOf('\\');
        String fileName = fileNameStartIndex >= 0 ? path.substring(fileNameStartIndex) : path;
        try {
            tempFile = FileUtil.createTempFile(fileName, null);
            tempFile.deleteOnExit();
            myDevice.pullFile(path, tempFile.getAbsolutePath());
            myFiles.put(path, tempFile);
        } catch (IOException | AdbCommandRejectedException | TimeoutException | SyncException e) {
        // TODO: Add logs
        }
    }
    return tempFile;
}
Also used : AdbCommandRejectedException(com.android.ddmlib.AdbCommandRejectedException) IOException(java.io.IOException) SyncException(com.android.ddmlib.SyncException) File(java.io.File) TimeoutException(com.android.ddmlib.TimeoutException)

Aggregations

AdbCommandRejectedException (com.android.ddmlib.AdbCommandRejectedException)4 TimeoutException (com.android.ddmlib.TimeoutException)4 IOException (java.io.IOException)4 ShellCommandUnresponsiveException (com.android.ddmlib.ShellCommandUnresponsiveException)3 CollectingOutputReceiver (com.android.ddmlib.CollectingOutputReceiver)1 IDevice (com.android.ddmlib.IDevice)1 InstallException (com.android.ddmlib.InstallException)1 SyncException (com.android.ddmlib.SyncException)1 AndroidRunConfigContext (com.android.tools.idea.run.AndroidRunConfigContext)1 InstalledApkCache (com.android.tools.idea.run.InstalledApkCache)1 InstalledPatchCache (com.android.tools.idea.run.InstalledPatchCache)1 SuppressForbidden (com.facebook.buck.annotations.SuppressForbidden)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 File (java.io.File)1 TimeUnit (java.util.concurrent.TimeUnit)1 Nullable (javax.annotation.Nullable)1 Before (org.junit.Before)1