Idmap format changes for bidirectional lookup

This change modifies the idmap file format to allow for target resources
to map to arbitrary type/value combinations and to allow overlay
resources to be mapped back to target resource ids so references to
overlay resources can appear as references to target resources at
runtime.

The mappings of target resources to overlay resources and vice-versa are
both encoded as sparse arrays. Instead of looking up a resource by
indexing into an array that maps to the overlay resource id, the runtime
will binary search over the sparse array to find the type and value that
overlays the target resource.

Bug: 135943783
Test: idmap2_tests
Change-Id: I5d5344cdb7fe35f4f2e8d6781016299dea5d1e20
diff --git a/cmds/idmap2/libidmap2/ResourceUtils.cpp b/cmds/idmap2/libidmap2/ResourceUtils.cpp
index 9d32692..a5df746 100644
--- a/cmds/idmap2/libidmap2/ResourceUtils.cpp
+++ b/cmds/idmap2/libidmap2/ResourceUtils.cpp
@@ -33,6 +33,40 @@
 
 namespace android::idmap2::utils {
 
+StringPiece DataTypeToString(uint8_t data_type) {
+  switch (data_type) {
+    case Res_value::TYPE_NULL:
+      return "null";
+    case Res_value::TYPE_REFERENCE:
+      return "reference";
+    case Res_value::TYPE_ATTRIBUTE:
+      return "attribute";
+    case Res_value::TYPE_STRING:
+      return "string";
+    case Res_value::TYPE_FLOAT:
+      return "float";
+    case Res_value::TYPE_DIMENSION:
+      return "dimension";
+    case Res_value::TYPE_FRACTION:
+      return "fraction";
+    case Res_value::TYPE_DYNAMIC_REFERENCE:
+      return "reference (dynamic)";
+    case Res_value::TYPE_DYNAMIC_ATTRIBUTE:
+      return "attribute (dynamic)";
+    case Res_value::TYPE_INT_DEC:
+    case Res_value::TYPE_INT_HEX:
+      return "integer";
+    case Res_value::TYPE_INT_BOOLEAN:
+      return "boolean";
+    case Res_value::TYPE_INT_COLOR_ARGB8:
+    case Res_value::TYPE_INT_COLOR_RGB8:
+    case Res_value::TYPE_INT_COLOR_RGB4:
+      return "color";
+    default:
+      return "unknown";
+  }
+}
+
 Result<std::string> ResToTypeEntryName(const AssetManager2& am, uint32_t resid) {
   AssetManager2::ResourceName name;
   if (!am.GetResourceName(resid, &name)) {
@@ -129,7 +163,7 @@
     info.requiredSystemPropertyName = *result_str;
   }
 
-   if (auto result_str = overlay_it->GetAttributeStringValue("requiredSystemPropertyValue")) {
+  if (auto result_str = overlay_it->GetAttributeStringValue("requiredSystemPropertyValue")) {
     info.requiredSystemPropertyValue = *result_str;
   }