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);
}
}
}
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.");
}
Aggregations