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/include/ui/EventHub.h b/include/ui/EventHub.h
index d322a34..5be17d3 100644
--- a/include/ui/EventHub.h
+++ b/include/ui/EventHub.h
@@ -60,6 +60,32 @@
 class KeyLayoutMap;
 
 /*
+ * Input device classes.
+ */
+enum {
+    /* The input device is a keyboard. */
+    INPUT_DEVICE_CLASS_KEYBOARD      = 0x00000001,
+
+    /* The input device is an alpha-numeric keyboard (not just a dial pad). */
+    INPUT_DEVICE_CLASS_ALPHAKEY      = 0x00000002,
+
+    /* The input device is a touchscreen (either single-touch or multi-touch). */
+    INPUT_DEVICE_CLASS_TOUCHSCREEN   = 0x00000004,
+
+    /* The input device is a trackball. */
+    INPUT_DEVICE_CLASS_TRACKBALL     = 0x00000008,
+
+    /* The input device is a multi-touch touchscreen. */
+    INPUT_DEVICE_CLASS_TOUCHSCREEN_MT= 0x00000010,
+
+    /* The input device is a directional pad. */
+    INPUT_DEVICE_CLASS_DPAD          = 0x00000020,
+
+    /* The input device is a gamepad (implies keyboard). */
+    INPUT_DEVICE_CLASS_GAMEPAD       = 0x00000040
+};
+
+/*
  * Grand Central Station for events.
  *
  * The event hub aggregates input events received across all known input
diff --git a/include/ui/Input.h b/include/ui/Input.h
index a7d23d4..f069888 100644
--- a/include/ui/Input.h
+++ b/include/ui/Input.h
@@ -32,7 +32,7 @@
     /*
      * Private control to determine when an app is tracking a key sequence.
      */
-    KEY_EVENT_FLAG_START_TRACKING = 0x40000000
+    AKEY_EVENT_FLAG_START_TRACKING = 0x40000000
 };
 
 /*
@@ -130,6 +130,11 @@
     float y;
     float pressure;
     float size;
+    float touchMajor;
+    float touchMinor;
+    float toolMajor;
+    float toolMinor;
+    float orientation;
 };
 
 /*
@@ -143,14 +148,14 @@
 
     inline int32_t getDeviceId() const { return mDeviceId; }
 
-    inline int32_t getNature() const { return mNature; }
+    inline int32_t getSource() const { return mSource; }
     
 protected:
-    void initialize(int32_t deviceId, int32_t nature);
+    void initialize(int32_t deviceId, int32_t source);
 
 private:
     int32_t mDeviceId;
-    int32_t mNature;
+    int32_t mSource;
 };
 
 /*
@@ -160,7 +165,7 @@
 public:
     virtual ~KeyEvent() { }
 
-    virtual int32_t getType() const { return INPUT_EVENT_TYPE_KEY; }
+    virtual int32_t getType() const { return AINPUT_EVENT_TYPE_KEY; }
 
     inline int32_t getAction() const { return mAction; }
 
@@ -188,7 +193,7 @@
     
     void initialize(
             int32_t deviceId,
-            int32_t nature,
+            int32_t source,
             int32_t action,
             int32_t flags,
             int32_t keyCode,
@@ -216,7 +221,7 @@
 public:
     virtual ~MotionEvent() { }
 
-    virtual int32_t getType() const { return INPUT_EVENT_TYPE_MOTION; }
+    virtual int32_t getType() const { return AINPUT_EVENT_TYPE_MOTION; }
 
     inline int32_t getAction() const { return mAction; }
 
@@ -264,6 +269,26 @@
         return getCurrentPointerCoords(pointerIndex).size;
     }
 
+    inline float getTouchMajor(size_t pointerIndex) const {
+        return getCurrentPointerCoords(pointerIndex).touchMajor;
+    }
+
+    inline float getTouchMinor(size_t pointerIndex) const {
+        return getCurrentPointerCoords(pointerIndex).touchMinor;
+    }
+
+    inline float getToolMajor(size_t pointerIndex) const {
+        return getCurrentPointerCoords(pointerIndex).toolMajor;
+    }
+
+    inline float getToolMinor(size_t pointerIndex) const {
+        return getCurrentPointerCoords(pointerIndex).toolMinor;
+    }
+
+    inline float getOrientation(size_t pointerIndex) const {
+        return getCurrentPointerCoords(pointerIndex).orientation;
+    }
+
     inline size_t getHistorySize() const { return mSampleEventTimes.size() - 1; }
 
     inline nsecs_t getHistoricalEventTime(size_t historicalIndex) const {
@@ -294,9 +319,29 @@
         return getHistoricalPointerCoords(pointerIndex, historicalIndex).size;
     }
 
+    inline float getHistoricalTouchMajor(size_t pointerIndex, size_t historicalIndex) const {
+        return getHistoricalPointerCoords(pointerIndex, historicalIndex).touchMajor;
+    }
+
+    inline float getHistoricalTouchMinor(size_t pointerIndex, size_t historicalIndex) const {
+        return getHistoricalPointerCoords(pointerIndex, historicalIndex).touchMinor;
+    }
+
+    inline float getHistoricalToolMajor(size_t pointerIndex, size_t historicalIndex) const {
+        return getHistoricalPointerCoords(pointerIndex, historicalIndex).toolMajor;
+    }
+
+    inline float getHistoricalToolMinor(size_t pointerIndex, size_t historicalIndex) const {
+        return getHistoricalPointerCoords(pointerIndex, historicalIndex).toolMinor;
+    }
+
+    inline float getHistoricalOrientation(size_t pointerIndex, size_t historicalIndex) const {
+        return getHistoricalPointerCoords(pointerIndex, historicalIndex).orientation;
+    }
+
     void initialize(
             int32_t deviceId,
-            int32_t nature,
+            int32_t source,
             int32_t action,
             int32_t edgeFlags,
             int32_t metaState,
diff --git a/include/ui/InputDevice.h b/include/ui/InputDevice.h
index 4420600..3b9c70e 100644
--- a/include/ui/InputDevice.h
+++ b/include/ui/InputDevice.h
@@ -42,6 +42,7 @@
 extern int32_t updateMetaState(int32_t keyCode, bool down, int32_t oldMetaState);
 extern int32_t rotateKeyCode(int32_t keyCode, int32_t orientation);
 
+
 /*
  * An input device structure tracks the state of a single input device.
  *
@@ -168,8 +169,11 @@
                 FIELD_ABS_MT_POSITION_X = 1,
                 FIELD_ABS_MT_POSITION_Y = 2,
                 FIELD_ABS_MT_TOUCH_MAJOR = 4,
-                FIELD_ABS_MT_WIDTH_MAJOR = 8,
-                FIELD_ABS_MT_TRACKING_ID = 16
+                FIELD_ABS_MT_TOUCH_MINOR = 8,
+                FIELD_ABS_MT_WIDTH_MAJOR = 16,
+                FIELD_ABS_MT_WIDTH_MINOR = 32,
+                FIELD_ABS_MT_ORIENTATION = 64,
+                FIELD_ABS_MT_TRACKING_ID = 128
             };
 
             uint32_t pointerCount;
@@ -179,7 +183,10 @@
                 int32_t absMTPositionX;
                 int32_t absMTPositionY;
                 int32_t absMTTouchMajor;
+                int32_t absMTTouchMinor;
                 int32_t absMTWidthMajor;
+                int32_t absMTWidthMinor;
+                int32_t absMTOrientation;
                 int32_t absMTTrackingId;
 
                 inline void clear() {
@@ -206,6 +213,11 @@
         int32_t y;
         int32_t pressure;
         int32_t size;
+        int32_t touchMajor;
+        int32_t touchMinor;
+        int32_t toolMajor;
+        int32_t toolMinor;
+        int32_t orientation;
     };
 
     struct TouchData {
@@ -236,6 +248,7 @@
             AbsoluteAxisInfo yAxis;
             AbsoluteAxisInfo pressureAxis;
             AbsoluteAxisInfo sizeAxis;
+            AbsoluteAxisInfo orientationAxis;
         } parameters;
 
         // The touch data of the current sample being processed.
@@ -290,6 +303,8 @@
 
             int32_t sizeOrigin;
             float sizeScale;
+
+            float orientationScale;
         } precalculated;
 
         void reset();
diff --git a/include/ui/InputDispatcher.h b/include/ui/InputDispatcher.h
index eb8f820..674852a 100644
--- a/include/ui/InputDispatcher.h
+++ b/include/ui/InputDispatcher.h
@@ -167,10 +167,10 @@
      */
     virtual void notifyConfigurationChanged(nsecs_t eventTime) = 0;
     virtual void notifyAppSwitchComing(nsecs_t eventTime) = 0;
-    virtual void notifyKey(nsecs_t eventTime, int32_t deviceId, int32_t nature,
+    virtual void notifyKey(nsecs_t eventTime, int32_t deviceId, int32_t source,
             uint32_t policyFlags, int32_t action, int32_t flags, int32_t keyCode,
             int32_t scanCode, int32_t metaState, nsecs_t downTime) = 0;
-    virtual void notifyMotion(nsecs_t eventTime, int32_t deviceId, int32_t nature,
+    virtual void notifyMotion(nsecs_t eventTime, int32_t deviceId, int32_t source,
             uint32_t policyFlags, int32_t action, int32_t metaState, int32_t edgeFlags,
             uint32_t pointerCount, const int32_t* pointerIds, const PointerCoords* pointerCoords,
             float xPrecision, float yPrecision, nsecs_t downTime) = 0;
@@ -232,10 +232,10 @@
 
     virtual void notifyConfigurationChanged(nsecs_t eventTime);
     virtual void notifyAppSwitchComing(nsecs_t eventTime);
-    virtual void notifyKey(nsecs_t eventTime, int32_t deviceId, int32_t nature,
+    virtual void notifyKey(nsecs_t eventTime, int32_t deviceId, int32_t source,
             uint32_t policyFlags, int32_t action, int32_t flags, int32_t keyCode,
             int32_t scanCode, int32_t metaState, nsecs_t downTime);
-    virtual void notifyMotion(nsecs_t eventTime, int32_t deviceId, int32_t nature,
+    virtual void notifyMotion(nsecs_t eventTime, int32_t deviceId, int32_t source,
             uint32_t policyFlags, int32_t action, int32_t metaState, int32_t edgeFlags,
             uint32_t pointerCount, const int32_t* pointerIds, const PointerCoords* pointerCoords,
             float xPrecision, float yPrecision, nsecs_t downTime);
@@ -281,7 +281,7 @@
 
     struct KeyEntry : EventEntry {
         int32_t deviceId;
-        int32_t nature;
+        int32_t source;
         uint32_t policyFlags;
         int32_t action;
         int32_t flags;
@@ -301,7 +301,7 @@
 
     struct MotionEntry : EventEntry {
         int32_t deviceId;
-        int32_t nature;
+        int32_t source;
         uint32_t policyFlags;
         int32_t action;
         int32_t metaState;
@@ -424,11 +424,11 @@
 
         ConfigurationChangedEntry* obtainConfigurationChangedEntry(nsecs_t eventTime);
         KeyEntry* obtainKeyEntry(nsecs_t eventTime,
-                int32_t deviceId, int32_t nature, uint32_t policyFlags, int32_t action,
+                int32_t deviceId, int32_t source, uint32_t policyFlags, int32_t action,
                 int32_t flags, int32_t keyCode, int32_t scanCode, int32_t metaState,
                 int32_t repeatCount, nsecs_t downTime);
         MotionEntry* obtainMotionEntry(nsecs_t eventTime,
-                int32_t deviceId, int32_t nature, uint32_t policyFlags, int32_t action,
+                int32_t deviceId, int32_t source, uint32_t policyFlags, int32_t action,
                 int32_t metaState, int32_t edgeFlags, float xPrecision, float yPrecision,
                 nsecs_t downTime, uint32_t pointerCount,
                 const int32_t* pointerIds, const PointerCoords* pointerCoords);
diff --git a/include/ui/InputTransport.h b/include/ui/InputTransport.h
index 226d1d5..31ec701 100644
--- a/include/ui/InputTransport.h
+++ b/include/ui/InputTransport.h
@@ -119,7 +119,7 @@
     };
 
     int32_t deviceId;
-    int32_t nature;
+    int32_t source;
 
     union {
         struct {
@@ -198,7 +198,7 @@
      */
     status_t publishKeyEvent(
             int32_t deviceId,
-            int32_t nature,
+            int32_t source,
             int32_t action,
             int32_t flags,
             int32_t keyCode,
@@ -216,7 +216,7 @@
      */
     status_t publishMotionEvent(
             int32_t deviceId,
-            int32_t nature,
+            int32_t source,
             int32_t action,
             int32_t edgeFlags,
             int32_t metaState,
@@ -233,7 +233,7 @@
     /* Appends a motion sample to a motion event unless already consumed.
      *
      * Returns OK on success.
-     * Returns INVALID_OPERATION if the current event is not a MOTION_EVENT_ACTION_MOVE event.
+     * Returns INVALID_OPERATION if the current event is not a AMOTION_EVENT_ACTION_MOVE event.
      * Returns FAILED_TRANSACTION if the current event has already been consumed.
      * Returns NO_MEMORY if the buffer is full and no additional samples can be added.
      */
@@ -272,7 +272,7 @@
     status_t publishInputEvent(
             int32_t type,
             int32_t deviceId,
-            int32_t nature);
+            int32_t source);
 };
 
 /*