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

Commit bdc5c98f authored by Roy Chou's avatar Roy Chou
Browse files

chore(magnification): add UserContextChangedNotifier class in AccessibilityController

In AccessibilityController#DisplayMagnifier, we create a new UserContextChangedNotifier inner class to wrap the callback notifying logic. Then we can add
extra flag-based notifying decision logic in the internal UserContextChangedNotifier class, as in the next cl.

Bug: 324949652
Flag: NONE
Test: manually
Change-Id: I3dc723bb91903d72f00069964c0ae6aa8e53d0e3
parent 9f89d4bd
Loading
Loading
Loading
Loading
+80 −29
Original line number Diff line number Diff line
@@ -93,6 +93,8 @@ import android.view.SurfaceControl;
import android.view.ViewConfiguration;
import android.view.WindowInfo;
import android.view.WindowManager;
import android.view.WindowManager.TransitionFlags;
import android.view.WindowManager.TransitionType;
import android.view.WindowManagerPolicyConstants;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
@@ -357,14 +359,15 @@ final class AccessibilityController {
        // Not relevant for the window observer.
    }

    void onWMTransition(int displayId, @WindowManager.TransitionType int type) {
    void onWMTransition(int displayId, @TransitionType int type, @TransitionFlags int flags) {
        if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK)) {
            mAccessibilityTracing.logTrace(TAG + ".onAppWindowTransition",
                    FLAGS_MAGNIFICATION_CALLBACK, "displayId=" + displayId + "; type=" + type);
            mAccessibilityTracing.logTrace(TAG + ".onWMTransition",
                    FLAGS_MAGNIFICATION_CALLBACK,
                    "displayId=" + displayId + "; type=" + type + "; flags=" + flags);
        }
        final DisplayMagnifier displayMagnifier = mDisplayMagnifiers.get(displayId);
        if (displayMagnifier != null) {
            displayMagnifier.onWMTransition(displayId, type);
            displayMagnifier.onWMTransition(displayId, type, flags);
        }
        // Not relevant for the window observer.
    }
@@ -574,6 +577,11 @@ final class AccessibilityController {
    void onFocusChanged(InputTarget lastTarget, InputTarget newTarget) {
        if (lastTarget != null) {
            mFocusedWindow.remove(lastTarget.getDisplayId());
            final DisplayMagnifier displayMagnifier =
                    mDisplayMagnifiers.get(lastTarget.getDisplayId());
            if (displayMagnifier != null) {
                displayMagnifier.onFocusLost(lastTarget);
            }
        }
        if (newTarget != null) {
            int displayId = newTarget.getDisplayId();
@@ -625,6 +633,7 @@ final class AccessibilityController {
        private final AccessibilityControllerInternalImpl mAccessibilityTracing;

        private final MagnificationCallbacks mCallbacks;
        private final UserContextChangedNotifier mUserContextChangedNotifier;

        private final long mLongAnimationDuration;

@@ -653,6 +662,7 @@ final class AccessibilityController {
            mDisplayContent = displayContent;
            mDisplay = display;
            mHandler = new MyHandler(mService.mH.getLooper());
            mUserContextChangedNotifier = new UserContextChangedNotifier(mHandler);
            mMagnifiedViewport = Flags.alwaysDrawMagnificationFullscreenBorder()
                    ? null : new MagnifiedViewport();
            mAccessibilityTracing =
@@ -764,7 +774,9 @@ final class AccessibilityController {
                        + " displayId: " + displayId);
            }
            final boolean isMagnifierActivated = isFullscreenMagnificationActivated();
            if (isMagnifierActivated) {
            if (!isMagnifierActivated) {
                return;
            }
            switch (transition) {
                case WindowManager.TRANSIT_OLD_ACTIVITY_OPEN:
                case WindowManager.TRANSIT_OLD_TASK_FRAGMENT_OPEN:
@@ -773,31 +785,32 @@ final class AccessibilityController {
                case WindowManager.TRANSIT_OLD_WALLPAPER_OPEN:
                case WindowManager.TRANSIT_OLD_WALLPAPER_CLOSE:
                case WindowManager.TRANSIT_OLD_WALLPAPER_INTRA_OPEN: {
                        mHandler.sendEmptyMessage(MyHandler.MESSAGE_NOTIFY_USER_CONTEXT_CHANGED);
                    }
                    mUserContextChangedNotifier.onAppWindowTransition(transition);
                }
            }
        }

        void onWMTransition(int displayId, @WindowManager.TransitionType int type) {
        void onWMTransition(int displayId, @TransitionType int type, @TransitionFlags int flags) {
            if (mAccessibilityTracing.isTracingEnabled(FLAGS_MAGNIFICATION_CALLBACK)) {
                mAccessibilityTracing.logTrace(LOG_TAG + ".onWMTransition",
                        FLAGS_MAGNIFICATION_CALLBACK, "displayId=" + displayId + "; type=" + type);
                        FLAGS_MAGNIFICATION_CALLBACK,
                        "displayId=" + displayId + "; type=" + type + "; flags=" + flags);
            }
            if (DEBUG_WINDOW_TRANSITIONS) {
                Slog.i(LOG_TAG, "Window transition: " + WindowManager.transitTypeToString(type)
                        + " displayId: " + displayId);
            }
            final boolean isMagnifierActivated = isFullscreenMagnificationActivated();
            if (isMagnifierActivated) {
            if (!isMagnifierActivated) {
                return;
            }
            // All opening/closing situations.
            switch (type) {
                case WindowManager.TRANSIT_OPEN:
                case WindowManager.TRANSIT_TO_FRONT:
                case WindowManager.TRANSIT_CLOSE:
                case WindowManager.TRANSIT_TO_BACK:
                        mHandler.sendEmptyMessage(MyHandler.MESSAGE_NOTIFY_USER_CONTEXT_CHANGED);
                }
                    mUserContextChangedNotifier.onWMTransition(type, flags);
            }
        }

@@ -813,13 +826,14 @@ final class AccessibilityController {
                        + " displayId: " + windowState.getDisplayId());
            }
            final boolean isMagnifierActivated = isFullscreenMagnificationActivated();
            if (!isMagnifierActivated || !windowState.shouldMagnify()) {
                return;
            }
            mUserContextChangedNotifier.onWindowTransition(windowState, transition);
            final int type = windowState.mAttrs.type;
            switch (transition) {
                case WindowManagerPolicy.TRANSIT_ENTER:
                case WindowManagerPolicy.TRANSIT_SHOW: {
                    if (!isMagnifierActivated || !windowState.shouldMagnify()) {
                        break;
                    }
                    switch (type) {
                        case WindowManager.LayoutParams.TYPE_APPLICATION:
                        case WindowManager.LayoutParams.TYPE_DRAWN_APPLICATION:
@@ -859,6 +873,14 @@ final class AccessibilityController {
            }
        }

        void onFocusLost(InputTarget target) {
            final boolean isMagnifierActivated = isFullscreenMagnificationActivated();
            if (!isMagnifierActivated) {
                return;
            }
            mUserContextChangedNotifier.onFocusLost(target);
        }

        void getMagnifiedFrameInContentCoords(Rect rect) {
            mMagnificationRegion.getBounds(rect);
            rect.offset((int) -mMagnificationSpec.offsetX, (int) -mMagnificationSpec.offsetY);
@@ -1584,6 +1606,35 @@ final class AccessibilityController {
                }
            }
        }

        private class UserContextChangedNotifier {

            private final Handler mHandler;

            UserContextChangedNotifier(Handler handler) {
                mHandler = handler;
            }

            void onAppWindowTransition(int transition) {
                sendUserContextChangedNotification();
            }

            void onWMTransition(@TransitionType int type, @TransitionFlags int flags) {
                sendUserContextChangedNotification();
            }

            void onWindowTransition(WindowState windowState, int transition) {
                // do nothing
            }

            void onFocusLost(InputTarget target) {
                // do nothing
            }

            private void sendUserContextChangedNotification() {
                mHandler.sendEmptyMessage(MyHandler.MESSAGE_NOTIFY_USER_CONTEXT_CHANGED);
            }
        }
    }

    static boolean isUntouchableNavigationBar(WindowState windowState,
+1 −1
Original line number Diff line number Diff line
@@ -1814,7 +1814,7 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener {
                final AccessibilityController accessibilityController =
                        dc.mWmService.mAccessibilityController;
                if (accessibilityController.hasCallbacks()) {
                    accessibilityController.onWMTransition(dc.getDisplayId(), mType);
                    accessibilityController.onWMTransition(dc.getDisplayId(), mType, mFlags);
                }
            }
        } else {