Fix minSdkVersion scanning to not throw warnings

For the UTF8/UTF16 switch code, we needed to know what was the
minSdkVersion specified as early as possible. Unfortunately, this threw
warnings when the SDK was compiling since we always set this field in
the Bundle.

This splits out the field used by the initial AndroidManifest.xml scan
to a separate one that we won't attempt to re-insert into the
AndroidManifest.xml  This also switches the logic to better reflect the
preference of UTF-8 over UTF-16; previously UTF-16 was the default.

Change-Id: Ia81f6b21047043ebb711eb24c2c3718534979ef6
diff --git a/tools/aapt/Resource.cpp b/tools/aapt/Resource.cpp
index c0ebb59..87f2420 100644
--- a/tools/aapt/Resource.cpp
+++ b/tools/aapt/Resource.cpp
@@ -226,7 +226,7 @@
                 if (minSdkIndex >= 0) {
                     const uint16_t* minSdk16 = block.getAttributeStringValue(minSdkIndex, &len);
                     const char* minSdk8 = strdup(String8(minSdk16).string());
-                    bundle->setMinSdkVersion(minSdk8);
+                    bundle->setManifestMinSdkVersion(minSdk8);
                 }
             }
         }
@@ -768,7 +768,13 @@
 
     // Standard flags for compiled XML and optional UTF-8 encoding
     int xmlFlags = XML_COMPILE_STANDARD_RESOURCE;
-    if (bundle->getUTF8()) {
+
+    /* Only enable UTF-8 if the caller of aapt didn't specifically
+     * request UTF-16 encoding and the parameters of this package
+     * allow UTF-8 to be used.
+     */
+    if (!bundle->getWantUTF16()
+            && bundle->isUTF8Available()) {
         xmlFlags |= XML_COMPILE_UTF8;
     }