Move the volume, media, call, camera and search key handling from
PhoneWindow to a new PhoneFallbackEventHandler class that is used
for all windows, not just ones with decors.

Bug: 3155146
Change-Id: Ib070fa3e523e3564b225bca576c08012fef4f416
diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java
index c7c2071..5b18715 100644
--- a/core/java/android/view/ViewRoot.java
+++ b/core/java/android/view/ViewRoot.java
@@ -59,6 +59,7 @@
 import android.view.inputmethod.InputConnection;
 import android.view.inputmethod.InputMethodManager;
 import android.widget.Scroller;
+import com.android.internal.policy.PolicyManager;
 import com.android.internal.view.BaseSurfaceHolder;
 import com.android.internal.view.IInputMethodCallback;
 import com.android.internal.view.IInputMethodSession;
@@ -160,6 +161,7 @@
     InputChannel mInputChannel;
     InputQueue.Callback mInputQueueCallback;
     InputQueue mInputQueue;
+    FallbackEventHandler mFallbackEventHandler;
     
     final Rect mTempRect; // used in the transaction to not thrash the heap.
     final Rect mVisRect; // used to retrieve visible rect of focused view.
@@ -273,6 +275,7 @@
         mAttachInfo = new View.AttachInfo(sWindowSession, mWindow, this, this);
         mViewConfiguration = ViewConfiguration.get(context);
         mDensity = context.getResources().getDisplayMetrics().densityDpi;
+        mFallbackEventHandler = PolicyManager.makeNewFallbackEventHandler(context);
     }
 
     public static void addFirstDrawHandler(Runnable callback) {
@@ -325,6 +328,7 @@
         synchronized (this) {
             if (mView == null) {
                 mView = view;
+                mFallbackEventHandler.setView(view);
                 mWindowAttributes.copyFrom(attrs);
                 attrs = mWindowAttributes;
                 
@@ -386,6 +390,7 @@
                     mView = null;
                     mAttachInfo.mRootView = null;
                     mInputChannel = null;
+                    mFallbackEventHandler.setView(null);
                     unscheduleTraversals();
                     throw new RuntimeException("Adding window failed", e);
                 } finally {
@@ -404,6 +409,7 @@
                     mView = null;
                     mAttachInfo.mRootView = null;
                     mAdded = false;
+                    mFallbackEventHandler.setView(null);
                     unscheduleTraversals();
                     switch (res) {
                         case WindowManagerImpl.ADD_BAD_APP_TOKEN:
@@ -2422,8 +2428,13 @@
                 if (Config.LOGV) {
                     captureKeyLog("captureDispatchKeyEvent", event);
                 }
+                mFallbackEventHandler.preDispatchKeyEvent(event);
                 boolean keyHandled = mView.dispatchKeyEvent(event);
 
+                if (!keyHandled) {
+                    mFallbackEventHandler.dispatchKeyEvent(event);
+                }
+
                 if (!keyHandled && isDown) {
                     int direction = 0;
                     switch (event.getKeyCode()) {