use of com.android.ddmlib.CollectingOutputReceiver in project buck by facebook.
the class AdbHelper method deviceGetExternalStorage.
/**
* Retrieves external storage location (SD card) from device.
*/
@Nullable
private String deviceGetExternalStorage(IDevice device) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
CollectingOutputReceiver receiver = new CollectingOutputReceiver();
device.executeShellCommand("echo $EXTERNAL_STORAGE", receiver, AdbHelper.GETPROP_TIMEOUT, TimeUnit.MILLISECONDS);
String value = receiver.getOutput().trim();
if (value.isEmpty()) {
return null;
}
return value;
}
use of com.android.ddmlib.CollectingOutputReceiver 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.CollectingOutputReceiver in project android by JetBrains.
the class DeployIapkTask method perform.
@Override
public boolean perform(@NotNull IDevice device, @NotNull LaunchStatus launchStatus, @NotNull ConsolePrinter printer) {
if (!myApks.iterator().hasNext()) {
printer.stderr("No Iapk provided.");
return false;
}
ApkInfo iapk = myApks.iterator().next();
File localFile = iapk.getFile();
if (!localFile.exists()) {
String message = "The APK file " + localFile.getPath() + " does not exist on disk.";
printer.stderr(message);
return false;
}
// This is currently the required location for uploading IAPKs and is liable to change
String remotePath = "/sdcard/instantapps/" + localFile.getName();
printer.stdout("$ adb push " + localFile + " " + remotePath);
try {
// In theory this is the only required step for running / debugging an IAPK
device.pushFile(localFile.getPath(), remotePath);
// The following commands are liable to change as the Instant App runtime matures.
CountDownLatch latch = new CountDownLatch(3);
CollectingOutputReceiver receiver = new CollectingOutputReceiver(latch);
printer.stdout("Starting / refreshing Instant App services");
device.executeShellCommand("am startservice -a \"com.google.android.instantapps.devman.iapk.LOAD\" " + "--es \"com.google.android.instantapps.devman.iapk.IAPK_PATH\" " + "\"" + remotePath + "\" -n \"com.google.android.instantapps.devman\"/.iapk.IapkLoadService", receiver);
device.executeShellCommand("pm clear com.google.android.instantapps.supervisor", receiver);
device.executeShellCommand("am force-stop com.google.android.instantapps.supervisor", receiver);
latch.await(3000, TimeUnit.MILLISECONDS);
} catch (Exception e) {
printer.stderr(e.toString());
return false;
}
printer.stdout("IAPK upload complete");
return true;
}
use of com.android.ddmlib.CollectingOutputReceiver in project android by JetBrains.
the class MultiUserUtils method hasMultipleUsers.
public static boolean hasMultipleUsers(@Nullable IDevice device, long timeout, TimeUnit units, boolean defaultValue) {
if (device == null) {
return defaultValue;
}
if (device.getVersion().getApiLevel() < AndroidVersion.SUPPORTS_MULTI_USER.getApiLevel()) {
return false;
}
CountDownLatch latch = new CountDownLatch(1);
CollectingOutputReceiver receiver = new CollectingOutputReceiver(latch);
try {
device.executeShellCommand("pm list users", receiver);
} catch (Exception e) {
return defaultValue;
}
try {
latch.await(timeout, units);
} catch (InterruptedException e) {
Logger.getInstance(MultiUserUtils.class).warn("Timed out waiting for output from `pm list users`, returning " + defaultValue);
return defaultValue;
}
// Output is of the form:
// <some devices have error messages here, e.g. WARNING: linker: libdvm.so has text relocations
// Users:
// UserInfo{0:Foo:13} running
// UserInfo{11:Sample Managed Profile:30} running
String[] lines = receiver.getOutput().trim().split("\n");
int numUsers = 0;
for (String line : lines) {
if (line.contains("UserInfo{")) {
numUsers++;
}
}
return numUsers > 1;
}
use of com.android.ddmlib.CollectingOutputReceiver in project intellij by bazelbuild.
the class UserIdHelper method getWorkProfileId.
@Nullable
public static Integer getWorkProfileId(IDevice device) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException {
CollectingOutputReceiver receiver = new CollectingOutputReceiver();
device.executeShellCommand("pm list users", receiver);
String result = receiver.getOutput();
Matcher matcher = USER_ID_REGEX.matcher(result);
if (matcher.find()) {
return Integer.parseInt(matcher.group(1));
}
return null;
}
Aggregations