Search in sources :

Example 21 with IDevice

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

the class NonGradleApkProviderTest method testGetApks.

public void testGetApks() throws Exception {
    IDevice device = Mockito.mock(IDevice.class);
    myFacet.getProperties().APK_PATH = "artifact.apk";
    NonGradleApkProvider provider = new NonGradleApkProvider(myFacet, new NonGradleApplicationIdProvider(myFacet), null);
    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("artifact.apk"));
}
Also used : IDevice(com.android.ddmlib.IDevice)

Example 22 with IDevice

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

the class RestartActivityAction method findDevices.

/**
   * Finds the devices associated with all run configurations for the given project
   */
@NotNull
private static List<IDevice> findDevices(@Nullable Project project) {
    if (project == null) {
        return Collections.emptyList();
    }
    List<RunContentDescriptor> runningProcesses = ExecutionManager.getInstance(project).getContentManager().getAllDescriptors();
    if (runningProcesses.isEmpty()) {
        return Collections.emptyList();
    }
    List<IDevice> devices = Lists.newArrayList();
    for (RunContentDescriptor descriptor : runningProcesses) {
        ProcessHandler processHandler = descriptor.getProcessHandler();
        if (processHandler == null || processHandler.isProcessTerminated() || processHandler.isProcessTerminating()) {
            continue;
        }
        devices.addAll(getConnectedDevices(processHandler));
    }
    return devices;
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) IDevice(com.android.ddmlib.IDevice) AndroidProcessHandler(com.android.tools.idea.run.AndroidProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with IDevice

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

the class InstantRunBuilderTest method setUp.

@Before
public void setUp() throws Exception {
    myDevice = mock(IDevice.class);
    when(myDevice.getSerialNumber()).thenReturn("device1-serial");
    myInstalledPatchCache = new InstalledPatchCache();
    myInstantRunContext = mock(InstantRunContext.class);
    when(myInstantRunContext.getInstantRunBuildInfo()).thenReturn(InstantRunBuildInfo.get(BUILD_INFO)).thenReturn(InstantRunBuildInfo.get(BUILD_INFO_RELOAD_DEX));
    when(myInstantRunContext.getApplicationId()).thenReturn(APPLICATION_ID);
    when(myInstantRunContext.getInstalledPatchCache()).thenReturn(myInstalledPatchCache);
    myRunConfigContext = new AndroidRunConfigContext();
    myRunConfigContext.setTargetDevices(DeviceFutures.forDevices(Collections.singletonList(myDevice)));
    myTasksProvider = mock(InstantRunTasksProvider.class);
    when(myTasksProvider.getFullBuildTasks()).thenReturn(ASSEMBLE_TASKS);
    when(myTasksProvider.getCleanAndGenerateSourcesTasks()).thenReturn(CLEAN_TASKS);
    myInstalledApkCache = new InstalledApkCache() {

        @Override
        protected String executeShellCommand(@NotNull IDevice device, @NotNull String cmd, long timeout, @NotNull TimeUnit timeUnit) throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException, IOException, InterruptedException {
            return myDumpsysPackageOutput;
        }
    };
    myApk = FileUtil.createTempFile("foo", "apk");
    myTaskRunner = new RecordingTaskRunner();
    myInstantRunClientDelegate = createInstantRunClientDelegate();
    myBuilder = new InstantRunBuilder(myDevice, myInstantRunContext, myRunConfigContext, myTasksProvider, false, myInstalledApkCache, myInstantRunClientDelegate);
}
Also used : AndroidRunConfigContext(com.android.tools.idea.run.AndroidRunConfigContext) IDevice(com.android.ddmlib.IDevice) IOException(java.io.IOException) InstalledPatchCache(com.android.tools.idea.run.InstalledPatchCache) InstalledApkCache(com.android.tools.idea.run.InstalledApkCache) ShellCommandUnresponsiveException(com.android.ddmlib.ShellCommandUnresponsiveException) AdbCommandRejectedException(com.android.ddmlib.AdbCommandRejectedException) TimeUnit(java.util.concurrent.TimeUnit) TimeoutException(com.android.ddmlib.TimeoutException) Before(org.junit.Before)

Example 24 with IDevice

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

the class AndroidProcessHandler method addClient.

private void addClient(@NotNull final Client client) {
    if (!myClients.add(client)) {
        return;
    }
    IDevice device = client.getDevice();
    notifyTextAvailable("Connected to process " + client.getClientData().getPid() + " on device " + device.getName() + "\n", ProcessOutputTypes.STDOUT);
}
Also used : IDevice(com.android.ddmlib.IDevice)

Example 25 with IDevice

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

the class AndroidRunConfigurationBase method getFastDeployDevices.

@Nullable
private static DeviceFutures getFastDeployDevices(@NotNull Executor executor, @NotNull AndroidFacet facet, @NotNull AndroidSessionInfo info) {
    if (!InstantRunSettings.isInstantRunEnabled()) {
        InstantRunManager.LOG.info("Instant run not enabled in settings");
        return null;
    }
    if (!info.getExecutorId().equals(executor.getId())) {
        String msg = String.format("Cannot Instant Run since old executor (%1$s) doesn't match current executor (%2$s)", info.getExecutorId(), executor.getId());
        InstantRunManager.LOG.info(msg);
        return null;
    }
    List<IDevice> devices = info.getDevices();
    if (devices == null || devices.isEmpty()) {
        InstantRunManager.LOG.info("Cannot Instant Run since we could not locate the devices from the existing launch session");
        return null;
    }
    if (devices.size() > 1) {
        InstantRunManager.LOG.info("Last run was on > 1 device, not reusing devices and prompting again");
        return null;
    }
    AndroidModuleModel model = AndroidModuleModel.get(facet);
    AndroidVersion version = devices.get(0).getVersion();
    InstantRunGradleSupport status = InstantRunGradleUtils.getIrSupportStatus(model, version);
    if (status != SUPPORTED) {
        InstantRunManager.LOG.info("Cannot Instant Run: " + status);
        return null;
    }
    return DeviceFutures.forDevices(devices);
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) IDevice(com.android.ddmlib.IDevice) InstantRunGradleSupport(com.android.tools.idea.fd.gradle.InstantRunGradleSupport) AndroidVersion(com.android.sdklib.AndroidVersion) Nullable(org.jetbrains.annotations.Nullable)

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