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

Commit fb3af5bb authored by Jacky Kao's avatar Jacky Kao
Browse files

Revert "Uses SF callback windows for the A11yWindowInfo [2/n]"

Revert submission 16249364-Surface Flinger

Reason for revert: Large increase (~200%) in system_server memory usage (b/214255324)
Reverted Changes:
I14c5e9889:Apply display transform to window bounds and node ...
I0ac0d0487:Use shellRoot to identify PIP menu window
I83e898d91:Uses SF callback windows for the A11yWindowInfo [2...
I94d7ed4fb:Uses SF callback windows for the A11yWindowInfo [1...

Change-Id: Ie868ad8e4480f7759aa07f25281fcdc08cea4009
parent 50f53e88
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -318,6 +318,11 @@ final class AccessibilityController {
        if (displayMagnifier != null) {
            displayMagnifier.onDisplaySizeChanged(displayContent);
        }
        final WindowsForAccessibilityObserver windowsForA11yObserver =
                mWindowsForAccessibilityObserver.get(displayId);
        if (windowsForA11yObserver != null) {
            windowsForA11yObserver.scheduleComputeChangedWindows();
        }
    }

    void onAppWindowTransition(int displayId, int transition) {
@@ -345,6 +350,11 @@ final class AccessibilityController {
        if (displayMagnifier != null) {
            displayMagnifier.onWindowTransition(windowState, transition);
        }
        final WindowsForAccessibilityObserver windowsForA11yObserver =
                mWindowsForAccessibilityObserver.get(displayId);
        if (windowsForA11yObserver != null) {
            windowsForA11yObserver.scheduleComputeChangedWindows();
        }
    }

    void onWindowFocusChangedNot(int displayId) {
+7 −60
Original line number Diff line number Diff line
@@ -48,14 +48,6 @@ import java.util.List;
public final class AccessibilityWindowsPopulator extends WindowInfosListener {

    private static final String TAG = AccessibilityWindowsPopulator.class.getSimpleName();
    // If the surface flinger callback is not coming within in 2 frames time, i.e. about
    // 35ms, then assuming the windows become stable.
    private static final int SURFACE_FLINGER_CALLBACK_WINDOWS_STABLE_TIMES_MS = 35;
    // To avoid the surface flinger callbacks always comes within in 2 frames, then no windows
    // are reported to the A11y framework, and the animation duration time is 500ms, so setting
    // this value as the max timeout value to force computing changed windows.
    private static final int WINDOWS_CHANGED_NOTIFICATION_MAX_DURATION_TIMES_MS = 500;

    private static final float[] sTempFloats = new float[9];

    private final WindowManagerService mService;
@@ -122,12 +114,6 @@ public final class AccessibilityWindowsPopulator extends WindowInfosListener {
                }
            }
            if (mWindowsNotificationEnabled) {
                if (!mHandler.hasMessages(
                        MyHandler.MESSAGE_NOTIFY_WINDOWS_CHANGED_BY_TIMEOUT)) {
                    mHandler.sendEmptyMessageDelayed(
                            MyHandler.MESSAGE_NOTIFY_WINDOWS_CHANGED_BY_TIMEOUT,
                            WINDOWS_CHANGED_NOTIFICATION_MAX_DURATION_TIMES_MS);
                }
                populateVisibleWindowHandlesAndNotifyWindowsChangeIfNeededLocked();
            }
        }
@@ -179,18 +165,11 @@ public final class AccessibilityWindowsPopulator extends WindowInfosListener {
            final int displayId = tempWindowHandleList.keyAt(i);
            mInputWindowHandlesOnDisplays.put(displayId, tempWindowHandleList.get(displayId));
        }

        if (displayIdsForWindowsChanged.size() > 0) {
            if (!mHandler.hasMessages(MyHandler.MESSAGE_NOTIFY_WINDOWS_CHANGED)) {
        if (displayIdsForWindowsChanged.size() > 0
                && !mHandler.hasMessages(MyHandler.MESSAGE_NOTIFY_WINDOWS_CHANGED)) {
            mHandler.obtainMessage(MyHandler.MESSAGE_NOTIFY_WINDOWS_CHANGED,
                    displayIdsForWindowsChanged).sendToTarget();
        }

            return;
        }
        mHandler.removeMessages(MyHandler.MESSAGE_NOTIFY_WINDOWS_CHANGED_BY_UI_STABLE);
        mHandler.sendEmptyMessageDelayed(MyHandler.MESSAGE_NOTIFY_WINDOWS_CHANGED_BY_UI_STABLE,
                SURFACE_FLINGER_CALLBACK_WINDOWS_STABLE_TIMES_MS);
    }

    private void getDisplaysForWindowsChangedLocked(List<Integer> outDisplayIdsForWindowsChanged,
@@ -259,39 +238,22 @@ public final class AccessibilityWindowsPopulator extends WindowInfosListener {
    }

    private void notifyWindowsChanged(@NonNull List<Integer> displayIdsForWindowsChanged) {
        mHandler.removeMessages(MyHandler.MESSAGE_NOTIFY_WINDOWS_CHANGED_BY_TIMEOUT);

        for (int i = 0; i < displayIdsForWindowsChanged.size(); i++) {
            mAccessibilityController.performComputeChangedWindowsNot(
                    displayIdsForWindowsChanged.get(i), false);
        }
    }

    private void forceUpdateWindows() {
        final List<Integer> displayIdsForWindowsChanged = new ArrayList<>();

        synchronized (mLock) {
            for (int i = 0; i < mInputWindowHandlesOnDisplays.size(); i++) {
                final int displayId = mInputWindowHandlesOnDisplays.keyAt(i);
                displayIdsForWindowsChanged.add(displayId);
            }
        }
        notifyWindowsChanged(displayIdsForWindowsChanged);
    }

    @GuardedBy("mLock")
    private void releaseResources() {
        mInputWindowHandlesOnDisplays.clear();
        mMagnificationSpecInverseMatrix.clear();
        mVisibleWindows.clear();
        mWindowsNotificationEnabled = false;
        mHandler.removeCallbacksAndMessages(null);
    }

    private class MyHandler extends Handler {
        public static final int MESSAGE_NOTIFY_WINDOWS_CHANGED = 1;
        public static final int MESSAGE_NOTIFY_WINDOWS_CHANGED_BY_UI_STABLE = 2;
        public static final int MESSAGE_NOTIFY_WINDOWS_CHANGED_BY_TIMEOUT = 3;

        MyHandler(Looper looper) {
            super(looper, null, false);
@@ -299,24 +261,9 @@ public final class AccessibilityWindowsPopulator extends WindowInfosListener {

        @Override
        public void handleMessage(Message message) {
            switch (message.what) {
                case MESSAGE_NOTIFY_WINDOWS_CHANGED: {
            if (message.what == MESSAGE_NOTIFY_WINDOWS_CHANGED) {
                final List<Integer> displayIdsForWindowsChanged = (List<Integer>) message.obj;
                notifyWindowsChanged(displayIdsForWindowsChanged);
                } break;

                case MESSAGE_NOTIFY_WINDOWS_CHANGED_BY_UI_STABLE: {
                    forceUpdateWindows();
                } break;

                case MESSAGE_NOTIFY_WINDOWS_CHANGED_BY_TIMEOUT: {
                    Slog.w(TAG, "Windows change within in 2 frames continuously over 500 ms "
                            + "and notify windows changed immediately");
                    mHandler.removeMessages(
                            MyHandler.MESSAGE_NOTIFY_WINDOWS_CHANGED_BY_UI_STABLE);

                    forceUpdateWindows();
                } break;
            }
        }
    }
+4 −0
Original line number Diff line number Diff line
@@ -197,5 +197,9 @@ public class ShellRoot {
                mAccessibilityWindow = null;
            }
        }
        if (mDisplayContent.mWmService.mAccessibilityController.hasCallbacks()) {
            mDisplayContent.mWmService.mAccessibilityController.onSomeWindowResizedOrMoved(
                    mDisplayContent.getDisplayId());
        }
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -4807,6 +4807,9 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        if (isAnimating()) {
            return;
        }
        if (mWmService.mAccessibilityController.hasCallbacks()) {
            mWmService.mAccessibilityController.onSomeWindowResizedOrMoved(getDisplayId());
        }

        if (!isSelfOrAncestorWindowAnimatingExit()) {
            return;