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

Commit f191ff1c authored by Hiroki Sato's avatar Hiroki Sato
Browse files

Cleanup AccessibilityWindowManager#onWindowsForAccessibilityChanged

Due to a flag compute_window_changes_on_a11y_v2,
AccessibilityWindowManager.DisplayWindowsObserver has two entry points,
one is #onWindowsForAccessibilityChanged (for flag disabled) and another
is #onAccessibilityWindowsChanged (for flag enabled).
Now that the flag is removed [1], we can merge them to simplify the
code.

[1] Ifd8328fd21f5547726313c65c60d2a4b0d6095af

Bug: 322444245
Test: atest AccessibilityEventAndCacheTest
Flag: EXEMPT cleanup after removintg com.android.server.accessibility.fix_merged_content_change_event_v2
Change-Id: Ia72589b03c6af12abb8cc990325303f3afed23ea
parent 21546066
Loading
Loading
Loading
Loading
+23 −36
Original line number Diff line number Diff line
@@ -433,10 +433,24 @@ public class AccessibilityWindowManager {
            return Collections.emptyList();
        }

        private void onWindowsForAccessibilityChanged(boolean forceSend, int topFocusedDisplayId,
                IBinder topFocusedWindowToken, @NonNull List<WindowInfo> windows) {
            // TODO(b/322444245): no longer need to get a lock.
        /**
         * Called when the windows for accessibility changed.
         *
         * @param forceSend             Send the windows for accessibility even if they haven't
         *                              changed.
         * @param topFocusedDisplayId   The display Id which has the top focused window.
         * @param topFocusedWindowToken The window token of top focused window.
         * @param screenSize            The size of the display that the change happened.
         * @param accessibilityWindows  The windows for accessibility.
         */
        @Override
        public void onAccessibilityWindowsChanged(boolean forceSend, int topFocusedDisplayId,
                @NonNull IBinder topFocusedWindowToken, @NonNull Point screenSize,
                @NonNull List<AccessibilityWindow> accessibilityWindows) {
            synchronized (mLock) {
                final List<WindowInfo> windows =
                        createWindowInfoListLocked(screenSize, accessibilityWindows);

                if (DEBUG) {
                    Slogf.i(LOG_TAG, "mDisplayId=%d, topFocusedDisplayId=%d, currentUserId=%d, "
                                    + "visibleBgUsers=%s", mDisplayId, topFocusedDisplayId,
@@ -451,14 +465,15 @@ public class AccessibilityWindowManager {
                        Slogf.i(LOG_TAG, "%d windows changed: %s", windows.size(), windowsInfo);
                    }
                }
                if (shouldUpdateWindowsLocked(forceSend, windows)) {

                if (forceSend || shouldUpdateWindowsLocked(windows)) {
                    mTopFocusedDisplayId = topFocusedDisplayId;
                    if (!isProxyed(topFocusedDisplayId)) {
                        mLastNonProxyTopFocusedDisplayId = topFocusedDisplayId;
                    }
                    mTopFocusedWindowToken = topFocusedWindowToken;
                    if (DEBUG) {
                        Slogf.d(LOG_TAG, "onWindowsForAccessibilityChanged(): updating windows for "
                        Slogf.d(LOG_TAG, "onAccessibilityWindowsChanged(): updating windows for "
                                        + "display %d and token %s",
                                topFocusedDisplayId, topFocusedWindowToken);
                    }
@@ -468,37 +483,14 @@ public class AccessibilityWindowManager {
                            windows);
                    // Someone may be waiting for the windows - advertise it.
                    mLock.notifyAll();
                }
                else if (DEBUG) {
                    Slogf.d(LOG_TAG, "onWindowsForAccessibilityChanged(): NOT updating windows for "
                } else if (DEBUG) {
                    Slogf.d(LOG_TAG, "onAccessibilityWindowsChanged(): NOT updating windows for "
                                    + "display %d and token %s",
                            topFocusedDisplayId, topFocusedWindowToken);
                }
            }
        }

        /**
         * Called when the windows for accessibility changed.
         *
         * @param forceSend             Send the windows for accessibility even if they haven't
         *                              changed.
         * @param topFocusedDisplayId   The display Id which has the top focused window.
         * @param topFocusedWindowToken The window token of top focused window.
         * @param screenSize            The size of the display that the change happened.
         * @param windows               The windows for accessibility.
         */
        @Override
        public void onAccessibilityWindowsChanged(boolean forceSend, int topFocusedDisplayId,
                @NonNull IBinder topFocusedWindowToken, @NonNull Point screenSize,
                @NonNull List<AccessibilityWindow> windows) {
            synchronized (mLock) {
                final List<WindowInfo> windowInfoList =
                        createWindowInfoListLocked(screenSize, windows);
                onWindowsForAccessibilityChanged(forceSend, topFocusedDisplayId,
                        topFocusedWindowToken, windowInfoList);
            }
        }

        private List<WindowInfo> createWindowInfoListLocked(@NonNull Point screenSize,
                @NonNull List<AccessibilityWindow> visibleWindows) {
            final Set<IBinder> addedWindows = new ArraySet<>();
@@ -650,12 +642,7 @@ public class AccessibilityWindowManager {
            windowInfo.locales = attributes.getLocales();
        }

        private boolean shouldUpdateWindowsLocked(boolean forceSend,
                @NonNull List<WindowInfo> windows) {
            if (forceSend) {
                return true;
            }

        private boolean shouldUpdateWindowsLocked(@NonNull List<WindowInfo> windows) {
            final int windowCount = windows.size();
            if (VERBOSE) {
                Slogf.v(LOG_TAG,