use of com.android.tools.build.bundletool.device.AdbServer in project bundletool by google.
the class BuildApksModule method provideDeviceSpec.
@CommandScoped
@Provides
static Optional<DeviceSpec> provideDeviceSpec(BuildApksCommand command) {
Optional<DeviceSpec> deviceSpec = command.getDeviceSpec();
if (command.getGenerateOnlyForConnectedDevice()) {
AdbServer adbServer = command.getAdbServer().get();
adbServer.init(command.getAdbPath().get());
deviceSpec = Optional.of(new DeviceAnalyzer(adbServer).getDeviceSpec(command.getDeviceId()));
}
if (command.getDeviceTier().isPresent()) {
// --device-tier can only be specified along with --device-spec or --connected-device, so
// deviceSpec should always be present in this case.
checkState(deviceSpec.isPresent(), "Device tier specified but no device was provided.");
deviceSpec = deviceSpec.map(spec -> spec.toBuilder().setDeviceTier(Int32Value.of(command.getDeviceTier().get())).build());
}
return deviceSpec;
}
use of com.android.tools.build.bundletool.device.AdbServer in project bundletool by google.
the class GetDeviceSpecCommand method execute.
public DeviceSpec execute() {
if (!getOverwriteOutput()) {
FilePreconditions.checkFileDoesNotExist(getOutputPath());
}
Path pathToAdb = getAdbPath();
FilePreconditions.checkFileExistsAndExecutable(pathToAdb);
AdbServer adb = getAdbServer();
adb.init(getAdbPath());
DeviceSpec deviceSpec = new DeviceAnalyzer(adb).getDeviceSpec(getDeviceId());
if (getDeviceTier().isPresent()) {
deviceSpec = deviceSpec.toBuilder().setDeviceTier(Int32Value.of(getDeviceTier().get())).build();
}
if (getDeviceGroups().isPresent()) {
deviceSpec = deviceSpec.toBuilder().addAllDeviceGroups(getDeviceGroups().get()).build();
}
writeDeviceSpecToFile(deviceSpec, getOutputPath());
return deviceSpec;
}
use of com.android.tools.build.bundletool.device.AdbServer 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.AdbServer in project bundletool by google.
the class InstallApksCommandTest method badSdkVersionDevice_throws.
@Test
public void badSdkVersionDevice_throws() throws Exception {
DeviceSpec deviceSpec = mergeSpecs(sdkVersion(1), density(480), abis("x86_64", "x86"), locales("en-US"));
FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, deviceSpec);
AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(fakeDevice));
InstallApksCommand command = InstallApksCommand.builder().setApksArchivePath(simpleApksPath).setAdbPath(adbPath).setAdbServer(adbServer).build();
Throwable exception = assertThrows(IllegalStateException.class, () -> command.execute());
assertThat(exception).hasMessageThat().contains("Error retrieving device SDK version");
}
use of com.android.tools.build.bundletool.device.AdbServer in project bundletool by google.
the class InstallApksCommandTest method localTestingMode_allModules.
@Test
@Theory
public void localTestingMode_allModules(@FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
String installTimeFeature = "installtime_feature";
String onDemandFeature = "ondemand_feature";
String installTimeAsset = "installtime_asset";
String onDemandAsset = "ondemand_asset";
ZipPath baseApk = ZipPath.create("base-master.apk");
ZipPath baseEnApk = ZipPath.create("base-en.apk");
ZipPath installTimeFeatureMasterApk = ZipPath.create(installTimeFeature + "-master.apk");
ZipPath installTimeFeatureEnApk = ZipPath.create(installTimeFeature + "-en.apk");
ZipPath installTimeFeaturePlApk = ZipPath.create(installTimeFeature + "-pl.apk");
ZipPath onDemandFeatureMasterApk = ZipPath.create(onDemandFeature + "-master.apk");
ZipPath installTimeAssetMasterApk = ZipPath.create(installTimeAsset + "-master.apk");
ZipPath installTimeAssetEnApk = ZipPath.create(installTimeAsset + "-en.apk");
ZipPath onDemandAssetMasterApk = ZipPath.create(onDemandAsset + "-master.apk");
BuildApksResult tableOfContent = BuildApksResult.newBuilder().setPackageName(PKG_NAME).setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(createVariant(VariantTargeting.getDefaultInstance(), createSplitApkSet("base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), baseApk), createApkDescription(apkLanguageTargeting("en"), baseEnApk, /* isMasterSplit= */
false)), createSplitApkSet(installTimeFeature, createMasterApkDescription(ApkTargeting.getDefaultInstance(), installTimeFeatureMasterApk), createApkDescription(apkLanguageTargeting("en"), installTimeFeatureEnApk, /* isMasterSplit= */
false), createApkDescription(apkLanguageTargeting("pl"), installTimeFeaturePlApk, /* isMasterSplit= */
false)), createSplitApkSet(onDemandFeature, DeliveryType.ON_DEMAND, /* moduleDependencies= */
ImmutableList.of(), createMasterApkDescription(ApkTargeting.getDefaultInstance(), onDemandFeatureMasterApk)))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(installTimeAsset).setDeliveryType(DeliveryType.INSTALL_TIME)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), installTimeAssetMasterApk)).addApkDescription(splitApkDescription(apkLanguageTargeting("en"), installTimeAssetEnApk))).addAssetSliceSet(AssetSliceSet.newBuilder().setAssetModuleMetadata(AssetModuleMetadata.newBuilder().setName(onDemandAsset).setDeliveryType(DeliveryType.ON_DEMAND)).addApkDescription(splitApkDescription(ApkTargeting.getDefaultInstance(), onDemandAssetMasterApk))).setLocalTestingInfo(LocalTestingInfo.newBuilder().setEnabled(true).setLocalTestingPath("local_testing").build()).build();
Path apksFile = createApks(tableOfContent, apksInDirectory);
List<Path> installedApks = new ArrayList<>();
List<Path> pushedFiles = new ArrayList<>();
FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, lDeviceWithLocales("en-US"));
AdbServer adbServer = new FakeAdbServer(/* hasInitialDeviceList= */
true, ImmutableList.of(fakeDevice));
fakeDevice.setInstallApksSideEffect((apks, installOptions) -> installedApks.addAll(apks));
fakeDevice.setPushSideEffect((files, installOptions) -> pushedFiles.addAll(files));
InstallApksCommand.builder().setApksArchivePath(apksFile).setAdbPath(adbPath).setAdbServer(adbServer).setModules(ImmutableSet.of("_ALL_")).build().execute();
// Base, install-time and on-demand features and install-time assets.
assertThat(getFileNames(installedApks)).containsExactly(baseApk.toString(), baseEnApk.toString(), installTimeFeatureMasterApk.toString(), installTimeFeatureEnApk.toString(), onDemandFeatureMasterApk.toString(), installTimeAssetMasterApk.toString(), installTimeAssetEnApk.toString());
// Base config splits, install-time and on-demand features and on-demand assets. All languages.
assertThat(getFileNames(pushedFiles)).containsExactly(baseEnApk.toString(), installTimeFeatureMasterApk.toString(), installTimeFeatureEnApk.toString(), installTimeFeaturePlApk.toString(), onDemandFeatureMasterApk.toString(), onDemandAssetMasterApk.toString());
}
Aggregations