use of com.android.tools.build.bundletool.model.AndroidManifest.NO_NAMESPACE_URI 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.tools.build.bundletool.model.AndroidManifest.NO_NAMESPACE_URI in project bundletool by google.
the class ResourceAnalyzerTest method transitive_deepChain.
@Test
public void transitive_deepChain() throws Exception {
// AndroidManifest
// --> 0x7f010001 (ref) --> 0x7f010002 (ref) --> 0x7f010003 (ref) --> 0x7f020004 (string)
XmlNode manifest = AndroidManifest.create(xmlNode(xmlElement("manifest", xmlNode(xmlElement("application", xmlResourceReferenceAttribute(NO_NAMESPACE_URI, "attribute_pointint_to_a_ref", /* attrResourceId= */
0x999999, /* valueResourceId= */
0x7f010001)))))).getManifestRoot().getProto();
ResourceTable resourceTable = resourceTable(pkg(0x7f, "com.test.app", type(0x01, "ref", entry(0x0001, "ref1", reference(0x7f010002, DEFAULT_CONFIG)), entry(0x0002, "ref2", reference(0x7f010003, DEFAULT_CONFIG)), entry(0x0003, "ref3", reference(0x7f020004, DEFAULT_CONFIG))), type(0x02, "string", entry(0x0004, "name_str", 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(0x7f010002), ResourceId.create(0x7f010003), ResourceId.create(0x7f020004));
}
use of com.android.tools.build.bundletool.model.AndroidManifest.NO_NAMESPACE_URI in project bundletool by google.
the class ResourceAnalyzerTest method transitive_item_ref.
@Test
public void transitive_item_ref() throws Exception {
// AndroidManifest --> 0x7f010001 (ref) --> 0x7f020002 (string)
XmlNode manifest = AndroidManifest.create(xmlNode(xmlElement("manifest", xmlNode(xmlElement("application", xmlResourceReferenceAttribute(NO_NAMESPACE_URI, "some_attribute_pointing_to_a_ref", /* attrResourceId= */
0x999999, /* valueResourceId= */
0x7f010001)))))).getManifestRoot().getProto();
ResourceTable resourceTable = resourceTable(pkg(0x7f, "com.test.app", type(0x01, "ref", entry(0x0001, "name_ref", reference(0x7f020002, DEFAULT_CONFIG))), type(0x02, "string", entry(0x0002, "name_str", 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));
}
use of com.android.tools.build.bundletool.model.AndroidManifest.NO_NAMESPACE_URI in project bundletool by google.
the class ResourceAnalyzerTest method attributeWithCompiledItem_nonRef_ignored.
@Test
public void attributeWithCompiledItem_nonRef_ignored() throws Exception {
XmlNode manifest = AndroidManifest.create(xmlNode(xmlElement("manifest", xmlNode(xmlElement("application", // Attributes of all possible types, except for ref.
ImmutableList.of(// str
xmlCompiledItemAttribute(NO_NAMESPACE_URI, "str", Item.newBuilder().setStr(String.getDefaultInstance()).build()), // raw_str
xmlCompiledItemAttribute(NO_NAMESPACE_URI, "raw_str", Item.newBuilder().setRawStr(RawString.getDefaultInstance()).build()), // styled_str
xmlCompiledItemAttribute(NO_NAMESPACE_URI, "styled_str", Item.newBuilder().setStyledStr(StyledString.getDefaultInstance()).build()), // file
xmlCompiledItemAttribute(NO_NAMESPACE_URI, "file", Item.newBuilder().setFile(FileReference.getDefaultInstance()).build()), // id
xmlCompiledItemAttribute(NO_NAMESPACE_URI, "id", Item.newBuilder().setId(Id.getDefaultInstance()).build()), // prim
xmlCompiledItemAttribute(NO_NAMESPACE_URI, "prim", Item.newBuilder().setPrim(Primitive.getDefaultInstance()).build()))))))).getManifestRoot().getProto();
ResourceTable resourceTable = resourceTable(pkg(0x0f, "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.tools.build.bundletool.model.AndroidManifest.NO_NAMESPACE_URI in project bundletool by google.
the class ResourceAnalyzerTest method transitive_item_xmlFileWithResourceReference.
@Test
public void transitive_item_xmlFileWithResourceReference() throws Exception {
// AndroidManifest --> 0x7f010001 (xml file) --> 0x7f020002 (string)
XmlNode manifest = AndroidManifest.create(xmlNode(xmlElement("manifest", xmlNode(xmlElement("application", xmlResourceReferenceAttribute(NO_NAMESPACE_URI, "attr_pointing_to_xml", /* attrResourceId= */
0x999999, /* valueResourceId= */
0x7f010001)))))).getManifestRoot().getProto();
XmlNode embeddedXmlFile = AndroidManifest.create(xmlNode(xmlElement("root", xmlResourceReferenceAttribute(ANDROID_NAMESPACE_URI, "name", /* attrResourceId= */
0x999999, /* valueResourceId= */
0x7f020002)))).getManifestRoot().getProto();
ResourceTable resourceTable = resourceTable(pkg(0x7f, "com.test.app", type(0x01, "file", entry(0x0001, "xml_file", fileReference("res/xml/embedded.xml", FileReference.Type.PROTO_XML, DEFAULT_CONFIG))), type(0x02, "string", entry(0x0002, "name_str", value("hello", DEFAULT_CONFIG)), entry(0x0099, "not_referenced", value("", DEFAULT_CONFIG)))));
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(manifest).setResourceTable(resourceTable).addFile("res/xml/embedded.xml", embeddedXmlFile.toByteArray())).build();
ImmutableSet<ResourceId> resourceIds = new ResourceAnalyzer(appBundle).findAllAppResourcesReachableFromBaseManifest();
assertThat(resourceIds).containsExactly(ResourceId.create(0x7f010001), ResourceId.create(0x7f020002));
}
Aggregations