use of com.android.ddmlib.IDevice in project android by JetBrains.
the class LaunchTaskRunner method run.
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setText(getTitle());
indicator.setIndeterminate(false);
LaunchStatus launchStatus = new ProcessHandlerLaunchStatus(myProcessHandler);
ConsolePrinter consolePrinter = new ProcessHandlerConsolePrinter(myProcessHandler);
List<ListenableFuture<IDevice>> listenableDeviceFutures = myDeviceFutures.get();
AndroidVersion androidVersion = myDeviceFutures.getDevices().size() == 1 ? myDeviceFutures.getDevices().get(0).getVersion() : null;
DebugConnectorTask debugSessionTask = myLaunchTasksProvider.getConnectDebuggerTask(launchStatus, androidVersion);
if (debugSessionTask != null && listenableDeviceFutures.size() != 1) {
launchStatus.terminateLaunch("Cannot launch a debug session on more than 1 device.");
}
if (debugSessionTask != null) {
// we need to copy over console output from the first console to the debug console once it is established
AndroidProcessText.attach(myProcessHandler);
}
DateFormat dateFormat = new SimpleDateFormat("MM/dd HH:mm:ss");
consolePrinter.stdout("\n" + dateFormat.format(new Date()) + ": Launching " + myConfigName);
for (ListenableFuture<IDevice> deviceFuture : listenableDeviceFutures) {
indicator.setText("Waiting for target device to come online");
IDevice device = waitForDevice(deviceFuture, indicator, launchStatus);
if (device == null) {
return;
}
List<LaunchTask> launchTasks = null;
try {
launchTasks = myLaunchTasksProvider.getTasks(device, launchStatus, consolePrinter);
} catch (com.intellij.execution.ExecutionException e) {
launchStatus.terminateLaunch(e.getMessage());
return;
} catch (IllegalStateException e) {
launchStatus.terminateLaunch(e.getMessage());
Logger.getInstance(LaunchTaskRunner.class).error(e);
return;
}
int totalDuration = listenableDeviceFutures.size() * getTotalDuration(launchTasks, debugSessionTask);
int elapsed = 0;
for (LaunchTask task : launchTasks) {
// perform each task
indicator.setText(task.getDescription());
if (!task.perform(device, launchStatus, consolePrinter)) {
myError = "Error " + task.getDescription();
launchStatus.terminateLaunch("Error while " + task.getDescription());
return;
}
// update progress
elapsed += task.getDuration();
indicator.setFraction((double) elapsed / totalDuration);
// check for cancellation via progress bar
if (indicator.isCanceled()) {
launchStatus.terminateLaunch("User cancelled launch");
return;
}
// check for cancellation via stop button
if (launchStatus.isLaunchTerminated()) {
return;
}
}
if (debugSessionTask != null) {
debugSessionTask.perform(myLaunchInfo, device, (ProcessHandlerLaunchStatus) launchStatus, (ProcessHandlerConsolePrinter) consolePrinter);
} else {
// we only need to inform the process handler if certain scenarios
if (// we are not doing a hot swap (in which case we are creating a new process)
myLaunchTasksProvider.createsNewProcess() && myProcessHandler instanceof AndroidProcessHandler) {
// we aren't debugging (in which case its a DebugProcessHandler)
((AndroidProcessHandler) myProcessHandler).addTargetDevice(device);
}
}
}
}
use of com.android.ddmlib.IDevice in project android by JetBrains.
the class AvdComboBox method doUpdateAvds.
private void doUpdateAvds() {
final Module module = getModule();
if (module == null || module.isDisposed()) {
return;
}
final AndroidFacet facet = AndroidFacet.getInstance(module);
final IdDisplay[] newAvds;
if (facet != null) {
final Set<String> filteringSet = new HashSet<String>();
if (myShowNotLaunchedOnly) {
final AndroidDebugBridge debugBridge = AndroidSdkUtils.getDebugBridge(facet.getModule().getProject());
if (debugBridge != null) {
for (IDevice device : debugBridge.getDevices()) {
final String avdName = device.getAvdName();
if (avdName != null && avdName.length() > 0) {
filteringSet.add(avdName);
}
}
}
}
final List<IdDisplay> newAvdList = new ArrayList<IdDisplay>();
if (myAddEmptyElement) {
newAvdList.add(IdDisplay.create("", ""));
}
for (AvdInfo avd : facet.getAllAvds()) {
String displayName = avd.getProperties().get(AvdManager.AVD_INI_DISPLAY_NAME);
final String avdName = displayName == null || displayName.isEmpty() ? avd.getName() : displayName;
if (!filteringSet.contains(avdName)) {
newAvdList.add(IdDisplay.create(avd.getName(), avdName));
}
}
newAvds = ArrayUtil.toObjectArray(newAvdList, IdDisplay.class);
} else {
newAvds = new IdDisplay[0];
}
if (!Arrays.equals(myOldAvds, newAvds)) {
myOldAvds = newAvds;
final Object selected = getComboBox().getSelectedItem();
getComboBox().setModel(new DefaultComboBoxModel(newAvds));
getComboBox().setSelectedItem(selected);
}
}
use of com.android.ddmlib.IDevice in project android by JetBrains.
the class DeviceChooser method refreshTable.
private void refreshTable(IDevice[] devices) {
final IDevice[] selectedDevices = getSelectedDevices(false);
final TIntArrayList selectedRows = new TIntArrayList();
for (int i = 0; i < devices.length; i++) {
if (ArrayUtil.indexOf(selectedDevices, devices[i]) >= 0) {
selectedRows.add(i);
}
}
myProcessSelectionFlag = false;
myDeviceTable.setModel(new MyDeviceTableModel(devices));
if (selectedRows.size() == 0 && devices.length > 0) {
myDeviceTable.getSelectionModel().setSelectionInterval(0, 0);
}
for (int selectedRow : selectedRows.toNativeArray()) {
if (selectedRow < devices.length) {
myDeviceTable.getSelectionModel().addSelectionInterval(selectedRow, selectedRow);
}
}
fireSelectedDevicesChanged();
myProcessSelectionFlag = true;
}
use of com.android.ddmlib.IDevice in project android by JetBrains.
the class AndroidProcessChooserDialog method getSelectedDevice.
@Nullable
private IDevice getSelectedDevice() {
final TreePath selectionPath = myProcessTree.getSelectionPath();
if (selectionPath == null || selectionPath.getPathCount() < 2) {
return null;
}
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) selectionPath.getPathComponent(1);
final Object obj = selectedNode.getUserObject();
return obj instanceof IDevice ? (IDevice) obj : null;
}
use of com.android.ddmlib.IDevice 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;
}
Aggregations