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

Commit 56e3f4e5 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Use sequence numbers to synchronize enabling Pointer Capture (2/2)

InputReader only processes configuration change from its main thread.
This means that if there is more than one Pointer Capture change
request when the thread is busy or sleeping, it will only process the
latest one. To ensure requests to enable Pointer Capture are synchronized
with Dispatcher, we must use sequence numbers.

Requests to enable Pointer Capture have a sequence number. Requests to
disable Pointer Capture do not have a value.

Bug: 195312888
Test: atest inputflinger_tests
Test: manual with GeforceNow app, see bug.
Merged-In: I52eb7493012d476664de45d2913ceefa23466a7c
Change-Id: I52eb7493012d476664de45d2913ceefa23466a7c
parent 72afe9d6
Loading
Loading
Loading
Loading
+11 −10
Original line number Original line Diff line number Diff line
@@ -337,7 +337,7 @@ public:
    void pokeUserActivity(nsecs_t eventTime, int32_t eventType, int32_t displayId) override;
    void pokeUserActivity(nsecs_t eventTime, int32_t eventType, int32_t displayId) override;
    bool checkInjectEventsPermissionNonReentrant(int32_t injectorPid, int32_t injectorUid) override;
    bool checkInjectEventsPermissionNonReentrant(int32_t injectorPid, int32_t injectorUid) override;
    void onPointerDownOutsideFocus(const sp<IBinder>& touchedToken) override;
    void onPointerDownOutsideFocus(const sp<IBinder>& touchedToken) override;
    void setPointerCapture(bool enabled) override;
    void setPointerCapture(const PointerCaptureRequest& request) override;
    void notifyDropWindow(const sp<IBinder>& token, float x, float y) override;
    void notifyDropWindow(const sp<IBinder>& token, float x, float y) override;


    /* --- PointerControllerPolicyInterface implementation --- */
    /* --- PointerControllerPolicyInterface implementation --- */
@@ -372,8 +372,8 @@ private:
        // Show touches feature enable/disable.
        // Show touches feature enable/disable.
        bool showTouches;
        bool showTouches;


        // Pointer capture feature enable/disable.
        // The latest request to enable or disable Pointer Capture.
        bool pointerCapture;
        PointerCaptureRequest pointerCaptureRequest;


        // Sprite controller singleton, created on first use.
        // Sprite controller singleton, created on first use.
        sp<SpriteController> spriteController;
        sp<SpriteController> spriteController;
@@ -417,7 +417,6 @@ NativeInputManager::NativeInputManager(jobject contextObj,
        mLocked.pointerSpeed = 0;
        mLocked.pointerSpeed = 0;
        mLocked.pointerGesturesEnabled = true;
        mLocked.pointerGesturesEnabled = true;
        mLocked.showTouches = false;
        mLocked.showTouches = false;
        mLocked.pointerCapture = false;
        mLocked.pointerDisplayId = ADISPLAY_ID_DEFAULT;
        mLocked.pointerDisplayId = ADISPLAY_ID_DEFAULT;
    }
    }
    mInteractive = true;
    mInteractive = true;
@@ -446,7 +445,9 @@ void NativeInputManager::dump(std::string& dump) {
        dump += StringPrintf(INDENT "Pointer Gestures Enabled: %s\n",
        dump += StringPrintf(INDENT "Pointer Gestures Enabled: %s\n",
                toString(mLocked.pointerGesturesEnabled));
                toString(mLocked.pointerGesturesEnabled));
        dump += StringPrintf(INDENT "Show Touches: %s\n", toString(mLocked.showTouches));
        dump += StringPrintf(INDENT "Show Touches: %s\n", toString(mLocked.showTouches));
        dump += StringPrintf(INDENT "Pointer Capture Enabled: %s\n", toString(mLocked.pointerCapture));
        dump += StringPrintf(INDENT "Pointer Capture: %s, seq=%" PRIu32 "\n",
                             mLocked.pointerCaptureRequest.enable ? "Enabled" : "Disabled",
                             mLocked.pointerCaptureRequest.seq);
    }
    }
    dump += "\n";
    dump += "\n";


@@ -634,7 +635,7 @@ void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outCon


        outConfig->showTouches = mLocked.showTouches;
        outConfig->showTouches = mLocked.showTouches;


        outConfig->pointerCapture = mLocked.pointerCapture;
        outConfig->pointerCaptureRequest = mLocked.pointerCaptureRequest;


        outConfig->setDisplayViewports(mLocked.viewports);
        outConfig->setDisplayViewports(mLocked.viewports);


@@ -1383,16 +1384,16 @@ void NativeInputManager::onPointerDownOutsideFocus(const sp<IBinder>& touchedTok
    checkAndClearExceptionFromCallback(env, "onPointerDownOutsideFocus");
    checkAndClearExceptionFromCallback(env, "onPointerDownOutsideFocus");
}
}


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


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


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


    mInputManager->getReader()->requestRefreshConfiguration(
    mInputManager->getReader()->requestRefreshConfiguration(