Search in sources :

Example 31 with IDevice

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());
    }
}
Also used : IDevice(com.android.ddmlib.IDevice) Client(com.android.ddmlib.Client)

Example 32 with IDevice

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(' ', '.');
}
Also used : IDevice(com.android.ddmlib.IDevice) ExecutionException(java.util.concurrent.ExecutionException)

Example 33 with IDevice

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;
}
Also used : Project(com.intellij.openapi.project.Project) IDevice(com.android.ddmlib.IDevice) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) NotNull(org.jetbrains.annotations.NotNull)

Example 34 with IDevice

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));
}
Also used : AvdManager(com.android.sdklib.internal.avd.AvdManager) IDevice(com.android.ddmlib.IDevice) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 35 with IDevice

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();
}
Also used : IDevice(com.android.ddmlib.IDevice) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge)

Aggregations

IDevice (com.android.ddmlib.IDevice)76 Test (org.junit.Test)17 AndroidDebugBridge (com.android.ddmlib.AndroidDebugBridge)11 AdbOptions (com.facebook.buck.step.AdbOptions)11 TargetDeviceOptions (com.facebook.buck.step.TargetDeviceOptions)11 NotNull (org.jetbrains.annotations.NotNull)10 Client (com.android.ddmlib.Client)6 File (java.io.File)6 AndroidVersion (com.android.sdklib.AndroidVersion)5 SuppressForbidden (com.facebook.buck.annotations.SuppressForbidden)5 TIntArrayList (gnu.trove.TIntArrayList)5 Nullable (org.jetbrains.annotations.Nullable)5 InstallException (com.android.ddmlib.InstallException)4 AvdInfo (com.android.sdklib.internal.avd.AvdInfo)4 ExecutionException (java.util.concurrent.ExecutionException)4 AdbCommandRejectedException (com.android.ddmlib.AdbCommandRejectedException)3 ShellCommandUnresponsiveException (com.android.ddmlib.ShellCommandUnresponsiveException)3 TimeoutException (com.android.ddmlib.TimeoutException)3 BuckEventBus (com.facebook.buck.event.BuckEventBus)3 TestConsole (com.facebook.buck.testutil.TestConsole)3