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);
}
}
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);
}
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;
}
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;
}
Aggregations