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

Commit 1652fc33 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Check window token when extending timeout" am: bbb7268d am: e8bcf6a4 am: fa8736c2

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1468548

Change-Id: Ia0424417dab79f477c5bdeef8595854350db45c0
parents a205e4c7 fa8736c2
Loading
Loading
Loading
Loading
+15 −15
Original line number Diff line number Diff line
@@ -518,7 +518,7 @@ nsecs_t InputDispatcher::processAnrsLocked() {
    connection->responsive = false;
    // Stop waking up for this unresponsive connection
    mAnrTracker.eraseToken(connection->inputChannel->getConnectionToken());
    onAnrLocked(connection);
    onAnrLocked(*connection);
    return LONG_LONG_MIN;
}

@@ -4542,12 +4542,12 @@ void InputDispatcher::onFocusChangedLocked(const sp<InputWindowHandle>& oldFocus
    postCommandLocked(std::move(commandEntry));
}

void InputDispatcher::onAnrLocked(const sp<Connection>& connection) {
void InputDispatcher::onAnrLocked(const Connection& connection) {
    // Since we are allowing the policy to extend the timeout, maybe the waitQueue
    // is already healthy again. Don't raise ANR in this situation
    if (connection->waitQueue.empty()) {
    if (connection.waitQueue.empty()) {
        ALOGI("Not raising ANR because the connection %s has recovered",
              connection->inputChannel->getName().c_str());
              connection.inputChannel->getName().c_str());
        return;
    }
    /**
@@ -4558,21 +4558,21 @@ void InputDispatcher::onAnrLocked(const sp<Connection>& connection) {
     * processes the events linearly. So providing information about the oldest entry seems to be
     * most useful.
     */
    DispatchEntry* oldestEntry = *connection->waitQueue.begin();
    DispatchEntry* oldestEntry = *connection.waitQueue.begin();
    const nsecs_t currentWait = now() - oldestEntry->deliveryTime;
    std::string reason =
            android::base::StringPrintf("%s is not responding. Waited %" PRId64 "ms for %s",
                                        connection->inputChannel->getName().c_str(),
                                        connection.inputChannel->getName().c_str(),
                                        ns2ms(currentWait),
                                        oldestEntry->eventEntry->getDescription().c_str());

    updateLastAnrStateLocked(getWindowHandleLocked(connection->inputChannel->getConnectionToken()),
    updateLastAnrStateLocked(getWindowHandleLocked(connection.inputChannel->getConnectionToken()),
                             reason);

    std::unique_ptr<CommandEntry> commandEntry =
            std::make_unique<CommandEntry>(&InputDispatcher::doNotifyAnrLockedInterruptible);
    commandEntry->inputApplicationHandle = nullptr;
    commandEntry->inputChannel = connection->inputChannel;
    commandEntry->inputChannel = connection.inputChannel;
    commandEntry->reason = std::move(reason);
    postCommandLocked(std::move(commandEntry));
}
@@ -4672,15 +4672,15 @@ void InputDispatcher::doNotifyAnrLockedInterruptible(CommandEntry* commandEntry)
void InputDispatcher::extendAnrTimeoutsLocked(const sp<InputApplicationHandle>& application,
                                              const sp<IBinder>& connectionToken,
                                              nsecs_t timeoutExtension) {
    sp<Connection> connection = getConnectionLocked(connectionToken);
    if (connection == nullptr) {
        if (mNoFocusedWindowTimeoutTime.has_value() && application != nullptr) {
            // Maybe ANR happened because there's no focused window?
    if (connectionToken == nullptr && application != nullptr) {
        // The ANR happened because there's no focused window
        mNoFocusedWindowTimeoutTime = now() + timeoutExtension;
        mAwaitedFocusedApplication = application;
        } else {
            // It's also possible that the connection already disappeared. No action necessary.
    }

    sp<Connection> connection = getConnectionLocked(connectionToken);
    if (connection == nullptr) {
        // It's possible that the connection already disappeared. No action necessary.
        return;
    }

+1 −1
Original line number Diff line number Diff line
@@ -489,7 +489,7 @@ private:
            REQUIRES(mLock);
    void onFocusChangedLocked(const sp<InputWindowHandle>& oldFocus,
                              const sp<InputWindowHandle>& newFocus) REQUIRES(mLock);
    void onAnrLocked(const sp<Connection>& connection) REQUIRES(mLock);
    void onAnrLocked(const Connection& connection) REQUIRES(mLock);
    void onAnrLocked(const sp<InputApplicationHandle>& application) REQUIRES(mLock);
    void updateLastAnrStateLocked(const sp<InputWindowHandle>& window, const std::string& reason)
            REQUIRES(mLock);
+1 −0
Original line number Diff line number Diff line
@@ -150,6 +150,7 @@ public:
        const std::chrono::duration waited = std::chrono::steady_clock::now() - start;
        if (mAnrApplications.empty() || mAnrWindowTokens.empty()) {
            ADD_FAILURE() << "Did not receive ANR callback";
            return {};
        }
        // Ensure that the ANR didn't get raised too early. We can't be too strict here because
        // the dispatcher started counting before this function was called