use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class CheckTransparencyCommandTest method bundleMode_verificationFailed_badCertificateProvidedByUser.
@Test
public void bundleMode_verificationFailed_badCertificateProvidedByUser() throws Exception {
String serializedJws = createJwsToken(CodeTransparency.newBuilder().setVersion(CodeTransparencyVersion.getCurrentVersion()).build(), transparencyKeyCertificate, transparencyPrivateKey);
AppBundleBuilder appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.test.app"))).addMetadataFile(BundleMetadata.BUNDLETOOL_NAMESPACE, BundleMetadata.TRANSPARENCY_SIGNED_FILE_NAME, CharSource.wrap(serializedJws).asByteSource(Charset.defaultCharset()));
new AppBundleSerializer().writeToDisk(appBundle.build(), bundlePath);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
X509Certificate badCertificate = CertificateFactory.buildSelfSignedCertificate(kpg.generateKeyPair(), "CN=CheckTransparencyCommandTest_BadCertificate");
CheckTransparencyCommand.builder().setMode(Mode.BUNDLE).setBundlePath(bundlePath).setTransparencyKeyCertificate(badCertificate).build().checkTransparency(new PrintStream(outputStream));
String output = new String(outputStream.toByteArray(), UTF_8);
assertThat(output).contains("No APK present. APK signature was not checked.");
assertThat(output).contains("Code transparency verification failed because the provided public key certificate does" + " not match the code transparency file.");
assertThat(output).contains("SHA-256 fingerprint of the certificate that was used to sign code" + " transparency file: " + CodeTransparencyCryptoUtils.getCertificateFingerprint(transparencyKeyCertificate));
assertThat(output).contains("SHA-256 fingerprint of the certificate that was provided: " + CodeTransparencyCryptoUtils.getCertificateFingerprint(badCertificate));
}
use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class BuildApksPreprocessingTest method renderscript32Bit_warningMessageDisplayed.
@Test
public void renderscript32Bit_warningMessageDisplayed() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").addFile("assets/script.bc").setManifest(androidManifest("com.test.app"))).build();
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
ByteArrayOutputStream output = new ByteArrayOutputStream();
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setOutputPrintStream(new PrintStream(output)).build();
command.execute();
assertThat(new String(output.toByteArray(), UTF_8)).contains("WARNING: App Bundle contains 32-bit RenderScript bitcode file (.bc)");
}
use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class ModuleDependenciesUtils method buildAdjacencyMap.
/**
* Builds a map of module dependencies.
*
* <p>If module "a" contains {@code <uses-split name="b"/>} manifest entry, then the map contains
* entry ("a", "b").
*
* <p>All modules implicitly depend on the "base" module. Hence the map contains also dependency
* ("base", "base").
*/
public static Multimap<String, String> buildAdjacencyMap(ImmutableList<BundleModule> modules) {
Multimap<String, String> moduleDependenciesMap = ArrayListMultimap.create();
for (BundleModule module : modules) {
String moduleName = module.getName().getName();
AndroidManifest manifest = module.getAndroidManifest();
checkArgument(!moduleDependenciesMap.containsKey(moduleName), "Module named '%s' was passed in multiple times.", moduleName);
moduleDependenciesMap.putAll(moduleName, manifest.getUsesSplits());
// (whose split ID actually is empty instead of "base" anyway).
if (moduleDependenciesMap.containsEntry(moduleName, BASE_MODULE_NAME.getName())) {
throw InvalidBundleException.builder().withUserMessage("Module '%s' declares dependency on the '%s' module, which is implicit.", moduleName, BASE_MODULE_NAME).build();
}
// Add implicit dependency on the base. Also ensures that every module has a key in the map.
moduleDependenciesMap.put(moduleName, BASE_MODULE_NAME.getName());
}
return Multimaps.unmodifiableMultimap(moduleDependenciesMap);
}
use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class ApkSerializerManager method getAssetModuleMetadata.
private AssetModuleMetadata getAssetModuleMetadata(BundleModule module) {
AndroidManifest manifest = module.getAndroidManifest();
AssetModuleMetadata.Builder metadataBuilder = AssetModuleMetadata.newBuilder().setName(module.getName().getName());
Optional<ManifestDeliveryElement> persistentDelivery = manifest.getManifestDeliveryElement();
metadataBuilder.setDeliveryType(persistentDelivery.map(delivery -> getDeliveryType(delivery)).orElse(DeliveryType.INSTALL_TIME));
// The module is instant if either the dist:instant attribute is true or the
// dist:instant-delivery element is present.
boolean isInstantModule = module.isInstantModule();
InstantMetadata.Builder instantMetadataBuilder = InstantMetadata.newBuilder().setIsInstant(isInstantModule);
// The ManifestDeliveryElement is present if the dist:instant-delivery element is used.
Optional<ManifestDeliveryElement> instantDelivery = manifest.getInstantManifestDeliveryElement();
if (isInstantModule) {
// If it's an instant-enabled module, the instant delivery is on-demand if the dist:instant
// attribute was set to true or if the dist:instant-delivery element was used without an
// install-time element.
instantMetadataBuilder.setDeliveryType(instantDelivery.map(delivery -> getDeliveryType(delivery)).orElse(DeliveryType.ON_DEMAND));
}
metadataBuilder.setInstantMetadata(instantMetadataBuilder.build());
return metadataBuilder.build();
}
use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class FusingAndroidManifestMerger method ensureOneManifestPerModule.
private static ImmutableMap<BundleModuleName, AndroidManifest> ensureOneManifestPerModule(SetMultimap<BundleModuleName, AndroidManifest> manifests) {
ImmutableMap.Builder<BundleModuleName, AndroidManifest> builder = ImmutableMap.builder();
for (BundleModuleName moduleName : manifests.keys()) {
Set<AndroidManifest> moduleManifests = manifests.get(moduleName);
if (moduleManifests.size() != 1) {
throw CommandExecutionException.builder().withInternalMessage("Expected exactly one %s module manifest, but found %d.", moduleName.getName(), moduleManifests.size()).build();
}
builder.put(moduleName, Iterables.getOnlyElement(moduleManifests));
}
return builder.build();
}
Aggregations