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

Commit a647595d authored by Roy Chou's avatar Roy Chou Committed by Android (Google) Code Review
Browse files

Merge changes from topic "324949652" into main

* changes:
  fix(magnification): magnification should not reset when pressing on navigation bar
  chore(magnification): add UserContextChangedNotifier class in AccessibilityController
parents 8ab36d44 f442934f
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -27,3 +27,13 @@ flag {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
  name: "delay_notification_to_magnification_when_recents_window_to_front_transition"
  namespace: "accessibility"
  description: "The flag controls whether the delaying of notification for recents window to-front transition is needed. In accessibilityController other callbacks will decide sending or canceling the delayed notification."
  bug: "324949652"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}
+111 −29
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_IS_ROUNDED_CO
import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_MAGNIFICATION_OVERLAY;
import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY;
import static android.view.WindowManager.TRANSIT_FLAG_IS_RECENTS;

import static com.android.internal.util.DumpUtils.dumpSparseArray;
import static com.android.internal.util.DumpUtils.dumpSparseArrayValues;
@@ -93,6 +94,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 +360,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 +578,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 +634,7 @@ final class AccessibilityController {
        private final AccessibilityControllerInternalImpl mAccessibilityTracing;

        private final MagnificationCallbacks mCallbacks;
        private final UserContextChangedNotifier mUserContextChangedNotifier;

        private final long mLongAnimationDuration;

@@ -653,6 +663,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 +775,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 +786,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 +827,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 +874,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 +1607,65 @@ final class AccessibilityController {
                }
            }
        }

        private class UserContextChangedNotifier {

            private final Handler mHandler;

            private boolean mHasDelayedNotificationForRecentsToFrontTransition;

            UserContextChangedNotifier(Handler handler) {
                mHandler = handler;
            }

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

            // For b/324949652, if the onWMTransition callback is triggered when the finger down
            // event on navigation bar to bring the recents window to front, we'll delay the
            // notifying of the context changed, then send it if there is a following onFocusChanged
            // callback triggered. Before the onFocusChanged, if there are some other transitions
            // causing the notifying, or the recents/home window is removed, then we won't need the
            // delayed notification anymore.
            void onWMTransition(@TransitionType int type, @TransitionFlags int flags) {
                if (Flags.delayNotificationToMagnificationWhenRecentsWindowToFrontTransition()
                        && type == WindowManager.TRANSIT_TO_FRONT
                        && (flags & TRANSIT_FLAG_IS_RECENTS) != 0) {
                    // Delay the recents to front transition notification then send after if needed.
                    mHasDelayedNotificationForRecentsToFrontTransition = true;
                } else {
                    sendUserContextChangedNotification();
                }
            }

            void onWindowTransition(WindowState windowState, int transition) {
                // If there is a delayed notification for recents to front transition but the
                // home/recents window has been removed from screen, the delayed notification is not
                // needed anymore.
                if (transition == WindowManagerPolicy.TRANSIT_EXIT
                        && windowState.isActivityTypeHomeOrRecents()
                        && mHasDelayedNotificationForRecentsToFrontTransition) {
                    mHasDelayedNotificationForRecentsToFrontTransition = false;
                }
            }

            void onFocusLost(InputTarget target) {
                // If there is a delayed notification for recents to front transition and
                // onFocusLost is triggered, we assume that the users leave current window to
                // the home/recents window, thus we'll need to send the delayed notification.
                if (mHasDelayedNotificationForRecentsToFrontTransition) {
                    sendUserContextChangedNotification();
                }
            }

            private void sendUserContextChangedNotification() {
                // Since the context changed will be notified, the delayed notification is
                // not needed anymore.
                mHasDelayedNotificationForRecentsToFrontTransition = false;
                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 {