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

Commit e2084a0c authored by Winson Chung's avatar Winson Chung Committed by Android (Google) Code Review
Browse files

Merge changes I2e77b13a,Ibd180775 into main

* changes:
  Use input-reported focus for accessibility
  Clean up requesting focus for SCVHs which aren't hosted inside windows
parents 18d73a38 e82227a8
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -624,4 +624,20 @@ public class SurfaceControlViewHost {
        }
        return wm.transferTouchGesture(embeddedToken, hostToken);
    }

    /**
     * Requests input focus for the given embedded view root, to be used for cases where the
     * embedded window is not rooted to any window (otherwise focus is managed by the hosting
     * SurfaceView).
     *
     * WM will enforce that callers also hold the INTERNAL_SYSTEM_WINDOW permission.
     * If `focused` is false, WM will resolve focus on the next window.
     * @hide
     */
    public boolean requestInputFocus(boolean focused) {
        if (mViewRoot == null) {
            return false;
        }
        return mWm.requestInputFocus(mViewRoot, focused);
    }
}
+26 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ public class WindowlessWindowManager implements IWindowSession {
     * Used to store SurfaceControl we've built for clients to
     * reconfigure them if relayout is called.
     */
    final HashMap<IBinder, State> mStateForWindow = new HashMap<IBinder, State>();
    final HashMap<IBinder, State> mStateForWindow = new HashMap<>();

    public interface ResizeCompleteCallback {
        public void finished(SurfaceControl.Transaction completion);
@@ -361,6 +361,31 @@ public class WindowlessWindowManager implements IWindowSession {
        return s.mSurfaceControl;
    }

    /**
     * Requests input focus for the given embedded view root, to be used for cases where the
     * embedded window is not rooted to any window (otherwise focus is managed by the hosting
     * SurfaceView).
     *
     * WM will enforce that callers also hold the INTERNAL_SYSTEM_WINDOW permission.
     * If `focused` is false, WM will resolve focus on the next window.
     * @hide
     */
    boolean requestInputFocus(@NonNull ViewRootImpl viewRoot, boolean focused) {
        final State s = mStateForWindow.get(viewRoot.mWindow.asBinder());
        if (s == null) {
            Log.w(TAG, "Invalid view root specified, not an embedded window");
            return false;
        }
        try {
            mRealWm.grantEmbeddedWindowFocus(null /* callingWin */, s.mInputTransferToken,
                    focused);
            return true;
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to request input focus on embedded window", e);
            return false;
        }
    }

    @Override
    public int relayout(IWindow window, WindowManager.LayoutParams inAttrs,
            int requestedWidth, int requestedHeight, int viewFlags, int flags, int seq,
+10 −0
Original line number Diff line number Diff line
@@ -126,3 +126,13 @@ flag {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "use_input_reported_focus_for_accessibility"
    namespace: "window_surfaces"
    description: "Use input-reported focus state when composing accessibility window info"
    bug: "424253885"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
+4 −5
Original line number Diff line number Diff line
@@ -47,7 +47,6 @@ import android.view.WindowManager;
import android.view.WindowRelayoutResult;
import android.view.WindowlessWindowManager;
import android.view.inputmethod.ImeTracker;
import android.window.InputTransferToken;

import com.android.internal.os.IResultReceiver;

@@ -193,16 +192,16 @@ public class SystemWindows {
    }

    /**
     * Gets a token associated with the view that can be used to grant the view focus.
     * Requests input focus for the specified window.
     */
    public InputTransferToken getFocusGrantToken(View view) {
    public boolean requestInputFocus(View view, boolean focused) {
        SurfaceControlViewHost root = mViewRoots.get(view);
        if (root == null) {
            Slog.e(TAG, "Couldn't get focus grant token since view does not exist in "
                    + "SystemWindow:" + view);
            return null;
            return false;
        }
        return root.getInputTransferToken();
        return root.requestInputFocus(focused);
    }

    private class PerDisplay {
+2 −7
Original line number Diff line number Diff line
@@ -24,13 +24,11 @@ import android.content.Context;
import android.graphics.Rect;
import android.os.Debug;
import android.os.Handler;
import android.os.RemoteException;
import android.util.Size;
import android.view.MotionEvent;
import android.view.SurfaceControl;
import android.view.View;
import android.view.ViewRootImpl;
import android.view.WindowManagerGlobal;

import com.android.internal.protolog.ProtoLog;
import com.android.wm.shell.common.DisplayController;
@@ -531,12 +529,9 @@ public class PhonePipMenuController implements PipMenuController {
            // Do not grant focus if IME is visible, which can cause the focus being granted
            // back and forth in between the IME and PiP menu, and causes flicker.
            final boolean grantFocus = !mIsImeVisible && (menuState != MENU_STATE_NONE);
            try {
                WindowManagerGlobal.getWindowSession().grantEmbeddedWindowFocus(null /* window */,
                        mSystemWindows.getFocusGrantToken(mPipMenuView), grantFocus);
            } catch (RemoteException e) {
            if (!mSystemWindows.requestInputFocus(mPipMenuView, grantFocus)) {
                ProtoLog.e(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                        "%s: Unable to update focus as menu appears/disappears, %s", TAG, e);
                        "%s: Unable to update focus as menu appears/disappears", TAG);
            }
        }
    }
Loading