use of com.facebook.buck.annotations.SuppressForbidden in project buck by facebook.
the class AdbHelper method filterDevices.
/**
* Returns list of devices that pass the filter. If there is an invalid combination or no
* devices are left after filtering this function prints an error and returns null.
*/
@Nullable
@VisibleForTesting
@SuppressForbidden
List<IDevice> filterDevices(IDevice[] allDevices) {
if (allDevices.length == 0) {
console.printBuildFailure("No devices are found.");
return null;
}
List<IDevice> devices = Lists.newArrayList();
Optional<Boolean> emulatorsOnly = Optional.empty();
if (deviceOptions.isEmulatorsOnlyModeEnabled() && options.isMultiInstallModeEnabled()) {
emulatorsOnly = Optional.empty();
} else if (deviceOptions.isEmulatorsOnlyModeEnabled()) {
emulatorsOnly = Optional.of(true);
} else if (deviceOptions.isRealDevicesOnlyModeEnabled()) {
emulatorsOnly = Optional.of(false);
}
int onlineDevices = 0;
for (IDevice device : allDevices) {
boolean passed = false;
if (device.isOnline()) {
onlineDevices++;
boolean serialMatches = true;
if (deviceOptions.getSerialNumber().isPresent()) {
serialMatches = device.getSerialNumber().equals(deviceOptions.getSerialNumber().get());
} else if (context.getEnvironment().containsKey(SERIAL_NUMBER_ENV)) {
serialMatches = device.getSerialNumber().equals(context.getEnvironment().get(SERIAL_NUMBER_ENV));
}
boolean deviceTypeMatches;
if (emulatorsOnly.isPresent()) {
// Only devices of specific type are accepted:
// either real devices only or emulators only.
deviceTypeMatches = (emulatorsOnly.get() == isEmulator(device));
} else {
// All online devices match.
deviceTypeMatches = true;
}
passed = serialMatches && deviceTypeMatches;
}
if (passed) {
devices.add(device);
}
}
// Filtered out all devices.
if (onlineDevices == 0) {
console.printBuildFailure("No devices are found.");
return null;
}
if (devices.isEmpty()) {
console.printBuildFailure(String.format("Found %d connected device(s), but none of them matches specified filter.", onlineDevices));
return null;
}
return devices;
}
use of com.facebook.buck.annotations.SuppressForbidden 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;
}
Aggregations