First stab at attaching native event dispatching.

Provides the basic infrastructure for a
NativeActivity's native code to get an object representing
its event stream that can be used to read input events.

Still work to do, probably some API changes, and reasonable
default key handling (so that for example back will still
work).

Change-Id: I6db891bc35dc9683181d7708eaed552b955a077e
diff --git a/include/ui/Input.h b/include/ui/Input.h
index 979d6e8..32f85b3 100644
--- a/include/ui/Input.h
+++ b/include/ui/Input.h
@@ -40,6 +40,11 @@
  */
 #define MAX_POINTERS 10
 
+/*
+ * Declare a concrete type for the NDK's input event forward declaration.
+ */
+struct input_event_t { };
+
 namespace android {
 
 /*
@@ -128,8 +133,6 @@
 /*
  * Input events.
  */
-struct input_event_t { };
-
 class InputEvent : public input_event_t {
 public:
     virtual ~InputEvent() { }
diff --git a/include/ui/InputTransport.h b/include/ui/InputTransport.h
index 7b182f3..d6bded6 100644
--- a/include/ui/InputTransport.h
+++ b/include/ui/InputTransport.h
@@ -330,4 +330,24 @@
 
 } // namespace android
 
+/*
+ * NDK input queue API.
+ */
+struct input_queue_t {
+public:
+    /* Creates a consumer associated with an input channel. */
+    explicit input_queue_t(const android::sp<android::InputChannel>& channel);
+
+    /* Destroys the consumer and releases its input channel. */
+    ~input_queue_t();
+
+    inline android::InputConsumer& getConsumer() { return mConsumer; }
+    
+    android::status_t consume(android::InputEvent** event);
+    
+private:
+    android::InputConsumer mConsumer;
+    android::PreallocatedInputEventFactory mInputEventFactory;
+};
+
 #endif // _UI_INPUT_TRANSPORT_H
diff --git a/libs/ui/Input.cpp b/libs/ui/Input.cpp
index 0e6f2f5..4121b5a 100644
--- a/libs/ui/Input.cpp
+++ b/libs/ui/Input.cpp
@@ -88,166 +88,3 @@
 }
 
 } // namespace android
-
-// NDK APIs
-
-using android::InputEvent;
-using android::KeyEvent;
-using android::MotionEvent;
-
-int32_t input_event_get_type(const input_event_t* event) {
-    return reinterpret_cast<const InputEvent*>(event)->getType();
-}
-
-int32_t input_event_get_device_id(const input_event_t* event) {
-    return reinterpret_cast<const InputEvent*>(event)->getDeviceId();
-}
-
-int32_t input_event_get_nature(const input_event_t* event) {
-    return reinterpret_cast<const InputEvent*>(event)->getNature();
-}
-
-int32_t key_event_get_action(const input_event_t* key_event) {
-    return reinterpret_cast<const KeyEvent*>(key_event)->getAction();
-}
-
-int32_t key_event_get_flags(const input_event_t* key_event) {
-    return reinterpret_cast<const KeyEvent*>(key_event)->getFlags();
-}
-
-int32_t key_event_get_key_code(const input_event_t* key_event) {
-    return reinterpret_cast<const KeyEvent*>(key_event)->getKeyCode();
-}
-
-int32_t key_event_get_scan_code(const input_event_t* key_event) {
-    return reinterpret_cast<const KeyEvent*>(key_event)->getScanCode();
-}
-
-int32_t key_event_get_meta_state(const input_event_t* key_event) {
-    return reinterpret_cast<const KeyEvent*>(key_event)->getMetaState();
-}
-int32_t key_event_get_repeat_count(const input_event_t* key_event) {
-    return reinterpret_cast<const KeyEvent*>(key_event)->getRepeatCount();
-}
-
-int64_t key_event_get_down_time(const input_event_t* key_event) {
-    return reinterpret_cast<const KeyEvent*>(key_event)->getDownTime();
-}
-
-int64_t key_event_get_event_time(const input_event_t* key_event) {
-    return reinterpret_cast<const KeyEvent*>(key_event)->getEventTime();
-}
-
-int32_t motion_event_get_action(const input_event_t* motion_event) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getAction();
-}
-
-int32_t motion_event_get_meta_state(const input_event_t* motion_event) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getMetaState();
-}
-
-int32_t motion_event_get_edge_flags(const input_event_t* motion_event) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getEdgeFlags();
-}
-
-int64_t motion_event_get_down_time(const input_event_t* motion_event) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getDownTime();
-}
-
-int64_t motion_event_get_event_time(const input_event_t* motion_event) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getEventTime();
-}
-
-float motion_event_get_x_offset(const input_event_t* motion_event) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getXOffset();
-}
-
-float motion_event_get_y_offset(const input_event_t* motion_event) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getYOffset();
-}
-
-float motion_event_get_x_precision(const input_event_t* motion_event) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getXPrecision();
-}
-
-float motion_event_get_y_precision(const input_event_t* motion_event) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getYPrecision();
-}
-
-size_t motion_event_get_pointer_count(const input_event_t* motion_event) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getPointerCount();
-}
-
-int32_t motion_event_get_pointer_id(const input_event_t* motion_event, size_t pointer_index) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getPointerId(pointer_index);
-}
-
-float motion_event_get_raw_x(const input_event_t* motion_event, size_t pointer_index) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getRawX(pointer_index);
-}
-
-float motion_event_get_raw_y(const input_event_t* motion_event, size_t pointer_index) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getRawY(pointer_index);
-}
-
-float motion_event_get_x(const input_event_t* motion_event, size_t pointer_index) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getX(pointer_index);
-}
-
-float motion_event_get_y(const input_event_t* motion_event, size_t pointer_index) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getY(pointer_index);
-}
-
-float motion_event_get_pressure(const input_event_t* motion_event, size_t pointer_index) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getPressure(pointer_index);
-}
-
-float motion_event_get_size(const input_event_t* motion_event, size_t pointer_index) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getSize(pointer_index);
-}
-
-size_t motion_event_get_history_size(const input_event_t* motion_event) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getHistorySize();
-}
-
-int64_t motion_event_get_historical_event_time(input_event_t* motion_event,
-        size_t history_index) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getHistoricalEventTime(
-            history_index);
-}
-
-float motion_event_get_historical_raw_x(input_event_t* motion_event, size_t pointer_index,
-        size_t history_index) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getHistoricalRawX(
-            pointer_index, history_index);
-}
-
-float motion_event_get_historical_raw_y(input_event_t* motion_event, size_t pointer_index,
-        size_t history_index) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getHistoricalRawY(
-            pointer_index, history_index);
-}
-
-float motion_event_get_historical_x(input_event_t* motion_event, size_t pointer_index,
-        size_t history_index) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getHistoricalX(
-            pointer_index, history_index);
-}
-
-float motion_event_get_historical_y(input_event_t* motion_event, size_t pointer_index,
-        size_t history_index) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getHistoricalY(
-            pointer_index, history_index);
-}
-
-float motion_event_get_historical_pressure(input_event_t* motion_event, size_t pointer_index,
-        size_t history_index) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getHistoricalPressure(
-            pointer_index, history_index);
-}
-
-float motion_event_get_historical_size(input_event_t* motion_event, size_t pointer_index,
-        size_t history_index) {
-    return reinterpret_cast<const MotionEvent*>(motion_event)->getHistoricalSize(
-            pointer_index, history_index);
-}
diff --git a/libs/ui/InputTransport.cpp b/libs/ui/InputTransport.cpp
index 86bbd37..b2842d0 100644
--- a/libs/ui/InputTransport.cpp
+++ b/libs/ui/InputTransport.cpp
@@ -686,3 +686,22 @@
 }
 
 } // namespace android
+
+// --- input_queue_t ---
+
+using android::InputEvent;
+using android::InputChannel;
+using android::InputConsumer;
+using android::sp;
+using android::status_t;
+
+input_queue_t::input_queue_t(const sp<InputChannel>& channel) :
+        mConsumer(channel) {
+}
+
+input_queue_t::~input_queue_t() {
+}
+
+status_t input_queue_t::consume(InputEvent** event) {
+    return mConsumer.consume(&mInputEventFactory, event);
+}