use of com.android.tools.build.bundletool.device.Device in project bundletool by google.
the class InstallMultiApksCommand method extractApkListFromApks.
/**
* Extracts the apk/apex files that will be installed from a given .apks.
*/
private static ImmutableList<PackagePathVersion> extractApkListFromApks(DeviceSpec deviceSpec, PackagePathVersion apksArchive, Optional<InstalledPackageInfo> installedPackage, TempDirectory tempDirectory) {
logger.info(String.format("Extracting package '%s'", apksArchive.getPackageName()));
try {
Path output = tempDirectory.getPath().resolve(apksArchive.getPackageName());
Files.createDirectory(output);
ExtractApksCommand.Builder extractApksCommand = ExtractApksCommand.builder().setApksArchivePath(apksArchive.getPath()).setDeviceSpec(deviceSpec).setOutputDirectory(output);
ImmutableList<Path> extractedPaths = fixExtension(extractApksCommand.build().execute(), installedPackage.map(InstalledPackageInfo::isApex).orElse(false));
return extractedPaths.stream().map(path -> PackagePathVersion.create(path, apksArchive.getPackageName(), apksArchive.getVersionCode())).collect(toImmutableList());
} catch (IncompatibleDeviceException e) {
logger.warning(String.format("Package '%s' is not supported by the attached device (SDK version %d). Skipping.", apksArchive.getPackageName(), deviceSpec.getSdkVersion()));
return ImmutableList.of();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of com.android.tools.build.bundletool.device.Device 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));
}
use of com.android.tools.build.bundletool.device.Device in project bundletool by google.
the class ConnectedDeviceModeTransparencyChecker method checkTransparency.
public static TransparencyCheckResult checkTransparency(CheckTransparencyCommand command) {
command.getAdbServer().get().init(command.getAdbPath().get());
AdbRunner adbRunner = new AdbRunner(command.getAdbServer().get());
Device adbDevice = getDevice(command.getAdbServer().get(), command.getDeviceId());
// Execute a shell command to retrieve paths to all APKs for the given package name.
AdbShellCommandTask adbShellCommandTask = new AdbShellCommandTask(adbDevice, "pm path " + command.getPackageName().get());
ImmutableList<String> pathsToApksOnDevice = adbShellCommandTask.execute().stream().filter(path -> path.startsWith(APK_PATH_ON_DEVICE_PREFIX)).map(path -> path.substring(APK_PATH_ON_DEVICE_PREFIX.length())).collect(toImmutableList());
if (pathsToApksOnDevice.isEmpty()) {
throw InvalidCommandException.builder().withInternalMessage("No files found for package " + command.getPackageName().get()).build();
}
// Pull APKs to a temporary directory and verify code transparency.
try (TempDirectory tempDir = new TempDirectory("connected-device-transparency-check")) {
Path apksExtractedSubDirectory = tempDir.getPath().resolve("extracted");
Files.createDirectory(apksExtractedSubDirectory);
ImmutableList<FilePullParams> pullParams = createPullParams(pathsToApksOnDevice, apksExtractedSubDirectory);
if (command.getDeviceId().isPresent()) {
adbRunner.run(device -> device.pull(pullParams), command.getDeviceId().get());
} else {
adbRunner.run(device -> device.pull(pullParams));
}
return ApkTransparencyCheckUtils.checkTransparency(pullParams.stream().map(FilePullParams::getDestinationPath).collect(toImmutableList()));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of com.android.tools.build.bundletool.device.Device 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;
}
use of com.android.tools.build.bundletool.device.Device in project bundletool by google.
the class ActivityManagerRunnerTest method preLDevice_noResults.
@Test
public void preLDevice_noResults() {
Device device = FakeDevice.fromDeviceSpec(SERIAL_NUMBER, DeviceState.ONLINE, mergeSpecs(sdkVersion(20), locales("en-US"), density(240), abis("armeabi")));
ActivityManagerRunner runner = new ActivityManagerRunner(device);
assertThat(runner.getDeviceLocales()).isEmpty();
assertThat(runner.getDeviceAbis()).isEmpty();
}
Aggregations