Search in sources :

Example 71 with IDevice

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

the class DevicePickerListModelTest method createMockDevice.

@NotNull
private static IDevice createMockDevice(boolean isEmulator, @Nullable String avdName, int apiLevel, @NotNull String buildVersion) {
    IDevice device = mock(IDevice.class);
    when(device.isEmulator()).thenReturn(isEmulator);
    when(device.getAvdName()).thenReturn(avdName);
    when(device.getVersion()).thenReturn(new AndroidVersion(apiLevel, buildVersion));
    return device;
}
Also used : IDevice(com.android.ddmlib.IDevice) AndroidVersion(com.android.sdklib.AndroidVersion) NotNull(org.jetbrains.annotations.NotNull)

Example 72 with IDevice

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

the class DevicePickerListModelTest method testRunningAvdsAreNotDuplicated.

@Test
public void testRunningAvdsAreNotDuplicated() {
    IDevice device = createMockDevice(false, null, 23, "6.0");
    IDevice runningAvd = createMockDevice(true, "emu1", 22, "5.0");
    AvdInfo emu1Info = createMockAvd("emu1");
    AvdInfo emu2Info = createMockAvd("emu2");
    myModel.reset(Arrays.asList(device, runningAvd), Arrays.asList(emu1Info, emu2Info));
    List<DevicePickerEntry> items = myModel.getItems();
    assertEquals("Expected 5 items (marker, 2 devices, marker, 1 avd info)", 5, items.size());
    assertEquals("emu2", items.get(4).getAndroidDevice().getName());
}
Also used : IDevice(com.android.ddmlib.IDevice) AvdInfo(com.android.sdklib.internal.avd.AvdInfo) Test(org.junit.Test)

Example 73 with IDevice

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

the class AndroidDataSourcePropertiesDialog method updateDataBases.

private void updateDataBases() {
    if (!myPanel.isShowing())
        return;
    final Object selectedItem = myDeviceComboBox.getSelectedItem();
    IDevice selectedDevice = selectedItem instanceof IDevice ? (IDevice) selectedItem : null;
    if (selectedDevice == null) {
        myDatabaseMap.clear();
        myPackageNameComboBox.setModel(new DefaultComboBoxModel());
        myDataBaseComboBox.setModel(new DefaultComboBoxModel());
    } else if (!selectedDevice.equals(mySelectedDevice)) {
        loadDatabases(selectedDevice);
        myPackageNameComboBox.setModel(new DefaultComboBoxModel(ArrayUtil.toStringArray(myDatabaseMap.keySet())));
        updateDbCombo();
    }
    mySelectedDevice = selectedDevice;
}
Also used : IDevice(com.android.ddmlib.IDevice)

Example 74 with IDevice

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

the class AndroidUploadDatabaseAction method uploadDatabase.

private static void uploadDatabase(@NotNull Project project, @NotNull AndroidDataSource dataSource, @NotNull ProgressIndicator indicator, @NotNull AndroidDebugBridge debugBridge) {
    final String localDbFilePath = dataSource.buildLocalDbFileOsPath();
    final AndroidDbErrorReporterImpl errorReporter = new AndroidDbErrorReporterImpl(project, dataSource, true);
    final AndroidDbConnectionInfo dbConnectionInfo = AndroidDbUtil.checkDataSource(dataSource, debugBridge, errorReporter);
    if (dbConnectionInfo == null) {
        return;
    }
    final IDevice device = dbConnectionInfo.getDevice();
    final String packageName = dbConnectionInfo.getPackageName();
    final String dbName = dbConnectionInfo.getDbName();
    final String localFileMd5Hash = getLocalFileMd5Hash(new File(localDbFilePath));
    final String deviceId = AndroidDbUtil.getDeviceId(device);
    final boolean external = dbConnectionInfo.isExternal();
    if (localFileMd5Hash == null || deviceId == null) {
        return;
    }
    if (AndroidDbUtil.uploadDatabase(device, packageName, dbName, external, localDbFilePath, indicator, errorReporter)) {
        final Long modificationTime = AndroidDbUtil.getModificationTime(device, packageName, dbName, external, errorReporter, indicator);
        if (modificationTime != null) {
            AndroidRemoteDataBaseManager.MyDatabaseInfo dbInfo = AndroidRemoteDataBaseManager.getInstance().getDatabaseInfo(deviceId, packageName, dbName, external);
            if (dbInfo == null) {
                dbInfo = new AndroidRemoteDataBaseManager.MyDatabaseInfo();
            }
            dbInfo.modificationTime = modificationTime;
            AndroidRemoteDataBaseManager.getInstance().setDatabaseInfo(deviceId, packageName, dbName, dbInfo, external);
        }
    }
}
Also used : IDevice(com.android.ddmlib.IDevice)

Example 75 with IDevice

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

the class AndroidDbUtil method checkDataSource.

@Nullable
public static AndroidDbConnectionInfo checkDataSource(@NotNull AndroidDataSource dataSource, @NotNull AndroidDebugBridge debugBridge, @NotNull AndroidDbErrorReporter errorReporter) {
    final AndroidDataSource.State state = dataSource.getState();
    final String deviceId = state.deviceId;
    if (deviceId == null) {
        errorReporter.reportError("device is not specified");
        return null;
    }
    final IDevice device = getDeviceById(debugBridge, deviceId);
    if (device == null) {
        errorReporter.reportError("device '" + getPresentableNameFromDeviceId(deviceId) + "' is not connected");
        return null;
    }
    if (!device.isOnline()) {
        errorReporter.reportError("the device is not online");
        return null;
    }
    final String packageName = dataSource.getState().packageName;
    if (packageName == null || packageName.length() == 0) {
        errorReporter.reportError("package name is not specified");
        return null;
    }
    final String dbName = dataSource.getState().databaseName;
    if (dbName == null || dbName.length() == 0) {
        errorReporter.reportError("database name is not specified");
        return null;
    }
    return new AndroidDbConnectionInfo(device, packageName, dbName, dataSource.getState().external);
}
Also used : IDevice(com.android.ddmlib.IDevice) Nullable(org.jetbrains.annotations.Nullable)

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