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

Commit a9258695 authored by Phil Weaver's avatar Phil Weaver Committed by Android (Google) Code Review
Browse files

Merge "Eliminate race condition for a11y windows"

parents 46577443 c72faad7
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -701,6 +701,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
    public int addAccessibilityInteractionConnection(IWindow windowToken,
            IAccessibilityInteractionConnection connection, String packageName,
            int userId) throws RemoteException {
        final int windowId;
        synchronized (mLock) {
            // We treat calls from a profile as if made by its parent as profiles
            // share the accessibility state of the parent. The call below
@@ -713,7 +714,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
            packageName = mSecurityPolicy.resolveValidReportedPackageLocked(
                    packageName, UserHandle.getCallingAppId(), resolvedUserId);

            final int windowId = sNextWindowId++;
            windowId = sNextWindowId++;
            // If the window is from a process that runs across users such as
            // the system UI or the system we add it to the global state that
            // is shared across users.
@@ -741,8 +742,10 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
                            + " and  token: " + windowToken.asBinder());
                }
            }
            return windowId;
        }
        WindowManagerInternal wm = LocalServices.getService(WindowManagerInternal.class);
        wm.computeWindowsForAccessibility();
        return windowId;
    }

    @Override
+35 −28
Original line number Diff line number Diff line
@@ -119,13 +119,13 @@ final class AccessibilityController {
        }
    }

    public void performComputeChangedWindowsNotLocked() {
    public void performComputeChangedWindowsNotLocked(boolean forceSend) {
        WindowsForAccessibilityObserver observer = null;
        synchronized (mService) {
            observer = mWindowsForAccessibilityObserver;
        }
        if (observer != null) {
            observer.performComputeChangedWindowsNotLocked();
            observer.performComputeChangedWindowsNotLocked(forceSend);
        }
    }

@@ -193,7 +193,7 @@ final class AccessibilityController {
            observer = mWindowsForAccessibilityObserver;
        }
        if (observer != null) {
            observer.performComputeChangedWindowsNotLocked();
            observer.performComputeChangedWindowsNotLocked(false);
        }
    }

@@ -1011,12 +1011,12 @@ final class AccessibilityController {
            mHandler = new MyHandler(mService.mH.getLooper());
            mRecurringAccessibilityEventsIntervalMillis = ViewConfiguration
                    .getSendRecurringAccessibilityEventsInterval();
            computeChangedWindows();
            computeChangedWindows(true);
        }

        public void performComputeChangedWindowsNotLocked() {
        public void performComputeChangedWindowsNotLocked(boolean forceSend) {
            mHandler.removeMessages(MyHandler.MESSAGE_COMPUTE_CHANGED_WINDOWS);
            computeChangedWindows();
            computeChangedWindows(forceSend);
        }

        public void scheduleComputeChangedWindowsLocked() {
@@ -1026,7 +1026,12 @@ final class AccessibilityController {
            }
        }

        public void computeChangedWindows() {
        /**
         * Check if windows have changed, and send them to the accessibilty subsystem if they have.
         *
         * @param forceSend Send the windows the accessibility even if they haven't changed.
         */
        public void computeChangedWindows(boolean forceSend) {
            if (DEBUG) {
                Slog.i(LOG_TAG, "computeChangedWindows()");
            }
@@ -1171,6 +1176,7 @@ final class AccessibilityController {
                visibleWindows.clear();
                addedWindows.clear();

                if (!forceSend) {
                    // We computed the windows and if they changed notify the client.
                    if (mOldWindows.size() != windows.size()) {
                        // Different size means something changed.
@@ -1191,16 +1197,17 @@ final class AccessibilityController {
                            }
                        }
                    }
                }

                if (windowsChanged) {
                if (forceSend || windowsChanged) {
                    cacheWindows(windows);
                }
            }

            // Now we do not hold the lock, so send the windows over.
            if (windowsChanged) {
            if (forceSend || windowsChanged) {
                if (DEBUG) {
                    Log.i(LOG_TAG, "Windows changed:" + windows);
                    Log.i(LOG_TAG, "Windows changed or force sending:" + windows);
                }
                mCallback.onWindowsForAccessibilityChanged(windows);
            } else {
@@ -1345,7 +1352,7 @@ final class AccessibilityController {
            public void handleMessage(Message message) {
                switch (message.what) {
                    case MESSAGE_COMPUTE_CHANGED_WINDOWS: {
                        computeChangedWindows();
                        computeChangedWindows(false);
                    } break;
                }
            }
+1 −1
Original line number Diff line number Diff line
@@ -410,7 +410,7 @@ public abstract class WindowManagerInternal {
    public abstract boolean isDockedDividerResizing();

    /**
     * Requests the window manager to recompute the windows for accessibility.
     * Requests the window manager to resend the windows for accessibility.
     */
    public abstract void computeWindowsForAccessibility();

+1 −1
Original line number Diff line number Diff line
@@ -7422,7 +7422,7 @@ public class WindowManagerService extends IWindowManager.Stub
                accessibilityController = mAccessibilityController;
            }
            if (accessibilityController != null) {
                accessibilityController.performComputeChangedWindowsNotLocked();
                accessibilityController.performComputeChangedWindowsNotLocked(true);
            }
        }