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

Commit 642e621f authored by Riley Jones's avatar Riley Jones
Browse files

Unlocking getDisplayByUserIdAndWindowId

The above function calls a synchronized function in a different service, which can cause an ANR when that service is slow to respond.
This change restructures the function to only apply a lock to the portion that does not call out to the other service.
Logic that should be synchronized will remain so, but this should prevent needlessly holding onto the lock.

Bug: 327710829
Test: atest AbstractAccessibilityServiceConnectionTest
Flag: N/A
Change-Id: I68f005e48660a70a9272bbf873020118ac898e82
parent 4da8139b
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -611,12 +611,12 @@ abstract class AbstractAccessibilityServiceConnection extends IAccessibilityServ
        if (svcConnTracingEnabled()) {
            logTraceSvcConn("getWindow", "windowId=" + windowId);
        }
        synchronized (mLock) {
        int displayId = Display.INVALID_DISPLAY;
        if (windowId != AccessibilityWindowInfo.UNDEFINED_WINDOW_ID) {
                displayId = mA11yWindowManager.getDisplayIdByUserIdAndWindowIdLocked(
            displayId = mA11yWindowManager.getDisplayIdByUserIdAndWindowId(
                    mSystemSupport.getCurrentUserIdLocked(), windowId);
        }
        synchronized (mLock) {
            ensureWindowsAvailableTimedLocked(displayId);

            if (!hasRightsToCurrentUserLocked()) {
+7 −8
Original line number Diff line number Diff line
@@ -1303,15 +1303,14 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
            // the computation for performance reasons.
            boolean shouldComputeWindows = false;
            int displayId = event.getDisplayId();
            synchronized (mLock) {
            final int windowId = event.getWindowId();
            if (windowId != AccessibilityWindowInfo.UNDEFINED_WINDOW_ID
                    && displayId == Display.INVALID_DISPLAY) {
                    displayId = mA11yWindowManager.getDisplayIdByUserIdAndWindowIdLocked(
                displayId = mA11yWindowManager.getDisplayIdByUserIdAndWindowId(
                        resolvedUserId, windowId);
                event.setDisplayId(displayId);
            }

            synchronized (mLock) {
                if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
                        && displayId != Display.INVALID_DISPLAY
                        && mA11yWindowManager.isTrackingWindowsLocked(displayId)) {
+5 −2
Original line number Diff line number Diff line
@@ -2038,8 +2038,11 @@ public class AccessibilityWindowManager {
     * @param windowId The windowId
     * @return The display ID
     */
    public int getDisplayIdByUserIdAndWindowIdLocked(int userId, int windowId) {
        final IBinder windowToken = getWindowTokenForUserAndWindowIdLocked(userId, windowId);
    public int getDisplayIdByUserIdAndWindowId(int userId, int windowId) {
        final IBinder windowToken;
        synchronized (mLock) {
            windowToken = getWindowTokenForUserAndWindowIdLocked(userId, windowId);
        }
        if (traceWMEnabled()) {
            logTraceWM("getDisplayIdForWindow", "token=" + windowToken);
        }
+1 −1
Original line number Diff line number Diff line
@@ -214,7 +214,7 @@ public class AbstractAccessibilityServiceConnectionTest {
                .thenReturn(mA11yWindowInfos.get(0));
        when(mMockA11yWindowManager.findA11yWindowInfoByIdLocked(PIP_WINDOWID))
                .thenReturn(mA11yWindowInfos.get(1));
        when(mMockA11yWindowManager.getDisplayIdByUserIdAndWindowIdLocked(USER_ID,
        when(mMockA11yWindowManager.getDisplayIdByUserIdAndWindowId(USER_ID,
            WINDOWID_ONSECONDDISPLAY)).thenReturn(SECONDARY_DISPLAY_ID);
        when(mMockA11yWindowManager.getWindowListLocked(SECONDARY_DISPLAY_ID))
            .thenReturn(mA11yWindowInfosOnSecondDisplay);