use of com.android.ddmlib.IDevice in project android by JetBrains.
the class AndroidSynchronizeHandler method doSynchronizeDataSource.
private static void doSynchronizeDataSource(@NotNull Project project, @NotNull AndroidDataSource dataSource, @NotNull ProgressIndicator progressIndicator, @NotNull AndroidDebugBridge debugBridge, @NotNull AndroidDbErrorReporter errorReporter) {
final AndroidDbConnectionInfo dbConnectionInfo = AndroidDbUtil.checkDataSource(dataSource, debugBridge, errorReporter);
if (dbConnectionInfo == null) {
return;
}
final IDevice device = dbConnectionInfo.getDevice();
final String deviceId = AndroidDbUtil.getDeviceId(device);
if (deviceId == null) {
return;
}
final String packageName = dbConnectionInfo.getPackageName();
final String dbName = dbConnectionInfo.getDbName();
final boolean external = dbConnectionInfo.isExternal();
final Long modificationTime = AndroidDbUtil.getModificationTime(device, packageName, dbName, external, errorReporter, progressIndicator);
progressIndicator.checkCanceled();
if (modificationTime == null) {
return;
}
final AndroidRemoteDataBaseManager remoteDbManager = AndroidRemoteDataBaseManager.getInstance();
AndroidRemoteDataBaseManager.MyDatabaseInfo info = remoteDbManager.getDatabaseInfo(deviceId, packageName, dbName, external);
if (info == null) {
info = new AndroidRemoteDataBaseManager.MyDatabaseInfo();
}
progressIndicator.checkCanceled();
final File localDbFile = new File(dataSource.buildLocalDbFileOsPath());
info.referringProjects.add(FileUtil.toCanonicalPath(project.getBasePath()));
if (!localDbFile.exists() || !modificationTime.equals(info.modificationTime)) {
if (AndroidDbUtil.downloadDatabase(device, packageName, dbName, external, localDbFile, progressIndicator, errorReporter)) {
info.modificationTime = modificationTime;
remoteDbManager.setDatabaseInfo(deviceId, packageName, dbName, info, external);
}
}
}
use of com.android.ddmlib.IDevice in project android by JetBrains.
the class AndroidDataSourcePropertiesDialog method loadDevices.
private void loadDevices() {
final AndroidDebugBridge bridge = AndroidSdkUtils.getDebugBridge(myProject);
final IDevice[] devices = bridge != null ? getDevicesWithValidDeviceId(bridge) : new IDevice[0];
final String deviceId = myDataSource.getState().deviceId;
final DefaultComboBoxModel<Object> model = new DefaultComboBoxModel<>(devices);
Object selectedItem = null;
if (deviceId != null && deviceId.length() > 0) {
for (IDevice device : devices) {
if (deviceId.equals(AndroidDbUtil.getDeviceId(device))) {
selectedItem = device;
break;
}
}
if (selectedItem == null) {
model.addElement(deviceId);
myMissingDeviceIds = deviceId;
selectedItem = deviceId;
}
}
myDeviceComboBoxModel = model;
myDeviceComboBox.setModel(model);
if (selectedItem != null) {
myDeviceComboBox.setSelectedItem(selectedItem);
}
}
use of com.android.ddmlib.IDevice in project android by JetBrains.
the class DevicePickerListModelTest method testConnectedDevice.
@Test
public void testConnectedDevice() {
IDevice device1 = createMockDevice(false, null, 23, "6.0");
myModel.reset(Collections.singletonList(device1), Collections.<AvdInfo>emptyList());
List<DevicePickerEntry> items = myModel.getItems();
assertEquals("Expected 2 items (separator, device1)", 2, items.size());
assertTrue(items.get(0).isMarker());
assertNotNull(items.get(1).getAndroidDevice());
}
use of com.android.ddmlib.IDevice in project android by JetBrains.
the class NonGradleApkProviderDependenciesTest method testGetApksWithDependencies.
public void testGetApksWithDependencies() throws Exception {
IDevice device = Mockito.mock(IDevice.class);
setIdAndApk(myFacet, "com.test.app", "app.apk");
for (Module module : myAdditionalModules) {
for (VirtualFile contentRoot : ModuleRootManager.getInstance(module).getContentRoots()) {
if (contentRoot.getPath().endsWith("dependencyApp1")) {
setIdAndApk(AndroidFacet.getInstance(module), "com.test.dep1", "dep1.apk");
break;
} else if (contentRoot.getPath().endsWith("dependencyApp2")) {
setIdAndApk(AndroidFacet.getInstance(module), "com.test.dep2", "dep2.apk");
break;
} else if (contentRoot.getPath().endsWith("dependencyLibrary")) {
assertTrue(module.getName() + " at " + contentRoot.getPath() + " should be an Android library.", AndroidFacet.getInstance(module).isLibraryProject());
break;
}
}
}
NonGradleApkProvider provider = new NonGradleApkProvider(myFacet, new NonGradleApplicationIdProvider(myFacet), null);
Collection<ApkInfo> apks = provider.getApks(device);
assertNotNull(apks);
assertEquals(3, apks.size());
// Sort the apks to keep test consistent.
List<ApkInfo> apkList = new ArrayList<>(apks);
Collections.sort(apkList, new Comparator<ApkInfo>() {
@Override
public int compare(ApkInfo a, ApkInfo b) {
return a.getApplicationId().compareTo(b.getApplicationId());
}
});
ApkInfo mainApk = apkList.get(0);
ApkInfo dep1Apk = apkList.get(1);
ApkInfo dep2Apk = apkList.get(2);
assertEquals("com.test.app", mainApk.getApplicationId());
assertTrue(mainApk.getFile().getPath().endsWith("app.apk"));
assertEquals("com.test.dep1", dep1Apk.getApplicationId());
assertTrue(dep1Apk.getFile().getPath().endsWith("dep1.apk"));
assertEquals("com.test.dep2", dep2Apk.getApplicationId());
assertTrue(dep2Apk.getFile().getPath().endsWith("dep2.apk"));
}
use of com.android.ddmlib.IDevice in project android by JetBrains.
the class NonGradleApkProviderTest method testGetApksWithArtifactName.
public void testGetApksWithArtifactName() throws Exception {
IDevice device = Mockito.mock(IDevice.class);
ArtifactManager artifactManager = ArtifactManager.getInstance(myFacet.getModule().getProject());
CompositePackagingElement<?> archive = PackagingElementFactory.getInstance().createArchive("right.apk");
archive.addFirstChild(new AndroidFinalPackageElement(myFacet.getModule().getProject(), myFacet));
artifactManager.addArtifact("customApk", AndroidApplicationArtifactType.getInstance(), archive);
myFacet.getProperties().APK_PATH = "wrong.apk";
NonGradleApkProvider provider = new NonGradleApkProvider(myFacet, new NonGradleApplicationIdProvider(myFacet), "customApk");
Collection<ApkInfo> apks = provider.getApks(device);
assertNotNull(apks);
assertEquals(1, apks.size());
ApkInfo apk = apks.iterator().next();
assertEquals("p1.p2", apk.getApplicationId());
assertTrue(apk.getFile().getPath().endsWith("right.apk"));
}
Aggregations