From 9a230e01a1237749a8a19a5de8d46531b0c8ca6a Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Thu, 6 Oct 2011 11:51:27 -0700 Subject: Fix issue #5371530: SYSTEMUI_FLAG_HIDE_NAVIGATION reasserts itself immediately This cleans up how ui flags are managed between the client and window manager. It still reports the global UI mode state to the callback, but we now only clear certain flags when the system goes out of a state (currently this just means the hide nav bar mode), and don't corrupt other flags in the application when the global state changes. Also introduces a sequence number between the app and window manager, to avoid using bad old data coming from the app during these transitions. Change-Id: I40bbd12d9b7b69fc0ff1c7dc0cb58a933d4dfb23 --- core/java/android/view/ViewRootImpl.java | 65 ++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 15 deletions(-) (limited to 'core/java/android/view/ViewRootImpl.java') diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index e7c91f9..bc60b44 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -165,6 +165,8 @@ public final class ViewRootImpl extends Handler implements ViewParent, final int mTargetSdkVersion; + int mSeq; + View mView; View mFocusedView; View mRealFocusedView; // this is not set to null in touch mode @@ -308,6 +310,13 @@ public final class ViewRootImpl extends Handler implements ViewParent, return sWindowSession; } } + + static final class SystemUiVisibilityInfo { + int seq; + int globalVisibility; + int localValue; + int localChanges; + } public ViewRootImpl(Context context) { super(); @@ -465,7 +474,7 @@ public final class ViewRootImpl extends Handler implements ViewParent, } try { mOrigWindowType = mWindowAttributes.type; - res = sWindowSession.add(mWindow, mWindowAttributes, + res = sWindowSession.add(mWindow, mSeq, mWindowAttributes, getHostVisibility(), mAttachInfo.mContentInsets, mInputChannel); } catch (RemoteException e) { @@ -1045,16 +1054,21 @@ public final class ViewRootImpl extends Handler implements ViewParent, attachInfo.mRecomputeGlobalAttributes = false; boolean oldScreenOn = attachInfo.mKeepScreenOn; int oldVis = attachInfo.mSystemUiVisibility; + boolean oldHasSystemUiListeners = attachInfo.mHasSystemUiListeners; attachInfo.mKeepScreenOn = false; attachInfo.mSystemUiVisibility = 0; attachInfo.mHasSystemUiListeners = false; host.dispatchCollectViewAttributes(0); if (attachInfo.mKeepScreenOn != oldScreenOn || attachInfo.mSystemUiVisibility != oldVis - || attachInfo.mHasSystemUiListeners) { + || attachInfo.mHasSystemUiListeners != oldHasSystemUiListeners) { params = lp; } } + if (attachInfo.mForceReportNewAttributes) { + attachInfo.mForceReportNewAttributes = false; + params = lp; + } if (mFirst || attachInfo.mViewVisibilityChanged) { attachInfo.mViewVisibilityChanged = false; @@ -1136,9 +1150,7 @@ public final class ViewRootImpl extends Handler implements ViewParent, params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; } params.subtreeSystemUiVisibility = attachInfo.mSystemUiVisibility; - params.hasSystemUiListeners = attachInfo.mHasSystemUiListeners - || params.subtreeSystemUiVisibility != 0 - || params.systemUiVisibility != 0; + params.hasSystemUiListeners = attachInfo.mHasSystemUiListeners; } if (DEBUG_LAYOUT) { Log.i(TAG, "host=w:" + host.getMeasuredWidth() + ", h:" + @@ -2545,7 +2557,7 @@ public final class ViewRootImpl extends Handler implements ViewParent, handleDragEvent(event); } break; case DISPATCH_SYSTEM_UI_VISIBILITY: { - handleDispatchSystemUiVisibilityChanged(msg.arg1); + handleDispatchSystemUiVisibilityChanged((SystemUiVisibilityInfo)msg.obj); } break; case UPDATE_CONFIGURATION: { Configuration config = (Configuration)msg.obj; @@ -3429,12 +3441,27 @@ public final class ViewRootImpl extends Handler implements ViewParent, event.recycle(); } - public void handleDispatchSystemUiVisibilityChanged(int visibility) { + public void handleDispatchSystemUiVisibilityChanged(SystemUiVisibilityInfo args) { + if (mSeq != args.seq) { + // The sequence has changed, so we need to update our value and make + // sure to do a traversal afterward so the window manager is given our + // most recent data. + mSeq = args.seq; + mAttachInfo.mForceReportNewAttributes = true; + scheduleTraversals(); + } if (mView == null) return; - if (mAttachInfo != null) { - mAttachInfo.mSystemUiVisibility = visibility; + if (args.localChanges != 0) { + if (mAttachInfo != null) { + mAttachInfo.mSystemUiVisibility = + (mAttachInfo.mSystemUiVisibility&~args.localChanges) + | (args.localValue&args.localChanges); + } + mView.updateLocalSystemUiVisibility(args.localValue, args.localChanges); + mAttachInfo.mRecomputeGlobalAttributes = true; + scheduleTraversals(); } - mView.dispatchSystemUiVisibilityChanged(visibility); + mView.dispatchSystemUiVisibilityChanged(args.globalVisibility); } public void getLastTouchPoint(Point outLocation) { @@ -3493,7 +3520,7 @@ public final class ViewRootImpl extends Handler implements ViewParent, } } int relayoutResult = sWindowSession.relayout( - mWindow, params, + mWindow, mSeq, params, (int) (mView.getMeasuredWidth() * appScale + 0.5f), (int) (mView.getMeasuredHeight() * appScale + 0.5f), viewVisibility, insetsPending, mWinFrame, @@ -3796,8 +3823,14 @@ public final class ViewRootImpl extends Handler implements ViewParent, sendMessage(msg); } - public void dispatchSystemUiVisibilityChanged(int visibility) { - sendMessage(obtainMessage(DISPATCH_SYSTEM_UI_VISIBILITY, visibility, 0)); + public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility, + int localValue, int localChanges) { + SystemUiVisibilityInfo args = new SystemUiVisibilityInfo(); + args.seq = seq; + args.globalVisibility = globalVisibility; + args.localValue = localValue; + args.localChanges = localChanges; + sendMessage(obtainMessage(DISPATCH_SYSTEM_UI_VISIBILITY, args)); } /** @@ -4052,10 +4085,12 @@ public final class ViewRootImpl extends Handler implements ViewParent, } } - public void dispatchSystemUiVisibilityChanged(int visibility) { + public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility, + int localValue, int localChanges) { final ViewRootImpl viewAncestor = mViewAncestor.get(); if (viewAncestor != null) { - viewAncestor.dispatchSystemUiVisibilityChanged(visibility); + viewAncestor.dispatchSystemUiVisibilityChanged(seq, globalVisibility, + localValue, localChanges); } } } -- cgit v1.1