Add support for new input sources.

Added several new coordinate values to MotionEvents to capture
touch major/minor area, tool major/minor area and orientation.

Renamed NDK input constants per convention.

Added InputDevice class in Java which will eventually provide
useful information about available input devices.

Added APIs for manufacturing new MotionEvent objects with multiple
pointers and all necessary coordinate data.

Fixed a bug in the input dispatcher where it could get stuck with
a pointer down forever.

Fixed a bug in the WindowManager where the input window list could
end up containing stale removed windows.

Fixed a bug in the WindowManager where the input channel was being
removed only after the final animation transition had taken place
which caused spurious WINDOW DIED log messages to be printed.

Change-Id: Ie55084da319b20aad29b28a0499b8dd98bb5da68
diff --git a/core/jni/android_view_MotionEvent.cpp b/core/jni/android_view_MotionEvent.cpp
index 78137e2..fe247e8 100644
--- a/core/jni/android_view_MotionEvent.cpp
+++ b/core/jni/android_view_MotionEvent.cpp
@@ -24,7 +24,7 @@
 #include "android_view_MotionEvent.h"
 
 // Number of float items per entry in a DVM sample data array
-#define NUM_SAMPLE_DATA 4
+#define NUM_SAMPLE_DATA 9
 
 namespace android {
 
@@ -36,13 +36,14 @@
     jmethodID obtain;
     jmethodID recycle;
 
+    jfieldID mDeviceId;
+    jfieldID mSource;
     jfieldID mDownTimeNano;
     jfieldID mAction;
     jfieldID mXOffset;
     jfieldID mYOffset;
     jfieldID mXPrecision;
     jfieldID mYPrecision;
-    jfieldID mDeviceId;
     jfieldID mEdgeFlags;
     jfieldID mMetaState;
     jfieldID mNumPointers;
@@ -70,6 +71,10 @@
         return NULL;
     }
 
+    env->SetIntField(eventObj, gMotionEventClassInfo.mDeviceId,
+            event->getDeviceId());
+    env->SetIntField(eventObj, gMotionEventClassInfo.mSource,
+            event->getSource());
     env->SetLongField(eventObj, gMotionEventClassInfo.mDownTimeNano,
             event->getDownTime());
     env->SetIntField(eventObj, gMotionEventClassInfo.mAction,
@@ -82,8 +87,6 @@
             event->getXPrecision());
     env->SetFloatField(eventObj, gMotionEventClassInfo.mYPrecision,
             event->getYPrecision());
-    env->SetIntField(eventObj, gMotionEventClassInfo.mDeviceId,
-            event->getDeviceId());
     env->SetIntField(eventObj, gMotionEventClassInfo.mEdgeFlags,
             event->getEdgeFlags());
     env->SetIntField(eventObj, gMotionEventClassInfo.mMetaState,
@@ -129,6 +132,11 @@
         *(destDataSamples++) = srcSamplePointerCoords->y;
         *(destDataSamples++) = srcSamplePointerCoords->pressure;
         *(destDataSamples++) = srcSamplePointerCoords->size;
+        *(destDataSamples++) = srcSamplePointerCoords->touchMajor;
+        *(destDataSamples++) = srcSamplePointerCoords->touchMinor;
+        *(destDataSamples++) = srcSamplePointerCoords->toolMajor;
+        *(destDataSamples++) = srcSamplePointerCoords->toolMinor;
+        *(destDataSamples++) = srcSamplePointerCoords->orientation;
         srcSamplePointerCoords += 1;
     }
 
@@ -142,15 +150,16 @@
     return eventObj;
 }
 
-void android_view_MotionEvent_toNative(JNIEnv* env, jobject eventObj, int32_t nature,
+void android_view_MotionEvent_toNative(JNIEnv* env, jobject eventObj,
         MotionEvent* event) {
+    jint deviceId = env->GetIntField(eventObj, gMotionEventClassInfo.mDeviceId);
+    jint source = env->GetIntField(eventObj, gMotionEventClassInfo.mSource);
     jlong downTimeNano = env->GetLongField(eventObj, gMotionEventClassInfo.mDownTimeNano);
     jint action = env->GetIntField(eventObj, gMotionEventClassInfo.mAction);
     jfloat xOffset = env->GetFloatField(eventObj, gMotionEventClassInfo.mXOffset);
     jfloat yOffset = env->GetFloatField(eventObj, gMotionEventClassInfo.mYOffset);
     jfloat xPrecision = env->GetFloatField(eventObj, gMotionEventClassInfo.mXPrecision);
     jfloat yPrecision = env->GetFloatField(eventObj, gMotionEventClassInfo.mYPrecision);
-    jint deviceId = env->GetIntField(eventObj, gMotionEventClassInfo.mDeviceId);
     jint edgeFlags = env->GetIntField(eventObj, gMotionEventClassInfo.mEdgeFlags);
     jint metaState = env->GetIntField(eventObj, gMotionEventClassInfo.mMetaState);
     jint numPointers = env->GetIntField(eventObj, gMotionEventClassInfo.mNumPointers);
@@ -180,9 +189,14 @@
         samplePointerCoords[j].y = *(srcDataSamples++);
         samplePointerCoords[j].pressure = *(srcDataSamples++);
         samplePointerCoords[j].size = *(srcDataSamples++);
+        samplePointerCoords[j].touchMajor = *(srcDataSamples++);
+        samplePointerCoords[j].touchMinor = *(srcDataSamples++);
+        samplePointerCoords[j].toolMajor = *(srcDataSamples++);
+        samplePointerCoords[j].toolMinor = *(srcDataSamples++);
+        samplePointerCoords[j].orientation = *(srcDataSamples++);
     }
 
-    event->initialize(deviceId, nature, action, edgeFlags, metaState,
+    event->initialize(deviceId, source, action, edgeFlags, metaState,
             xOffset, yOffset, xPrecision, yPrecision, downTimeNano, sampleEventTime,
             numPointers, pointerIdentifiers, samplePointerCoords);
 
@@ -193,6 +207,11 @@
             samplePointerCoords[j].y = *(srcDataSamples++);
             samplePointerCoords[j].pressure = *(srcDataSamples++);
             samplePointerCoords[j].size = *(srcDataSamples++);
+            samplePointerCoords[j].touchMajor = *(srcDataSamples++);
+            samplePointerCoords[j].touchMinor = *(srcDataSamples++);
+            samplePointerCoords[j].toolMajor = *(srcDataSamples++);
+            samplePointerCoords[j].toolMinor = *(srcDataSamples++);
+            samplePointerCoords[j].orientation = *(srcDataSamples++);
         }
         event->addSample(sampleEventTime, samplePointerCoords);
     }
@@ -242,6 +261,10 @@
     GET_METHOD_ID(gMotionEventClassInfo.recycle, gMotionEventClassInfo.clazz,
             "recycle", "()V");
 
+    GET_FIELD_ID(gMotionEventClassInfo.mDeviceId, gMotionEventClassInfo.clazz,
+            "mDeviceId", "I");
+    GET_FIELD_ID(gMotionEventClassInfo.mSource, gMotionEventClassInfo.clazz,
+            "mSource", "I");
     GET_FIELD_ID(gMotionEventClassInfo.mDownTimeNano, gMotionEventClassInfo.clazz,
             "mDownTimeNano", "J");
     GET_FIELD_ID(gMotionEventClassInfo.mAction, gMotionEventClassInfo.clazz,
@@ -254,8 +277,6 @@
             "mXPrecision", "F");
     GET_FIELD_ID(gMotionEventClassInfo.mYPrecision, gMotionEventClassInfo.clazz,
             "mYPrecision", "F");
-    GET_FIELD_ID(gMotionEventClassInfo.mDeviceId, gMotionEventClassInfo.clazz,
-            "mDeviceId", "I");
     GET_FIELD_ID(gMotionEventClassInfo.mEdgeFlags, gMotionEventClassInfo.clazz,
             "mEdgeFlags", "I");
     GET_FIELD_ID(gMotionEventClassInfo.mMetaState, gMotionEventClassInfo.clazz,