Search in sources :

Example 61 with IDevice

use of com.android.ddmlib.IDevice in project android by JetBrains.

the class AndroidRunConfigurationBase method canInstantRun.

@NotNull
private InstantRunGradleSupport canInstantRun(@NotNull Module module, @NotNull List<AndroidDevice> targetDevices) {
    if (targetDevices.size() != 1) {
        return CANNOT_BUILD_FOR_MULTIPLE_DEVICES;
    }
    AndroidDevice device = targetDevices.get(0);
    AndroidVersion version = device.getVersion();
    if (!InstantRunManager.isInstantRunCapableDeviceVersion(version)) {
        return API_TOO_LOW_FOR_INSTANT_RUN;
    }
    IDevice targetDevice = MakeBeforeRunTaskProvider.getLaunchedDevice(device);
    if (targetDevice != null) {
        if (MultiUserUtils.hasMultipleUsers(targetDevice, 200, TimeUnit.MILLISECONDS, false)) {
            if (// run config explicitly specifies launching as a different user
            getUserIdFromAmParameters() != MultiUserUtils.PRIMARY_USERID || !MultiUserUtils.isCurrentUserThePrimaryUser(targetDevice, 200, TimeUnit.MILLISECONDS, true)) {
                // activity manager says current user is not primary
                return CANNOT_DEPLOY_FOR_SECONDARY_USER;
            }
        }
    }
    InstantRunGradleSupport irSupportStatus = InstantRunGradleUtils.getIrSupportStatus(InstantRunGradleUtils.getAppModel(module), version);
    if (irSupportStatus != SUPPORTED) {
        return irSupportStatus;
    }
    // Gradle will instrument against the runtime android.jar (see commit 353f46cbc7363e3fca44c53a6dc0b4d17347a6ac).
    // This means that the SDK platform corresponding to the device needs to be installed, otherwise the build will fail.
    // We do this as the last check because it is actually possible to recover from this failure. In the future, maybe issues
    // that have fixes will have to be handled in a more generic way.
    AndroidPlatform platform = AndroidPlatform.getInstance(module);
    if (platform == null) {
        return SUPPORTED;
    }
    IAndroidTarget[] targets = platform.getSdkData().getTargets();
    for (int i = targets.length - 1; i >= 0; i--) {
        if (!targets[i].isPlatform()) {
            continue;
        }
        if (targets[i].getVersion().equals(version)) {
            return SUPPORTED;
        }
    }
    return TARGET_PLATFORM_NOT_INSTALLED;
}
Also used : IDevice(com.android.ddmlib.IDevice) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) InstantRunGradleSupport(com.android.tools.idea.fd.gradle.InstantRunGradleSupport) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidVersion(com.android.sdklib.AndroidVersion) NotNull(org.jetbrains.annotations.NotNull)

Example 62 with IDevice

use of com.android.ddmlib.IDevice in project android by JetBrains.

the class DeviceSelectionUtils method getAllCompatibleDevices.

@NotNull
public static List<IDevice> getAllCompatibleDevices(Predicate<IDevice> deviceFilter) {
    final List<IDevice> compatibleDevices = new ArrayList<IDevice>();
    final AndroidDebugBridge bridge = AndroidDebugBridge.getBridge();
    if (bridge != null) {
        IDevice[] devices = bridge.getDevices();
        for (IDevice device : devices) {
            if (deviceFilter.apply(device)) {
                compatibleDevices.add(device);
            }
        }
    }
    return compatibleDevices;
}
Also used : ArrayList(java.util.ArrayList) IDevice(com.android.ddmlib.IDevice) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge) NotNull(org.jetbrains.annotations.NotNull)

Example 63 with IDevice

use of com.android.ddmlib.IDevice in project android by JetBrains.

the class DeviceChooser method getFilteredDevices.

@NotNull
private IDevice[] getFilteredDevices() {
    AndroidDebugBridge bridge = AndroidDebugBridge.getBridge();
    if (bridge == null || !bridge.isConnected()) {
        return EMPTY_DEVICE_ARRAY;
    }
    final List<IDevice> filteredDevices = new ArrayList<IDevice>();
    for (IDevice device : bridge.getDevices()) {
        if (myFilter == null || myFilter.apply(device)) {
            filteredDevices.add(device);
        }
    }
    return filteredDevices.toArray(new IDevice[filteredDevices.size()]);
}
Also used : TIntArrayList(gnu.trove.TIntArrayList) IDevice(com.android.ddmlib.IDevice) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge) NotNull(org.jetbrains.annotations.NotNull)

Example 64 with IDevice

use of com.android.ddmlib.IDevice in project android by JetBrains.

the class DeviceChooser method getSelectedDevices.

@NotNull
private IDevice[] getSelectedDevices(boolean onlyCompatible) {
    int[] rows = mySelectedRows != null ? mySelectedRows : myDeviceTable.getSelectedRows();
    List<IDevice> result = new ArrayList<IDevice>();
    for (int row : rows) {
        if (row >= 0) {
            if (onlyCompatible && !isRowCompatible(row)) {
                continue;
            }
            Object serial = myDeviceTable.getValueAt(row, SERIAL_COLUMN_INDEX);
            IDevice[] devices = getFilteredDevices();
            for (IDevice device : devices) {
                if (device.getSerialNumber().equals(serial.toString())) {
                    result.add(device);
                    break;
                }
            }
        }
    }
    return result.toArray(new IDevice[result.size()]);
}
Also used : TIntArrayList(gnu.trove.TIntArrayList) IDevice(com.android.ddmlib.IDevice) NotNull(org.jetbrains.annotations.NotNull)

Example 65 with IDevice

use of com.android.ddmlib.IDevice in project android by JetBrains.

the class DeviceChooserDialog method updateOkButton.

private void updateOkButton() {
    IDevice[] devices = getSelectedDevices();
    boolean enabled = devices.length > 0;
    for (IDevice device : devices) {
        if (!device.isOnline()) {
            enabled = false;
        }
    }
    getOKAction().setEnabled(enabled);
}
Also used : IDevice(com.android.ddmlib.IDevice)

Aggregations

IDevice (com.android.ddmlib.IDevice)75 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 AndroidVersion (com.android.sdklib.AndroidVersion)5 SuppressForbidden (com.facebook.buck.annotations.SuppressForbidden)5 TIntArrayList (gnu.trove.TIntArrayList)5 File (java.io.File)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