use of com.android.tools.build.bundletool.model.AndroidManifest.NAME_RESOURCE_ID in project bundletool by google.
the class ManifestEditor method setMetadataValue.
private ManifestEditor setMetadataValue(String name, XmlProtoAttributeBuilder valueAttr) {
XmlProtoElementBuilder applicationEl = manifestElement.getOrCreateChildElement(APPLICATION_ELEMENT_NAME);
Optional<XmlProtoElementBuilder> existingMetadataEl = applicationEl.getChildrenElements(META_DATA_ELEMENT_NAME).filter(metadataEl -> metadataEl.getAndroidAttribute(NAME_RESOURCE_ID).map(nameAttr -> name.equals(nameAttr.getValueAsString())).orElse(false)).collect(toOptional());
if (existingMetadataEl.isPresent()) {
existingMetadataEl.get().removeAndroidAttribute(VALUE_RESOURCE_ID).addAttribute(valueAttr);
} else {
applicationEl.addChildElement(XmlProtoElementBuilder.create(META_DATA_ELEMENT_NAME).addAttribute(createAndroidAttribute("name", NAME_RESOURCE_ID).setValueAsString(name)).addAttribute(valueAttr));
}
return this;
}
use of com.android.tools.build.bundletool.model.AndroidManifest.NAME_RESOURCE_ID 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.tools.build.bundletool.model.AndroidManifest.NAME_RESOURCE_ID 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);
}
Aggregations