AAPT2: Sort artifacts based on the Play Store rules.

Sort output artifacts so that the updated versionCode manifest entry
will allow correct handling of updates from Play Store. The most
important dimension is Android SDK version. It is important that a split
based on min SDK version will allow a user to get a new APK if they
upgrade the OS on their device to support a new split.

ABI splits need to also be taken into consideration as it is possible
for a device to run in ARM emulation mode and installing an ARM APK over
a x86 APK could cause performance regressions.

The XML file format was updated to give each of the configuration groups
have their own section of the XML file. This allows the sort order to be
determined by a groups ordering. Artifacts can now be added to the
configuration file in an arbitrary order. Since this will be the common
case for developers, it will help reduce errors from inserting a new
artifact in the wrong spot.

The implementation follows the rules outlined at:
https://developer.android.com/google/play/publishing/multiple-apks.html

Test: Unit tests
Test: Manual process XML configuration

Change-Id: I0face862c6d6b9d3cd2d99088afe5b9491be0120
diff --git a/tools/aapt2/configuration/ConfigurationParser.h b/tools/aapt2/configuration/ConfigurationParser.h
index ca58910..7f1d445 100644
--- a/tools/aapt2/configuration/ConfigurationParser.h
+++ b/tools/aapt2/configuration/ConfigurationParser.h
@@ -71,7 +71,8 @@
 };
 
 struct AndroidSdk {
-  Maybe<int> min_sdk_version;
+  std::string label;
+  int min_sdk_version;  // min_sdk_version is mandatory if splitting by SDK.
   Maybe<int> target_sdk_version;
   Maybe<int> max_sdk_version;
   Maybe<AndroidManifest> manifest;
@@ -113,15 +114,19 @@
   Maybe<AndroidSdk> android_sdk;
   std::vector<DeviceFeature> features;
   std::vector<GlTexture> textures;
+
+  inline int GetMinSdk(int default_value = -1) const {
+    if (!android_sdk) {
+      return default_value;
+    }
+    return android_sdk.value().min_sdk_version;
+  }
 };
 
 }  // namespace configuration
 
 // Forward declaration of classes used in the API.
 struct IDiagnostics;
-namespace xml {
-class Element;
-}
 
 /**
  * XML configuration file parser for the split and optimize commands.
@@ -133,8 +138,8 @@
   static Maybe<ConfigurationParser> ForPath(const std::string& path);
 
   /** Returns a ConfigurationParser for the configuration in the provided file contents. */
-  static ConfigurationParser ForContents(const std::string& contents) {
-    ConfigurationParser parser{contents};
+  static ConfigurationParser ForContents(const std::string& contents, const std::string& path) {
+    ConfigurationParser parser{contents, path};
     return parser;
   }
 
@@ -156,7 +161,7 @@
    * diagnostics context. The default diagnostics context can be overridden with a call to
    * WithDiagnostics(IDiagnostics *).
    */
-  explicit ConfigurationParser(std::string contents);
+  ConfigurationParser(std::string contents, const std::string& config_path);
 
   /** Returns the current diagnostics context to any subclasses. */
   IDiagnostics* diagnostics() {
@@ -166,6 +171,8 @@
  private:
   /** The contents of the configuration file to parse. */
   const std::string contents_;
+  /** Path to the input configuration. */
+  const std::string config_path_;
   /** The diagnostics context to send messages to. */
   IDiagnostics* diag_;
 };