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

Commit 82bbfc39 authored by Arthur Hung's avatar Arthur Hung
Browse files

Input devices configure on per-display basis (2/2)

While computing the new configuration values based on
display info and input devices, some input devices may be
associated with a specific display.
This patch would apply the right corresponding config from the input
devices which are associated with current display or no associated.

The virtual display will still follow default display.

Bug: 116767202
Test: atest WindowConfigurationTests
Test: atest inputflinger_tests
Test: atest ActivityManagerMultiDisplayTests
Change-Id: I1dbd6e07ab81b5018be7bdb8c71dd44f2036eb4a
parent 41c6a0ad
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -234,6 +234,7 @@ public class InputManagerService extends IInputManager.Stub
    private static native void nativeReloadPointerIcons(long ptr);
    private static native void nativeSetCustomPointerIcon(long ptr, PointerIcon icon);
    private static native void nativeSetPointerCapture(long ptr, boolean detached);
    private static native boolean nativeCanDispatchToDisplay(long ptr, int deviceId, int displayId);

    // Input event injection constants defined in InputDispatcher.h.
    private static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0;
@@ -1890,6 +1891,16 @@ public class InputManagerService extends IInputManager.Stub
        return new String[0];
    }

    /**
     * Gets if an input device could dispatch to the given display".
     * @param deviceId The input device id.
     * @param displayId The specific display id.
     * @return True if the device could dispatch to the given display, false otherwise.
     */
    public boolean canDispatchToDisplay(int deviceId, int displayId) {
        return nativeCanDispatchToDisplay(mPtr, deviceId, displayId);
    }

    // Native callback.
    private int getKeyRepeatTimeout() {
        return ViewConfiguration.getKeyRepeatTimeout();
+33 −26
Original line number Diff line number Diff line
@@ -1657,16 +1657,24 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        final int len = devices != null ? devices.length : 0;
        for (int i = 0; i < len; i++) {
            InputDevice device = devices[i];
            if (!device.isVirtual()) {
            // Ignore virtual input device.
            if (device.isVirtual()) {
                continue;
            }

            // Check if input device can dispatch events to current display.
            // If display type is virtual, will follow the default display.
            if (!mWmService.mInputManager.canDispatchToDisplay(device.getId(),
                    displayInfo.type == Display.TYPE_VIRTUAL ? DEFAULT_DISPLAY : mDisplayId)) {
                continue;
            }

            final int sources = device.getSources();
                final int presenceFlag = device.isExternal() ?
                        WindowManagerPolicy.PRESENCE_EXTERNAL :
                        WindowManagerPolicy.PRESENCE_INTERNAL;
            final int presenceFlag = device.isExternal()
                    ? WindowManagerPolicy.PRESENCE_EXTERNAL : WindowManagerPolicy.PRESENCE_INTERNAL;

                // TODO(multi-display): Configure on per-display basis.
            if (mWmService.mIsTouchDevice) {
                    if ((sources & InputDevice.SOURCE_TOUCHSCREEN) ==
                            InputDevice.SOURCE_TOUCHSCREEN) {
                if ((sources & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) {
                    config.touchscreen = Configuration.TOUCHSCREEN_FINGER;
                }
            } else {
@@ -1687,7 +1695,6 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
                keyboardPresence |= presenceFlag;
            }
        }
        }

        if (config.navigation == Configuration.NAVIGATION_NONAV && mWmService.mHasPermanentDpad) {
            config.navigation = Configuration.NAVIGATION_DPAD;
+9 −0
Original line number Diff line number Diff line
@@ -1652,6 +1652,13 @@ static void nativeSetCustomPointerIcon(JNIEnv* env, jclass /* clazz */,
    im->setCustomPointerIcon(spriteIcon);
}

static jboolean nativeCanDispatchToDisplay(JNIEnv* env, jclass /* clazz */, jlong ptr,
        jint deviceId, jint displayId) {

    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
    return im->getInputManager()->getReader()->canDispatchToDisplay(deviceId, displayId);
}

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

static const JNINativeMethod gInputManagerMethods[] = {
@@ -1726,6 +1733,8 @@ static const JNINativeMethod gInputManagerMethods[] = {
            (void*) nativeReloadPointerIcons },
    { "nativeSetCustomPointerIcon", "(JLandroid/view/PointerIcon;)V",
            (void*) nativeSetCustomPointerIcon },
    { "nativeCanDispatchToDisplay", "(JII)Z",
            (void*) nativeCanDispatchToDisplay },
};

#define FIND_CLASS(var, className) \