Search in sources :

Example 76 with IDevice

use of com.android.ddmlib.IDevice in project intellij by bazelbuild.

the class BlazeApkBuildStepMobileInstall method build.

@Override
public boolean build(BlazeContext context, BlazeAndroidDeviceSelector.DeviceSession deviceSession) {
    ScopedTask<Void> buildTask = new ScopedTask<Void>(context) {

        @Override
        protected Void execute(BlazeContext context) {
            DeviceFutures deviceFutures = deviceSession.deviceFutures;
            assert deviceFutures != null;
            IDevice device = resolveDevice(context, deviceFutures);
            if (device == null) {
                return null;
            }
            BlazeCommand.Builder command = BlazeCommand.builder(Blaze.getBuildSystemProvider(project).getBinaryPath(), BlazeCommandName.MOBILE_INSTALL);
            command.addBlazeFlags(BlazeFlags.DEVICE, device.getSerialNumber());
            // Redundant, but we need this to get around bug in bazel.
            // https://github.com/bazelbuild/bazel/issues/4922
            command.addBlazeFlags(BlazeFlags.ADB_ARG + "-s ", BlazeFlags.ADB_ARG + device.getSerialNumber());
            if (USE_SDK_ADB.getValue()) {
                File adb = AndroidSdkUtils.getAdb(project);
                if (adb != null) {
                    command.addBlazeFlags(BlazeFlags.ADB, adb.toString());
                }
            }
            WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
            BlazeApkDeployInfoProtoHelper deployInfoHelper = new BlazeApkDeployInfoProtoHelper(project, blazeFlags);
            BuildResultHelper buildResultHelper = deployInfoHelper.getBuildResultHelper();
            command.addTargets(label).addBlazeFlags(blazeFlags).addBlazeFlags(buildResultHelper.getBuildFlags()).addBlazeFlags("--output_groups=android_deploy_info").addExeFlags(exeFlags);
            SaveUtil.saveAllFiles();
            int retVal = ExternalTask.builder(workspaceRoot).addBlazeCommand(command.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
            FileCaches.refresh(project);
            if (retVal != 0) {
                context.setHasError();
                return null;
            }
            deployInfo = deployInfoHelper.readDeployInfo(context);
            if (deployInfo == null) {
                IssueOutput.error("Could not read apk deploy info from build").submit(context);
            }
            return null;
        }
    };
    ListenableFuture<Void> buildFuture = ProgressiveTaskWithProgressIndicator.builder(project).setTitle(String.format("Executing %s apk build", Blaze.buildSystemName(project))).submitTaskWithResult(buildTask);
    try {
        Futures.get(buildFuture, ExecutionException.class);
    } catch (ExecutionException e) {
        context.setHasError();
    } catch (CancellationException e) {
        context.setCancelled();
    }
    return context.shouldContinue();
}
Also used : BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) IDevice(com.android.ddmlib.IDevice) DeviceFutures(com.android.tools.idea.run.DeviceFutures) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) ScopedTask(com.google.idea.blaze.base.scope.ScopedTask) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) BlazeApkDeployInfoProtoHelper(com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper) CancellationException(java.util.concurrent.CancellationException) ExecutionException(com.intellij.execution.ExecutionException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) File(java.io.File)

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