From 4eff8d37da8f9fa24c00dc4b1fa33300b2b510c8 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Thu, 10 Nov 2011 19:38:40 -0800 Subject: [PATCH] Fix issue #5522658: Menu button shown on lock screen if app underneath requests it Drive the menu button off of the currently focused window. That is, after all, the one that is going to receive the menu key event. Change-Id: I61cac1e274602e5ea53402ab15bd63a9cd89e9cd --- .../policy/impl/PhoneWindowManager.java | 51 +++++-------------- 1 file changed, 12 insertions(+), 39 deletions(-) diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index 1a068a3dab360..5861728a1a003 100755 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -360,6 +360,9 @@ public class PhoneWindowManager implements WindowManagerPolicy { int mResettingSystemUiFlags = 0; // Bits that we are currently always keeping cleared. int mForceClearedSystemUiFlags = 0; + // What we last reported to system UI about whether the compatibility + // menu needs to be displayed. + boolean mLastFocusNeedsMenu = false; FakeWindow mHideNavFakeWindow = null; @@ -370,8 +373,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { static final Rect mTmpNavigationFrame = new Rect(); WindowState mTopFullscreenOpaqueWindowState; - WindowState mTopAppWindowState; - WindowState mLastTopAppWindowState; boolean mTopIsFullscreen; boolean mForceStatusBar; boolean mHideLockScreen; @@ -2250,7 +2251,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { /** {@inheritDoc} */ public void beginAnimationLw(int displayWidth, int displayHeight) { mTopFullscreenOpaqueWindowState = null; - mTopAppWindowState = null; mForceStatusBar = false; mHideLockScreen = false; @@ -2288,12 +2288,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } } - if (mTopAppWindowState == null && win.isVisibleOrBehindKeyguardLw()) { - if (attrs.type >= FIRST_APPLICATION_WINDOW - && attrs.type <= LAST_APPLICATION_WINDOW) { - mTopAppWindowState = win; - } - } } /** {@inheritDoc} */ @@ -2349,35 +2343,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { mTopIsFullscreen = topIsFullscreen; - if (mTopAppWindowState != null && mTopAppWindowState != mLastTopAppWindowState) { - mLastTopAppWindowState = mTopAppWindowState; - - final boolean topNeedsMenu = (mTopAppWindowState.getAttrs().flags - & WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0; - - mHandler.post(new Runnable() { - public void run() { - if (mStatusBarService == null) { - // This is the one that can not go away, but it doesn't come up - // before the window manager does, so don't fail if it doesn't - // exist. This works as long as no fullscreen windows come up - // before the status bar service does. - mStatusBarService = IStatusBarService.Stub.asInterface( - ServiceManager.getService("statusbar")); - } - final IStatusBarService sbs = mStatusBarService; - if (mStatusBarService != null) { - try { - sbs.topAppWindowChanged(topNeedsMenu); - } catch (RemoteException e) { - // This should be impossible because we're in the same process. - mStatusBarService = null; - } - } - } - }); - } - // Hide the key guard if a visible window explicitly specifies that it wants to be displayed // when the screen is locked if (mKeyguard != null) { @@ -3710,10 +3675,13 @@ public class PhoneWindowManager implements WindowManagerPolicy { & ~mResettingSystemUiFlags & ~mForceClearedSystemUiFlags; int diff = visibility ^ mLastSystemUiFlags; - if (diff == 0) { + final boolean needsMenu = (mFocusedWindow.getAttrs().flags + & WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0; + if (diff == 0 && mLastFocusNeedsMenu == needsMenu) { return 0; } mLastSystemUiFlags = visibility; + mLastFocusNeedsMenu = needsMenu; mHandler.post(new Runnable() { public void run() { if (mStatusBarService == null) { @@ -3723,6 +3691,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { if (mStatusBarService != null) { try { mStatusBarService.setSystemUiVisibility(visibility); + mStatusBarService.topAppWindowChanged(needsMenu); } catch (RemoteException e) { // not much to be done mStatusBarService = null; @@ -3755,6 +3724,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { pw.print(" mForceClearedSystemUiFlags=0x"); pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); } + if (mLastFocusNeedsMenu) { + pw.print(prefix); pw.print("mLastFocusNeedsMenu="); + pw.println(mLastFocusNeedsMenu); + } pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); pw.print(" mDockMode="); pw.print(mDockMode); pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);