Input system bug fixes, particularly for stylus.
Bug: 5049148

Finished stylus support, including support for indirect stylus
and mouse tools.

Added TILT axis.  When stylus tilt X/Y is available, it is transformed
into an orientation and tilt inclination which is a more convenient
representation and a simpler extension to the exiting API.

Touch devices now only report touch data using a single input
source.  Previously touch devices in pointer mode would report
both absolute touch pad data and cooked pointer gestures.
Now we just pick one.  The touch device switches modes as needed
when the focused application enables/disables pointer gestures.
This change greatly simplifies the code and reduces the load
on the input dispatcher.

Fixed an incorrect assumption that the value of ABS_(MT_)DISTANCE
would be zero whenever the stylus was in direct contact.  It appears
that the correct way to determine whether the stylus is in direct
contact (rather than hovering) is by checking for a non-zero
reported pressure.

Added code to read the initial state of tool buttons and axis values
when the input devices are initialized or reset.  This fixes
problems where the input mapper state might have the wrong initial
state.

Moved responsibility for cancelling pending inputs (keys down,
touches, etc.) to the InputDispatcher by sending it a device reset
notification.  This frees the InputReader from having to synthesize
events during reset, which was cumbersome and somewhat brittle
to begin with.

Consolidated more of the common accumulator logic from
SingleTouchInputMapper and MultiTouchInputMapper into
TouchInputMapper.

Improved the PointerLocation output.

Change-Id: I595d3647f7fd7cb1e3eff8b3c76b85043b5fe2f0
diff --git a/services/input/InputDispatcher.h b/services/input/InputDispatcher.h
index cae1610..3c83691 100644
--- a/services/input/InputDispatcher.h
+++ b/services/input/InputDispatcher.h
@@ -381,6 +381,7 @@
     virtual void notifyKey(const NotifyKeyArgs* args);
     virtual void notifyMotion(const NotifyMotionArgs* args);
     virtual void notifySwitch(const NotifySwitchArgs* args);
+    virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args);
 
     virtual int32_t injectInputEvent(const InputEvent* event,
             int32_t injectorPid, int32_t injectorUid, int32_t syncMode, int32_t timeoutMillis,
@@ -424,6 +425,7 @@
     struct EventEntry : Link<EventEntry> {
         enum {
             TYPE_CONFIGURATION_CHANGED,
+            TYPE_DEVICE_RESET,
             TYPE_KEY,
             TYPE_MOTION
         };
@@ -453,6 +455,15 @@
         virtual ~ConfigurationChangedEntry();
     };
 
+    struct DeviceResetEntry : EventEntry {
+        int32_t deviceId;
+
+        DeviceResetEntry(nsecs_t eventTime, int32_t deviceId);
+
+    protected:
+        virtual ~DeviceResetEntry();
+    };
+
     struct KeyEntry : EventEntry {
         int32_t deviceId;
         uint32_t source;
@@ -688,8 +699,11 @@
         // The specific keycode of the key event to cancel, or -1 to cancel any key event.
         int32_t keyCode;
 
+        // The specific device id of events to cancel, or -1 to cancel events from any device.
+        int32_t deviceId;
+
         CancelationOptions(Mode mode, const char* reason) :
-                mode(mode), reason(reason), keyCode(-1) { }
+                mode(mode), reason(reason), keyCode(-1), deviceId(-1) { }
     };
 
     /* Tracks dispatched key and motion event state so that cancelation events can be
@@ -982,6 +996,8 @@
     // Dispatch inbound events.
     bool dispatchConfigurationChangedLocked(
             nsecs_t currentTime, ConfigurationChangedEntry* entry);
+    bool dispatchDeviceResetLocked(
+            nsecs_t currentTime, DeviceResetEntry* entry);
     bool dispatchKeyLocked(
             nsecs_t currentTime, KeyEntry* entry,
             DropReason* dropReason, nsecs_t* nextWakeupTime);