Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a9d131c3 authored by Jeff Brown's avatar Jeff Brown
Browse files

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
parent bbd28a29
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -300,16 +300,22 @@ class ServerThread extends Thread {
            Watchdog.getInstance().init(context, battery, power, alarm,
                    ActivityManagerService.self());

            Slog.i(TAG, "Input Manager");
            inputManager = new InputManagerService(context, wmHandler);

            Slog.i(TAG, "Window Manager");
            wm = WindowManagerService.main(context, power, display,
            wm = WindowManagerService.main(context, power, display, inputManager,
                    uiHandler, wmHandler,
                    factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL,
                    !firstBoot, onlyCore);
            ServiceManager.addService(Context.WINDOW_SERVICE, wm);
            inputManager = wm.getInputManagerService();
            ServiceManager.addService(Context.INPUT_SERVICE, inputManager);

            ActivityManagerService.self().setWindowManager(wm);

            inputManager.setWindowManagerCallbacks(wm.getInputMonitor());
            inputManager.start();

            display.setWindowManager(wm);
            display.setInputManager(inputManager);

+21 −17
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import android.os.Bundle;
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.InputDevice;
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 @@ public class InputManagerService extends IInputManager.Stub
    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 @@ public class InputManagerService extends IInputManager.Stub
    /** 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 @@ public class InputManagerService extends IInputManager.Stub

    // Native callback.
    private void notifyConfigurationChanged(long whenNanos) {
        mCallbacks.notifyConfigurationChanged();
        mWindowManagerCallbacks.notifyConfigurationChanged();
    }

    // Native callback.
@@ -1224,20 +1228,20 @@ public class InputManagerService extends IInputManager.Stub
    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 @@ public class InputManagerService extends IInputManager.Stub

    // 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 @@ public class InputManagerService extends IInputManager.Stub

    // Native callback.
    private int getPointerLayer() {
        return mCallbacks.getPointerLayer();
        return mWindowManagerCallbacks.getPointerLayer();
    }

    // Native callback.
@@ -1414,7 +1418,7 @@ public class InputManagerService extends IInputManager.Stub
    /**
     * 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 @@ public class InputManagerService extends IInputManager.Stub
     * 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
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ import android.view.WindowManager;
import java.util.ArrayList;
import java.util.Arrays;

final class InputMonitor implements InputManagerService.Callbacks {
final class InputMonitor implements InputManagerService.WindowManagerCallbacks {
    private final WindowManagerService mService;
    
    // Current window with input focus for keys and other non-touch events.  May be null.
+8 −7
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.hardware.display.DisplayManager;
import android.hardware.input.InputManager;
import android.os.Binder;
import android.os.Bundle;
import android.os.Debug;
@@ -738,6 +739,7 @@ public class WindowManagerService extends IWindowManager.Stub

    public static WindowManagerService main(final Context context,
            final PowerManagerService pm, final DisplayManagerService dm,
            final InputManagerService im,
            final Handler uiHandler, final Handler wmHandler,
            final boolean haveInputMethods, final boolean showBootMsgs,
            final boolean onlyCore) {
@@ -745,7 +747,7 @@ public class WindowManagerService extends IWindowManager.Stub
        wmHandler.runWithScissors(new Runnable() {
            @Override
            public void run() {
                holder[0] = new WindowManagerService(context, pm, dm,
                holder[0] = new WindowManagerService(context, pm, dm, im,
                        uiHandler, haveInputMethods, showBootMsgs, onlyCore);
            }
        }, 0);
@@ -767,7 +769,8 @@ public class WindowManagerService extends IWindowManager.Stub
    }

    private WindowManagerService(Context context, PowerManagerService pm,
            DisplayManagerService displayManager, Handler uiHandler,
            DisplayManagerService displayManager, InputManagerService inputManager,
            Handler uiHandler,
            boolean haveInputMethods, boolean showBootMsgs, boolean onlyCore) {
        mContext = context;
        mHaveInputMethods = haveInputMethods;
@@ -814,14 +817,12 @@ public class WindowManagerService extends IWindowManager.Stub
                | PowerManager.ON_AFTER_RELEASE, TAG);
        mHoldingScreenWakeLock.setReferenceCounted(false);

        mInputManager = new InputManagerService(context, mInputMonitor);
        mInputManager = inputManager;
        mFxSession = new SurfaceSession();
        mAnimator = new WindowAnimator(this);

        initPolicy(uiHandler);

        mInputManager.start();

        // Add ourself to the Watchdog monitors.
        Watchdog.getInstance().addMonitor(this);

@@ -833,8 +834,8 @@ public class WindowManagerService extends IWindowManager.Stub
        }
    }

    public InputManagerService getInputManagerService() {
        return mInputManager;
    public InputMonitor getInputMonitor() {
        return mInputMonitor;
    }

    @Override