use of com.android.tools.build.bundletool.androidtools.AdbCommand in project bundletool by google.
the class InstallMultiApksCommand method execute.
public void execute() throws TimeoutException, IOException {
validateInput();
AdbServer adbServer = getAdbServer();
adbServer.init(getAdbPath());
try (TempDirectory tempDirectory = new TempDirectory()) {
DeviceAnalyzer deviceAnalyzer = new DeviceAnalyzer(adbServer);
DeviceSpec deviceSpec = deviceAnalyzer.getDeviceSpec(getDeviceId());
Device device = deviceAnalyzer.getAndValidateDevice(getDeviceId());
if (getTimeout().isPresent() && !device.getVersion().isGreaterOrEqualThan(Versions.ANDROID_S_API_VERSION)) {
throw InvalidCommandException.builder().withInternalMessage("'%s' flag is supported for Android 12+ devices.", TIMEOUT_MILLIS_FLAG.getName()).build();
}
Path aapt2Dir = tempDirectory.getPath().resolve("aapt2");
Files.createDirectory(aapt2Dir);
Supplier<Aapt2Command> aapt2CommandSupplier = Suppliers.memoize(() -> getOrExtractAapt2Command(aapt2Dir));
ImmutableMap<String, InstalledPackageInfo> existingPackages = getPackagesInstalledOnDevice(device);
ImmutableList<PackagePathVersion> installableApksFilesWithBadgingInfo = getActualApksPaths(tempDirectory).stream().flatMap(apksArchivePath -> stream(apksWithPackageName(apksArchivePath, deviceSpec, aapt2CommandSupplier))).filter(apks -> shouldInstall(apks, existingPackages)).collect(toImmutableList());
ImmutableList<PackagePathVersion> apkFilesToInstall = uniqueApksByPackageName(installableApksFilesWithBadgingInfo).stream().flatMap(apks -> extractApkListFromApks(deviceSpec, apks, Optional.ofNullable(existingPackages.get(apks.getPackageName())), tempDirectory).stream()).collect(toImmutableList());
ImmutableListMultimap<String, String> apkToInstallByPackage = apkFilesToInstall.stream().collect(toImmutableListMultimap(PackagePathVersion::getPackageName, packagePathVersion -> packagePathVersion.getPath().toAbsolutePath().toString()));
if (apkFilesToInstall.isEmpty()) {
logger.warning("No packages found to install! Exiting...");
return;
}
AdbCommand adbCommand = getOrCreateAdbCommand();
ImmutableList<String> commandResults = adbCommand.installMultiPackage(apkToInstallByPackage, getStaged(), getEnableRollback(), getTimeout(), getDeviceId());
logger.info(String.format("Output:\n%s", String.join("\n", commandResults)));
logger.info("Please reboot device to complete installation.");
}
}
Aggregations