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/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java
index a41c690..8984b74 100644
--- a/core/java/android/view/ViewRoot.java
+++ b/core/java/android/view/ViewRoot.java
@@ -154,7 +154,9 @@
 
     final View.AttachInfo mAttachInfo;
     InputChannel mInputChannel;
-
+    InputConsumer.Callback mInputConsumerCallback;
+    InputConsumer mInputConsumer;
+    
     final Rect mTempRect; // used in the transaction to not thrash the heap.
     final Rect mVisRect; // used to retrieve visible rect of focused view.
 
@@ -555,8 +557,17 @@
                 }
 
                 if (WindowManagerPolicy.ENABLE_NATIVE_INPUT_DISPATCH) {
-                    InputQueue.registerInputChannel(mInputChannel, mInputHandler,
-                            Looper.myQueue());
+                    if (view instanceof RootViewSurfaceTaker) {
+                        mInputConsumerCallback =
+                            ((RootViewSurfaceTaker)view).willYouTakeTheInputConsumer();
+                    }
+                    if (mInputConsumerCallback != null) {
+                        mInputConsumer = new InputConsumer(mInputChannel);
+                        mInputConsumerCallback.onInputConsumerCreated(mInputConsumer);
+                    } else {
+                        InputQueue.registerInputChannel(mInputChannel, mInputHandler,
+                                Looper.myQueue());
+                    }
                 }
                 
                 view.assignParent(this);
@@ -1736,7 +1747,12 @@
 
         if (WindowManagerPolicy.ENABLE_NATIVE_INPUT_DISPATCH) {
             if (mInputChannel != null) {
-                InputQueue.unregisterInputChannel(mInputChannel);
+                if (mInputConsumerCallback != null) {
+                    mInputConsumerCallback.onInputConsumerDestroyed(mInputConsumer);
+                    mInputConsumerCallback = null;
+                } else {
+                    InputQueue.unregisterInputChannel(mInputChannel);
+                }
                 mInputChannel.dispose();
                 mInputChannel = null;
             }