// utility method to create or get an existing use-sdk xml element under manifest.
    // this could be made more generic by adding more metadata to the enum but since there is
    // only one case so far, keep it simple.
    private static XmlElement createOrGetUseSdk(
        ActionRecorder actionRecorder, XmlDocument document) {

      Element manifest = document.getXml().getDocumentElement();
      NodeList usesSdks =
          manifest.getElementsByTagName(ManifestModel.NodeTypes.USES_SDK.toXmlName());
      if (usesSdks.getLength() == 0) {
        usesSdks =
            manifest.getElementsByTagNameNS(
                SdkConstants.ANDROID_URI, ManifestModel.NodeTypes.USES_SDK.toXmlName());
      }
      if (usesSdks.getLength() == 0) {
        // create it first.
        Element useSdk =
            manifest.getOwnerDocument().createElement(ManifestModel.NodeTypes.USES_SDK.toXmlName());
        manifest.appendChild(useSdk);
        XmlElement xmlElement = new XmlElement(useSdk, document);
        Actions.NodeRecord nodeRecord =
            new Actions.NodeRecord(
                Actions.ActionType.INJECTED,
                new Actions.ActionLocation(xmlElement.getSourceLocation(), PositionImpl.UNKNOWN),
                xmlElement.getId(),
                "use-sdk injection requested",
                NodeOperationType.STRICT);
        actionRecorder.recordNodeAction(xmlElement, nodeRecord);
        return xmlElement;
      } else {
        return new XmlElement((Element) usesSdks.item(0), document);
      }
    }
    // utility method to add an attribute which name is derived from the enum name().
    private static void addToElement(
        SystemProperty systemProperty, ActionRecorder actionRecorder, String value, XmlElement to) {

      to.getXml().setAttribute(systemProperty.toCamelCase(), value);
      XmlAttribute xmlAttribute =
          new XmlAttribute(to, to.getXml().getAttributeNode(systemProperty.toCamelCase()), null);
      actionRecorder.recordAttributeAction(
          xmlAttribute,
          new Actions.AttributeRecord(
              Actions.ActionType.INJECTED,
              new Actions.ActionLocation(to.getSourceLocation(), PositionImpl.UNKNOWN),
              xmlAttribute.getId(),
              null, /* reason */
              null /* attributeOperationType */));
    }
    // utility method to add an attribute in android namespace which local name is derived from
    // the enum name().
    private static void addToElementInAndroidNS(
        SystemProperty systemProperty, ActionRecorder actionRecorder, String value, XmlElement to) {

      String toolsPrefix = getAndroidPrefix(to.getXml());
      to.getXml()
          .setAttributeNS(
              SdkConstants.ANDROID_URI,
              toolsPrefix + XmlUtils.NS_SEPARATOR + systemProperty.toCamelCase(),
              value);
      Attr attr =
          to.getXml().getAttributeNodeNS(SdkConstants.ANDROID_URI, systemProperty.toCamelCase());

      XmlAttribute xmlAttribute = new XmlAttribute(to, attr, null);
      actionRecorder.recordAttributeAction(
          xmlAttribute,
          new Actions.AttributeRecord(
              Actions.ActionType.INJECTED,
              new Actions.ActionLocation(to.getSourceLocation(), PositionImpl.UNKNOWN),
              xmlAttribute.getId(),
              null, /* reason */
              null /* attributeOperationType */));
    }