AAPT2: Add support to specify stable IDs

The --stable-ids flag allows the user to specify a file containing
a list of resource name and resource ID pairs in the form of:

package:type/name = 0xPPTTEEEE

This assigns the given resource the specified ID. It helps ensure
that when adding or removing resources, IDs are assigned in a stable
fashion.

If a package, type, or name is not found, no error or warning is
raised.

Change-Id: Ibc2f4e05cc924be255fedd862d835cb5b18d7584
diff --git a/tools/aapt2/ResourceUtils.cpp b/tools/aapt2/ResourceUtils.cpp
index 31d6435a6..7dc88ded 100644
--- a/tools/aapt2/ResourceUtils.cpp
+++ b/tools/aapt2/ResourceUtils.cpp
@@ -436,6 +436,22 @@
     return false;
 }
 
+Maybe<ResourceId> tryParseResourceId(const StringPiece& str) {
+    StringPiece trimmedStr(util::trimWhitespace(str));
+
+    std::u16string str16 = util::utf8ToUtf16(trimmedStr);
+    android::Res_value value;
+    if (android::ResTable::stringToInt(str16.data(), str16.size(), &value)) {
+        if (value.dataType == android::Res_value::TYPE_INT_HEX) {
+            ResourceId id(value.data);
+            if (id.isValid()) {
+                return id;
+            }
+        }
+    }
+    return {};
+}
+
 Maybe<int> tryParseSdkVersion(const StringPiece& str) {
     StringPiece trimmedStr(util::trimWhitespace(str));