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;
}
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());
}
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;
}
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);
}
}
}
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);
}
Aggregations