use of com.android.ddmlib.IDevice in project android by JetBrains.
the class ShowChooserTargetProvider method showPrompt.
@Override
@Nullable
public DeployTarget showPrompt(@NotNull Executor executor, @NotNull ExecutionEnvironment env, @NotNull AndroidFacet facet, @NotNull DeviceCount deviceCount, boolean androidTests, @NotNull Map<String, DeployTargetState> deployTargetStates, int runConfigId, @NotNull LaunchCompatibilityChecker compatibilityChecker) {
State showChooserState = (State) deployTargetStates.get(getId());
Project project = facet.getModule().getProject();
if (showChooserState.USE_LAST_SELECTED_DEVICE) {
// If the last selection was a custom run profile state, then use that
DeployTarget target = DevicePickerStateService.getInstance(project).getDeployTargetPickerResult(runConfigId);
if (target != null && target.hasCustomRunProfileState(executor)) {
return target;
}
// If the last selection was a device, we can't just use the saved deploy target, since the list of devices could be stale,
// which would happen if the result was to launch an emulator. So we use the state of the devices instead
Collection<IDevice> devices = ManualTargetChooser.getLastUsedDevices(project, runConfigId, deviceCount);
if (!devices.isEmpty()) {
return new RealizedDeployTarget(null, null, DeviceFutures.forDevices(devices));
}
}
List<DeployTargetProvider> applicableTargets = getTargetsProvidingRunProfileState(executor, androidTests);
// show the dialog and get the state
DeployTargetPickerDialog dialog = new DeployTargetPickerDialog(runConfigId, facet, deviceCount, applicableTargets, deployTargetStates, compatibilityChecker);
if (dialog.showAndGet()) {
DeployTarget result = dialog.getSelectedDeployTarget();
if (result == null) {
return null;
}
if (showChooserState.USE_LAST_SELECTED_DEVICE) {
DevicePickerStateService.getInstance(project).setDeployPickerResult(runConfigId, result.hasCustomRunProfileState(executor) ? result : null);
// TODO: we only save the running devices, which means that the AVD selection is lost if the AVD wasn't running
// TODO: the getRunningDevices() returns an empty list right now if there is an AVD to be selected, which at least makes the dialog
// show up again, but eventually, we need to be able to handle a transition from AVD -> running device
DevicePickerStateService.getInstance(project).setDevicesUsedInLaunch(runConfigId, getRunningDevices(dialog.getSelectedDevices()), ManualTargetChooser.getOnlineDevices(project));
}
return result;
} else {
return null;
}
}
use of com.android.ddmlib.IDevice in project android by JetBrains.
the class AndroidProcessChooserDialog method doUpdateTree.
private void doUpdateTree(boolean showAllProcesses) {
final AndroidDebugBridge debugBridge = AndroidSdkUtils.getDebugBridge(myProject);
final DefaultMutableTreeNode root = new DefaultMutableTreeNode();
final DefaultTreeModel model = new DefaultTreeModel(root);
if (debugBridge == null) {
myProcessTree.setModel(model);
return;
}
final Set<String> processNames = collectAllProcessNames(myProject);
TreeNode selectedDeviceNode = null;
TreeNode selectedClientNode = null;
Object[] firstTreePath = null;
final IDevice[] devices = debugBridge.getDevices();
for (IDevice device : devices) {
final DefaultMutableTreeNode deviceNode = new DefaultMutableTreeNode(device);
root.add(deviceNode);
final String deviceName = device.getName();
if (deviceName.equals(myLastSelectedDevice)) {
selectedDeviceNode = deviceNode;
}
List<Client> clients = Lists.newArrayList(device.getClients());
Collections.sort(clients, (c1, c2) -> {
String n1 = StringUtil.notNullize(c1.getClientData().getClientDescription());
String n2 = StringUtil.notNullize(c2.getClientData().getClientDescription());
return n1.compareTo(n2);
});
for (Client client : clients) {
final String clientDescription = client.getClientData().getClientDescription();
if (clientDescription != null && (showAllProcesses || isRelatedProcess(processNames, clientDescription))) {
final DefaultMutableTreeNode clientNode = new DefaultMutableTreeNode(client);
deviceNode.add(clientNode);
if (clientDescription.equals(myLastSelectedProcess) && (selectedDeviceNode == null || deviceName.equals(myLastSelectedDevice))) {
selectedClientNode = clientNode;
selectedDeviceNode = deviceNode;
}
if (firstTreePath == null) {
firstTreePath = new Object[] { root, deviceNode, clientNode };
}
}
}
}
final Object[] pathToSelect;
if (selectedDeviceNode != null && selectedClientNode != null) {
pathToSelect = new Object[] { root, selectedDeviceNode, selectedClientNode };
} else if (selectedDeviceNode != null) {
pathToSelect = new Object[] { root, selectedDeviceNode };
} else {
pathToSelect = firstTreePath;
}
UIUtil.invokeLaterIfNeeded(() -> {
myProcessTree.setModel(model);
if (pathToSelect != null) {
myProcessTree.getSelectionModel().setSelectionPath(new TreePath(pathToSelect));
} else {
getOKAction().setEnabled(false);
}
TreeUtil.expandAll(myProcessTree);
});
}
use of com.android.ddmlib.IDevice in project android by JetBrains.
the class AndroidProcessChooserDialog method doOKAction.
@Override
protected void doOKAction() {
final PropertiesComponent properties = PropertiesComponent.getInstance(myProject);
final IDevice selectedDevice = getSelectedDevice();
if (selectedDevice == null) {
return;
}
mySelectedClient = getSelectedClient();
if (mySelectedClient == null) {
return;
}
myAndroidDebugger = (AndroidDebugger) myDebuggerTypeCombo.getSelectedItem();
properties.setValue(DEBUGGABLE_DEVICE_PROPERTY, getPersistableName(selectedDevice));
properties.setValue(DEBUGGABLE_PROCESS_PROPERTY, getPersistableName(mySelectedClient));
properties.setValue(SHOW_ALL_PROCESSES_PROPERTY, Boolean.toString(myShowAllProcessesCheckBox.isSelected()));
if (myAndroidDebugger != null) {
properties.setValue(DEBUGGER_ID_PROPERTY, myAndroidDebugger.getId());
}
super.doOKAction();
}
use of com.android.ddmlib.IDevice in project android by JetBrains.
the class FlightRecorder method setLaunchTarget.
public void setLaunchTarget(@NotNull AndroidDevice device) {
try {
Path deviceLog = myBasePath.resolve(timeStampToFolder(myTimestamp)).resolve(getDeviceLogFileName(device));
Files.write(deviceLog, new byte[0]);
} catch (IOException e) {
Logger.getInstance(FlightRecorder.class).info("Unable to record deployment device info", e);
}
// start monitoring logcat if device is online
if (device.getLaunchedDevice().isDone()) {
try {
IDevice d = device.getLaunchedDevice().get();
myLogcatRecorder.startMonitoring(d, myTimestamp);
} catch (InterruptedException | ExecutionException e) {
Logger.getInstance(FlightRecorder.class).info("Unable to start recording logcat", e);
}
}
}
use of com.android.ddmlib.IDevice in project android by JetBrains.
the class LogcatRecorder method startMonitoring.
public void startMonitoring(@NotNull IDevice device, @NotNull LocalDateTime buildTimeStamp) {
IDevice old = myDeviceRef.getAndSet(device);
if (old != device) {
if (old != null) {
myLogcatService.removeListener(old, myLogListener);
}
myLogcatService.addListener(device, myLogListener);
enableInstantRunLog(device);
}
addLog("------------Launch on " + device.getName() + " @ " + buildTimeStamp.toString());
}
Aggregations