Search in sources :

Example 1 with DeviceAnalyzer

use of com.android.tools.build.bundletool.device.DeviceAnalyzer 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;
}
Also used : DeviceSpec(com.android.bundle.Devices.DeviceSpec) DefaultSigningConfigurationProvider(com.android.tools.build.bundletool.model.DefaultSigningConfigurationProvider) ApkModifier(com.android.tools.build.bundletool.model.ApkModifier) ApkListener(com.android.tools.build.bundletool.model.ApkListener) DeviceSpec(com.android.bundle.Devices.DeviceSpec) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) Retention(java.lang.annotation.Retention) DeviceAnalyzer(com.android.tools.build.bundletool.device.DeviceAnalyzer) Module(dagger.Module) Qualifier(javax.inject.Qualifier) ApkSerializerModule(com.android.tools.build.bundletool.io.ApkSerializerModule) OptimizationsMerger(com.android.tools.build.bundletool.optimizations.OptimizationsMerger) Version(com.android.tools.build.bundletool.model.version.Version) AdbServer(com.android.tools.build.bundletool.device.AdbServer) Provides(dagger.Provides) SourceStamp(com.android.tools.build.bundletool.model.SourceStamp) PrintStream(java.io.PrintStream) Int32Value(com.google.protobuf.Int32Value) SigningConfigurationProvider(com.android.tools.build.bundletool.model.SigningConfigurationProvider) ApkOptimizations(com.android.tools.build.bundletool.optimizations.ApkOptimizations) RUNTIME(java.lang.annotation.RetentionPolicy.RUNTIME) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ApkBuildMode(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode) BundleConfig(com.android.bundle.Config.BundleConfig) Optional(java.util.Optional) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) DeviceAnalyzer(com.android.tools.build.bundletool.device.DeviceAnalyzer) AdbServer(com.android.tools.build.bundletool.device.AdbServer) Provides(dagger.Provides)

Example 2 with DeviceAnalyzer

use of com.android.tools.build.bundletool.device.DeviceAnalyzer 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;
}
Also used : Path(java.nio.file.Path) DeviceSpec(com.android.bundle.Devices.DeviceSpec) DeviceAnalyzer(com.android.tools.build.bundletool.device.DeviceAnalyzer) AdbServer(com.android.tools.build.bundletool.device.AdbServer)

Example 3 with DeviceAnalyzer

use of com.android.tools.build.bundletool.device.DeviceAnalyzer 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 4 with DeviceAnalyzer

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

the class ConnectedDeviceModeTransparencyChecker method getDevice.

private static Device getDevice(AdbServer adbServer, Optional<String> deviceId) {
    DeviceAnalyzer deviceAnalyzer = new DeviceAnalyzer(adbServer);
    Device device;
    try {
        device = deviceAnalyzer.getAndValidateDevice(deviceId);
    } catch (TimeoutException e) {
        throw new UncheckedTimeoutException(e);
    }
    return device;
}
Also used : Device(com.android.tools.build.bundletool.device.Device) DeviceAnalyzer(com.android.tools.build.bundletool.device.DeviceAnalyzer) UncheckedTimeoutException(com.google.common.util.concurrent.UncheckedTimeoutException) TimeoutException(java.util.concurrent.TimeoutException) UncheckedTimeoutException(com.google.common.util.concurrent.UncheckedTimeoutException)

Example 5 with DeviceAnalyzer

use of com.android.tools.build.bundletool.device.DeviceAnalyzer 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.");
    }
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) TimeoutException(java.util.concurrent.TimeoutException) SYSTEM_PATH_VARIABLE(com.android.tools.build.bundletool.model.utils.SdkToolsLocator.SYSTEM_PATH_VARIABLE) DeviceSpec(com.android.bundle.Devices.DeviceSpec) DeviceAnalyzer(com.android.tools.build.bundletool.device.DeviceAnalyzer) TempDirectory(com.android.tools.build.bundletool.io.TempDirectory) ImmutableListMultimap.toImmutableListMultimap(com.google.common.collect.ImmutableListMultimap.toImmutableListMultimap) Locale(java.util.Locale) Flag(com.android.tools.build.bundletool.flags.Flag) Duration(java.time.Duration) AdbShellCommandTask(com.android.tools.build.bundletool.device.AdbShellCommandTask) ZipFile(java.util.zip.ZipFile) FilePreconditions.checkFileHasExtension(com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileHasExtension) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) InstalledPackageInfo(com.android.tools.build.bundletool.device.PackagesParser.InstalledPackageInfo) ImmutableSet(com.google.common.collect.ImmutableSet) BadgingInfo(com.android.tools.build.bundletool.device.BadgingInfoParser.BadgingInfo) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Aapt2Command(com.android.tools.build.bundletool.androidtools.Aapt2Command) Device(com.android.tools.build.bundletool.device.Device) ParsedFlags(com.android.tools.build.bundletool.flags.ParsedFlags) CanIgnoreReturnValue(com.google.errorprone.annotations.CanIgnoreReturnValue) Streams(com.google.common.collect.Streams) Logger(java.util.logging.Logger) UncheckedIOException(java.io.UncheckedIOException) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) SystemEnvironmentProvider(com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) AutoValue(com.google.auto.value.AutoValue) ByteStreams(com.google.common.io.ByteStreams) Optional(java.util.Optional) FilePreconditions.checkFileExistsAndReadable(com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileExistsAndReadable) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Supplier(java.util.function.Supplier) ImmutableList(com.google.common.collect.ImmutableList) DefaultSystemEnvironmentProvider(com.android.tools.build.bundletool.model.utils.DefaultSystemEnvironmentProvider) BadgingInfoParser(com.android.tools.build.bundletool.device.BadgingInfoParser) Suppliers(com.google.common.base.Suppliers) Comparator.comparing(java.util.Comparator.comparing) AdbServer(com.android.tools.build.bundletool.device.AdbServer) OutputStream(java.io.OutputStream) ANDROID_HOME_VARIABLE(com.android.tools.build.bundletool.model.utils.SdkToolsLocator.ANDROID_HOME_VARIABLE) FilePreconditions.checkFileExistsAndExecutable(com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileExistsAndExecutable) AdbCommand(com.android.tools.build.bundletool.androidtools.AdbCommand) Files(java.nio.file.Files) ANDROID_SERIAL_VARIABLE(com.android.tools.build.bundletool.commands.CommandUtils.ANDROID_SERIAL_VARIABLE) Collectors.maxBy(java.util.stream.Collectors.maxBy) IOException(java.io.IOException) PackagesParser(com.android.tools.build.bundletool.device.PackagesParser) Streams.stream(com.google.common.collect.Streams.stream) IncompatibleDeviceException(com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) FlagDescription(com.android.tools.build.bundletool.commands.CommandHelp.FlagDescription) Versions(com.android.tools.build.bundletool.model.utils.Versions) CommandDescription(com.android.tools.build.bundletool.commands.CommandHelp.CommandDescription) InputStream(java.io.InputStream) Aapt2Command(com.android.tools.build.bundletool.androidtools.Aapt2Command) Device(com.android.tools.build.bundletool.device.Device) DeviceAnalyzer(com.android.tools.build.bundletool.device.DeviceAnalyzer) DeviceSpec(com.android.bundle.Devices.DeviceSpec) TempDirectory(com.android.tools.build.bundletool.io.TempDirectory) InstalledPackageInfo(com.android.tools.build.bundletool.device.PackagesParser.InstalledPackageInfo) AdbServer(com.android.tools.build.bundletool.device.AdbServer) AdbCommand(com.android.tools.build.bundletool.androidtools.AdbCommand)

Aggregations

DeviceAnalyzer (com.android.tools.build.bundletool.device.DeviceAnalyzer)5 DeviceSpec (com.android.bundle.Devices.DeviceSpec)4 AdbServer (com.android.tools.build.bundletool.device.AdbServer)4 Device (com.android.tools.build.bundletool.device.Device)2 TempDirectory (com.android.tools.build.bundletool.io.TempDirectory)2 Path (java.nio.file.Path)2 TimeoutException (java.util.concurrent.TimeoutException)2 BuildApksResult (com.android.bundle.Commands.BuildApksResult)1 BundleConfig (com.android.bundle.Config.BundleConfig)1 Aapt2Command (com.android.tools.build.bundletool.androidtools.Aapt2Command)1 AdbCommand (com.android.tools.build.bundletool.androidtools.AdbCommand)1 ApkBuildMode (com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode)1 CommandDescription (com.android.tools.build.bundletool.commands.CommandHelp.CommandDescription)1 FlagDescription (com.android.tools.build.bundletool.commands.CommandHelp.FlagDescription)1 ANDROID_SERIAL_VARIABLE (com.android.tools.build.bundletool.commands.CommandUtils.ANDROID_SERIAL_VARIABLE)1 AdbRunner (com.android.tools.build.bundletool.device.AdbRunner)1 AdbShellCommandTask (com.android.tools.build.bundletool.device.AdbShellCommandTask)1 BadgingInfoParser (com.android.tools.build.bundletool.device.BadgingInfoParser)1 BadgingInfo (com.android.tools.build.bundletool.device.BadgingInfoParser.BadgingInfo)1 InstallOptions (com.android.tools.build.bundletool.device.Device.InstallOptions)1