From 04db1762fb75a3938dda34537626c41c8e97d9c5 Mon Sep 17 00:00:00 2001 From: John Spurlock Date: Mon, 13 May 2013 12:46:41 -0400 Subject: Window manager cleanup. Specifically: - Fix policy vs wm lock management issues. - Share runnable to avoid allocation. - Remove unused noop runnable. - Make sure to handle status bar = null case. - Fix javadoc typo. Bug: 8890313 Change-Id: I242eaef8e946025f6885d6dba3225722fb0ca7ce --- .../internal/policy/impl/PhoneWindowManager.java | 55 ++++++++++------------ 1 file changed, 25 insertions(+), 30 deletions(-) (limited to 'policy') diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index 08fb48f..1fab35f 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -114,7 +114,7 @@ import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; * WindowManagerPolicy implementation for the Android phone UI. This * introduces a new method suffix, Lp, for an internal lock of the * PhoneWindowManager. This is used to protect some internal state, and - * can be acquired with either thw Lw and Li lock held, so has the restrictions + * can be acquired with either the Lw and Li lock held, so has the restrictions * of both of those when held. */ public class PhoneWindowManager implements WindowManagerPolicy { @@ -921,18 +921,20 @@ public class PhoneWindowManager implements WindowManagerPolicy { new SystemGestures.Callbacks() { @Override public void onSwipeFromTop() { - showHideybars(mStatusBar); + if (mStatusBar != null) { + requestHideybars(mStatusBar); + } } @Override public void onSwipeFromBottom() { - if (mNavigationBarOnBottom) { - showHideybars(mNavigationBar); + if (mNavigationBar != null && mNavigationBarOnBottom) { + requestHideybars(mNavigationBar); } } @Override public void onSwipeFromRight() { - if (!mNavigationBarOnBottom) { - showHideybars(mNavigationBar); + if (mNavigationBar != null && !mNavigationBarOnBottom) { + requestHideybars(mNavigationBar); } } @Override @@ -2436,13 +2438,15 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } - /** - * A delayed callback use to determine when it is okay to re-allow applications - * to use certain system UI flags. This is used to prevent applications from - * spamming system UI changes that prevent the navigation bar from being shown. - */ - final Runnable mAllowSystemUiDelay = new Runnable() { - @Override public void run() { + private final Runnable mClearHideNavigationFlag = new Runnable() { + @Override + public void run() { + synchronized (mWindowManagerFuncs.getWindowManagerLock()) { + // Clear flags. + mForceClearedSystemUiFlags &= + ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; + } + mWindowManagerFuncs.reevaluateStatusBarVisibility(); } }; @@ -2466,7 +2470,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { // When the user taps down, we re-show the nav bar. boolean changed = false; - synchronized (mLock) { + synchronized (mWindowManagerFuncs.getWindowManagerLock()) { // Any user activity always causes us to show the // navigation controls, if they had been hidden. // We also clear the low profile and only content @@ -2488,16 +2492,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { if (mForceClearedSystemUiFlags != newVal) { mForceClearedSystemUiFlags = newVal; changed = true; - mHandler.postDelayed(new Runnable() { - @Override public void run() { - synchronized (mLock) { - // Clear flags. - mForceClearedSystemUiFlags &= - ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; - } - mWindowManagerFuncs.reevaluateStatusBarVisibility(); - } - }, 1000); + mHandler.postDelayed(mClearHideNavigationFlag, 1000); } } if (changed) { @@ -2521,7 +2516,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { @Override public int adjustSystemUiVisibilityLw(int visibility) { - if (mStatusHideybar == HIDEYBAR_SHOWING && + if (mStatusBar != null && mStatusHideybar == HIDEYBAR_SHOWING && 0 == (visibility & View.STATUS_BAR_OVERLAY)) { mStatusHideybar = HIDEYBAR_HIDING; mStatusBar.hideLw(true); @@ -4134,7 +4129,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { // force a re-application of focused window sysui visibility. // the window may never have been shown for this user // e.g. the keyguard when going through the new-user setup flow - synchronized(mLock) { + synchronized (mWindowManagerFuncs.getWindowManagerLock()) { mLastSystemUiFlags = 0; updateSystemUiVisibilityLw(); } @@ -4142,8 +4137,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { } }; - private void showHideybars(WindowState swipeTarget) { - synchronized(mLock) { + private void requestHideybars(WindowState swipeTarget) { + synchronized (mWindowManagerFuncs.getWindowManagerLock()) { boolean sb = checkShowHideybar("status", mStatusHideybar, mStatusBar); boolean nb = checkShowHideybar("navigation", mNavigationHideybar, mNavigationBar); if (sb || nb) { @@ -5056,9 +5051,9 @@ public class PhoneWindowManager implements WindowManagerPolicy { || (hideStatusBarSysui && overlayAllowed) || statusBarHasFocus; - if (!statusHideyAllowed) { + if (mStatusBar == null || !statusHideyAllowed) { mStatusHideybar = HIDEYBAR_NONE; - if (hideStatusBarSysui) { + if (mStatusBar != null && hideStatusBarSysui) { // clear the clearable flags instead int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; if (newVal != mResettingSystemUiFlags) { -- cgit v1.1