use of com.android.tools.build.bundletool.device.AdbRunner 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.AdbRunner 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);
}
}
Aggregations