Search in sources :

Example 1 with PackagesParser

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

the class InstallMultiApksCommand method getPackagesInstalledOnDevice.

private static ImmutableMap<String, InstalledPackageInfo> getPackagesInstalledOnDevice(Device device) {
    // List standard packages (excluding apex)
    ImmutableList<String> listPackagesOutput = new AdbShellCommandTask(device, "pm list packages --show-versioncode").execute();
    // List .apex packages.
    ImmutableList<String> listApexPackagesOutput = new AdbShellCommandTask(device, "pm list packages --apex-only --show-versioncode").execute();
    ImmutableSet<InstalledPackageInfo> installedApks = new PackagesParser(/* isApex= */
    false).parse(listPackagesOutput);
    ImmutableSet<InstalledPackageInfo> installedApexPackages = new PackagesParser(/* isApex= */
    true).parse(listApexPackagesOutput);
    return Streams.concat(installedApks.stream(), installedApexPackages.stream()).collect(toImmutableMap(InstalledPackageInfo::getPackageName, installedPackageInfo -> installedPackageInfo));
}
Also used : 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) AdbShellCommandTask(com.android.tools.build.bundletool.device.AdbShellCommandTask) PackagesParser(com.android.tools.build.bundletool.device.PackagesParser) InstalledPackageInfo(com.android.tools.build.bundletool.device.PackagesParser.InstalledPackageInfo)

Aggregations

DeviceSpec (com.android.bundle.Devices.DeviceSpec)1 Aapt2Command (com.android.tools.build.bundletool.androidtools.Aapt2Command)1 AdbCommand (com.android.tools.build.bundletool.androidtools.AdbCommand)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 AdbServer (com.android.tools.build.bundletool.device.AdbServer)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 Device (com.android.tools.build.bundletool.device.Device)1 DeviceAnalyzer (com.android.tools.build.bundletool.device.DeviceAnalyzer)1 PackagesParser (com.android.tools.build.bundletool.device.PackagesParser)1 InstalledPackageInfo (com.android.tools.build.bundletool.device.PackagesParser.InstalledPackageInfo)1 Flag (com.android.tools.build.bundletool.flags.Flag)1 ParsedFlags (com.android.tools.build.bundletool.flags.ParsedFlags)1 TempDirectory (com.android.tools.build.bundletool.io.TempDirectory)1 ZipPath (com.android.tools.build.bundletool.model.ZipPath)1 IncompatibleDeviceException (com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException)1 InvalidCommandException (com.android.tools.build.bundletool.model.exceptions.InvalidCommandException)1