Search in sources :

Example 16 with IDevice

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

Example 17 with IDevice

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

Example 18 with IDevice

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

Example 19 with IDevice

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"));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IDevice(com.android.ddmlib.IDevice) Module(com.intellij.openapi.module.Module)

Example 20 with IDevice

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"));
}
Also used : ArtifactManager(com.intellij.packaging.artifacts.ArtifactManager) AndroidFinalPackageElement(org.jetbrains.android.compiler.artifact.AndroidFinalPackageElement) IDevice(com.android.ddmlib.IDevice)

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