Disentangle input manager service startup.
We will be adding additional callbacks for other components.
This change makes it clearer how the input manager is started
and where the callbacks are initialized.
Bug: 6548391
Change-Id: I4b2a61482126a12b7cf11fafe513f846c76c11e5
diff --git a/services/java/com/android/server/input/InputManagerService.java b/services/java/com/android/server/input/InputManagerService.java
index 805818a..3709314 100644
--- a/services/java/com/android/server/input/InputManagerService.java
+++ b/services/java/com/android/server/input/InputManagerService.java
@@ -53,6 +53,7 @@
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
+import android.os.Looper;
import android.os.Message;
import android.os.MessageQueue;
import android.os.Process;
@@ -70,7 +71,6 @@
import android.view.InputEvent;
import android.view.KeyEvent;
import android.view.PointerIcon;
-import android.view.Surface;
import android.view.ViewConfiguration;
import android.view.WindowManagerPolicy;
import android.widget.Toast;
@@ -109,8 +109,9 @@
private final int mPtr;
private final Context mContext;
- private final Callbacks mCallbacks;
private final InputManagerHandler mHandler;
+
+ private WindowManagerCallbacks mWindowManagerCallbacks;
private boolean mSystemReady;
private NotificationManager mNotificationManager;
@@ -217,15 +218,18 @@
/** Switch code: Keypad slide. When set, keyboard is exposed. */
public static final int SW_KEYPAD_SLIDE = 0x0a;
- public InputManagerService(Context context, Callbacks callbacks) {
+ public InputManagerService(Context context, Handler handler) {
this.mContext = context;
- this.mCallbacks = callbacks;
- this.mHandler = new InputManagerHandler();
+ this.mHandler = new InputManagerHandler(handler.getLooper());
Slog.i(TAG, "Initializing input manager");
mPtr = nativeInit(this, mContext, mHandler.getLooper().getQueue());
}
+ public void setWindowManagerCallbacks(WindowManagerCallbacks callbacks) {
+ mWindowManagerCallbacks = callbacks;
+ }
+
public void start() {
Slog.i(TAG, "Starting input manager");
nativeStart(mPtr);
@@ -1204,7 +1208,7 @@
// Native callback.
private void notifyConfigurationChanged(long whenNanos) {
- mCallbacks.notifyConfigurationChanged();
+ mWindowManagerCallbacks.notifyConfigurationChanged();
}
// Native callback.
@@ -1224,20 +1228,20 @@
private void notifySwitch(long whenNanos, int switchCode, int switchValue) {
switch (switchCode) {
case SW_LID:
- mCallbacks.notifyLidSwitchChanged(whenNanos, switchValue == 0);
+ mWindowManagerCallbacks.notifyLidSwitchChanged(whenNanos, switchValue == 0);
break;
}
}
// Native callback.
private void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
- mCallbacks.notifyInputChannelBroken(inputWindowHandle);
+ mWindowManagerCallbacks.notifyInputChannelBroken(inputWindowHandle);
}
// Native callback.
private long notifyANR(InputApplicationHandle inputApplicationHandle,
InputWindowHandle inputWindowHandle) {
- return mCallbacks.notifyANR(inputApplicationHandle, inputWindowHandle);
+ return mWindowManagerCallbacks.notifyANR(inputApplicationHandle, inputWindowHandle);
}
// Native callback.
@@ -1258,25 +1262,25 @@
// Native callback.
private int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
- return mCallbacks.interceptKeyBeforeQueueing(
+ return mWindowManagerCallbacks.interceptKeyBeforeQueueing(
event, policyFlags, isScreenOn);
}
// Native callback.
private int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {
- return mCallbacks.interceptMotionBeforeQueueingWhenScreenOff(policyFlags);
+ return mWindowManagerCallbacks.interceptMotionBeforeQueueingWhenScreenOff(policyFlags);
}
// Native callback.
private long interceptKeyBeforeDispatching(InputWindowHandle focus,
KeyEvent event, int policyFlags) {
- return mCallbacks.interceptKeyBeforeDispatching(focus, event, policyFlags);
+ return mWindowManagerCallbacks.interceptKeyBeforeDispatching(focus, event, policyFlags);
}
// Native callback.
private KeyEvent dispatchUnhandledKey(InputWindowHandle focus,
KeyEvent event, int policyFlags) {
- return mCallbacks.dispatchUnhandledKey(focus, event, policyFlags);
+ return mWindowManagerCallbacks.dispatchUnhandledKey(focus, event, policyFlags);
}
// Native callback.
@@ -1359,7 +1363,7 @@
// Native callback.
private int getPointerLayer() {
- return mCallbacks.getPointerLayer();
+ return mWindowManagerCallbacks.getPointerLayer();
}
// Native callback.
@@ -1414,7 +1418,7 @@
/**
* Callback interface implemented by the Window Manager.
*/
- public interface Callbacks {
+ public interface WindowManagerCallbacks {
public void notifyConfigurationChanged();
public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen);
@@ -1441,8 +1445,8 @@
* Private handler for the input manager.
*/
private final class InputManagerHandler extends Handler {
- public InputManagerHandler() {
- super(true /*async*/);
+ public InputManagerHandler(Looper looper) {
+ super(looper, null, true /*async*/);
}
@Override