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

Commit eb90ca88 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

SyncPointerCapture (6/n): Move Pointer Capture to InputDispatcher

This CL relays requests to enable or disable Pointer Capture in
InputManagerService to InputDispatcher.

Windows now request Pointer Capture using their InputChannel token
instead of their IWindow tokens.

Bug: 141749603
Test: manual: flash crosshatch, test pointer capture.

Change-Id: Ic6fc01eae0068dfbba496051d988a71bcabcd0b3
parent 27049987
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -94,7 +94,7 @@ interface IInputManager {
    void setPointerIconType(int typeId);
    void setCustomPointerIcon(in PointerIcon icon);

    void requestPointerCapture(IBinder windowToken, boolean enabled);
    oneway void requestPointerCapture(IBinder inputChannelToken, boolean enabled);

    /** Create an input monitor for gestures. */
    InputMonitor monitorGestureInput(String name, int displayId);
+11 −1
Original line number Diff line number Diff line
@@ -4668,7 +4668,12 @@ public final class ViewRootImpl implements ViewParent,
        if (mPointerCapture == enabled) {
            return;
        }
        InputManager.getInstance().requestPointerCapture(mAttachInfo.mWindowToken, enabled);
        final IBinder inputToken = getInputToken();
        if (inputToken == null) {
            Log.e(mTag, "No input channel to request Pointer Capture.");
            return;
        }
        InputManager.getInstance().requestPointerCapture(inputToken, enabled);
    }

    private void handlePointerCaptureChanged(boolean hasCapture) {
@@ -8369,6 +8374,11 @@ public final class ViewRootImpl implements ViewParent,
            windowFocusChanged(hasFocus, inTouchMode);
        }

        @Override
        public void onPointerCaptureEvent(boolean pointerCaptureEnabled) {
            dispatchPointerCaptureChanged(pointerCaptureEnabled);
        }

        @Override
        public void dispose() {
            unscheduleConsumeBatchedInput();
+8 −11
Original line number Diff line number Diff line
@@ -285,7 +285,8 @@ public class InputManagerService extends IInputManager.Stub
    private static native void nativeSetPointerIconType(long ptr, int iconId);
    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 void nativeRequestPointerCapture(long ptr, IBinder windowToken,
            boolean enabled);
    private static native boolean nativeCanDispatchToDisplay(long ptr, int deviceId, int displayId);
    private static native void nativeNotifyPortAssociationsChanged(long ptr);
    private static native void nativeSetMotionClassifierEnabled(long ptr, boolean enabled);
@@ -1611,12 +1612,12 @@ public class InputManagerService extends IInputManager.Stub
    }

    @Override
    public void requestPointerCapture(IBinder windowToken, boolean enabled) {
        boolean requestConfigurationRefresh =
                mWindowManagerCallbacks.requestPointerCapture(windowToken, enabled);
        if (requestConfigurationRefresh) {
            nativeSetPointerCapture(mPtr, enabled);
    public void requestPointerCapture(IBinder inputChannelToken, boolean enabled) {
        if (inputChannelToken == null) {
            return;
        }

        nativeRequestPointerCapture(mPtr, inputChannelToken, enabled);
    }

    public void setInputDispatchMode(boolean enabled, boolean frozen) {
@@ -2189,11 +2190,7 @@ public class InputManagerService extends IInputManager.Stub

    // Native callback
    private void notifyFocusChanged(IBinder oldToken, IBinder newToken) {
        final boolean requestConfigurationRefresh =
        mWindowManagerCallbacks.notifyFocusChanged(oldToken, newToken);
        if (requestConfigurationRefresh) {
            nativeSetPointerCapture(mPtr, false);
        }
    }

    // Native callback
+26 −20
Original line number Diff line number Diff line
@@ -240,8 +240,8 @@ public:
    void reloadCalibration();
    void setPointerIconType(int32_t iconId);
    void reloadPointerIcons();
    void requestPointerCapture(const sp<IBinder>& windowToken, bool enabled);
    void setCustomPointerIcon(const SpriteIcon& icon);
    void setPointerCapture(bool enabled);
    void setMotionClassifierEnabled(bool enabled);

    /* --- InputReaderPolicyInterface implementation --- */
@@ -280,6 +280,7 @@ public:
    void pokeUserActivity(nsecs_t eventTime, int32_t eventType) override;
    bool checkInjectEventsPermissionNonReentrant(int32_t injectorPid, int32_t injectorUid) override;
    void onPointerDownOutsideFocus(const sp<IBinder>& touchedToken) override;
    void setPointerCapture(bool enabled) override;

    /* --- PointerControllerPolicyInterface implementation --- */

@@ -930,20 +931,8 @@ void NativeInputManager::setShowTouches(bool enabled) {
            InputReaderConfiguration::CHANGE_SHOW_TOUCHES);
}

void NativeInputManager::setPointerCapture(bool enabled) {
    { // acquire lock
        AutoMutex _l(mLock);

        if (mLocked.pointerCapture == enabled) {
            return;
        }

        ALOGI("Setting pointer capture to %s.", enabled ? "enabled" : "disabled");
        mLocked.pointerCapture = enabled;
    } // release lock

    mInputManager->getReader()->requestRefreshConfiguration(
            InputReaderConfiguration::CHANGE_POINTER_CAPTURE);
void NativeInputManager::requestPointerCapture(const sp<IBinder>& windowToken, bool enabled) {
    mInputManager->getDispatcher()->requestPointerCapture(windowToken, enabled);
}

void NativeInputManager::setInteractive(bool interactive) {
@@ -1215,7 +1204,6 @@ void NativeInputManager::pokeUserActivity(nsecs_t eventTime, int32_t eventType)
    android_server_PowerManagerService_userActivity(eventTime, eventType);
}


bool NativeInputManager::checkInjectEventsPermissionNonReentrant(
        int32_t injectorPid, int32_t injectorUid) {
    ATRACE_CALL();
@@ -1238,6 +1226,22 @@ void NativeInputManager::onPointerDownOutsideFocus(const sp<IBinder>& touchedTok
    checkAndClearExceptionFromCallback(env, "onPointerDownOutsideFocus");
}

void NativeInputManager::setPointerCapture(bool enabled) {
    { // acquire lock
        AutoMutex _l(mLock);

        if (mLocked.pointerCapture == enabled) {
            return;
        }

        ALOGV("%s pointer capture.", enabled ? "Enabling" : "Disabling");
        mLocked.pointerCapture = enabled;
    } // release lock

    mInputManager->getReader()->requestRefreshConfiguration(
            InputReaderConfiguration::CHANGE_POINTER_CAPTURE);
}

void NativeInputManager::loadPointerIcon(SpriteIcon* icon, int32_t displayId) {
    ATRACE_CALL();
    JNIEnv* env = jniEnv();
@@ -1631,11 +1635,12 @@ static void nativeSetFocusedDisplay(JNIEnv* env, jclass /* clazz */,
    im->setFocusedDisplay(env, displayId);
}

static void nativeSetPointerCapture(JNIEnv* env, jclass /* clazz */, jlong ptr,
        jboolean enabled) {
static void nativeRequestPointerCapture(JNIEnv* env, jclass /* clazz */, jlong ptr,
                                        jobject tokenObj, jboolean enabled) {
    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
    sp<IBinder> windowToken = ibinderForJavaObject(env, tokenObj);

    im->setPointerCapture(enabled);
    im->requestPointerCapture(windowToken, enabled);
}

static void nativeSetInputDispatchMode(JNIEnv* /* env */,
@@ -1941,7 +1946,8 @@ static const JNINativeMethod gInputManagerMethods[] = {
        {"nativeSetFocusedApplication", "(JILandroid/view/InputApplicationHandle;)V",
         (void*)nativeSetFocusedApplication},
        {"nativeSetFocusedDisplay", "(JI)V", (void*)nativeSetFocusedDisplay},
        {"nativeSetPointerCapture", "(JZ)V", (void*)nativeSetPointerCapture},
        {"nativeRequestPointerCapture", "(JLandroid/os/IBinder;Z)V",
         (void*)nativeRequestPointerCapture},
        {"nativeSetInputDispatchMode", "(JZZ)V", (void*)nativeSetInputDispatchMode},
        {"nativeSetSystemUiLightsOut", "(JZ)V", (void*)nativeSetSystemUiLightsOut},
        {"nativeTransferTouchFocus", "(JLandroid/os/IBinder;Landroid/os/IBinder;)Z",