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

Commit 4e670e5d authored by Robert Carr's avatar Robert Carr
Browse files

InputDispatcher: Look up channel by token.

When comparing InputChannels coming from the client (for example to see if
a connection has dissapeared in the latest list), we need to compare by token
not by equality since of course they will now be different objects
each call to setInputWindows.

Bug: 80101428
Bug: 113136004
Bug: 111440400
Test: Manual
Change-Id: Ic384822df8418c80fb5578213149863044f890f4
parent 803535b9
Loading
Loading
Loading
Loading
+16 −11
Original line number Original line Diff line number Diff line
@@ -58,6 +58,7 @@
#include <utils/Trace.h>
#include <utils/Trace.h>
#include <powermanager/PowerManager.h>
#include <powermanager/PowerManager.h>
#include <ui/Region.h>
#include <ui/Region.h>
#include <binder/Binder.h>


#define INDENT "  "
#define INDENT "  "
#define INDENT2 "    "
#define INDENT2 "    "
@@ -3018,7 +3019,8 @@ bool InputDispatcher::hasWindowHandleLocked(
        const Vector<sp<InputWindowHandle>> windowHandles = it.second;
        const Vector<sp<InputWindowHandle>> windowHandles = it.second;
        size_t numWindows = windowHandles.size();
        size_t numWindows = windowHandles.size();
        for (size_t i = 0; i < numWindows; i++) {
        for (size_t i = 0; i < numWindows; i++) {
            if (windowHandles.itemAt(i) == windowHandle) {
            if (windowHandles.itemAt(i)->getInputChannel()->getToken()
                    == windowHandle->getInputChannel()->getToken()) {
                if (windowHandle->getInfo()->displayId != it.first) {
                if (windowHandle->getInfo()->displayId != it.first) {
                    ALOGE("Found window %s in display %" PRId32
                    ALOGE("Found window %s in display %" PRId32
                            ", but it should belong to display %" PRId32,
                            ", but it should belong to display %" PRId32,
@@ -3649,16 +3651,19 @@ status_t InputDispatcher::registerInputChannel(const sp<InputChannel>& inputChan
    { // acquire lock
    { // acquire lock
        AutoMutex _l(mLock);
        AutoMutex _l(mLock);


        // If InputWindowHandle is null and displayId is not ADISPLAY_ID_NONE,
        // treat inputChannel as monitor channel for displayId.
        bool monitor = inputChannel->getToken() == nullptr && displayId != ADISPLAY_ID_NONE;
        if (monitor) {
            inputChannel->setToken(new BBinder());
        }

        if (getConnectionIndexLocked(inputChannel) >= 0) {
        if (getConnectionIndexLocked(inputChannel) >= 0) {
            ALOGW("Attempted to register already registered input channel '%s'",
            ALOGW("Attempted to register already registered input channel '%s'",
                    inputChannel->getName().c_str());
                    inputChannel->getName().c_str());
            return BAD_VALUE;
            return BAD_VALUE;
        }
        }


        // If InputWindowHandle is null and displayId is not ADISPLAY_ID_NONE,
        // treat inputChannel as monitor channel for displayId.
        bool monitor = inputChannel->getToken() == nullptr && displayId != ADISPLAY_ID_NONE;

        sp<Connection> connection = new Connection(inputChannel, monitor);
        sp<Connection> connection = new Connection(inputChannel, monitor);


        int fd = inputChannel->getFd();
        int fd = inputChannel->getFd();
@@ -3744,17 +3749,17 @@ void InputDispatcher::removeMonitorChannelLocked(const sp<InputChannel>& inputCh
}
}


ssize_t InputDispatcher::getConnectionIndexLocked(const sp<InputChannel>& inputChannel) {
ssize_t InputDispatcher::getConnectionIndexLocked(const sp<InputChannel>& inputChannel) {
    if (!inputChannel) {
    if (inputChannel == nullptr) {
        return -1;
        return -1;
    }
    }


    ssize_t connectionIndex = mConnectionsByFd.indexOfKey(inputChannel->getFd());
    for (size_t i = 0; i < mConnectionsByFd.size(); i++) {
    if (connectionIndex >= 0) {
        sp<Connection> connection = mConnectionsByFd.valueAt(i);
        sp<Connection> connection = mConnectionsByFd.valueAt(connectionIndex);
        if (connection->inputChannel->getToken() == inputChannel->getToken()) {
        if (connection->inputChannel.get() == inputChannel.get()) {
            return i;
            return connectionIndex;
        }
        }
    }
    }

    return -1;
    return -1;
}
}


+1 −1
Original line number Original line Diff line number Diff line
@@ -338,7 +338,6 @@ protected:
            const std::string name, int32_t displayId) :
            const std::string name, int32_t displayId) :
                mDispatcher(dispatcher), mName(name), mDisplayId(displayId) {
                mDispatcher(dispatcher), mName(name), mDisplayId(displayId) {
            InputChannel::openInputChannelPair(name, mServerChannel, mClientChannel);
            InputChannel::openInputChannelPair(name, mServerChannel, mClientChannel);
            mServerChannel->setToken(new BBinder());


            mConsumer = new InputConsumer(mClientChannel);
            mConsumer = new InputConsumer(mClientChannel);
        }
        }
@@ -370,6 +369,7 @@ public:
            InputWindowHandle(inputApplicationHandle),
            InputWindowHandle(inputApplicationHandle),
            FakeInputReceiver(dispatcher, name, displayId),
            FakeInputReceiver(dispatcher, name, displayId),
            mFocused(false) {
            mFocused(false) {
            mServerChannel->setToken(new BBinder());
            mDispatcher->registerInputChannel(mServerChannel, displayId);
            mDispatcher->registerInputChannel(mServerChannel, displayId);
    }
    }