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

Commit 30ac454e authored by Vaibhav Devmurari's avatar Vaibhav Devmurari
Browse files

[Bugfix] Overlapping key gesture handlers: check existing pid alive

Binder linktoDeath() callback might occur after the sysui process is
restarted in case of an overloaded system. Check if the binder for
the existing handler is still alive before throwing exception.

Bug: 414477543
Flag: com.android.window.flags.delegate_back_gesture_to_shell
Test: manual by not listening to binderDied callback and killing sysui
Change-Id: Ib9885c249968f4fb8dc32e4744618179e981f1fa
parent f3a4b71e
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -1297,9 +1297,21 @@ final class KeyGestureController {
            }
            for (int gestureType : keyGesturesToHandle) {
                if (mSupportedKeyGestureToPidMap.indexOfKey(gestureType) >= 0) {
                    // Check if existing registered pid is dead or not.
                    // Due to race conditions it is possible to get cases where the process is
                    // killed and we haven't yet received the binderDied() callback.
                    int existingPid = mSupportedKeyGestureToPidMap.get(gestureType);
                    KeyGestureHandlerRecord existingHandler = Objects.requireNonNull(
                            mKeyGestureHandlerRecords.get(existingPid));
                    if (existingHandler.mKeyGestureHandler.asBinder().isBinderAlive()) {
                        throw new IllegalArgumentException(
                                "Key gesture " + gestureType + " is already registered by pid = "
                                    + mSupportedKeyGestureToPidMap.get(gestureType));
                                        + existingPid);
                    } else {
                        Slog.w(TAG, "registerKeyGestureHandler: pid = " + existingPid
                                + " was killed but we didn't receive binderDied callback");
                        onKeyGestureHandlerRemoved(existingPid);
                    }
                }
            }
            KeyGestureHandlerRecord record = new KeyGestureHandlerRecord(pid, handler);