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

Commit 2b4782c8 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Use connection token in CommandEntry

To prepare for the upcoming ANR refactor, use a connection token inside
CommandEntry instead of storing the entire input channel.

We don't actually need the entire input channel, because WM uses it to
look up windows using the token.

Bug: 171218828
Test: atest inputflinger_tests
Change-Id: Ia82f05685db2fcb7de3b8dc00c57e5d108baf902
parent d7c0aa94
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -250,7 +250,7 @@ struct CommandEntry {
    int32_t userActivityEventType;
    uint32_t seq;
    bool handled;
    std::shared_ptr<InputChannel> inputChannel;
    sp<IBinder> connectionToken;
    sp<IBinder> oldToken;
    sp<IBinder> newToken;
    std::string obscuringPackage;
+6 −14
Original line number Diff line number Diff line
@@ -1230,9 +1230,7 @@ bool InputDispatcher::dispatchKeyLocked(nsecs_t currentTime, std::shared_ptr<Key
                    &InputDispatcher::doInterceptKeyBeforeDispatchingLockedInterruptible);
            sp<IBinder> focusedWindowToken =
                    getValueByKey(mFocusedWindowTokenByDisplay, getTargetDisplayId(*entry));
            if (focusedWindowToken != nullptr) {
                commandEntry->inputChannel = getInputChannelLocked(focusedWindowToken);
            }
            commandEntry->connectionToken = focusedWindowToken;
            commandEntry->keyEntry = entry;
            postCommandLocked(std::move(commandEntry));
            return false; // wait for the command to run
@@ -4920,14 +4918,13 @@ void InputDispatcher::onAnrLocked(const Connection& connection) {
                                        connection.inputChannel->getName().c_str(),
                                        ns2ms(currentWait),
                                        oldestEntry->eventEntry->getDescription().c_str());

    updateLastAnrStateLocked(getWindowHandleLocked(connection.inputChannel->getConnectionToken()),
                             reason);
    sp<IBinder> connectionToken = connection.inputChannel->getConnectionToken();
    updateLastAnrStateLocked(getWindowHandleLocked(connectionToken), reason);

    std::unique_ptr<CommandEntry> commandEntry =
            std::make_unique<CommandEntry>(&InputDispatcher::doNotifyAnrLockedInterruptible);
    commandEntry->inputApplicationHandle = nullptr;
    commandEntry->inputChannel = connection.inputChannel;
    commandEntry->connectionToken = connectionToken;
    commandEntry->reason = std::move(reason);
    postCommandLocked(std::move(commandEntry));
}
@@ -4941,7 +4938,6 @@ void InputDispatcher::onAnrLocked(const std::shared_ptr<InputApplicationHandle>&
    std::unique_ptr<CommandEntry> commandEntry =
            std::make_unique<CommandEntry>(&InputDispatcher::doNotifyAnrLockedInterruptible);
    commandEntry->inputApplicationHandle = application;
    commandEntry->inputChannel = nullptr;
    commandEntry->reason = std::move(reason);
    postCommandLocked(std::move(commandEntry));
}
@@ -5010,10 +5006,8 @@ void InputDispatcher::doNotifyFocusChangedLockedInterruptible(CommandEntry* comm
}

void InputDispatcher::doNotifyAnrLockedInterruptible(CommandEntry* commandEntry) {
    sp<IBinder> token =
            commandEntry->inputChannel ? commandEntry->inputChannel->getConnectionToken() : nullptr;
    mLock.unlock();

    const sp<IBinder>& token = commandEntry->connectionToken;
    const std::chrono::nanoseconds timeoutExtension =
            mPolicy->notifyAnr(commandEntry->inputApplicationHandle, token, commandEntry->reason);

@@ -5076,9 +5070,7 @@ void InputDispatcher::doInterceptKeyBeforeDispatchingLockedInterruptible(
    mLock.unlock();

    android::base::Timer t;
    sp<IBinder> token = commandEntry->inputChannel != nullptr
            ? commandEntry->inputChannel->getConnectionToken()
            : nullptr;
    const sp<IBinder>& token = commandEntry->connectionToken;
    nsecs_t delay = mPolicy->interceptKeyBeforeDispatching(token, &event, entry.policyFlags);
    if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) {
        ALOGW("Excessive delay in interceptKeyBeforeDispatching; took %s ms",
+15 −19
Original line number Diff line number Diff line
@@ -198,7 +198,7 @@ private:
    std::condition_variable mNotifyAnr;
    std::chrono::nanoseconds mAnrTimeout = 0ms;

    virtual void notifyConfigurationChanged(nsecs_t when) override {
    void notifyConfigurationChanged(nsecs_t when) override {
        std::scoped_lock lock(mLock);
        mConfigurationChangedTime = when;
    }
@@ -213,17 +213,17 @@ private:
        return mAnrTimeout;
    }

    virtual void notifyInputChannelBroken(const sp<IBinder>&) override {}
    void notifyInputChannelBroken(const sp<IBinder>&) override {}

    virtual void notifyFocusChanged(const sp<IBinder>&, const sp<IBinder>&) override {}
    void notifyFocusChanged(const sp<IBinder>&, const sp<IBinder>&) override {}

    virtual void notifyUntrustedTouch(const std::string& obscuringPackage) override {}
    void notifyUntrustedTouch(const std::string& obscuringPackage) override {}

    virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) override {
    void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) override {
        *outConfig = mConfig;
    }

    virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override {
    bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override {
        std::scoped_lock lock(mLock);
        switch (inputEvent->getType()) {
            case AINPUT_EVENT_TYPE_KEY: {
@@ -241,21 +241,19 @@ private:
        return true;
    }

    virtual void interceptKeyBeforeQueueing(const KeyEvent*, uint32_t&) override {}
    void interceptKeyBeforeQueueing(const KeyEvent*, uint32_t&) override {}

    virtual void interceptMotionBeforeQueueing(int32_t, nsecs_t, uint32_t&) override {}
    void interceptMotionBeforeQueueing(int32_t, nsecs_t, uint32_t&) override {}

    virtual nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent*,
                                                  uint32_t) override {
    nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent*, uint32_t) override {
        return 0;
    }

    virtual bool dispatchUnhandledKey(const sp<IBinder>&, const KeyEvent*, uint32_t,
                                      KeyEvent*) override {
    bool dispatchUnhandledKey(const sp<IBinder>&, const KeyEvent*, uint32_t, KeyEvent*) override {
        return false;
    }

    virtual void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask,
    void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask,
                      uint32_t policyFlags) override {
        std::scoped_lock lock(mLock);
        /** We simply reconstruct NotifySwitchArgs in policy because InputDispatcher is
@@ -264,13 +262,11 @@ private:
        mLastNotifySwitch = NotifySwitchArgs(1 /*id*/, when, policyFlags, switchValues, switchMask);
    }

    virtual void pokeUserActivity(nsecs_t, int32_t) override {}
    void pokeUserActivity(nsecs_t, int32_t) override {}

    virtual bool checkInjectEventsPermissionNonReentrant(int32_t, int32_t) override {
        return false;
    }
    bool checkInjectEventsPermissionNonReentrant(int32_t, int32_t) override { return false; }

    virtual void onPointerDownOutsideFocus(const sp<IBinder>& newToken) override {
    void onPointerDownOutsideFocus(const sp<IBinder>& newToken) override {
        std::scoped_lock lock(mLock);
        mOnPointerDownToken = newToken;
    }