Skip to content

Commit 73ab6a4

Browse files
author
Dianne Hackborn
committed
Fix issue #5755172: Soft menu key disappears when menu is open
We need to work more like before in determining whether the menu key is needed -- in some cases look back in the window list to determine this if we don't know the value from the current window. This requires adding a new private flag indicating whether the compat menu state is known for a window, which is set by PhoneWindow as part of its existing process of computing the flag for its own windows. Now we can have a new API on WindowState to determine the value of this flag for a window, which if needed walks back in the window list to find a window the value is known for (or stops at what the policy has determined is the top full-screen window, so we stop like we used to at things like the lock screen or the bottom of an application). Change-Id: I829de6d629b5af8bcb422cb85249ee4041c7205e
1 parent f0bbc49 commit 73ab6a4

File tree

7 files changed

+52
-2
lines changed

7 files changed

+52
-2
lines changed

core/java/android/view/Window.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,9 @@ public void clearFlags(int flags) {
743743
public void setFlags(int flags, int mask) {
744744
final WindowManager.LayoutParams attrs = getAttributes();
745745
attrs.flags = (attrs.flags&~mask) | (flags&mask);
746+
if ((mask&WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0) {
747+
attrs.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY;
748+
}
746749
mForcedWindowFlags |= mask;
747750
if (mCallback != null) {
748751
mCallback.onWindowAttributesChanged(attrs);

core/java/android/view/WindowManager.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,16 @@ public static class LayoutParams extends ViewGroup.LayoutParams
823823
*/
824824
public static final int PRIVATE_FLAG_WANTS_OFFSET_NOTIFICATIONS = 0x00000004;
825825

826+
/**
827+
* This is set for a window that has explicitly specified its
828+
* FLAG_NEEDS_MENU_KEY, so we know the value on this window is the
829+
* appropriate one to use. If this is not set, we should look at
830+
* windows behind it to determine the appropriate value.
831+
*
832+
* @hide
833+
*/
834+
public static final int PRIVATE_FLAG_SET_NEEDS_MENU_KEY = 0x00000008;
835+
826836
/**
827837
* Control flags that are private to the platform.
828838
* @hide

core/java/android/view/WindowManagerPolicy.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,14 @@ public void computeFrameLw(Rect parentFrame, Rect displayFrame,
237237
*/
238238
public WindowManager.LayoutParams getAttrs();
239239

240+
/**
241+
* Return whether this window needs the menu key shown. Must be called
242+
* with window lock held, because it may need to traverse down through
243+
* window list to determine the result.
244+
* @param bottom The bottom-most window to consider when determining this.
245+
*/
246+
public boolean getNeedsMenuLw(WindowState bottom);
247+
240248
/**
241249
* Retrieve the current system UI visibility flags associated with
242250
* this window.

policy/src/com/android/internal/policy/impl/KeyguardViewManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public synchronized void show() {
138138
lp.privateFlags |=
139139
WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
140140
}
141+
lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY;
141142
lp.setTitle("Keyguard");
142143
mWindowLayoutParams = lp;
143144

policy/src/com/android/internal/policy/impl/PhoneWindow.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2582,6 +2582,8 @@ protected ViewGroup generateLayout(DecorView decor) {
25822582

25832583
if (targetPreHoneycomb || (targetPreIcs && targetHcNeedsOptions && noActionBar)) {
25842584
addFlags(WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY);
2585+
} else {
2586+
clearFlags(WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY);
25852587
}
25862588

25872589
if (mAlwaysReadCloseOnTouchAttr || getContext().getApplicationInfo().targetSdkVersion

policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3707,8 +3707,7 @@ private int updateSystemUiVisibilityLw() {
37073707
& ~mResettingSystemUiFlags
37083708
& ~mForceClearedSystemUiFlags;
37093709
int diff = visibility ^ mLastSystemUiFlags;
3710-
final boolean needsMenu = (mFocusedWindow.getAttrs().flags
3711-
& WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0;
3710+
final boolean needsMenu = mFocusedWindow.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
37123711
if (diff == 0 && mLastFocusNeedsMenu == needsMenu
37133712
&& mFocusedApp == mFocusedWindow.getAppToken()) {
37143713
return 0;

services/java/com/android/server/wm/WindowState.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,33 @@ public WindowManager.LayoutParams getAttrs() {
562562
return mAttrs;
563563
}
564564

565+
public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) {
566+
int index = -1;
567+
WindowState ws = this;
568+
while (true) {
569+
if ((ws.mAttrs.privateFlags
570+
& WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY) != 0) {
571+
return (ws.mAttrs.flags & WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0;
572+
}
573+
// If we reached the bottom of the range of windows we are considering,
574+
// assume no menu is needed.
575+
if (ws == bottom) {
576+
return false;
577+
}
578+
// The current window hasn't specified whether menu key is needed;
579+
// look behind it.
580+
// First, we may need to determine the starting position.
581+
if (index < 0) {
582+
index = mService.mWindows.indexOf(ws);
583+
}
584+
index--;
585+
if (index < 0) {
586+
return false;
587+
}
588+
ws = mService.mWindows.get(index);
589+
}
590+
}
591+
565592
public int getSystemUiVisibility() {
566593
return mSystemUiVisibility;
567594
}

0 commit comments

Comments
 (0)