use of com.android.aapt.Resources.XmlAttribute in project bundletool by google.
the class ManifestEditorTest method copyPermissionGroups.
@Test
public void copyPermissionGroups() throws Exception {
XmlElement permisisonGroupElement = xmlElement("permission-group", xmlAttribute(ANDROID_NAMESPACE_URI, "name", NAME_RESOURCE_ID, "group.1"));
AndroidManifest manifestWithPermissionGroups = AndroidManifest.create(xmlNode(xmlElement("manifest", xmlNode(permisisonGroupElement))));
AndroidManifest manifestToUpdate = AndroidManifest.create(androidManifest("com.test.app"));
AndroidManifest updatedManifest = manifestToUpdate.toEditor().copyPermissionGroups(manifestWithPermissionGroups).save();
ImmutableList<XmlElement> copiedPermissionGroups = updatedManifest.getManifestRoot().getProto().getElement().getChildList().stream().map(XmlNode::getElement).filter(childElement -> childElement.getName().equals("permission-group")).collect(toImmutableList());
assertThat(copiedPermissionGroups).containsExactly(permisisonGroupElement);
}
use of com.android.aapt.Resources.XmlAttribute in project bundletool by google.
the class ManifestEditorTest method copyPermissions.
@Test
public void copyPermissions() throws Exception {
XmlElement permisisonElement = xmlElement("permission", xmlAttribute(ANDROID_NAMESPACE_URI, "name", NAME_RESOURCE_ID, "SEND_SMS"));
AndroidManifest manifestWithPermissions = AndroidManifest.create(xmlNode(xmlElement("manifest", xmlNode(permisisonElement))));
AndroidManifest manifestToUpdate = AndroidManifest.create(androidManifest("com.test.app"));
AndroidManifest updatedManifest = manifestToUpdate.toEditor().copyPermissions(manifestWithPermissions).save();
ImmutableList<XmlElement> copiedPermissions = updatedManifest.getManifestRoot().getProto().getElement().getChildList().stream().map(XmlNode::getElement).filter(childElement -> childElement.getName().equals("permission")).collect(toImmutableList());
assertThat(copiedPermissions).containsExactly(permisisonElement);
}
use of com.android.aapt.Resources.XmlAttribute in project bundletool by google.
the class XmlProtoElementBuilderTest method getAttributeIgnoringNamespace_duplicate.
@Test
public void getAttributeIgnoringNamespace_duplicate() {
XmlAttribute attribute = XmlAttribute.newBuilder().setName("attribute").build();
XmlElement protoElement = XmlElement.newBuilder().addAttribute(attribute).addAttribute(attribute).build();
XmlProtoElementBuilder element = new XmlProtoElementBuilder(protoElement.toBuilder());
XmlProtoAttributeBuilder fetchedAttribute = element.getAttributeIgnoringNamespace("attribute").get();
assertThat(fetchedAttribute.getProto().build()).isEqualTo(attribute);
assertThat(element.getProto().build()).isEqualTo(protoElement);
}
use of com.android.aapt.Resources.XmlAttribute in project bundletool by google.
the class XmlProtoElementBuilderTest method getOrCreateAndroidAttribute_attributeDoesNotExist.
@Test
public void getOrCreateAndroidAttribute_attributeDoesNotExist() {
XmlAttribute attributeNotAndroid = XmlAttribute.newBuilder().setName("attribute").setNamespaceUri("namespace").setResourceId(0x123).build();
XmlAttribute attributeAndroid = XmlAttribute.newBuilder().setName("attribute").setNamespaceUri(ANDROID_NAMESPACE_URI).setResourceId(0x123).build();
XmlAttribute attributeNoNamespace = XmlAttribute.newBuilder().setName("attribute").setResourceId(0x123).build();
XmlProtoElementBuilder element = new XmlProtoElementBuilder(XmlElement.newBuilder().addAttribute(attributeNotAndroid).addAttribute(attributeNoNamespace));
XmlProtoAttributeBuilder fetchedAttribute = element.getOrCreateAndroidAttribute("attribute", 0x123);
assertThat(fetchedAttribute.getProto().build()).isEqualTo(attributeAndroid);
assertThat(element.getProto().build()).isEqualTo(XmlElement.newBuilder().addAttribute(attributeNotAndroid).addAttribute(attributeNoNamespace).addAttribute(attributeAndroid).build());
}
use of com.android.aapt.Resources.XmlAttribute in project bundletool by google.
the class XmlProtoElementBuilderTest method getOrCreateAttribute_attributeDiffersByNamespace.
@Test
public void getOrCreateAttribute_attributeDiffersByNamespace() {
XmlAttribute attrWithoutNamespace = XmlAttribute.newBuilder().setName("attribute").build();
XmlAttribute attrWithNamespace = XmlAttribute.newBuilder().setName("attribute").setNamespaceUri("namespace").build();
XmlProtoElementBuilder element = new XmlProtoElementBuilder(XmlElement.newBuilder().addAttribute(attrWithNamespace));
XmlProtoAttributeBuilder fetchedAttribute = element.getOrCreateAttribute("attribute");
assertThat(fetchedAttribute.getProto().build()).isEqualTo(attrWithoutNamespace);
assertThat(element.getProto().build()).isEqualTo(XmlElement.newBuilder().addAttribute(attrWithNamespace).addAttribute(attrWithoutNamespace).build());
}
Aggregations