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

Commit 87079024 authored by Tiger Huang's avatar Tiger Huang Committed by Android (Google) Code Review
Browse files

Merge "Move the display targeted by a key event to top"

parents 0b9b1d42 dda14a7e
Loading
Loading
Loading
Loading
+29 −7
Original line number Diff line number Diff line
@@ -567,6 +567,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private boolean mScreenshotChordPowerKeyTriggered;
    private long mScreenshotChordPowerKeyTime;

    private static final long MOVING_DISPLAY_TO_TOP_DURATION_MILLIS = 10;
    private volatile boolean mMovingDisplayToTopKeyTriggered;
    private volatile long mMovingDisplayToTopKeyTime;

    // Ringer toggle should reuse timing and triggering from screenshot power and a11y vol up
    private int mRingerToggleChord = VOLUME_HUSH_OFF;

@@ -606,7 +610,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private boolean mAodShowing;

    private boolean mPerDisplayFocusEnabled = false;
    private int mTopFocusedDisplayId = INVALID_DISPLAY;
    private volatile int mTopFocusedDisplayId = INVALID_DISPLAY;

    private static final int MSG_ENABLE_POINTER_LOCATION = 1;
    private static final int MSG_DISABLE_POINTER_LOCATION = 2;
@@ -634,6 +638,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
    private static final int MSG_POWER_VERY_LONG_PRESS = 25;
    private static final int MSG_NOTIFY_USER_ACTIVITY = 26;
    private static final int MSG_RINGER_TOGGLE_CHORD = 27;
    private static final int MSG_MOVE_DISPLAY_TO_TOP = 28;

    private class PolicyHandler extends Handler {
        @Override
@@ -729,6 +734,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                case MSG_RINGER_TOGGLE_CHORD:
                    handleRingerChordGesture();
                    break;
                case MSG_MOVE_DISPLAY_TO_TOP:
                    mWindowManagerFuncs.moveDisplayToTop(msg.arg1);
                    mMovingDisplayToTopKeyTriggered = false;
                    break;
            }
        }
    }
@@ -2570,12 +2579,25 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        final int eventDisplayId = event.getDisplayId();
        if (result == 0 && !mPerDisplayFocusEnabled
                && eventDisplayId != INVALID_DISPLAY && eventDisplayId != mTopFocusedDisplayId) {
            // Someone tries to send a key event to a display which doesn't have a focused window.
            // We drop the event here, or it will cause ANR.
            // TODO (b/121057974): The user may be confused about why the key doesn't work, so we
            // may need to deal with this problem.
            Slog.i(TAG, "Dropping this event targeting display #" + eventDisplayId
                    + " because the focus is on display #" + mTopFocusedDisplayId);
            // An event is targeting a non-focused display. Try to move the display to top so that
            // it can become the focused display to interact with the user.
            final long eventDownTime = event.getDownTime();
            if (mMovingDisplayToTopKeyTime < eventDownTime) {
                // We have not handled this event yet. Move the display to top, and then tell
                // dispatcher to try again later.
                mMovingDisplayToTopKeyTime = eventDownTime;
                mMovingDisplayToTopKeyTriggered = true;
                mHandler.sendMessage(
                        mHandler.obtainMessage(MSG_MOVE_DISPLAY_TO_TOP, eventDisplayId, 0));
                return MOVING_DISPLAY_TO_TOP_DURATION_MILLIS;
            } else if (mMovingDisplayToTopKeyTriggered) {
                // The message has not been handled yet. Tell dispatcher to try again later.
                return MOVING_DISPLAY_TO_TOP_DURATION_MILLIS;
            }
            // The target display is still not the top focused display. Drop the event because the
            // display may not contain any window which can receive keys.
            Slog.w(TAG, "Dropping key targeting non-focused display #" + eventDisplayId
                    + " keyCode=" + KeyEvent.keyCodeToString(event.getKeyCode()));
            return -1;
        }
        return result;
+6 −0
Original line number Diff line number Diff line
@@ -634,6 +634,12 @@ public interface WindowManagerPolicy extends WindowManagerPolicyConstants {
         * Notifies window manager that user is switched.
         */
        void onUserSwitched();

        /**
         * Hint to window manager that the user is interacting with a display that should be treated
         * as the top display.
         */
        void moveDisplayToTop(int displayId);
    }

    /**
+2 −3
Original line number Diff line number Diff line
@@ -47,10 +47,9 @@ import android.view.IWindowId;
import android.view.IWindowSession;
import android.view.IWindowSessionCallback;
import android.view.InputChannel;
import android.view.Surface;
import android.view.InsetsState;
import android.view.SurfaceControl;
import android.view.SurfaceSession;
import android.view.InsetsState;
import android.view.WindowManager;

import com.android.internal.os.logging.MetricsLoggerWrapper;
@@ -432,7 +431,7 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {

    @Override
    public void insetsModified(IWindow window, InsetsState state) {
        synchronized (mService.mWindowMap) {
        synchronized (mService.mGlobalLock) {
            final WindowState windowState = mService.windowForClientLocked(this, window,
                    false /* throwOnError */);
            if (windowState != null) {
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ public class TaskTapPointerEventListener implements PointerEventListener {
                    return;
                }
                WindowContainer parent = mDisplayContent.getParent();
                if (parent != null) {
                if (parent != null && parent.getTopChild() != mDisplayContent) {
                    parent.positionChildAt(WindowContainer.POSITION_TOP, mDisplayContent,
                            true /* includingParents */);
                }
+3 −1
Original line number Diff line number Diff line
@@ -437,6 +437,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
                if (mChildren.peekLast() != child) {
                    mChildren.remove(child);
                    mChildren.add(child);
                    onChildPositionChanged();
                }
                if (includingParents && getParent() != null) {
                    getParent().positionChildAt(POSITION_TOP, this /* child */,
@@ -447,6 +448,7 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
                if (mChildren.peekFirst() != child) {
                    mChildren.remove(child);
                    mChildren.addFirst(child);
                    onChildPositionChanged();
                }
                if (includingParents && getParent() != null) {
                    getParent().positionChildAt(POSITION_BOTTOM, this /* child */,
@@ -460,9 +462,9 @@ class WindowContainer<E extends WindowContainer> extends ConfigurationContainer<
                //       doing this adjustment here and remove any adjustments in the callers.
                mChildren.remove(child);
                mChildren.add(position, child);
        }
                onChildPositionChanged();
        }
    }

    /**
     * Notify that a child's position has changed. Possible changes are adding or removing a child.
Loading