use of com.android.ddmlib.IDevice in project android by JetBrains.
the class DevicePanel method updateClientCombo.
private void updateClientCombo() {
myIgnoreActionEvents = true;
IDevice device = (IDevice) myDeviceCombo.getSelectedItem();
Client selected = (Client) myClientCombo.getSelectedItem();
Client toSelect = null;
boolean update = true;
myClientCombo.removeAllItems();
if (device != null) {
// Change the currently selected client if the user has a preference.
String preferred = getPreferredClientForDevice(device.getName());
if (preferred != null) {
Client preferredClient = device.getClient(preferred);
if (preferredClient != null) {
toSelect = preferredClient;
}
}
List<Client> clients = Lists.newArrayList(device.getClients());
// There's a chance we got this update because a client we were debugging just crashed or was
// closed. At this point we have our old handle to it but it's not in the client list
// reported by the phone anymore. We still want to keep it in the list though, so the user
// can look over any final error messages / profiling states.
// However, we might get here because our device changed, so discard selected clients that
// come from another device
boolean selectedClientDied = selected != null && selected.getDevice() == device && !clients.contains(selected);
if (selectedClientDied) {
if (toSelect == null) {
toSelect = selected;
}
clients.add(selected);
}
Collections.sort(clients, new ClientCellRenderer.ClientComparator());
for (Client client : clients) {
//noinspection unchecked
myClientCombo.addItem(client);
}
myClientCombo.setSelectedItem(toSelect);
update = toSelect != selected;
}
myIgnoreActionEvents = false;
if (update) {
myDeviceContext.fireClientSelected((Client) myClientCombo.getSelectedItem());
}
}
use of com.android.ddmlib.IDevice in project android by JetBrains.
the class FlightRecorder method getDeviceLogFileName.
// We need very little detail about the device itself, so we can encode it directly in the file name
private static String getDeviceLogFileName(@NotNull AndroidDevice device) {
// for avds, everything we need is already included in idea.log
if (device.isVirtual()) {
return "TARGET-AVD";
}
ListenableFuture<IDevice> launchedDevice = device.getLaunchedDevice();
if (!launchedDevice.isDone()) {
return "OFFLINE";
}
IDevice d;
try {
d = launchedDevice.get();
} catch (InterruptedException | ExecutionException e) {
return "OFFLINE";
}
return DevicePropertyUtil.getManufacturer(d, "unknown").replace(' ', '.') + '-' + DevicePropertyUtil.getModel(d, "unknown").replace(' ', '.');
}
use of com.android.ddmlib.IDevice in project android by JetBrains.
the class DeviceSelectionUtils method chooseDevicesManually.
@NotNull
private static IDevice[] chooseDevicesManually(@NotNull AndroidFacet facet, @NotNull Predicate<IDevice> filter, @NotNull DeviceCount deviceCount) {
final Project project = facet.getModule().getProject();
String value = PropertiesComponent.getInstance(project).getValue(ANDROID_TARGET_DEVICES_PROPERTY);
String[] selectedSerials = value != null ? deserialize(value) : null;
AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
if (platform == null) {
LOG.error("Android platform not set for module: " + facet.getModule().getName());
return DeviceChooser.EMPTY_DEVICE_ARRAY;
}
DeviceChooserDialog chooser = new DeviceChooserDialog(facet, platform.getTarget(), deviceCount.isMultiple(), selectedSerials, filter);
chooser.show();
IDevice[] devices = chooser.getSelectedDevices();
if (chooser.getExitCode() != DialogWrapper.OK_EXIT_CODE || devices.length == 0) {
return DeviceChooser.EMPTY_DEVICE_ARRAY;
}
PropertiesComponent.getInstance(project).setValue(ANDROID_TARGET_DEVICES_PROPERTY, serialize(devices));
return devices;
}
use of com.android.ddmlib.IDevice in project android by JetBrains.
the class EmulatorTargetChooser method getDevices.
@Nullable
public DeviceFutures getDevices(@NotNull DeviceCount deviceCount) {
TargetDeviceFilter deviceFilter = new TargetDeviceFilter.EmulatorFilter(myFacet, myAvd);
Collection<IDevice> runningDevices = DeviceSelectionUtils.chooseRunningDevice(myFacet, deviceFilter, deviceCount);
if (runningDevices == null) {
// The user canceled.
return null;
}
if (!runningDevices.isEmpty()) {
return DeviceFutures.forDevices(runningDevices);
}
// We need to launch an emulator.
final String avd = myAvd != null ? myAvd : chooseAvd();
if (avd == null) {
// The user canceled.
return null;
}
AvdManager manager = myFacet.getAvdManagerSilently();
if (manager == null) {
LOG.warn("Could not obtain AVD Manager.");
return null;
}
AvdInfo avdInfo = manager.getAvd(avd, true);
if (avdInfo == null) {
LOG.warn("Unable to obtain info for AVD: " + avd);
return null;
}
LaunchableAndroidDevice androidDevice = new LaunchableAndroidDevice(avdInfo);
// LAUNCH EMULATOR
androidDevice.launch(myFacet.getModule().getProject());
return new DeviceFutures(Collections.<AndroidDevice>singletonList(androidDevice));
}
use of com.android.ddmlib.IDevice in project android by JetBrains.
the class DevicePicker method updateModel.
private void updateModel() {
AndroidDebugBridge bridge = AndroidDebugBridge.getBridge();
if (bridge == null || !bridge.isConnected()) {
return;
}
if (!ApplicationManager.getApplication().isDispatchThread()) {
UIUtil.invokeLaterIfNeeded(this::updateModel);
return;
}
if (myDevicesList == null) {
// happens if this was scheduled post disposal of the dialog
return;
}
Set<String> selectedSerials = getSelectedSerials(myDevicesList.getSelectedValues());
List<IDevice> connectedDevices = Lists.newArrayList(bridge.getDevices());
myModel.reset(connectedDevices, myAvdInfos);
myDeviceCount = connectedDevices.size();
if (selectedSerials.isEmpty()) {
selectedSerials = getDefaultSelection();
}
myDevicesList.setSelectedIndices(getIndices(myModel.getItems(), selectedSerials));
// The help hyper link is shown only when there is no inline troubleshoot link
myHelpHyperlink.setVisible(!connectedDevices.isEmpty());
updateErrorCheck();
}
Aggregations