Even more native input dispatch work in progress.

Added more tests.
Fixed a regression in Vector.
Fixed bugs in pointer tracking.
Fixed a starvation issue in PollLoop when setting or removing callbacks.
Fixed a couple of policy nits.

Modified the internal representation of MotionEvent to be more
efficient and more consistent.

Added code to skip/cancel virtual key processing when there are multiple
pointers down.  This helps to better disambiguate virtual key presses
from stray touches (such as cheek presses).

Change-Id: I2a7d2cce0195afb9125b23378baa94fd2fc6671c
diff --git a/services/jni/com_android_server_InputManager.cpp b/services/jni/com_android_server_InputManager.cpp
index a988a96..ab3922f 100644
--- a/services/jni/com_android_server_InputManager.cpp
+++ b/services/jni/com_android_server_InputManager.cpp
@@ -294,9 +294,7 @@
 
     if (wmActions & WM_ACTION_PASS_TO_USER) {
         actions |= InputReaderPolicyInterface::ACTION_DISPATCH;
-    }
 
-    if (! (wmActions & WM_ACTION_PASS_TO_USER)) {
         if (down && isAppSwitchKey(keyCode)) {
             env->CallVoidMethod(mCallbacksObj, gCallbacksClassInfo.notifyAppSwitchComing);
             checkExceptionFromCallback(env, "notifyAppSwitchComing");
@@ -312,12 +310,18 @@
     LOGD("interceptTouch - when=%lld", when);
 #endif
 
-    if (! isScreenOn()) {
-        // Touch events do not wake the device.
-        return InputReaderPolicyInterface::ACTION_NONE;
+    int32_t actions = InputReaderPolicyInterface::ACTION_NONE;
+    if (isScreenOn()) {
+        // Only dispatch touch events when the device is awake.
+        actions |= InputReaderPolicyInterface::ACTION_DISPATCH;
     }
 
-    return InputReaderPolicyInterface::ACTION_DISPATCH;
+    if (! isScreenBright()) {
+        // Brighten the screen if dimmed.
+        actions |= InputReaderPolicyInterface::ACTION_BRIGHT_HERE;
+    }
+
+    return actions;
 }
 
 int32_t NativeInputManager::interceptTrackball(nsecs_t when,
@@ -327,12 +331,18 @@
             when, buttonChanged, buttonDown, rolled);
 #endif
 
-    if (! isScreenOn()) {
-        // Trackball motions and button presses do not wake the device.
-        return InputReaderPolicyInterface::ACTION_NONE;
+    int32_t actions = InputReaderPolicyInterface::ACTION_NONE;
+    if (isScreenOn()) {
+        // Only dispatch trackball events when the device is awake.
+        actions |= InputReaderPolicyInterface::ACTION_DISPATCH;
     }
 
-    return InputReaderPolicyInterface::ACTION_DISPATCH;
+    if (! isScreenBright()) {
+        // Brighten the screen if dimmed.
+        actions |= InputReaderPolicyInterface::ACTION_BRIGHT_HERE;
+    }
+
+    return actions;
 }
 
 int32_t NativeInputManager::interceptSwitch(nsecs_t when, int32_t switchCode,