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

Commit e0a353c6 authored by Robert Carr's avatar Robert Carr
Browse files

WindowManager: Communicate with input system by WindowTokens.

Once we switch to a model of passing InputWindowInfo through
SurfaceFlinger, the handles will be parcelled and we will
no longer receive the same literal object back from "interceptKeyBeforeQueueing"
or other input callbacks. This means the approach of saddling a WindowState
on to the object for later retreival will no longer work. Instead we pass
the IBinder WindowState#mClient in when registering the input channel, and modify the
input system to pass it back to us as a sort of UUID.

Bug: 80101428
Bug: 113136004
Bug: 111440400
Test: Home button still works.
Change-Id: I0f41e0d08b034aa037518c3a8fb21be1453565da
parent 788f5748
Loading
Loading
Loading
Loading
+16 −5
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.view;

import android.annotation.UnsupportedAppUsage;
import android.os.Parcel;
import android.os.IBinder;
import android.os.Parcelable;
import android.util.Slog;

@@ -58,6 +59,8 @@ public final class InputChannel implements Parcelable {
    private native void nativeReadFromParcel(Parcel parcel);
    private native void nativeWriteToParcel(Parcel parcel);
    private native void nativeDup(InputChannel target);
    private native IBinder nativeGetToken();
    private native void nativeSetToken(IBinder token);

    private native String nativeGetName();

@@ -169,4 +172,12 @@ public final class InputChannel implements Parcelable {
    public String toString() {
        return getName();
    }

    public IBinder getToken() {
        return nativeGetToken();
    }

    public void setToken(IBinder token) {
        nativeSetToken(token);
    }
}
+1 −5
Original line number Diff line number Diff line
@@ -34,9 +34,6 @@ public final class InputWindowHandle {
    // The input application handle.
    public final InputApplicationHandle inputApplicationHandle;

    // The window manager's window state.
    public final Object windowState;

    // The client window.
    public final IWindow clientWindow;

@@ -97,9 +94,8 @@ public final class InputWindowHandle {
    private native void nativeDispose();

    public InputWindowHandle(InputApplicationHandle inputApplicationHandle,
            Object windowState, IWindow clientWindow, int displayId) {
            IWindow clientWindow, int displayId) {
        this.inputApplicationHandle = inputApplicationHandle;
        this.windowState = windowState;
        this.clientWindow = clientWindow;
        this.displayId = displayId;
    }
+22 −0
Original line number Diff line number Diff line
@@ -249,6 +249,24 @@ static void android_view_InputChannel_nativeDup(JNIEnv* env, jobject obj, jobjec
    }
}

static jobject android_view_InputChannel_nativeGetToken(JNIEnv* env, jobject obj) {
    NativeInputChannel* nativeInputChannel =
        android_view_InputChannel_getNativeInputChannel(env, obj);
    if (nativeInputChannel) {
        return javaObjectForIBinder(env, nativeInputChannel->getInputChannel()->getToken());
    }
    return 0;
}

static void android_view_InputChannel_nativeSetToken(JNIEnv* env, jobject obj, jobject tokenObj) {
    NativeInputChannel* nativeInputChannel =
        android_view_InputChannel_getNativeInputChannel(env, obj);
    sp<IBinder> token = ibinderForJavaObject(env, tokenObj);
    if (nativeInputChannel != nullptr) {
        nativeInputChannel->getInputChannel()->setToken(token);
    }
}

// ----------------------------------------------------------------------------

static const JNINativeMethod gInputChannelMethods[] = {
@@ -267,6 +285,10 @@ static const JNINativeMethod gInputChannelMethods[] = {
            (void*)android_view_InputChannel_nativeGetName },
    { "nativeDup", "(Landroid/view/InputChannel;)V",
            (void*)android_view_InputChannel_nativeDup },
    { "nativeGetToken", "()Landroid/os/IBinder;",
            (void*)android_view_InputChannel_nativeGetToken },
    { "nativeSetToken", "(Landroid/os/IBinder;)V",
            (void*)android_view_InputChannel_nativeSetToken }
};

int register_android_view_InputChannel(JNIEnv* env) {
+19 −17
Original line number Diff line number Diff line
@@ -199,7 +199,7 @@ public class InputManagerService extends IInputManager.Stub
    private static native boolean nativeHasKeys(long ptr,
            int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists);
    private static native void nativeRegisterInputChannel(long ptr, InputChannel inputChannel,
            InputWindowHandle inputWindowHandle, int displayId);
            int displayId);
    private static native void nativeUnregisterInputChannel(long ptr, InputChannel inputChannel);
    private static native void nativeSetInputFilterEnabled(long ptr, boolean enable);
    private static native int nativeInjectInputEvent(long ptr, InputEvent event,
@@ -488,8 +488,7 @@ public class InputManagerService extends IInputManager.Stub
        }

        InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
        // Register channel for monitor.
        nativeRegisterInputChannel(mPtr, inputChannels[0], null, displayId);
        nativeRegisterInputChannel(mPtr, inputChannels[0], displayId);
        inputChannels[0].dispose(); // don't need to retain the Java object reference
        return inputChannels[1];
    }
@@ -500,14 +499,17 @@ public class InputManagerService extends IInputManager.Stub
     * @param inputWindowHandle The handle of the input window associated with the
     * input channel, or null if none.
     */
    public void registerInputChannel(InputChannel inputChannel,
            InputWindowHandle inputWindowHandle) {
    public void registerInputChannel(InputChannel inputChannel, IBinder token) {
        if (inputChannel == null) {
            throw new IllegalArgumentException("inputChannel must not be null.");
        }

        // Register channel for normal.
        nativeRegisterInputChannel(mPtr, inputChannel, inputWindowHandle, Display.INVALID_DISPLAY);
        if (token == null) {
            token = new Binder();
        }
        inputChannel.setToken(token);

        nativeRegisterInputChannel(mPtr, inputChannel, Display.INVALID_DISPLAY);
    }

    /**
@@ -1793,15 +1795,15 @@ public class InputManagerService extends IInputManager.Stub
    }

    // Native callback.
    private void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
        mWindowManagerCallbacks.notifyInputChannelBroken(inputWindowHandle);
    private void notifyInputChannelBroken(IBinder token) {
        mWindowManagerCallbacks.notifyInputChannelBroken(token);
    }

    // Native callback.
    private long notifyANR(InputApplicationHandle inputApplicationHandle,
            InputWindowHandle inputWindowHandle, String reason) {
            IBinder token, String reason) {
        return mWindowManagerCallbacks.notifyANR(
                inputApplicationHandle, inputWindowHandle, reason);
                inputApplicationHandle, token, reason);
    }

    // Native callback.
@@ -1832,13 +1834,13 @@ public class InputManagerService extends IInputManager.Stub
    }

    // Native callback.
    private long interceptKeyBeforeDispatching(InputWindowHandle focus,
    private long interceptKeyBeforeDispatching(IBinder focus,
            KeyEvent event, int policyFlags) {
        return mWindowManagerCallbacks.interceptKeyBeforeDispatching(focus, event, policyFlags);
    }

    // Native callback.
    private KeyEvent dispatchUnhandledKey(InputWindowHandle focus,
    private KeyEvent dispatchUnhandledKey(IBinder focus,
            KeyEvent event, int policyFlags) {
        return mWindowManagerCallbacks.dispatchUnhandledKey(focus, event, policyFlags);
    }
@@ -1989,19 +1991,19 @@ public class InputManagerService extends IInputManager.Stub

        public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered);

        public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle);
        public void notifyInputChannelBroken(IBinder token);

        public long notifyANR(InputApplicationHandle inputApplicationHandle,
                InputWindowHandle inputWindowHandle, String reason);
                IBinder token, String reason);

        public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags);

        public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags);

        public long interceptKeyBeforeDispatching(InputWindowHandle focus,
        public long interceptKeyBeforeDispatching(IBinder token,
                KeyEvent event, int policyFlags);

        public KeyEvent dispatchUnhandledKey(InputWindowHandle focus,
        public KeyEvent dispatchUnhandledKey(IBinder token,
                KeyEvent event, int policyFlags);

        public int getPointerLayer();
+1 −1
Original line number Diff line number Diff line
@@ -223,7 +223,7 @@ class DragState {
            mDragApplicationHandle.dispatchingTimeoutNanos =
                    WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;

            mDragWindowHandle = new InputWindowHandle(mDragApplicationHandle, null, null,
            mDragWindowHandle = new InputWindowHandle(mDragApplicationHandle, null,
                    display.getDisplayId());
            mDragWindowHandle.name = "drag";
            mDragWindowHandle.inputChannel = mServerChannel;
Loading