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

Commit c570bfdb authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Send touch mode state to input

WindowManager remains the source of truth of the touchmode state.
However, we need to keep a copy of this state in input.

The apps determine the touch mode state. Therefore, a single app will
affect the global state. That state change needs to be propagated to
other apps, when they become focused.

If the input dispatches focus to the apps instead of the WindowManager,
input needs to keep a copy of the touch mode state.

Since the touch mode state changes infrequently, this should not have
performance impact.

Bug: 70668286
Test: presubmit
Change-Id: I44ca9cd87876bca65259043260f7e0da75d104ea
parent 4ca4a363
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -171,7 +171,6 @@ public class InputManagerService extends IInputManager.Stub
    private final ArrayList<InputDevice>
            mTempFullKeyboards = new ArrayList<InputDevice>(); // handler thread only
    private boolean mKeyboardLayoutNotificationShown;
    private PendingIntent mKeyboardLayoutIntent;
    private Toast mSwitchedKeyboardLayoutToast;

    // State for vibrator tokens.
@@ -205,6 +204,7 @@ public class InputManagerService extends IInputManager.Stub
    private static native void nativeUnregisterInputChannel(long ptr, InputChannel inputChannel);
    private static native void nativePilferPointers(long ptr, IBinder token);
    private static native void nativeSetInputFilterEnabled(long ptr, boolean enable);
    private static native void nativeSetInTouchMode(long ptr, boolean inTouchMode);
    private static native int nativeInjectInputEvent(long ptr, InputEvent event,
            int injectorPid, int injectorUid, int syncMode, int timeoutMillis,
            int policyFlags);
@@ -603,6 +603,25 @@ public class InputManagerService extends IInputManager.Stub
        }
    }

    /**
     * Set the state of the touch mode.
     *
     * WindowManager remains the source of truth of the touch mode state.
     * However, we need to keep a copy of this state in input.
     *
     * The apps determine the touch mode state. Therefore, a single app will
     * affect the global state. That state change needs to be propagated to
     * other apps, when they become focused.
     *
     * When input dispatches focus to the apps, the touch mode state
     * will be sent together with the focus change.
     *
     * @param inTouchMode true if the device is in touch mode.
     */
    public void setInTouchMode(boolean inTouchMode) {
        nativeSetInTouchMode(mPtr, inTouchMode);
    }

    @Override // Binder call
    public boolean injectInputEvent(InputEvent event, int mode) {
        return injectInputEventInternal(event, mode);
+2 −0
Original line number Diff line number Diff line
@@ -1104,6 +1104,7 @@ public class WindowManagerService extends IWindowManager.Stub
                com.android.internal.R.bool.config_hasPermanentDpad);
        mInTouchMode = context.getResources().getBoolean(
                com.android.internal.R.bool.config_defaultInTouchMode);
        inputManager.setInTouchMode(mInTouchMode);
        mDrawLockTimeoutMillis = context.getResources().getInteger(
                com.android.internal.R.integer.config_drawLockTimeoutMillis);
        mAllowAnimationsInLowPowerMode = context.getResources().getBoolean(
@@ -3402,6 +3403,7 @@ public class WindowManagerService extends IWindowManager.Stub
        synchronized (mGlobalLock) {
            mInTouchMode = mode;
        }
        mInputManager.setInTouchMode(mode);
    }

    public void showEmulatorDisplayOverlayIfNeeded() {
+9 −0
Original line number Diff line number Diff line
@@ -1502,6 +1502,13 @@ static void nativeSetInputFilterEnabled(JNIEnv* /* env */, jclass /* clazz */,
    im->getInputManager()->getDispatcher()->setInputFilterEnabled(enabled);
}

static void nativeSetInTouchMode(JNIEnv* /* env */, jclass /* clazz */,
        jlong ptr, jboolean inTouchMode) {
    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);

    im->getInputManager()->getDispatcher()->setInTouchMode(inTouchMode);
}

static jint nativeInjectInputEvent(JNIEnv* env, jclass /* clazz */,
        jlong ptr, jobject inputEventObj, jint injectorPid, jint injectorUid,
        jint syncMode, jint timeoutMillis, jint policyFlags) {
@@ -1781,6 +1788,8 @@ static const JNINativeMethod gInputManagerMethods[] = {
            (void*) nativePilferPointers },
    { "nativeSetInputFilterEnabled", "(JZ)V",
            (void*) nativeSetInputFilterEnabled },
    { "nativeSetInTouchMode", "(JZ)V",
            (void*) nativeSetInTouchMode },
    { "nativeInjectInputEvent", "(JLandroid/view/InputEvent;IIIII)I",
            (void*) nativeInjectInputEvent },
    { "nativeToggleCapsLock", "(JI)V",