Refactor input system into its own service.

Extracted the input system from the window manager service into
a new input manager service.  This will make it easier to
offer new input-related features to applications.

Cleaned up the input manager service JNI layer somewhat to get rid
of all of the unnecessary checks for whether the input manager
had been initialized.  Simplified the callback layer as well.

Change-Id: I3175d01307aed1420780d3c093d2694b41edf66e
diff --git a/services/java/com/android/server/wm/AppWindowToken.java b/services/java/com/android/server/wm/AppWindowToken.java
index 3069b74..55d571d 100644
--- a/services/java/com/android/server/wm/AppWindowToken.java
+++ b/services/java/com/android/server/wm/AppWindowToken.java
@@ -18,6 +18,7 @@
 
 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
 
+import com.android.server.input.InputApplicationHandle;
 import com.android.server.wm.WindowManagerService.H;
 
 import android.content.pm.ActivityInfo;
diff --git a/services/java/com/android/server/wm/DragState.java b/services/java/com/android/server/wm/DragState.java
index a19035a..b2cf3e0 100644
--- a/services/java/com/android/server/wm/DragState.java
+++ b/services/java/com/android/server/wm/DragState.java
@@ -16,6 +16,8 @@
 
 package com.android.server.wm;
 
+import com.android.server.input.InputApplicationHandle;
+import com.android.server.input.InputWindowHandle;
 import com.android.server.wm.WindowManagerService.DragInputEventReceiver;
 import com.android.server.wm.WindowManagerService.H;
 
diff --git a/services/java/com/android/server/wm/FakeWindowImpl.java b/services/java/com/android/server/wm/FakeWindowImpl.java
index 121ce18..2527f46 100644
--- a/services/java/com/android/server/wm/FakeWindowImpl.java
+++ b/services/java/com/android/server/wm/FakeWindowImpl.java
@@ -16,6 +16,9 @@
 
 package com.android.server.wm;
 
+import com.android.server.input.InputApplicationHandle;
+import com.android.server.input.InputWindowHandle;
+
 import android.os.Looper;
 import android.os.Process;
 import android.util.Slog;
diff --git a/services/java/com/android/server/wm/InputApplicationHandle.java b/services/java/com/android/server/wm/InputApplicationHandle.java
deleted file mode 100644
index 1812f11..0000000
--- a/services/java/com/android/server/wm/InputApplicationHandle.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.wm;
-
-
-/**
- * Functions as a handle for an application that can receive input.
- * Enables the native input dispatcher to refer indirectly to the window manager's
- * application window token.
- * @hide
- */
-public final class InputApplicationHandle {
-    // Pointer to the native input application handle.
-    // This field is lazily initialized via JNI.
-    @SuppressWarnings("unused")
-    private int ptr;
-
-    // The window manager's application window token.
-    public final AppWindowToken appWindowToken;
-
-    // Application name.
-    public String name;
-
-    // Dispatching timeout.
-    public long dispatchingTimeoutNanos;
-
-    private native void nativeDispose();
-
-    public InputApplicationHandle(AppWindowToken appWindowToken) {
-        this.appWindowToken = appWindowToken;
-    }
-
-    @Override
-    protected void finalize() throws Throwable {
-        try {
-            nativeDispose();
-        } finally {
-            super.finalize();
-        }
-    }
-}
diff --git a/services/java/com/android/server/wm/InputFilter.java b/services/java/com/android/server/wm/InputFilter.java
deleted file mode 100644
index 8f0001a..0000000
--- a/services/java/com/android/server/wm/InputFilter.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.wm;
-
-import android.os.Handler;
-import android.os.Looper;
-import android.os.Message;
-import android.view.InputEvent;
-import android.view.InputEventConsistencyVerifier;
-import android.view.KeyEvent;
-import android.view.MotionEvent;
-import android.view.WindowManagerPolicy;
-
-/**
- * Filters input events before they are dispatched to the system.
- * <p>
- * At most one input filter can be installed by calling
- * {@link WindowManagerService#setInputFilter}.  When an input filter is installed, the
- * system's behavior changes as follows:
- * <ul>
- * <li>Input events are first delivered to the {@link WindowManagerPolicy}
- * interception methods before queueing as usual.  This critical step takes care of managing
- * the power state of the device and handling wake keys.</li>
- * <li>Input events are then asynchronously delivered to the input filter's
- * {@link #onInputEvent(InputEvent)} method instead of being enqueued for dispatch to
- * applications as usual.  The input filter only receives input events that were
- * generated by input device; the input filter will not receive input events that were
- * injected into the system by other means, such as by instrumentation.</li>
- * <li>The input filter processes and optionally transforms the stream of events.  For example,
- * it may transform a sequence of motion events representing an accessibility gesture into
- * a different sequence of motion events, key presses or other system-level interactions.
- * The input filter can send events to be dispatched by calling
- * {@link #sendInputEvent(InputEvent)} and passing appropriate policy flags for the
- * input event.</li>
- * </ul>
- * </p>
- * <h3>The importance of input event consistency</h3>
- * <p>
- * The input filter mechanism is very low-level.  At a minimum, it needs to ensure that it
- * sends an internally consistent stream of input events to the dispatcher.  There are
- * very important invariants to be maintained.
- * </p><p>
- * For example, if a key down is sent, a corresponding key up should also be sent eventually.
- * Likewise, for touch events, each pointer must individually go down with
- * {@link MotionEvent#ACTION_DOWN} or {@link MotionEvent#ACTION_POINTER_DOWN} and then
- * individually go up with {@link MotionEvent#ACTION_POINTER_UP} or {@link MotionEvent#ACTION_UP}
- * and the sequence of pointer ids used must be consistent throughout the gesture.
- * </p><p>
- * Sometimes a filter may wish to cancel a previously dispatched key or motion.  It should
- * use {@link KeyEvent#FLAG_CANCELED} or {@link MotionEvent#ACTION_CANCEL} accordingly.
- * </p><p>
- * The input filter must take into account the fact that the input events coming from different
- * devices or even different sources all consist of distinct streams of input.
- * Use {@link InputEvent#getDeviceId()} and {@link InputEvent#getSource()} to identify
- * the source of the event and its semantics.  There are be multiple sources of keys,
- * touches and other input: they must be kept separate.
- * </p>
- * <h3>Policy flags</h3>
- * <p>
- * Input events received from the dispatcher and sent to the dispatcher have policy flags
- * associated with them.  Policy flags control some functions of the dispatcher.
- * </p><p>
- * The early policy interception decides whether an input event should be delivered
- * to applications or dropped.  The policy indicates its decision by setting the
- * {@link WindowManagerPolicy#FLAG_PASS_TO_USER} policy flag.  The input filter may
- * sometimes receive events that do not have this flag set.  It should take note of
- * the fact that the policy intends to drop the event, clean up its state, and
- * then send appropriate cancelation events to the dispatcher if needed.
- * </p><p>
- * For example, suppose the input filter is processing a gesture and one of the touch events
- * it receives does not have the {@link WindowManagerPolicy#FLAG_PASS_TO_USER} flag set.
- * The input filter should clear its internal state about the gesture and then send key or
- * motion events to the dispatcher to cancel any keys or pointers that are down.
- * </p><p>
- * Corollary: Events that set sent to the dispatcher should usually include the
- * {@link WindowManagerPolicy#FLAG_PASS_TO_USER} flag.  Otherwise, they will be dropped!
- * </p><p>
- * It may be prudent to disable automatic key repeating for synthetically generated
- * keys by setting the {@link WindowManagerPolicy#FLAG_DISABLE_KEY_REPEAT} policy flag.
- * </p>
- */
-public abstract class InputFilter {
-    private static final int MSG_INSTALL = 1;
-    private static final int MSG_UNINSTALL = 2;
-    private static final int MSG_INPUT_EVENT = 3;
-
-    private final H mH;
-    private Host mHost;
-
-    // Consistency verifiers for debugging purposes.
-    private final InputEventConsistencyVerifier mInboundInputEventConsistencyVerifier =
-            InputEventConsistencyVerifier.isInstrumentationEnabled() ?
-                    new InputEventConsistencyVerifier(this,
-                            InputEventConsistencyVerifier.FLAG_RAW_DEVICE_INPUT,
-                            "InputFilter#InboundInputEventConsistencyVerifier") : null;
-    private final InputEventConsistencyVerifier mOutboundInputEventConsistencyVerifier =
-            InputEventConsistencyVerifier.isInstrumentationEnabled() ?
-                    new InputEventConsistencyVerifier(this,
-                            InputEventConsistencyVerifier.FLAG_RAW_DEVICE_INPUT,
-                            "InputFilter#OutboundInputEventConsistencyVerifier") : null;
-
-    /**
-     * Creates the input filter.
-     *
-     * @param looper The looper to run callbacks on.
-     */
-    public InputFilter(Looper looper) {
-        mH = new H(looper);
-    }
-
-    /**
-     * Called when the input filter is installed.
-     * This method is guaranteed to be non-reentrant.
-     *
-     * @param host The input filter host environment.
-     */
-    final void install(Host host) {
-        mH.obtainMessage(MSG_INSTALL, host).sendToTarget();
-    }
-
-    /**
-     * Called when the input filter is uninstalled.
-     * This method is guaranteed to be non-reentrant.
-     */
-    final void uninstall() {
-        mH.obtainMessage(MSG_UNINSTALL).sendToTarget();
-    }
-
-    /**
-     * Called to enqueue the input event for filtering.
-     * The event will be recycled after the input filter processes it.
-     * This method is guaranteed to be non-reentrant.
-     *
-     * @param event The input event to enqueue.
-     */
-    final void filterInputEvent(InputEvent event, int policyFlags) {
-        mH.obtainMessage(MSG_INPUT_EVENT, policyFlags, 0, event).sendToTarget();
-    }
-
-    /**
-     * Sends an input event to the dispatcher.
-     *
-     * @param event The input event to publish.
-     * @param policyFlags The input event policy flags.
-     */
-    public void sendInputEvent(InputEvent event, int policyFlags) {
-        if (event == null) {
-            throw new IllegalArgumentException("event must not be null");
-        }
-        if (mHost == null) {
-            throw new IllegalStateException("Cannot send input event because the input filter " +
-                    "is not installed.");
-        }
-        if (mOutboundInputEventConsistencyVerifier != null) {
-            mOutboundInputEventConsistencyVerifier.onInputEvent(event, 0);
-        }
-        mHost.sendInputEvent(event, policyFlags);
-    }
-
-    /**
-     * Called when an input event has been received from the dispatcher.
-     * <p>
-     * The default implementation sends the input event back to the dispatcher, unchanged.
-     * </p><p>
-     * The event will be recycled when this method returns.  If you want to keep it around,
-     * make a copy!
-     * </p>
-     *
-     * @param event The input event that was received.
-     * @param policyFlags The input event policy flags.
-     */
-    public void onInputEvent(InputEvent event, int policyFlags) {
-        sendInputEvent(event, policyFlags);
-    }
-
-    /**
-     * Called when the filter is installed into the dispatch pipeline.
-     * <p>
-     * This method is called before the input filter receives any input events.
-     * The input filter should take this opportunity to prepare itself.
-     * </p>
-     */
-    public void onInstalled() {
-    }
-
-    /**
-     * Called when the filter is uninstalled from the dispatch pipeline.
-     * <p>
-     * This method is called after the input filter receives its last input event.
-     * The input filter should take this opportunity to clean up.
-     * </p>
-     */
-    public void onUninstalled() {
-    }
-
-    private final class H extends Handler {
-        public H(Looper looper) {
-            super(looper);
-        }
-
-        @Override
-        public void handleMessage(Message msg) {
-            switch (msg.what) {
-                case MSG_INSTALL:
-                    mHost = (Host)msg.obj;
-                    if (mInboundInputEventConsistencyVerifier != null) {
-                        mInboundInputEventConsistencyVerifier.reset();
-                    }
-                    if (mOutboundInputEventConsistencyVerifier != null) {
-                        mOutboundInputEventConsistencyVerifier.reset();
-                    }
-                    onInstalled();
-                    break;
-
-                case MSG_UNINSTALL:
-                    try {
-                        onUninstalled();
-                    } finally {
-                        mHost = null;
-                    }
-                    break;
-
-                case MSG_INPUT_EVENT: {
-                    final InputEvent event = (InputEvent)msg.obj;
-                    try {
-                        if (mInboundInputEventConsistencyVerifier != null) {
-                            mInboundInputEventConsistencyVerifier.onInputEvent(event, 0);
-                        }
-                        onInputEvent(event, msg.arg1);
-                    } finally {
-                        event.recycle();
-                    }
-                    break;
-                }
-            }
-        }
-    }
-
-    interface Host {
-        public void sendInputEvent(InputEvent event, int policyFlags);
-    }
-}
diff --git a/services/java/com/android/server/wm/InputManager.java b/services/java/com/android/server/wm/InputManager.java
deleted file mode 100644
index 56c3519..0000000
--- a/services/java/com/android/server/wm/InputManager.java
+++ /dev/null
@@ -1,683 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.wm;
-
-import com.android.internal.util.XmlUtils;
-import com.android.server.Watchdog;
-
-import org.xmlpull.v1.XmlPullParser;
-
-import android.content.Context;
-import android.content.pm.PackageManager;
-import android.content.res.Configuration;
-import android.database.ContentObserver;
-import android.os.Environment;
-import android.os.Looper;
-import android.os.MessageQueue;
-import android.os.SystemProperties;
-import android.provider.Settings;
-import android.provider.Settings.SettingNotFoundException;
-import android.util.Slog;
-import android.util.Xml;
-import android.view.InputChannel;
-import android.view.InputDevice;
-import android.view.InputEvent;
-import android.view.KeyEvent;
-import android.view.PointerIcon;
-import android.view.Surface;
-import android.view.ViewConfiguration;
-import android.view.WindowManager;
-import android.view.WindowManagerPolicy;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-
-/*
- * Wraps the C++ InputManager and provides its callbacks.
- */
-public class InputManager implements Watchdog.Monitor {
-    static final String TAG = "InputManager";
-    
-    private static final boolean DEBUG = false;
-
-    private final Callbacks mCallbacks;
-    private final Context mContext;
-    private final WindowManagerService mWindowManagerService;
-
-    private static native void nativeInit(Context context,
-            Callbacks callbacks, MessageQueue messageQueue);
-    private static native void nativeStart();
-    private static native void nativeSetDisplaySize(int displayId, int width, int height,
-            int externalWidth, int externalHeight);
-    private static native void nativeSetDisplayOrientation(int displayId, int rotation);
-    
-    private static native int nativeGetScanCodeState(int deviceId, int sourceMask,
-            int scanCode);
-    private static native int nativeGetKeyCodeState(int deviceId, int sourceMask,
-            int keyCode);
-    private static native int nativeGetSwitchState(int deviceId, int sourceMask,
-            int sw);
-    private static native boolean nativeHasKeys(int deviceId, int sourceMask,
-            int[] keyCodes, boolean[] keyExists);
-    private static native void nativeRegisterInputChannel(InputChannel inputChannel,
-            InputWindowHandle inputWindowHandle, boolean monitor);
-    private static native void nativeUnregisterInputChannel(InputChannel inputChannel);
-    private static native void nativeSetInputFilterEnabled(boolean enable);
-    private static native int nativeInjectInputEvent(InputEvent event,
-            int injectorPid, int injectorUid, int syncMode, int timeoutMillis,
-            int policyFlags);
-    private static native void nativeSetInputWindows(InputWindowHandle[] windowHandles);
-    private static native void nativeSetInputDispatchMode(boolean enabled, boolean frozen);
-    private static native void nativeSetSystemUiVisibility(int visibility);
-    private static native void nativeSetFocusedApplication(InputApplicationHandle application);
-    private static native InputDevice nativeGetInputDevice(int deviceId);
-    private static native void nativeGetInputConfiguration(Configuration configuration);
-    private static native int[] nativeGetInputDeviceIds();
-    private static native boolean nativeTransferTouchFocus(InputChannel fromChannel,
-            InputChannel toChannel);
-    private static native void nativeSetPointerSpeed(int speed);
-    private static native void nativeSetShowTouches(boolean enabled);
-    private static native String nativeDump();
-    private static native void nativeMonitor();
-    
-    // Input event injection constants defined in InputDispatcher.h.
-    static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0;
-    static final int INPUT_EVENT_INJECTION_PERMISSION_DENIED = 1;
-    static final int INPUT_EVENT_INJECTION_FAILED = 2;
-    static final int INPUT_EVENT_INJECTION_TIMED_OUT = 3;
-    
-    // Input event injection synchronization modes defined in InputDispatcher.h
-    static final int INPUT_EVENT_INJECTION_SYNC_NONE = 0;
-    static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT = 1;
-    static final int INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH = 2;
-    
-    // Key states (may be returned by queries about the current state of a
-    // particular key code, scan code or switch).
-    
-    /** The key state is unknown or the requested key itself is not supported. */
-    public static final int KEY_STATE_UNKNOWN = -1;
-
-    /** The key is up. /*/
-    public static final int KEY_STATE_UP = 0;
-
-    /** The key is down. */
-    public static final int KEY_STATE_DOWN = 1;
-
-    /** The key is down but is a virtual key press that is being emulated by the system. */
-    public static final int KEY_STATE_VIRTUAL = 2;
-
-    // State for the currently installed input filter.
-    final Object mInputFilterLock = new Object();
-    InputFilter mInputFilter;
-    InputFilterHost mInputFilterHost;
-
-    public InputManager(Context context, WindowManagerService windowManagerService) {
-        this.mContext = context;
-        this.mWindowManagerService = windowManagerService;
-        this.mCallbacks = new Callbacks();
-
-        Looper looper = windowManagerService.mH.getLooper();
-
-        Slog.i(TAG, "Initializing input manager");
-        nativeInit(mContext, mCallbacks, looper.getQueue());
-
-        // Add ourself to the Watchdog monitors.
-        Watchdog.getInstance().addMonitor(this);
-    }
-
-    public void start() {
-        Slog.i(TAG, "Starting input manager");
-        nativeStart();
-
-        registerPointerSpeedSettingObserver();
-        registerShowTouchesSettingObserver();
-
-        updatePointerSpeedFromSettings();
-        updateShowTouchesFromSettings();
-    }
-    
-    public void setDisplaySize(int displayId, int width, int height,
-            int externalWidth, int externalHeight) {
-        if (width <= 0 || height <= 0 || externalWidth <= 0 || externalHeight <= 0) {
-            throw new IllegalArgumentException("Invalid display id or dimensions.");
-        }
-        
-        if (DEBUG) {
-            Slog.d(TAG, "Setting display #" + displayId + " size to " + width + "x" + height
-                    + " external size " + externalWidth + "x" + externalHeight);
-        }
-        nativeSetDisplaySize(displayId, width, height, externalWidth, externalHeight);
-    }
-    
-    public void setDisplayOrientation(int displayId, int rotation) {
-        if (rotation < Surface.ROTATION_0 || rotation > Surface.ROTATION_270) {
-            throw new IllegalArgumentException("Invalid rotation.");
-        }
-        
-        if (DEBUG) {
-            Slog.d(TAG, "Setting display #" + displayId + " orientation to " + rotation);
-        }
-        nativeSetDisplayOrientation(displayId, rotation);
-    }
-    
-    public void getInputConfiguration(Configuration config) {
-        if (config == null) {
-            throw new IllegalArgumentException("config must not be null.");
-        }
-        
-        nativeGetInputConfiguration(config);
-    }
-    
-    /**
-     * Gets the current state of a key or button by key code.
-     * @param deviceId The input device id, or -1 to consult all devices.
-     * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
-     * consider all input sources.  An input device is consulted if at least one of its
-     * non-class input source bits matches the specified source mask.
-     * @param keyCode The key code to check.
-     * @return The key state.
-     */
-    public int getKeyCodeState(int deviceId, int sourceMask, int keyCode) {
-        return nativeGetKeyCodeState(deviceId, sourceMask, keyCode);
-    }
-    
-    /**
-     * Gets the current state of a key or button by scan code.
-     * @param deviceId The input device id, or -1 to consult all devices.
-     * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
-     * consider all input sources.  An input device is consulted if at least one of its
-     * non-class input source bits matches the specified source mask.
-     * @param scanCode The scan code to check.
-     * @return The key state.
-     */
-    public int getScanCodeState(int deviceId, int sourceMask, int scanCode) {
-        return nativeGetScanCodeState(deviceId, sourceMask, scanCode);
-    }
-    
-    /**
-     * Gets the current state of a switch by switch code.
-     * @param deviceId The input device id, or -1 to consult all devices.
-     * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
-     * consider all input sources.  An input device is consulted if at least one of its
-     * non-class input source bits matches the specified source mask.
-     * @param switchCode The switch code to check.
-     * @return The switch state.
-     */
-    public int getSwitchState(int deviceId, int sourceMask, int switchCode) {
-        return nativeGetSwitchState(deviceId, sourceMask, switchCode);
-    }
-
-    /**
-     * Determines whether the specified key codes are supported by a particular device.
-     * @param deviceId The input device id, or -1 to consult all devices.
-     * @param sourceMask The input sources to consult, or {@link InputDevice#SOURCE_ANY} to
-     * consider all input sources.  An input device is consulted if at least one of its
-     * non-class input source bits matches the specified source mask.
-     * @param keyCodes The array of key codes to check.
-     * @param keyExists An array at least as large as keyCodes whose entries will be set
-     * to true or false based on the presence or absence of support for the corresponding
-     * key codes.
-     * @return True if the lookup was successful, false otherwise.
-     */
-    public boolean hasKeys(int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists) {
-        if (keyCodes == null) {
-            throw new IllegalArgumentException("keyCodes must not be null.");
-        }
-        if (keyExists == null || keyExists.length < keyCodes.length) {
-            throw new IllegalArgumentException("keyExists must not be null and must be at "
-                    + "least as large as keyCodes.");
-        }
-        
-        return nativeHasKeys(deviceId, sourceMask, keyCodes, keyExists);
-    }
-    
-    /**
-     * Creates an input channel that will receive all input from the input dispatcher.
-     * @param inputChannelName The input channel name.
-     * @return The input channel.
-     */
-    public InputChannel monitorInput(String inputChannelName) {
-        if (inputChannelName == null) {
-            throw new IllegalArgumentException("inputChannelName must not be null.");
-        }
-        
-        InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
-        nativeRegisterInputChannel(inputChannels[0], null, true);
-        inputChannels[0].dispose(); // don't need to retain the Java object reference
-        return inputChannels[1];
-    }
-
-    /**
-     * Registers an input channel so that it can be used as an input event target.
-     * @param inputChannel The input channel to register.
-     * @param inputWindowHandle The handle of the input window associated with the
-     * input channel, or null if none.
-     */
-    public void registerInputChannel(InputChannel inputChannel,
-            InputWindowHandle inputWindowHandle) {
-        if (inputChannel == null) {
-            throw new IllegalArgumentException("inputChannel must not be null.");
-        }
-        
-        nativeRegisterInputChannel(inputChannel, inputWindowHandle, false);
-    }
-    
-    /**
-     * Unregisters an input channel.
-     * @param inputChannel The input channel to unregister.
-     */
-    public void unregisterInputChannel(InputChannel inputChannel) {
-        if (inputChannel == null) {
-            throw new IllegalArgumentException("inputChannel must not be null.");
-        }
-        
-        nativeUnregisterInputChannel(inputChannel);
-    }
-
-    /**
-     * Sets an input filter that will receive all input events before they are dispatched.
-     * The input filter may then reinterpret input events or inject new ones.
-     *
-     * To ensure consistency, the input dispatcher automatically drops all events
-     * in progress whenever an input filter is installed or uninstalled.  After an input
-     * filter is uninstalled, it can no longer send input events unless it is reinstalled.
-     * Any events it attempts to send after it has been uninstalled will be dropped.
-     *
-     * @param filter The input filter, or null to remove the current filter.
-     */
-    public void setInputFilter(InputFilter filter) {
-        synchronized (mInputFilterLock) {
-            final InputFilter oldFilter = mInputFilter;
-            if (oldFilter == filter) {
-                return; // nothing to do
-            }
-
-            if (oldFilter != null) {
-                mInputFilter = null;
-                mInputFilterHost.disconnectLocked();
-                mInputFilterHost = null;
-                oldFilter.uninstall();
-            }
-
-            if (filter != null) {
-                mInputFilter = filter;
-                mInputFilterHost = new InputFilterHost();
-                filter.install(mInputFilterHost);
-            }
-
-            nativeSetInputFilterEnabled(filter != null);
-        }
-    }
-
-    /**
-     * Injects an input event into the event system on behalf of an application.
-     * The synchronization mode determines whether the method blocks while waiting for
-     * input injection to proceed.
-     * 
-     * {@link #INPUT_EVENT_INJECTION_SYNC_NONE} never blocks.  Injection is asynchronous and
-     * is assumed always to be successful.
-     * 
-     * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT} waits for previous events to be
-     * dispatched so that the input dispatcher can determine whether input event injection will
-     * be permitted based on the current input focus.  Does not wait for the input event to
-     * finish processing.
-     * 
-     * {@link #INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH} waits for the input event to
-     * be completely processed.
-     * 
-     * @param event The event to inject.
-     * @param injectorPid The pid of the injecting application.
-     * @param injectorUid The uid of the injecting application.
-     * @param syncMode The synchronization mode.
-     * @param timeoutMillis The injection timeout in milliseconds.
-     * @return One of the INPUT_EVENT_INJECTION_XXX constants.
-     */
-    public int injectInputEvent(InputEvent event, int injectorPid, int injectorUid,
-            int syncMode, int timeoutMillis) {
-        if (event == null) {
-            throw new IllegalArgumentException("event must not be null");
-        }
-        if (injectorPid < 0 || injectorUid < 0) {
-            throw new IllegalArgumentException("injectorPid and injectorUid must not be negative.");
-        }
-        if (timeoutMillis <= 0) {
-            throw new IllegalArgumentException("timeoutMillis must be positive");
-        }
-
-        return nativeInjectInputEvent(event, injectorPid, injectorUid, syncMode, timeoutMillis,
-                WindowManagerPolicy.FLAG_DISABLE_KEY_REPEAT);
-    }
-
-    /**
-     * Gets information about the input device with the specified id.
-     * @param id The device id.
-     * @return The input device or null if not found.
-     */
-    public InputDevice getInputDevice(int deviceId) {
-        return nativeGetInputDevice(deviceId);
-    }
-    
-    /**
-     * Gets the ids of all input devices in the system.
-     * @return The input device ids.
-     */
-    public int[] getInputDeviceIds() {
-        return nativeGetInputDeviceIds();
-    }
-    
-    public void setInputWindows(InputWindowHandle[] windowHandles) {
-        nativeSetInputWindows(windowHandles);
-    }
-    
-    public void setFocusedApplication(InputApplicationHandle application) {
-        nativeSetFocusedApplication(application);
-    }
-    
-    public void setInputDispatchMode(boolean enabled, boolean frozen) {
-        nativeSetInputDispatchMode(enabled, frozen);
-    }
-
-    public void setSystemUiVisibility(int visibility) {
-        nativeSetSystemUiVisibility(visibility);
-    }
-
-    /**
-     * Atomically transfers touch focus from one window to another as identified by
-     * their input channels.  It is possible for multiple windows to have
-     * touch focus if they support split touch dispatch
-     * {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} but this
-     * method only transfers touch focus of the specified window without affecting
-     * other windows that may also have touch focus at the same time.
-     * @param fromChannel The channel of a window that currently has touch focus.
-     * @param toChannel The channel of the window that should receive touch focus in
-     * place of the first.
-     * @return True if the transfer was successful.  False if the window with the
-     * specified channel did not actually have touch focus at the time of the request.
-     */
-    public boolean transferTouchFocus(InputChannel fromChannel, InputChannel toChannel) {
-        if (fromChannel == null) {
-            throw new IllegalArgumentException("fromChannel must not be null.");
-        }
-        if (toChannel == null) {
-            throw new IllegalArgumentException("toChannel must not be null.");
-        }
-        return nativeTransferTouchFocus(fromChannel, toChannel);
-    }
-
-    /**
-     * Set the pointer speed.
-     * @param speed The pointer speed as a value between -7 (slowest) and 7 (fastest)
-     * where 0 is the default speed.
-     */
-    public void setPointerSpeed(int speed) {
-        speed = Math.min(Math.max(speed, -7), 7);
-        nativeSetPointerSpeed(speed);
-    }
-
-    public void updatePointerSpeedFromSettings() {
-        int speed = getPointerSpeedSetting(0);
-        setPointerSpeed(speed);
-    }
-
-    private void registerPointerSpeedSettingObserver() {
-        mContext.getContentResolver().registerContentObserver(
-                Settings.System.getUriFor(Settings.System.POINTER_SPEED), true,
-                new ContentObserver(mWindowManagerService.mH) {
-                    @Override
-                    public void onChange(boolean selfChange) {
-                        updatePointerSpeedFromSettings();
-                    }
-                });
-    }
-
-    private int getPointerSpeedSetting(int defaultValue) {
-        int speed = defaultValue;
-        try {
-            speed = Settings.System.getInt(mContext.getContentResolver(),
-                    Settings.System.POINTER_SPEED);
-        } catch (SettingNotFoundException snfe) {
-        }
-        return speed;
-    }
-
-    public void updateShowTouchesFromSettings() {
-        int setting = getShowTouchesSetting(0);
-        nativeSetShowTouches(setting != 0);
-    }
-
-    private void registerShowTouchesSettingObserver() {
-        mContext.getContentResolver().registerContentObserver(
-                Settings.System.getUriFor(Settings.System.SHOW_TOUCHES), true,
-                new ContentObserver(mWindowManagerService.mH) {
-                    @Override
-                    public void onChange(boolean selfChange) {
-                        updateShowTouchesFromSettings();
-                    }
-                });
-    }
-
-    private int getShowTouchesSetting(int defaultValue) {
-        int result = defaultValue;
-        try {
-            result = Settings.System.getInt(mContext.getContentResolver(),
-                    Settings.System.SHOW_TOUCHES);
-        } catch (SettingNotFoundException snfe) {
-        }
-        return result;
-    }
-
-    public void dump(PrintWriter pw) {
-        String dumpStr = nativeDump();
-        if (dumpStr != null) {
-            pw.println(dumpStr);
-        }
-    }
-
-    // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
-    public void monitor() {
-        synchronized (mInputFilterLock) { }
-        nativeMonitor();
-    }
-
-    private final class InputFilterHost implements InputFilter.Host {
-        private boolean mDisconnected;
-
-        public void disconnectLocked() {
-            mDisconnected = true;
-        }
-
-        public void sendInputEvent(InputEvent event, int policyFlags) {
-            if (event == null) {
-                throw new IllegalArgumentException("event must not be null");
-            }
-
-            synchronized (mInputFilterLock) {
-                if (!mDisconnected) {
-                    nativeInjectInputEvent(event, 0, 0, INPUT_EVENT_INJECTION_SYNC_NONE, 0,
-                            policyFlags | WindowManagerPolicy.FLAG_FILTERED);
-                }
-            }
-        }
-    }
-
-    /*
-     * Callbacks from native.
-     */
-    private final class Callbacks {
-        static final String TAG = "InputManager-Callbacks";
-        
-        private static final boolean DEBUG_VIRTUAL_KEYS = false;
-        private static final String EXCLUDED_DEVICES_PATH = "etc/excluded-input-devices.xml";
-        private static final String CALIBRATION_DIR_PATH = "usr/idc/";
-        
-        @SuppressWarnings("unused")
-        public void notifyConfigurationChanged(long whenNanos) {
-            mWindowManagerService.mInputMonitor.notifyConfigurationChanged();
-        }
-        
-        @SuppressWarnings("unused")
-        public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
-            mWindowManagerService.mInputMonitor.notifyLidSwitchChanged(whenNanos, lidOpen);
-        }
-        
-        @SuppressWarnings("unused")
-        public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
-            mWindowManagerService.mInputMonitor.notifyInputChannelBroken(inputWindowHandle);
-        }
-        
-        @SuppressWarnings("unused")
-        public long notifyANR(InputApplicationHandle inputApplicationHandle,
-                InputWindowHandle inputWindowHandle) {
-            return mWindowManagerService.mInputMonitor.notifyANR(
-                    inputApplicationHandle, inputWindowHandle);
-        }
-
-        @SuppressWarnings("unused")
-        final boolean filterInputEvent(InputEvent event, int policyFlags) {
-            synchronized (mInputFilterLock) {
-                if (mInputFilter != null) {
-                    mInputFilter.filterInputEvent(event, policyFlags);
-                    return false;
-                }
-            }
-            event.recycle();
-            return true;
-        }
-
-        @SuppressWarnings("unused")
-        public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
-            return mWindowManagerService.mInputMonitor.interceptKeyBeforeQueueing(
-                    event, policyFlags, isScreenOn);
-        }
-
-        @SuppressWarnings("unused")
-        public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {
-            return mWindowManagerService.mInputMonitor.interceptMotionBeforeQueueingWhenScreenOff(
-                    policyFlags);
-        }
-
-        @SuppressWarnings("unused")
-        public long interceptKeyBeforeDispatching(InputWindowHandle focus,
-                KeyEvent event, int policyFlags) {
-            return mWindowManagerService.mInputMonitor.interceptKeyBeforeDispatching(
-                    focus, event, policyFlags);
-        }
-        
-        @SuppressWarnings("unused")
-        public KeyEvent dispatchUnhandledKey(InputWindowHandle focus,
-                KeyEvent event, int policyFlags) {
-            return mWindowManagerService.mInputMonitor.dispatchUnhandledKey(
-                    focus, event, policyFlags);
-        }
-        
-        @SuppressWarnings("unused")
-        public boolean checkInjectEventsPermission(int injectorPid, int injectorUid) {
-            return mContext.checkPermission(
-                    android.Manifest.permission.INJECT_EVENTS, injectorPid, injectorUid)
-                    == PackageManager.PERMISSION_GRANTED;
-        }
-
-        @SuppressWarnings("unused")
-        public int getVirtualKeyQuietTimeMillis() {
-            return mContext.getResources().getInteger(
-                    com.android.internal.R.integer.config_virtualKeyQuietTimeMillis);
-        }
-
-        @SuppressWarnings("unused")
-        public String[] getExcludedDeviceNames() {
-            ArrayList<String> names = new ArrayList<String>();
-            
-            // Read partner-provided list of excluded input devices
-            XmlPullParser parser = null;
-            // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
-            File confFile = new File(Environment.getRootDirectory(), EXCLUDED_DEVICES_PATH);
-            FileReader confreader = null;
-            try {
-                confreader = new FileReader(confFile);
-                parser = Xml.newPullParser();
-                parser.setInput(confreader);
-                XmlUtils.beginDocument(parser, "devices");
-
-                while (true) {
-                    XmlUtils.nextElement(parser);
-                    if (!"device".equals(parser.getName())) {
-                        break;
-                    }
-                    String name = parser.getAttributeValue(null, "name");
-                    if (name != null) {
-                        names.add(name);
-                    }
-                }
-            } catch (FileNotFoundException e) {
-                // It's ok if the file does not exist.
-            } catch (Exception e) {
-                Slog.e(TAG, "Exception while parsing '" + confFile.getAbsolutePath() + "'", e);
-            } finally {
-                try { if (confreader != null) confreader.close(); } catch (IOException e) { }
-            }
-            
-            return names.toArray(new String[names.size()]);
-        }
-
-        @SuppressWarnings("unused")
-        public int getKeyRepeatTimeout() {
-            return ViewConfiguration.getKeyRepeatTimeout();
-        }
-
-        @SuppressWarnings("unused")
-        public int getKeyRepeatDelay() {
-            return ViewConfiguration.getKeyRepeatDelay();
-        }
-
-        @SuppressWarnings("unused")
-        public int getHoverTapTimeout() {
-            return ViewConfiguration.getHoverTapTimeout();
-        }
-
-        @SuppressWarnings("unused")
-        public int getHoverTapSlop() {
-            return ViewConfiguration.getHoverTapSlop();
-        }
-
-        @SuppressWarnings("unused")
-        public int getDoubleTapTimeout() {
-            return ViewConfiguration.getDoubleTapTimeout();
-        }
-
-        @SuppressWarnings("unused")
-        public int getLongPressTimeout() {
-            return ViewConfiguration.getLongPressTimeout();
-        }
-
-        @SuppressWarnings("unused")
-        public int getPointerLayer() {
-            return mWindowManagerService.mPolicy.windowTypeToLayerLw(
-                    WindowManager.LayoutParams.TYPE_POINTER)
-                    * WindowManagerService.TYPE_LAYER_MULTIPLIER
-                    + WindowManagerService.TYPE_LAYER_OFFSET;
-        }
-
-        @SuppressWarnings("unused")
-        public PointerIcon getPointerIcon() {
-            return PointerIcon.getDefaultIcon(mContext);
-        }
-    }
-}
diff --git a/services/java/com/android/server/wm/InputMonitor.java b/services/java/com/android/server/wm/InputMonitor.java
index fb74d27..c28cfa2 100644
--- a/services/java/com/android/server/wm/InputMonitor.java
+++ b/services/java/com/android/server/wm/InputMonitor.java
@@ -16,6 +16,10 @@
 
 package com.android.server.wm;
 
+import com.android.server.input.InputManagerService;
+import com.android.server.input.InputApplicationHandle;
+import com.android.server.input.InputWindowHandle;
+
 import android.graphics.Rect;
 import android.os.RemoteException;
 import android.util.Log;
@@ -27,7 +31,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 
-final class InputMonitor {
+final class InputMonitor implements InputManagerService.Callbacks {
     private final WindowManagerService mService;
     
     // Current window with input focus for keys and other non-touch events.  May be null.
@@ -93,7 +97,7 @@
         }
         
         if (appWindowToken == null && inputApplicationHandle != null) {
-            appWindowToken = inputApplicationHandle.appWindowToken;
+            appWindowToken = (AppWindowToken)inputApplicationHandle.appWindowToken;
             if (appWindowToken != null) {
                 Slog.i(WindowManagerService.TAG,
                         "Input event dispatching timed out sending to application "
@@ -301,7 +305,14 @@
         WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
         return mService.mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
     }
-    
+
+    /* Callback to get pointer layer. */
+    public int getPointerLayer() {
+        return mService.mPolicy.windowTypeToLayerLw(WindowManager.LayoutParams.TYPE_POINTER)
+                * WindowManagerService.TYPE_LAYER_MULTIPLIER
+                + WindowManagerService.TYPE_LAYER_OFFSET;
+    }
+
     /* Called when the current input focus changes.
      * Layer assignment is assumed to be complete by the time this is called.
      */
diff --git a/services/java/com/android/server/wm/InputWindowHandle.java b/services/java/com/android/server/wm/InputWindowHandle.java
deleted file mode 100644
index 264877c..0000000
--- a/services/java/com/android/server/wm/InputWindowHandle.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.server.wm;
-
-import android.graphics.Region;
-import android.view.InputChannel;
-import android.view.WindowManagerPolicy;
-
-/**
- * Functions as a handle for a window that can receive input.
- * Enables the native input dispatcher to refer indirectly to the window manager's window state.
- * @hide
- */
-public final class InputWindowHandle {
-    // Pointer to the native input window handle.
-    // This field is lazily initialized via JNI.
-    @SuppressWarnings("unused")
-    private int ptr;
-
-    // The input application handle.
-    public final InputApplicationHandle inputApplicationHandle;
-
-    // The window manager's window state.
-    public final WindowManagerPolicy.WindowState windowState;
-
-    // The input channel associated with the window.
-    public InputChannel inputChannel;
-
-    // The window name.
-    public String name;
-
-    // Window layout params attributes.  (WindowManager.LayoutParams)
-    public int layoutParamsFlags;
-    public int layoutParamsType;
-
-    // Dispatching timeout.
-    public long dispatchingTimeoutNanos;
-
-    // Window frame.
-    public int frameLeft;
-    public int frameTop;
-    public int frameRight;
-    public int frameBottom;
-
-    // Global scaling factor applied to touch events when they are dispatched
-    // to the window
-    public float scaleFactor;
-
-    // Window touchable region.
-    public final Region touchableRegion = new Region();
-
-    // Window is visible.
-    public boolean visible;
-
-    // Window can receive keys.
-    public boolean canReceiveKeys;
-
-    // Window has focus.
-    public boolean hasFocus;
-
-    // Window has wallpaper.  (window is the current wallpaper target)
-    public boolean hasWallpaper;
-
-    // Input event dispatching is paused.
-    public boolean paused;
-
-    // Window layer.
-    public int layer;
-
-    // Id of process and user that owns the window.
-    public int ownerPid;
-    public int ownerUid;
-
-    // Window input features.
-    public int inputFeatures;
-
-    private native void nativeDispose();
-
-    public InputWindowHandle(InputApplicationHandle inputApplicationHandle,
-            WindowManagerPolicy.WindowState windowState) {
-        this.inputApplicationHandle = inputApplicationHandle;
-        this.windowState = windowState;
-    }
-
-    @Override
-    protected void finalize() throws Throwable {
-        try {
-            nativeDispose();
-        } finally {
-            super.finalize();
-        }
-    }
-}
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index afbc348..da56ef7 100644
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -44,6 +44,8 @@
 import com.android.server.PowerManagerService;
 import com.android.server.Watchdog;
 import com.android.server.am.BatteryStatsService;
+import com.android.server.input.InputFilter;
+import com.android.server.input.InputManagerService;
 
 import android.Manifest;
 import android.app.ActivityManagerNative;
@@ -577,7 +579,7 @@
     float mTransitionAnimationScale = 1.0f;
     float mAnimatorDurationScale = 1.0f;
 
-    final InputManager mInputManager;
+    final InputManagerService mInputManager;
 
     // Who is holding the screen on.
     Session mHoldingScreenOn;
@@ -843,7 +845,7 @@
                 "KEEP_SCREEN_ON_FLAG");
         mHoldingScreenWakeLock.setReferenceCounted(false);
 
-        mInputManager = new InputManager(context, this);
+        mInputManager = new InputManagerService(context, mInputMonitor);
         mAnimator = new WindowAnimator(this, context, mPolicy);
 
         PolicyThread thr = new PolicyThread(mPolicy, this, context, pm);
@@ -864,6 +866,10 @@
         Watchdog.getInstance().addMonitor(this);
     }
 
+    public InputManagerService getInputManagerService() {
+        return mInputManager;
+    }
+
     @Override
     public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
             throws RemoteException {
@@ -6416,8 +6422,8 @@
         final long ident = Binder.clearCallingIdentity();
         
         final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
-                sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
-                        : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
+                sync ? InputManagerService.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
+                        : InputManagerService.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
                 INJECTION_TIMEOUT_MILLIS);
         
         Binder.restoreCallingIdentity(ident);
@@ -6446,8 +6452,8 @@
         }
         
         final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
-                sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
-                        : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
+                sync ? InputManagerService.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
+                        : InputManagerService.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
                 INJECTION_TIMEOUT_MILLIS);
         
         Binder.restoreCallingIdentity(ident);
@@ -6476,8 +6482,8 @@
         }
         
         final int result = mInputManager.injectInputEvent(newEvent, pid, uid,
-                sync ? InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
-                        : InputManager.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
+                sync ? InputManagerService.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_FINISH
+                        : InputManagerService.INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT,
                 INJECTION_TIMEOUT_MILLIS);
         
         Binder.restoreCallingIdentity(ident);
@@ -6498,7 +6504,7 @@
         final long ident = Binder.clearCallingIdentity();
         
         final int result = mInputManager.injectInputEvent(ev, pid, uid,
-                InputManager.INPUT_EVENT_INJECTION_SYNC_NONE,
+                InputManagerService.INPUT_EVENT_INJECTION_SYNC_NONE,
                 INJECTION_TIMEOUT_MILLIS);
         
         Binder.restoreCallingIdentity(ident);
@@ -6507,16 +6513,16 @@
     
     private boolean reportInjectionResult(int result, int pid) {
         switch (result) {
-            case InputManager.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
+            case InputManagerService.INPUT_EVENT_INJECTION_PERMISSION_DENIED:
                 Slog.w(TAG, "Input event injection from pid " + pid + " permission denied.");
                 throw new SecurityException(
                         "Injecting to another application requires INJECT_EVENTS permission");
-            case InputManager.INPUT_EVENT_INJECTION_SUCCEEDED:
+            case InputManagerService.INPUT_EVENT_INJECTION_SUCCEEDED:
                 return true;
-            case InputManager.INPUT_EVENT_INJECTION_TIMED_OUT:
+            case InputManagerService.INPUT_EVENT_INJECTION_TIMED_OUT:
                 Slog.w(TAG, "Input event injection from pid " + pid + " timed out.");
                 return false;
-            case InputManager.INPUT_EVENT_INJECTION_FAILED:
+            case InputManagerService.INPUT_EVENT_INJECTION_FAILED:
             default:
                 Slog.w(TAG, "Input event injection from pid " + pid + " failed.");
                 return false;
@@ -9192,11 +9198,6 @@
         mPolicy.lockNow();
     }
 
-    void dumpInput(FileDescriptor fd, PrintWriter pw, boolean dumpAll) {
-        pw.println("WINDOW MANAGER INPUT (dumpsys window input)");
-        mInputManager.dump(pw);
-    }
-
     void dumpPolicyLocked(FileDescriptor fd, PrintWriter pw, String[] args, boolean dumpAll) {
         pw.println("WINDOW MANAGER POLICY STATE (dumpsys window policy)");
         mPolicy.dump("    ", fd, pw, args);
@@ -9592,7 +9593,6 @@
                 pw.println("Window manager dump options:");
                 pw.println("  [-a] [-h] [cmd] ...");
                 pw.println("  cmd may be one of:");
-                pw.println("    i[input]: input subsystem state");
                 pw.println("    p[policy]: policy state");
                 pw.println("    s[essions]: active sessions");
                 pw.println("    t[okens]: token list");
@@ -9613,10 +9613,7 @@
         if (opti < args.length) {
             String cmd = args[opti];
             opti++;
-            if ("input".equals(cmd) || "i".equals(cmd)) {
-                dumpInput(fd, pw, true);
-                return;
-            } else if ("policy".equals(cmd) || "p".equals(cmd)) {
+            if ("policy".equals(cmd) || "p".equals(cmd)) {
                 synchronized(mWindowMap) {
                     dumpPolicyLocked(fd, pw, args, true);
                 }
@@ -9651,8 +9648,6 @@
             }
         }
 
-        dumpInput(fd, pw, dumpAll);
-
         synchronized(mWindowMap) {
             if (dumpAll) {
                 pw.println("-------------------------------------------------------------------------------");
diff --git a/services/java/com/android/server/wm/WindowState.java b/services/java/com/android/server/wm/WindowState.java
index b74aa61..d65b947 100644
--- a/services/java/com/android/server/wm/WindowState.java
+++ b/services/java/com/android/server/wm/WindowState.java
@@ -23,6 +23,8 @@
 import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
 import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
 
+import com.android.server.input.InputWindowHandle;
+
 import android.content.Context;
 import android.content.res.Configuration;
 import android.graphics.Matrix;