From d48bec9beb2c45c230e87896657352df3e516390 Mon Sep 17 00:00:00 2001 From: Ben Lin Date: Fri, 2 Jul 2021 11:39:08 -0700 Subject: [PATCH] PiP: Update accessibility window as menu shows/hides. When calculcating accessibility regions w/ shell root, currently since shell root has no information on the child views' alpha, visibility, etc, it is always detected as active by the a11y controller. Update the accessibility region for PIP as menu shows and hides so that the controller can take this into consideration. Bug: 192524653 Test: Switch access to PIP when menu shows - able to navigate around menu items. Switch Access to PIP when menu is gone - able to select PIP itself. Change-Id: I7d5649ecbf98751a117c58ac8127584bc3196910 --- .../wm/shell/common/SystemWindows.java | 37 +++++++++++++++---- .../pip/phone/PhonePipMenuController.java | 9 +++++ 2 files changed, 38 insertions(+), 8 deletions(-) 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 ef113dc5e10ab..97c89d042be0d 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 @@ -133,6 +133,18 @@ public class SystemWindows { root.relayout((WindowManager.LayoutParams) params); } + /** + * Sets the accessibility window for the given {@param shellRootLayer}. + */ + public void setShellRootAccessibilityWindow(int displayId, + @WindowManager.ShellRootLayer int shellRootLayer, View view) { + PerDisplay pd = mPerDisplay.get(displayId); + if (pd == null) { + return; + } + pd.setShellRootAccessibilityWindow(shellRootLayer, view); + } + /** * Sets the touchable region of a view's window. This will be cropped to the window size. * @param view @@ -202,15 +214,9 @@ public class SystemWindows { attrs.flags |= FLAG_HARDWARE_ACCELERATED; viewRoot.setView(view, attrs); mViewRoots.put(view, viewRoot); - - try { - mWmService.setShellRootAccessibilityWindow(mDisplayId, shellRootLayer, - viewRoot.getWindowToken()); - } catch (RemoteException e) { - Slog.e(TAG, "Error setting accessibility window for " + mDisplayId + ":" - + shellRootLayer, e); - } + setShellRootAccessibilityWindow(shellRootLayer, view); } + SysUiWindowManager addRoot(@WindowManager.ShellRootLayer int shellRootLayer) { SysUiWindowManager wwm = mWwms.get(shellRootLayer); if (wwm != null) { @@ -240,6 +246,21 @@ public class SystemWindows { return wwm.mContainerWindow; } + void setShellRootAccessibilityWindow(@WindowManager.ShellRootLayer int shellRootLayer, + View view) { + SysUiWindowManager wwm = mWwms.get(shellRootLayer); + if (wwm == null) { + return; + } + try { + mWmService.setShellRootAccessibilityWindow(mDisplayId, shellRootLayer, + view != null ? mViewRoots.get(view).getWindowToken() : null); + } catch (RemoteException e) { + Slog.e(TAG, "Error setting accessibility window for " + mDisplayId + ":" + + shellRootLayer, e); + } + } + void updateConfiguration(Configuration configuration) { for (int i = 0; i < mWwms.size(); ++i) { mWwms.valueAt(i).updateConfiguration(configuration); 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 bc8e1e72b830c..a646b07c49dc9 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 @@ -524,6 +524,15 @@ public class PhonePipMenuController implements PipMenuController { mListeners.forEach(l -> l.onPipMenuStateChangeFinish(menuState)); } mMenuState = menuState; + switch (mMenuState) { + case MENU_STATE_NONE: + mSystemWindows.setShellRootAccessibilityWindow(0, SHELL_ROOT_LAYER_PIP, null); + break; + default: + mSystemWindows.setShellRootAccessibilityWindow(0, SHELL_ROOT_LAYER_PIP, + mPipMenuView); + break; + } } /**