use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ResourceAnalyzer method findAllReferencedAppResources.
private ImmutableSet<ResourceId> findAllReferencedAppResources(Item item) {
switch(item.getValueCase()) {
case REF:
if (item.getRef().getId() != 0) {
return ImmutableSet.of(ResourceId.create(item.getRef().getId()));
}
// we don't need to consider it.
break;
case FILE:
FileReference fileRef = item.getFile();
if (!fileRef.getType().equals(FileReference.Type.PROTO_XML)) {
return ImmutableSet.of();
}
ZipPath xmlResourcePath = ZipPath.create(fileRef.getPath());
try (InputStream is = appBundle.getBaseModule().getEntry(xmlResourcePath).get().getContent().openStream()) {
XmlNode xmlRoot = XmlNode.parseFrom(is);
return findAllReferencedAppResources(xmlRoot);
} catch (InvalidProtocolBufferException e) {
throw CommandExecutionException.builder().withInternalMessage("Error parsing XML file '%s'.", xmlResourcePath).withCause(e).build();
} catch (IOException e) {
throw new UncheckedIOException(String.format("Failed to parse file '%s' in base module.", xmlResourcePath), e);
}
default:
break;
}
return ImmutableSet.of();
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ModuleSplitterTest method applicationElementAdded.
@Test
public void applicationElementAdded() throws Exception {
XmlNode manifest = androidManifest("com.test.app", clearApplication());
checkState(!AndroidManifest.create(manifest).hasApplicationElement(), "Expected manifest with no <application> element.");
BundleModule bundleModule = new BundleModuleBuilder("testModule").setManifest(manifest).build();
ImmutableList<ModuleSplit> moduleSplits = ModuleSplitter.createForTest(bundleModule, BUNDLETOOL_VERSION).splitModule();
assertThat(moduleSplits).hasSize(1);
ModuleSplit masterSplit = moduleSplits.get(0);
assertThat(masterSplit.getAndroidManifest().getManifestRoot().getElement().getOptionalChildElement(APPLICATION_ELEMENT_NAME)).isPresent();
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ResourceAnalyzerTest method emptyManifest.
@Test
public void emptyManifest() throws Exception {
XmlNode manifest = androidManifest("com.app");
ResourceTable resourceTable = resourceTable(pkg(0x7f, "com.test.app", type(0x01, "string", entry(0x0099, "not_referenced", value("", DEFAULT_CONFIG)))));
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(manifest).setResourceTable(resourceTable)).build();
ImmutableSet<ResourceId> resourceIds = new ResourceAnalyzer(appBundle).findAllAppResourcesReachableFromBaseManifest();
assertThat(resourceIds).isEmpty();
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ResourceAnalyzerTest method transitive_compoundValue_attribute.
@Test
public void transitive_compoundValue_attribute() throws Exception {
// AndroidManifest --> 0x7f01000 (attr) --> 0x7f020002 (string)
// |-> 0x7f020003 (string)
XmlNode manifest = AndroidManifest.create(xmlNode(xmlElement("manifest", xmlNode(xmlElement("application", xmlResourceReferenceAttribute(NO_NAMESPACE_URI, "xml_attribute_confusingly_pointing_to_a_resource_attribute", /* attrResourceId= */
0x999999, /* valueResourceId= */
0x7f010001)))))).getManifestRoot().getProto();
ResourceTable resourceTable = resourceTable(pkg(0x7f, "com.test.app", type(0x01, "attr", entry(0x0001, "some_attr", compoundValueAttrWithResourceReferences(0x7f020002, 0x7f020003))), type(0x02, "string", entry(0x0002, "str1", value("hello", DEFAULT_CONFIG)), entry(0x0003, "str2", value("hello", DEFAULT_CONFIG)), entry(0x0099, "not_referenced", value("", DEFAULT_CONFIG)))));
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(manifest).setResourceTable(resourceTable)).build();
ImmutableSet<ResourceId> resourceIds = new ResourceAnalyzer(appBundle).findAllAppResourcesReachableFromBaseManifest();
assertThat(resourceIds).containsExactly(ResourceId.create(0x7f010001), ResourceId.create(0x7f020002), ResourceId.create(0x7f020003));
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class ResourceAnalyzerTest method attributeWithCompiledItem_refToUnknownResourceInBase_ignored.
@Test
public void attributeWithCompiledItem_refToUnknownResourceInBase_ignored() throws Exception {
XmlNode manifest = AndroidManifest.create(xmlNode(xmlElement("manifest", xmlNode(xmlElement("application", xmlResourceReferenceAttribute(ANDROID_NAMESPACE_URI, "name", /* attrResourceId= */
0x999999, /* valueResourceId= */
0x12345678)))))).getManifestRoot().getProto();
ResourceTable resourceTable = resourceTable(pkg(0x12, "com.test.app.feature", type(0x34, "string", entry(0x5678, "name", value("hello", DEFAULT_CONFIG)))));
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(manifest)).addModule("feature", builder -> builder.setManifest(androidManifest("com.test.app.feature")).setResourceTable(resourceTable)).build();
ImmutableSet<ResourceId> resourceIds = new ResourceAnalyzer(appBundle).findAllAppResourcesReachableFromBaseManifest();
assertThat(resourceIds).isEmpty();
}
Aggregations