Improve support for external keyboards.

Use Vendor ID, Product ID and optionally the Version to
locate keymaps and configuration files for external devices.

Moved virtual key definition parsing to native code so that
EventHub can identify touch screens with virtual keys and load
the appropriate key layout file.

Cleaned up a lot of old code in EventHub.

Fixed a regression in ViewRoot's fallback event handling.

Fixed a minor bug in FileMap that caused it to try to munmap
or close invalid handled when released if the attempt to map
the file failed.

Added a couple of new String8 conveniences for formatting strings.

Modified Tokenizer to fall back to open+read when mmap fails since
we can't mmap sysfs files as needed to open the virtual key
definition files in /sys/board_properties/.

Change-Id: I6ca5e5f9547619fd082ddac47e87ce185da69ee6
diff --git a/tools/validatekeymaps/Main.cpp b/tools/validatekeymaps/Main.cpp
index 6ec223b..097b109 100644
--- a/tools/validatekeymaps/Main.cpp
+++ b/tools/validatekeymaps/Main.cpp
@@ -16,6 +16,7 @@
 
 #include <ui/KeyCharacterMap.h>
 #include <ui/KeyLayoutMap.h>
+#include <ui/VirtualKeyMap.h>
 #include <utils/String8.h>
 
 #include <stdio.h>
@@ -30,6 +31,7 @@
     FILETYPE_UNKNOWN,
     FILETYPE_KEYLAYOUT,
     FILETYPE_KEYCHARACTERMAP,
+    FILETYPE_VIRTUALKEYDEFINITION,
 };
 
 
@@ -37,8 +39,10 @@
     fprintf(stderr, "Keymap Validation Tool\n\n");
     fprintf(stderr, "Usage:\n");
     fprintf(stderr,
-        " %s [FILENAME.kl] [FILENAME.kcm] [...]\n"
-        "   Validates the specified key layout and/or key character map files.\n\n", gProgName);
+        " %s [*.kl] [*.kcm] [virtualkeys.*] [...]\n"
+        "   Validates the specified key layouts, key character maps \n"
+        "   or virtual key definitions.\n\n",
+        gProgName);
 }
 
 static FileType getFileType(const char* filename) {
@@ -51,6 +55,11 @@
             return FILETYPE_KEYCHARACTERMAP;
         }
     }
+
+    if (strstr(filename, "virtualkeys.")) {
+        return FILETYPE_VIRTUALKEYDEFINITION;
+    }
+
     return FILETYPE_UNKNOWN;
 }
 
@@ -60,7 +69,7 @@
     FileType fileType = getFileType(filename);
     switch (fileType) {
     case FILETYPE_UNKNOWN:
-        fprintf(stderr, "File extension must be .kl or .kcm.\n\n");
+        fprintf(stderr, "Supported file types: *.kl, *.kcm, virtualkeys.*\n\n");
         return false;
 
     case FILETYPE_KEYLAYOUT: {
@@ -82,6 +91,16 @@
         }
         break;
     }
+
+    case FILETYPE_VIRTUALKEYDEFINITION: {
+        VirtualKeyMap* map;
+        status_t status = VirtualKeyMap::load(String8(filename), &map);
+        if (status) {
+            fprintf(stderr, "Error %d parsing virtual key definition file.\n\n", status);
+            return false;
+        }
+        break;
+    }
     }
 
     fputs("No errors.\n\n", stdout);