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

Commit 163ee65a authored by Hiroki Sato's avatar Hiroki Sato Committed by Android (Google) Code Review
Browse files

Merge "Extract a11y window computation into a method" into main

parents fc68661a a57edbca
Loading
Loading
Loading
Loading
+70 −60
Original line number Diff line number Diff line
@@ -1610,7 +1610,7 @@ final class AccessibilityController {
                Slog.i(LOG_TAG, "computeChangedWindows()");
            }

            final List<WindowInfo> windows = new ArrayList<>();
            final List<WindowInfo> windows;
            final List<AccessibilityWindow> visibleWindows = new ArrayList<>();
            final int topFocusedDisplayId;
            IBinder topFocusedWindowToken = null;
@@ -1640,28 +1640,49 @@ final class AccessibilityController {
                }
                final Display display = dc.getDisplay();
                display.getRealSize(mTempPoint);
                final int screenWidth = mTempPoint.x;
                final int screenHeight = mTempPoint.y;

                Region unaccountedSpace = mTempRegion;
                unaccountedSpace.set(0, 0, screenWidth, screenHeight);

                mA11yWindowsPopulator.populateVisibleWindowsOnScreenLocked(
                        mDisplayId, visibleWindows);
                Set<IBinder> addedWindows = mTempBinderSet;

                windows = buildWindowInfoListLocked(visibleWindows, mTempPoint);

                // Gets the top focused display Id and window token for supporting multi-display.
                topFocusedDisplayId = mService.mRoot.getTopFocusedDisplayContent().getDisplayId();
                topFocusedWindowToken = topFocusedWindowState.mClient.asBinder();
            }
            mCallback.onWindowsForAccessibilityChanged(forceSend, topFocusedDisplayId,
                    topFocusedWindowToken, windows);

            // Recycle the windows as we do not need them.
            for (final AccessibilityWindowsPopulator.AccessibilityWindow window : visibleWindows) {
                window.getWindowInfo().recycle();
            }
            mInitialized = true;
        }

        /**
         * From a list of windows, decides windows to be exposed to accessibility based on touchable
         * region in the screen.
         */
        private List<WindowInfo> buildWindowInfoListLocked(List<AccessibilityWindow> visibleWindows,
                Point screenSize) {
            final List<WindowInfo> windows = new ArrayList<>();
            final Set<IBinder> addedWindows = mTempBinderSet;
            addedWindows.clear();

            boolean focusedWindowAdded = false;

            final int visibleWindowCount = visibleWindows.size();

            Region unaccountedSpace = mTempRegion;
            unaccountedSpace.set(0, 0, screenSize.x, screenSize.y);

            // Iterate until we figure out what is touchable for the entire screen.
            for (int i = 0; i < visibleWindowCount; i++) {
                final AccessibilityWindow a11yWindow = visibleWindows.get(i);
                final Region regionInWindow = new Region();
                a11yWindow.getTouchableRegionInWindow(regionInWindow);
                    if (windowMattersToAccessibility(a11yWindow, regionInWindow,
                            unaccountedSpace)) {
                if (windowMattersToAccessibility(a11yWindow, regionInWindow, unaccountedSpace)) {
                    addPopulatedWindowInfo(a11yWindow, regionInWindow, windows, addedWindows);
                    if (windowMattersToUnaccountedSpaceComputation(a11yWindow)) {
                        updateUnaccountedSpace(a11yWindow, unaccountedSpace);
@@ -1704,18 +1725,7 @@ final class AccessibilityController {

            addedWindows.clear();

                // Gets the top focused display Id and window token for supporting multi-display.
                topFocusedDisplayId = mService.mRoot.getTopFocusedDisplayContent().getDisplayId();
                topFocusedWindowToken = topFocusedWindowState.mClient.asBinder();
            }
            mCallback.onWindowsForAccessibilityChanged(forceSend, topFocusedDisplayId,
                    topFocusedWindowToken, windows);

            // Recycle the windows as we do not need them.
            for (final AccessibilityWindowsPopulator.AccessibilityWindow window : visibleWindows) {
                window.getWindowInfo().recycle();
            }
            mInitialized = true;
            return windows;
        }

        // Some windows should be excluded from unaccounted space computation, though they still