Search in sources :

Example 1 with InstallOptions

use of com.android.tools.build.bundletool.device.Device.InstallOptions in project bundletool by google.

the class InstallApksCommand method execute.

public void execute() {
    BuildApksResult toc = readBuildApksResult();
    validateInput(toc);
    AdbServer adbServer = getAdbServer();
    adbServer.init(getAdbPath());
    try (TempDirectory tempDirectory = new TempDirectory()) {
        DeviceSpec deviceSpec = new DeviceAnalyzer(adbServer).getDeviceSpec(getDeviceId());
        if (getDeviceTier().isPresent()) {
            deviceSpec = deviceSpec.toBuilder().setDeviceTier(Int32Value.of(getDeviceTier().get())).build();
        }
        if (getDeviceGroups().isPresent()) {
            deviceSpec = deviceSpec.toBuilder().addAllDeviceGroups(getDeviceGroups().get()).build();
        }
        final ImmutableList<Path> apksToInstall = getApksToInstall(toc, deviceSpec, tempDirectory.getPath());
        final ImmutableList<Path> filesToPush = ImmutableList.<Path>builder().addAll(getApksToPushToStorage(toc, deviceSpec, tempDirectory.getPath())).addAll(getAdditionalLocalTestingFiles().orElse(ImmutableList.of())).build();
        AdbRunner adbRunner = new AdbRunner(adbServer);
        InstallOptions installOptions = InstallOptions.builder().setAllowDowngrade(getAllowDowngrade()).setAllowTestOnly(getAllowTestOnly()).setTimeout(getTimeout()).build();
        if (getDeviceId().isPresent()) {
            adbRunner.run(device -> device.installApks(apksToInstall, installOptions), getDeviceId().get());
        } else {
            adbRunner.run(device -> device.installApks(apksToInstall, installOptions));
        }
        if (!filesToPush.isEmpty()) {
            pushFiles(filesToPush, toc, adbRunner);
        }
        if (toc.getLocalTestingInfo().getEnabled()) {
            cleanUpEmulatedSplits(adbRunner, toc);
        }
    }
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) Path(java.nio.file.Path) TempDirectory(com.android.tools.build.bundletool.io.TempDirectory) BuildApksResult(com.android.bundle.Commands.BuildApksResult) AdbRunner(com.android.tools.build.bundletool.device.AdbRunner) DeviceAnalyzer(com.android.tools.build.bundletool.device.DeviceAnalyzer) InstallOptions(com.android.tools.build.bundletool.device.Device.InstallOptions) AdbServer(com.android.tools.build.bundletool.device.AdbServer)

Example 2 with InstallOptions

use of com.android.tools.build.bundletool.device.Device.InstallOptions in project bundletool by google.

the class AdbRunnerTest method installApks_withDeviceId_disconnectedDevice_throws.

@Test
public void installApks_withDeviceId_disconnectedDevice_throws() {
    FakeDevice disconnectedDevice = FakeDevice.inDisconnectedState("device2", DeviceState.UNAUTHORIZED);
    AdbServer testAdbServer = new FakeAdbServer(/* hasInitialDeviceList= */
    true, ImmutableList.of(FakeDevice.fromDeviceSpec("device1", DeviceState.ONLINE, lDeviceWithLocales("en-US")), disconnectedDevice));
    testAdbServer.init(Paths.get("/test/adb"));
    AdbRunner adbRunner = new AdbRunner(testAdbServer);
    disconnectedDevice.setInstallApksSideEffect((apks, installOptions) -> {
        throw CommandExecutionException.builder().withInternalMessage("Enable USB debugging on the connected device.").build();
    });
    Throwable exception = assertThrows(CommandExecutionException.class, () -> adbRunner.run(device -> device.installApks(ImmutableList.of(apkPath), DEFAULT_INSTALL_OPTIONS), "device2"));
    assertThat(exception).hasMessageThat().contains("Enable USB debugging on the connected device.");
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Files(java.nio.file.Files) DeviceState(com.android.ddmlib.IDevice.DeviceState) CommandExecutionException(com.android.tools.build.bundletool.model.exceptions.CommandExecutionException) DeviceFactory.lDeviceWithLocales(com.android.tools.build.bundletool.testing.DeviceFactory.lDeviceWithLocales) InstallOptions(com.android.tools.build.bundletool.device.Device.InstallOptions) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Rule(org.junit.Rule) ImmutableList(com.google.common.collect.ImmutableList) Paths(java.nio.file.Paths) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Duration(java.time.Duration) Path(java.nio.file.Path) TemporaryFolder(org.junit.rules.TemporaryFolder) Before(org.junit.Before) FakeDevice(com.android.tools.build.bundletool.testing.FakeDevice) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Test(org.junit.Test)

Aggregations

InstallOptions (com.android.tools.build.bundletool.device.Device.InstallOptions)2 Path (java.nio.file.Path)2 BuildApksResult (com.android.bundle.Commands.BuildApksResult)1 DeviceSpec (com.android.bundle.Devices.DeviceSpec)1 DeviceState (com.android.ddmlib.IDevice.DeviceState)1 AdbRunner (com.android.tools.build.bundletool.device.AdbRunner)1 AdbServer (com.android.tools.build.bundletool.device.AdbServer)1 DeviceAnalyzer (com.android.tools.build.bundletool.device.DeviceAnalyzer)1 TempDirectory (com.android.tools.build.bundletool.io.TempDirectory)1 CommandExecutionException (com.android.tools.build.bundletool.model.exceptions.CommandExecutionException)1 DeviceFactory.lDeviceWithLocales (com.android.tools.build.bundletool.testing.DeviceFactory.lDeviceWithLocales)1 FakeAdbServer (com.android.tools.build.bundletool.testing.FakeAdbServer)1 FakeDevice (com.android.tools.build.bundletool.testing.FakeDevice)1 ImmutableList (com.google.common.collect.ImmutableList)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 Duration (java.time.Duration)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1