Search in sources :

Example 1 with InstantRunBuildInfo

use of com.android.tools.fd.client.InstantRunBuildInfo in project android by JetBrains.

the class InstantRunStatsService method notifyDeployType.

public void notifyDeployType(@NotNull DeployType type, @NotNull InstantRunContext context, @NotNull IDevice device) {
    BuildSelection selection = context.getBuildSelection();
    BuildCause buildCause = selection == null ? null : selection.why;
    InstantRunBuildInfo buildInfo = context.getInstantRunBuildInfo();
    String verifierStatus = buildInfo == null ? "unknown" : buildInfo.getVerifierStatus();
    notifyDeployType(type, buildCauseToProto(buildCause), verifierStatusToProto(verifierStatus), context.getGradlePluginVersion().toString(), device);
}
Also used : InstantRunBuildInfo(com.android.tools.fd.client.InstantRunBuildInfo) InstantRunIdeBuildCause(com.google.wireless.android.sdk.stats.InstantRun.InstantRunIdeBuildCause)

Example 2 with InstantRunBuildInfo

use of com.android.tools.fd.client.InstantRunBuildInfo in project android by JetBrains.

the class AndroidRunState method execute.

@Nullable
@Override
public ExecutionResult execute(Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
    ProcessHandler processHandler;
    ConsoleView console;
    String applicationId;
    try {
        applicationId = myApplicationIdProvider.getPackageName();
    } catch (ApkProvisionException e) {
        throw new ExecutionException("Unable to obtain application id", e);
    }
    // TODO: this class is independent of gradle, except for this hack
    AndroidModuleModel model = AndroidModuleModel.get(myModule);
    if (InstantRunSettings.isInstantRunEnabled() && InstantRunGradleUtils.getIrSupportStatus(model, null) == InstantRunGradleSupport.SUPPORTED) {
        assert model != null;
        InstantRunBuildInfo info = InstantRunGradleUtils.getBuildInfo(model);
        if (info != null && !info.isCompatibleFormat()) {
            throw new ExecutionException("This version of Android Studio is incompatible with the Gradle Plugin used. " + "Try disabling Instant Run (or updating either the IDE or the Gradle plugin to " + "the latest version)");
        }
    }
    LaunchTasksProvider launchTasksProvider = myLaunchTasksProviderFactory.get();
    if (launchTasksProvider.createsNewProcess()) {
        // and the new one).
        if (myPreviousSessionProcessHandler != null) {
            myPreviousSessionProcessHandler.detachProcess();
        }
        processHandler = new AndroidProcessHandler(applicationId, launchTasksProvider.monitorRemoteProcess());
        console = attachConsole(processHandler, executor);
    } else {
        assert myPreviousSessionProcessHandler != null : "No process handler from previous session, yet current tasks don't create one";
        processHandler = myPreviousSessionProcessHandler;
        console = null;
    }
    LaunchInfo launchInfo = new LaunchInfo(executor, runner, myEnv, myConsoleProvider);
    LaunchTaskRunner task = new LaunchTaskRunner(myModule.getProject(), myLaunchConfigName, launchInfo, processHandler, myDeviceFutures, launchTasksProvider);
    ProgressManager.getInstance().run(task);
    return console == null ? null : new DefaultExecutionResult(console, processHandler);
}
Also used : InstantRunBuildInfo(com.android.tools.fd.client.InstantRunBuildInfo) DefaultExecutionResult(com.intellij.execution.DefaultExecutionResult) ConsoleView(com.intellij.execution.ui.ConsoleView) LaunchTasksProvider(com.android.tools.idea.run.tasks.LaunchTasksProvider) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionException(com.intellij.execution.ExecutionException) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with InstantRunBuildInfo

use of com.android.tools.fd.client.InstantRunBuildInfo in project android by JetBrains.

the class AndroidLaunchTasksProviderFactory method get.

@NotNull
@Override
public LaunchTasksProvider get() {
    Project project = myEnv.getProject();
    InstantRunStatsService.get(project).notifyDeployStarted();
    InstantRunBuildAnalyzer analyzer = null;
    InstantRunBuildInfo instantRunBuildInfo = myInstantRunContext != null ? myInstantRunContext.getInstantRunBuildInfo() : null;
    if (instantRunBuildInfo != null) {
        analyzer = new InstantRunBuildAnalyzer(project, myInstantRunContext, myPreviousSessionProcessHandler);
        if (InstantRunSettings.isRecorderEnabled()) {
            if (!myDeviceFutures.getDevices().isEmpty()) {
                // Instant Run is guaranteed to be for exactly 1 device
                FlightRecorder.get(project).setLaunchTarget(myDeviceFutures.getDevices().get(0));
            }
            FlightRecorder.get(project).saveBuildInfo(instantRunBuildInfo);
        }
    }
    if (analyzer != null && analyzer.canReuseProcessHandler()) {
        return new UpdateSessionTasksProvider(analyzer);
    }
    return new AndroidLaunchTasksProvider(myRunConfig, myEnv, myFacet, analyzer, myApplicationIdProvider, myApkProvider, myLaunchOptions);
}
Also used : InstantRunBuildInfo(com.android.tools.fd.client.InstantRunBuildInfo) Project(com.intellij.openapi.project.Project) UpdateSessionTasksProvider(com.android.tools.idea.run.tasks.UpdateSessionTasksProvider) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with InstantRunBuildInfo

use of com.android.tools.fd.client.InstantRunBuildInfo in project android by JetBrains.

the class InstantRunBuilder method buildTimestampsMatch.

/**
   * Returns whether the device has the same timestamp as the existing build on disk.
   */
private boolean buildTimestampsMatch(@NotNull IDevice device, @Nullable Integer userId) {
    InstantRunBuildInfo instantRunBuildInfo = myInstantRunContext.getInstantRunBuildInfo();
    String localTimestamp = instantRunBuildInfo == null ? null : instantRunBuildInfo.getTimeStamp();
    if (StringUtil.isEmpty(localTimestamp)) {
        InstantRunManager.LOG.info("Local build timestamp is empty!");
        return false;
    }
    // https://code.google.com/p/android/issues/detail?id=198715
    if (!isAppInstalledForUser(device, myInstantRunContext.getApplicationId(), userId)) {
        return false;
    }
    String deviceBuildTimestamp = myInstantRunClientDelegate.getDeviceBuildTimestamp(device, myInstantRunContext);
    InstantRunManager.LOG.info(String.format("Build timestamps: Local: %1$s, Device: %2$s", localTimestamp, deviceBuildTimestamp));
    return localTimestamp.equals(deviceBuildTimestamp);
}
Also used : InstantRunBuildInfo(com.android.tools.fd.client.InstantRunBuildInfo)

Example 5 with InstantRunBuildInfo

use of com.android.tools.fd.client.InstantRunBuildInfo in project android by JetBrains.

the class SplitApkDeployTask method perform.

@Override
public boolean perform(@NotNull IDevice device, @NotNull LaunchStatus launchStatus, @NotNull ConsolePrinter printer) {
    InstantRunBuildInfo buildInfo = myInstantRunContext.getInstantRunBuildInfo();
    assert buildInfo != null;
    List<InstantRunArtifact> artifacts = buildInfo.getArtifacts();
    // TODO: should we pass in pm install options?
    List<String> installOptions = Lists.newArrayList();
    if (buildInfo.isPatchBuild()) {
        // partial install
        installOptions.add("-p");
        installOptions.add(myInstantRunContext.getApplicationId());
    }
    List<File> apks = Lists.newArrayListWithExpectedSize(artifacts.size());
    for (InstantRunArtifact artifact : artifacts) {
        if (artifact.type == InstantRunArtifactType.SPLIT_MAIN || artifact.type == InstantRunArtifactType.SPLIT) {
            apks.add(artifact.file);
        }
    }
    RetryingInstaller.Installer installer = new SplitApkInstaller(printer, apks, installOptions);
    RetryingInstaller retryingInstaller = new RetryingInstaller(myProject, device, installer, myInstantRunContext.getApplicationId(), printer, launchStatus);
    boolean status = retryingInstaller.install();
    if (status) {
        printer.stdout("Split APKs installed");
    }
    assert myInstantRunContext.getBuildSelection() != null;
    InstantRunStatsService.get(myProject).notifyDeployType(DeployType.SPLITAPK, myInstantRunContext, device);
    return status;
}
Also used : InstantRunBuildInfo(com.android.tools.fd.client.InstantRunBuildInfo) RetryingInstaller(com.android.tools.idea.run.RetryingInstaller) InstantRunArtifact(com.android.tools.fd.client.InstantRunArtifact) File(java.io.File)

Aggregations

InstantRunBuildInfo (com.android.tools.fd.client.InstantRunBuildInfo)8 InstantRunArtifact (com.android.tools.fd.client.InstantRunArtifact)2 NotNull (org.jetbrains.annotations.NotNull)2 InstantRunClient (com.android.tools.fd.client.InstantRunClient)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 RetryingInstaller (com.android.tools.idea.run.RetryingInstaller)1 LaunchTasksProvider (com.android.tools.idea.run.tasks.LaunchTasksProvider)1 UpdateSessionTasksProvider (com.android.tools.idea.run.tasks.UpdateSessionTasksProvider)1 InstantRunIdeBuildCause (com.google.wireless.android.sdk.stats.InstantRun.InstantRunIdeBuildCause)1 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)1 ExecutionException (com.intellij.execution.ExecutionException)1 ProcessHandler (com.intellij.execution.process.ProcessHandler)1 ConsoleView (com.intellij.execution.ui.ConsoleView)1 Project (com.intellij.openapi.project.Project)1 File (java.io.File)1 HashMap (java.util.HashMap)1 Nullable (org.jetbrains.annotations.Nullable)1