From 70190ee1386ee6efa6b8e70b286831e11684c864 Mon Sep 17 00:00:00 2001 From: Vishnu Nair Date: Thu, 10 Feb 2022 10:00:50 -0800 Subject: [PATCH] PIP: pass grant focus token to focus requests Update remaining uses of grantEmbeddedWindowFocus to pass in a grantFocusToken instead of the input token. Test: steps in b/218436735 Fixes: 218436735 Change-Id: Idadbd584c06f75ea64dd18a6a002d14426de8998 --- core/java/android/view/SurfaceControlViewHost.java | 9 ++++++++- .../com/android/wm/shell/common/SystemWindows.java | 13 +++++++++++++ .../wm/shell/pip/phone/PhonePipMenuController.java | 7 ++----- .../wm/shell/pip/tv/TvPipMenuController.java | 1 + .../com/android/wm/shell/pip/tv/TvPipMenuView.java | 8 +++++++- 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/core/java/android/view/SurfaceControlViewHost.java b/core/java/android/view/SurfaceControlViewHost.java index 3fb0fe7ff0474..2edfda5d065c3 100644 --- a/core/java/android/view/SurfaceControlViewHost.java +++ b/core/java/android/view/SurfaceControlViewHost.java @@ -28,9 +28,9 @@ import android.os.Parcel; import android.os.Parcelable; import android.os.RemoteException; import android.util.Log; -import android.view.accessibility.IAccessibilityEmbeddedConnection; import android.view.InsetsState; import android.view.WindowManagerGlobal; +import android.view.accessibility.IAccessibilityEmbeddedConnection; import java.util.Objects; @@ -428,4 +428,11 @@ public class SurfaceControlViewHost { WindowManagerGlobal.getInstance().removeWindowlessRoot(mViewRoot); mReleased = true; } + + /** + * @hide + */ + public IBinder getFocusGrantToken() { + return mWm.getFocusGrantToken(); + } } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java index 1039e2ac4fd9d..51067a45381cd 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/SystemWindows.java @@ -191,6 +191,19 @@ public class SystemWindows { return null; } + /** + * Gets a token associated with the view that can be used to grant the view focus. + */ + public IBinder getFocusGrantToken(View view) { + 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 root.getFocusGrantToken(); + } + private class PerDisplay { final int mDisplayId; private final SparseArray mWwms = new SparseArray<>(); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java index 6ec8f5b924f8a..71cff025a7a87 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PhonePipMenuController.java @@ -28,7 +28,6 @@ import android.graphics.Rect; import android.graphics.RectF; import android.os.Debug; import android.os.Handler; -import android.os.IBinder; import android.os.RemoteException; import android.util.Log; import android.util.Size; @@ -126,7 +125,6 @@ public class PhonePipMenuController implements PipMenuController { private int mMenuState; private PipMenuView mPipMenuView; - private IBinder mPipMenuInputToken; private ActionListener mMediaActionListener = new ActionListener() { @Override @@ -206,7 +204,6 @@ public class PhonePipMenuController implements PipMenuController { mApplier = null; mSystemWindows.removeView(mPipMenuView); mPipMenuView = null; - mPipMenuInputToken = null; } /** @@ -392,7 +389,6 @@ public class PhonePipMenuController implements PipMenuController { if (mApplier == null) { mApplier = new SyncRtSurfaceTransactionApplier(mPipMenuView); - mPipMenuInputToken = mPipMenuView.getViewRootImpl().getInputToken(); } return mApplier != null; @@ -539,7 +535,8 @@ public class PhonePipMenuController implements PipMenuController { try { WindowManagerGlobal.getWindowSession().grantEmbeddedWindowFocus(null /* window */, - mPipMenuInputToken, menuState != MENU_STATE_NONE /* grantFocus */); + mSystemWindows.getFocusGrantToken(mPipMenuView), + menuState != MENU_STATE_NONE /* grantFocus */); } catch (RemoteException e) { Log.e(TAG, "Unable to update focus as menu appears/disappears", e); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuController.java index 32861b698daaf..f838a0bece814 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuController.java @@ -143,6 +143,7 @@ public class TvPipMenuController implements PipMenuController, TvPipMenuView.Lis mSystemWindows.addView(mPipMenuView, getPipMenuLayoutParams(MENU_WINDOW_TITLE, 0 /* width */, 0 /* height */), 0, SHELL_ROOT_LAYER_PIP); + mPipMenuView.setFocusGrantToken(mSystemWindows.getFocusGrantToken(mPipMenuView)); } @Override diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuView.java index 0141b6a1859e5..84eae9e0febbb 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuView.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/tv/TvPipMenuView.java @@ -28,6 +28,7 @@ import android.app.PendingIntent; import android.app.RemoteAction; import android.content.Context; import android.os.Handler; +import android.os.IBinder; import android.util.AttributeSet; import android.util.Log; import android.view.Gravity; @@ -69,6 +70,7 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener { private final ImageView mArrowRight; private final ImageView mArrowDown; private final ImageView mArrowLeft; + private IBinder mFocusGrantToken = null; public TvPipMenuView(@NonNull Context context) { this(context, null); @@ -108,6 +110,10 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener { mListener = listener; } + void setFocusGrantToken(IBinder token) { + mFocusGrantToken = token; + } + void show(boolean inMoveMode, int gravity) { if (DEBUG) Log.d(TAG, "show(), inMoveMode: " + inMoveMode); grantWindowFocus(true); @@ -162,7 +168,7 @@ public class TvPipMenuView extends FrameLayout implements View.OnClickListener { try { WindowManagerGlobal.getWindowSession().grantEmbeddedWindowFocus(null /* window */, - getViewRootImpl().getInputToken(), grantFocus); + mFocusGrantToken, grantFocus); } catch (Exception e) { Log.e(TAG, "Unable to update focus", e); }