AAPT2: XML schema and an example configuraiton

The current iteration of the schema allows for both Split and Optimize
commands running off the same file. A split command is multiple optimize
command, and an optimize is a split with only a single artifact. To
combine the two, a single file with one or more artifacts can be passed
to either command. If multiple artifiacts are used for an optimize
command, the required artifact can be specified on the command line. A
configuration with only a single artifact can be used with either
command to get the same result.

Change-Id: Ie48eda6e2f9f8bf25d75ef7bcc3b3401a2d3e8eb
Bugs: 37847908
Test: xmllint --noout --schema aapt2.xsd example/config.xml
diff --git a/tools/aapt2/configuration/aapt2.xsd b/tools/aapt2/configuration/aapt2.xsd
new file mode 100644
index 0000000..47bf99e
--- /dev/null
+++ b/tools/aapt2/configuration/aapt2.xsd
@@ -0,0 +1,146 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<xsd:schema
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+    elementFormDefault="qualified"
+    xmlns="http://schemas.android.com/tools/aapt2"
+    targetNamespace="http://schemas.android.com/tools/aapt2">
+
+  <xsd:element name="post-process">
+    <xsd:complexType>
+      <xsd:sequence>
+        <xsd:element name="groups" type="groups"/>
+        <xsd:element name="artifacts" type="artifacts"/>
+      </xsd:sequence>
+    </xsd:complexType>
+  </xsd:element>
+
+  <xsd:complexType name="groups">
+    <xsd:sequence>
+      <xsd:element name="abi-group" type="abi-group" maxOccurs="unbounded"/>
+      <xsd:element name="screen-density-group" type="screen-density-group" maxOccurs="unbounded"/>
+      <xsd:element name="locale-group" type="locale-group" maxOccurs="unbounded"/>
+      <xsd:element name="android-sdk-group" type="android-sdk-group" maxOccurs="unbounded"/>
+      <xsd:element
+          name="gl-texture-group"
+          type="gl-texture-group"
+          maxOccurs="unbounded"/>
+      <xsd:element name="device-feature-group" type="device-feature-group" maxOccurs="unbounded"/>
+    </xsd:sequence>
+  </xsd:complexType>
+
+  <xsd:complexType name="artifacts">
+    <xsd:sequence>
+      <xsd:element name="artifact-format" type="xsd:string"/>
+      <xsd:element name="artifact" type="artifact" maxOccurs="unbounded"/>
+    </xsd:sequence>
+    <xsd:attribute name="generate-all" type="xsd:boolean"/>
+  </xsd:complexType>
+
+  <!-- Groups output artifacts together by dimension labels. -->
+  <xsd:complexType name="artifact">
+    <xsd:attribute name="name" type="xsd:string"/>
+    <xsd:attribute name="abi-group" type="xsd:string"/>
+    <xsd:attribute name="android-sdk-group" type="xsd:string"/>
+    <xsd:attribute name="device-feature-group" type="xsd:string"/>
+    <xsd:attribute name="gl-texture-group" type="xsd:string"/>
+    <xsd:attribute name="screen-density-group" type="xsd:string"/>
+    <xsd:attribute name="locale-group" type="xsd:string"/>
+  </xsd:complexType>
+
+  <xsd:complexType name="gl-texture-group">
+    <xsd:sequence>
+      <xsd:element name="gl-texture" type="gl-texture" maxOccurs="unbounded"/>
+    </xsd:sequence>
+    <xsd:attribute name="label" type="xsd:string" use="optional"/>
+  </xsd:complexType>
+
+  <xsd:complexType name="gl-texture">
+    <xsd:sequence>
+      <xsd:element name="texture-path" type="xsd:string" maxOccurs="unbounded"/>
+    </xsd:sequence>
+    <xsd:attribute name="name" type="xsd:string" use="required"/>
+  </xsd:complexType>
+
+  <xsd:complexType name="device-feature-group">
+    <xsd:sequence>
+      <xsd:element name="supports-feature" type="xsd:string" maxOccurs="unbounded"/>
+    </xsd:sequence>
+    <xsd:attribute name="label" type="xsd:string" use="optional"/>
+  </xsd:complexType>
+
+  <xsd:complexType name="abi-group">
+    <xsd:sequence>
+      <xsd:element name="abi" type="abi-name" maxOccurs="unbounded"/>
+    </xsd:sequence>
+    <xsd:attribute name="label" type="xsd:string" use="optional"/>
+  </xsd:complexType>
+
+  <xsd:simpleType name="abi-name">
+    <xsd:restriction base="xsd:string">
+      <xsd:enumeration value="armeabi"/>
+      <xsd:enumeration value="armeabi-v7a"/>
+      <xsd:enumeration value="arm64-v8a"/>
+      <xsd:enumeration value="x86"/>
+      <xsd:enumeration value="x86_64"/>
+      <xsd:enumeration value="mips"/>
+      <xsd:enumeration value="mips64"/>
+      <xsd:enumeration value="fat"/>
+    </xsd:restriction>
+  </xsd:simpleType>
+
+  <xsd:complexType name="screen-density-group">
+    <xsd:sequence>
+      <xsd:element name="screen-density" type="screen-density" maxOccurs="unbounded"/>
+    </xsd:sequence>
+    <xsd:attribute name="label" type="xsd:string" use="optional"/>
+  </xsd:complexType>
+
+  <xsd:simpleType name="screen-density">
+    <xsd:restriction base="xsd:string">
+      <xsd:enumeration value="alldpi"/>
+      <xsd:enumeration value="ldpi"/>
+      <xsd:enumeration value="mdpi"/>
+      <xsd:enumeration value="hdpi"/>
+      <xsd:enumeration value="xhdpi"/>
+      <xsd:enumeration value="xxhdpi"/>
+      <xsd:enumeration value="xxxhdpi"/>
+    </xsd:restriction>
+  </xsd:simpleType>
+
+  <xsd:complexType name="android-sdk-group">
+    <xsd:sequence>
+      <xsd:element name="android-sdk" type="android-sdk" maxOccurs="unbounded"/>
+    </xsd:sequence>
+    <xsd:attribute name="label" type="xsd:string" use="optional"/>
+  </xsd:complexType>
+
+  <xsd:complexType name="android-sdk">
+    <!-- TODO(safarmer): Add permissions to add/remove. -->
+    <!-- TODO(safarmer): Add option for uncompressed native libs. -->
+    <xsd:sequence>
+      <xsd:element name="manifest" type="manifest"/>
+    </xsd:sequence>
+    <xsd:attribute name="minSdkVersion" type="xsd:integer"/>
+    <xsd:attribute name="targetSdkVersion" type="xsd:integer"/>
+    <xsd:attribute name="maxSdkVersion" type="xsd:integer"/>
+  </xsd:complexType>
+
+  <!-- TODO(safarmer): Figure out the best way to handle manifest updates. -->
+  <xsd:simpleType name="manifest">
+    <xsd:restriction base="xsd:string"/>
+  </xsd:simpleType>
+
+  <xsd:complexType name="locale-group">
+    <xsd:sequence>
+      <xsd:element name="locale" type="locale" maxOccurs="unbounded"/>
+    </xsd:sequence>
+    <xsd:attribute name="label" type="xsd:string" use="optional"/>
+  </xsd:complexType>
+
+  <xsd:complexType name="locale">
+    <xsd:attribute name="lang" type="xsd:string"/>
+    <xsd:attribute name="region" type="xsd:string"/>
+    <xsd:attribute name="compressed" type="xsd:boolean"/>
+  </xsd:complexType>
+
+</xsd:schema>
diff --git a/tools/aapt2/configuration/example/config.xml b/tools/aapt2/configuration/example/config.xml
new file mode 100644
index 0000000..a8360f8
--- /dev/null
+++ b/tools/aapt2/configuration/example/config.xml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<post-process xmlns="http://schemas.android.com/tools/aapt2">
+  <groups>
+    <abi-group label="arm">
+      <abi>armeabi-v7a</abi>
+      <abi>arm64-v8a</abi>
+    </abi-group>
+
+    <abi-group label="other">
+      <abi>x86</abi>
+      <abi>mips</abi>
+    </abi-group>
+
+    <screen-density-group label="large">
+      <screen-density>xhdpi</screen-density>
+      <screen-density>xxhdpi</screen-density>
+      <screen-density>xxxhdpi</screen-density>
+    </screen-density-group>
+
+    <screen-density-group label="alldpi">
+      <screen-density>ldpi</screen-density>
+      <screen-density>mdpi</screen-density>
+      <screen-density>hdpi</screen-density>
+      <screen-density>xhdpi</screen-density>
+      <screen-density>xxhdpi</screen-density>
+      <screen-density>xxxhdpi</screen-density>
+    </screen-density-group>
+
+    <locale-group label="europe">
+      <locale lang="en"/>
+      <locale lang="es"/>
+      <locale lang="fr"/>
+      <locale lang="de" compressed="true"/>
+    </locale-group>
+
+    <locale-group label="north-america">
+      <locale lang="en"/>
+      <locale lang="es" region="MX"/>
+      <locale lang="fr" region="CA" compressed="true"/>
+    </locale-group>
+
+    <locale-group label="all">
+      <locale compressed="true"/>
+    </locale-group>
+
+    <android-sdk-group label="19">
+      <android-sdk
+          minSdkVersion="19"
+          targetSdkVersion="24"
+          maxSdkVersion="25">
+        <manifest>
+          <!--- manifest additions here XSLT? TODO -->
+        </manifest>
+      </android-sdk>
+    </android-sdk-group>
+
+    <gl-texture-group label="dxt1">
+      <gl-texture name="GL_EXT_texture_compression_dxt1">
+        <texture-path>assets/dxt1/*</texture-path>
+      </gl-texture>
+    </gl-texture-group>
+
+    <device-feature-group label="low-latency">
+      <supports-feature>android.hardware.audio.low_latency</supports-feature>
+    </device-feature-group>
+  </groups>
+
+  <artifacts>
+    <artifact-format>
+      ${base}.${abi}.${screen-density}.${locale}.${sdk}.${gl}.${feature}.release
+    </artifact-format>
+
+    <artifact
+        abi-group="arm"
+        screen-density-group="large"
+        locale-group="europe"
+        android-sdk-group="19"
+        gl-texture-group="dxt1"
+        device-feature-group="low-latency"/>
+
+    <artifact
+        abi-group="other"
+        screen-density-group="alldpi"
+        locale-group="north-america"
+        android-sdk-group="19"
+        gl-texture-group="dxt1"
+        device-feature-group="low-latency"/>
+
+  </artifacts>
+</post-process>