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

Commit 94ee6d72 authored by Lee Shombert's avatar Lee Shombert
Browse files

Dispatch pending events outside a lock

This minimizes the time that dispatchPending() holds the mCallback
lock.  mPendingEvents (which is guarded by mCallback) is copied to an
array inside the lock.  Any pending events are then transmitted
outside the lock.  This is done so that, if the client is frozen
during transmission (unlikely), the binder callback will not be
blocked.

Flag: com.android.server.am.defer_display_events_when_frozen
Bug: 298055811
Test: atest
 * DisplayServiceTests
 * CtsDisplayTestCases
Change-Id: Iaeedd8d67caba44dd0a0517316f39bb8d756ea17
parent dd4984e9
Loading
Loading
Loading
Loading
+20 −17
Original line number Diff line number Diff line
@@ -4382,7 +4382,7 @@ public final class DisplayManagerService extends SystemService {
        // would be unusual to do so.  The method returns true on success.
        // This is only used if {@link deferDisplayEventsWhenFrozen()} is true.
        public boolean dispatchPending() {
            try {
            Event[] pending;
            synchronized (mCallback) {
                if (mPendingEvents == null || mPendingEvents.isEmpty() || !mAlive) {
                    return true;
@@ -4390,8 +4390,13 @@ public final class DisplayManagerService extends SystemService {
                if (!isReadyLocked()) {
                    return false;
                }
                    for (int i = 0; i < mPendingEvents.size(); i++) {
                        Event displayEvent = mPendingEvents.get(i);
                pending = new Event[mPendingEvents.size()];
                pending = mPendingEvents.toArray(pending);
                mPendingEvents.clear();
            }
            try {
                for (int i = 0; i < pending.length; i++) {
                    Event displayEvent = pending[i];
                    if (DEBUG) {
                        Slog.d(TAG, "Send pending display event #" + i + " "
                                + displayEvent.displayId + "/"
@@ -4399,9 +4404,7 @@ public final class DisplayManagerService extends SystemService {
                    }
                    transmitDisplayEvent(displayEvent.displayId, displayEvent.event);
                }
                    mPendingEvents.clear();
                return true;
                }
            } catch (RemoteException ex) {
                Slog.w(TAG, "Failed to notify process "
                        + mPid + " that display topology changed, assuming it died.", ex);