Skip to content

Commit 85b9edf

Browse files
Dianne HackbornAndroid (Google) Code Review
authored andcommitted
Merge "Fix issue #5371530: SYSTEMUI_FLAG_HIDE_NAVIGATION reasserts itself immediately"
2 parents 7853c57 + 9a230e0 commit 85b9edf

File tree

15 files changed

+160
-49
lines changed

15 files changed

+160
-49
lines changed

core/java/android/service/wallpaper/WallpaperService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ void updateSurface(boolean forceRelayout, boolean forceReport, boolean redrawNee
565565
mLayout.windowAnimations =
566566
com.android.internal.R.style.Animation_Wallpaper;
567567
mInputChannel = new InputChannel();
568-
if (mSession.add(mWindow, mLayout, View.VISIBLE, mContentInsets,
568+
if (mSession.add(mWindow, mWindow.mSeq, mLayout, View.VISIBLE, mContentInsets,
569569
mInputChannel) < 0) {
570570
Log.w(TAG, "Failed to add window while updating wallpaper surface.");
571571
return;
@@ -580,7 +580,7 @@ void updateSurface(boolean forceRelayout, boolean forceReport, boolean redrawNee
580580
mDrawingAllowed = true;
581581

582582
final int relayoutResult = mSession.relayout(
583-
mWindow, mLayout, mWidth, mHeight,
583+
mWindow, mWindow.mSeq, mLayout, mWidth, mHeight,
584584
View.VISIBLE, false, mWinFrame, mContentInsets,
585585
mVisibleInsets, mConfiguration, mSurfaceHolder.mSurface);
586586

core/java/android/view/IWindow.aidl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,6 @@ oneway interface IWindow {
7474
/**
7575
* System chrome visibility changes
7676
*/
77-
void dispatchSystemUiVisibilityChanged(int visibility);
77+
void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility,
78+
int localValue, int localChanges);
7879
}

core/java/android/view/IWindowSession.aidl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ import android.view.Surface;
3434
* {@hide}
3535
*/
3636
interface IWindowSession {
37-
int add(IWindow window, in WindowManager.LayoutParams attrs,
37+
int add(IWindow window, int seq, in WindowManager.LayoutParams attrs,
3838
in int viewVisibility, out Rect outContentInsets,
3939
out InputChannel outInputChannel);
40-
int addWithoutInputChannel(IWindow window, in WindowManager.LayoutParams attrs,
40+
int addWithoutInputChannel(IWindow window, int seq, in WindowManager.LayoutParams attrs,
4141
in int viewVisibility, out Rect outContentInsets);
4242
void remove(IWindow window);
4343

@@ -49,6 +49,7 @@ interface IWindowSession {
4949
* to draw the window's contents.
5050
*
5151
* @param window The window being modified.
52+
* @param seq Ordering sequence number.
5253
* @param attrs If non-null, new attributes to apply to the window.
5354
* @param requestedWidth The width the window wants to be.
5455
* @param requestedHeight The height the window wants to be.
@@ -77,7 +78,7 @@ interface IWindowSession {
7778
* @return int Result flags: {@link WindowManagerImpl#RELAYOUT_SHOW_FOCUS},
7879
* {@link WindowManagerImpl#RELAYOUT_FIRST_TIME}.
7980
*/
80-
int relayout(IWindow window, in WindowManager.LayoutParams attrs,
81+
int relayout(IWindow window, int seq, in WindowManager.LayoutParams attrs,
8182
int requestedWidth, int requestedHeight, int viewVisibility,
8283
boolean insetsPending, out Rect outFrame, out Rect outContentInsets,
8384
out Rect outVisibleInsets, out Configuration outConfig,

core/java/android/view/SurfaceView.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ protected void hideSurface() {
266266
try {
267267
DisplayMetrics metrics = getResources().getDisplayMetrics();
268268
mLayout.x = metrics.widthPixels * 3;
269-
mSession.relayout(mWindow, mLayout, mWidth, mHeight, VISIBLE, false,
269+
mSession.relayout(mWindow, mWindow.mSeq, mLayout, mWidth, mHeight, VISIBLE, false,
270270
mWinFrame, mContentInsets, mVisibleInsets, mConfiguration, mSurface);
271271
} catch (RemoteException e) {
272272
// Ignore
@@ -492,7 +492,7 @@ private void updateWindow(boolean force, boolean redrawNeeded) {
492492
mWindow = new MyWindow(this);
493493
mLayout.type = mWindowType;
494494
mLayout.gravity = Gravity.LEFT|Gravity.TOP;
495-
mSession.addWithoutInputChannel(mWindow, mLayout,
495+
mSession.addWithoutInputChannel(mWindow, mWindow.mSeq, mLayout,
496496
mVisible ? VISIBLE : GONE, mContentInsets);
497497
}
498498

@@ -513,7 +513,7 @@ private void updateWindow(boolean force, boolean redrawNeeded) {
513513
mDrawingStopped = !visible;
514514

515515
final int relayoutResult = mSession.relayout(
516-
mWindow, mLayout, mWidth, mHeight,
516+
mWindow, mWindow.mSeq, mLayout, mWidth, mHeight,
517517
visible ? VISIBLE : GONE, false, mWinFrame, mContentInsets,
518518
mVisibleInsets, mConfiguration, mSurface);
519519
if ((relayoutResult&WindowManagerImpl.RELAYOUT_FIRST_TIME) != 0) {

core/java/android/view/View.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,15 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
19241924
*/
19251925
public static final int PUBLIC_STATUS_BAR_VISIBILITY_MASK = 0x0000FFFF;
19261926

1927+
/**
1928+
* These are the system UI flags that can be cleared by events outside
1929+
* of an application. Currently this is just the ability to tap on the
1930+
* screen while hiding the navigation bar to have it return.
1931+
* @hide
1932+
*/
1933+
public static final int SYSTEM_UI_CLEARABLE_FLAGS =
1934+
SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_HIDE_NAVIGATION;
1935+
19271936
/**
19281937
* Find views that render the specified text.
19291938
*
@@ -13019,6 +13028,8 @@ public void setOnSystemUiVisibilityChangeListener(OnSystemUiVisibilityChangeList
1301913028
}
1302013029

1302113030
/**
13031+
* Dispatch callbacks to {@link #setOnSystemUiVisibilityChangeListener} down
13032+
* the view hierarchy.
1302213033
*/
1302313034
public void dispatchSystemUiVisibilityChanged(int visibility) {
1302413035
if (mOnSystemUiVisibilityChangeListener != null) {
@@ -13027,6 +13038,13 @@ public void dispatchSystemUiVisibilityChanged(int visibility) {
1302713038
}
1302813039
}
1302913040

13041+
void updateLocalSystemUiVisibility(int localValue, int localChanges) {
13042+
int val = (mSystemUiVisibility&~localChanges) | (localValue&localChanges);
13043+
if (val != mSystemUiVisibility) {
13044+
setSystemUiVisibility(val);
13045+
}
13046+
}
13047+
1303013048
/**
1303113049
* Creates an image that the system displays during the drag and drop
1303213050
* operation. This is called a &quot;drag shadow&quot;. The default implementation
@@ -14100,7 +14118,8 @@ public interface OnCreateContextMenuListener {
1410014118

1410114119
/**
1410214120
* Interface definition for a callback to be invoked when the status bar changes
14103-
* visibility.
14121+
* visibility. This reports <strong>global</strong> changes to the system UI
14122+
* state, not just what the application is requesting.
1410414123
*
1410514124
* @see View#setOnSystemUiVisibilityChangeListener(android.view.View.OnSystemUiVisibilityChangeListener)
1410614125
*/
@@ -14110,7 +14129,9 @@ public interface OnSystemUiVisibilityChangeListener {
1411014129
* {@link View#setSystemUiVisibility(int)}.
1411114130
*
1411214131
* @param visibility Bitwise-or of flags {@link #SYSTEM_UI_FLAG_LOW_PROFILE} or
14113-
* {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}.
14132+
* {@link #SYSTEM_UI_FLAG_HIDE_NAVIGATION}. This tells you the
14133+
* <strong>global</strong> state of the UI visibility flags, not what your
14134+
* app is currently applying.
1411414135
*/
1411514136
public void onSystemUiVisibilityChange(int visibility);
1411614137
}
@@ -14367,6 +14388,11 @@ public void setPooled(boolean isPooled) {
1436714388
*/
1436814389
boolean mRecomputeGlobalAttributes;
1436914390

14391+
/**
14392+
* Always report new attributes at next traversal.
14393+
*/
14394+
boolean mForceReportNewAttributes;
14395+
1437014396
/**
1437114397
* Set during a traveral if any views want to keep the screen on.
1437214398
*/

core/java/android/view/ViewGroup.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,18 @@ public void dispatchSystemUiVisibilityChanged(int visible) {
12001200
}
12011201
}
12021202

1203+
@Override
1204+
void updateLocalSystemUiVisibility(int localValue, int localChanges) {
1205+
super.updateLocalSystemUiVisibility(localValue, localChanges);
1206+
1207+
final int count = mChildrenCount;
1208+
final View[] children = mChildren;
1209+
for (int i=0; i <count; i++) {
1210+
final View child = children[i];
1211+
child.updateLocalSystemUiVisibility(localValue, localChanges);
1212+
}
1213+
}
1214+
12031215
/**
12041216
* {@inheritDoc}
12051217
*/

core/java/android/view/ViewRootImpl.java

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ public final class ViewRootImpl extends Handler implements ViewParent,
165165

166166
final int mTargetSdkVersion;
167167

168+
int mSeq;
169+
168170
View mView;
169171
View mFocusedView;
170172
View mRealFocusedView; // this is not set to null in touch mode
@@ -308,6 +310,13 @@ public static IWindowSession getWindowSession(Looper mainLooper) {
308310
return sWindowSession;
309311
}
310312
}
313+
314+
static final class SystemUiVisibilityInfo {
315+
int seq;
316+
int globalVisibility;
317+
int localValue;
318+
int localChanges;
319+
}
311320

312321
public ViewRootImpl(Context context) {
313322
super();
@@ -465,7 +474,7 @@ public void setView(View view, WindowManager.LayoutParams attrs, View panelParen
465474
}
466475
try {
467476
mOrigWindowType = mWindowAttributes.type;
468-
res = sWindowSession.add(mWindow, mWindowAttributes,
477+
res = sWindowSession.add(mWindow, mSeq, mWindowAttributes,
469478
getHostVisibility(), mAttachInfo.mContentInsets,
470479
mInputChannel);
471480
} catch (RemoteException e) {
@@ -1044,16 +1053,21 @@ private void performTraversals() {
10441053
attachInfo.mRecomputeGlobalAttributes = false;
10451054
boolean oldScreenOn = attachInfo.mKeepScreenOn;
10461055
int oldVis = attachInfo.mSystemUiVisibility;
1056+
boolean oldHasSystemUiListeners = attachInfo.mHasSystemUiListeners;
10471057
attachInfo.mKeepScreenOn = false;
10481058
attachInfo.mSystemUiVisibility = 0;
10491059
attachInfo.mHasSystemUiListeners = false;
10501060
host.dispatchCollectViewAttributes(0);
10511061
if (attachInfo.mKeepScreenOn != oldScreenOn
10521062
|| attachInfo.mSystemUiVisibility != oldVis
1053-
|| attachInfo.mHasSystemUiListeners) {
1063+
|| attachInfo.mHasSystemUiListeners != oldHasSystemUiListeners) {
10541064
params = lp;
10551065
}
10561066
}
1067+
if (attachInfo.mForceReportNewAttributes) {
1068+
attachInfo.mForceReportNewAttributes = false;
1069+
params = lp;
1070+
}
10571071

10581072
if (mFirst || attachInfo.mViewVisibilityChanged) {
10591073
attachInfo.mViewVisibilityChanged = false;
@@ -1134,9 +1148,7 @@ private void performTraversals() {
11341148
params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
11351149
}
11361150
params.subtreeSystemUiVisibility = attachInfo.mSystemUiVisibility;
1137-
params.hasSystemUiListeners = attachInfo.mHasSystemUiListeners
1138-
|| params.subtreeSystemUiVisibility != 0
1139-
|| params.systemUiVisibility != 0;
1151+
params.hasSystemUiListeners = attachInfo.mHasSystemUiListeners;
11401152
}
11411153
if (DEBUG_LAYOUT) {
11421154
Log.i(TAG, "host=w:" + host.getMeasuredWidth() + ", h:" +
@@ -2545,7 +2557,7 @@ public void handleMessage(Message msg) {
25452557
handleDragEvent(event);
25462558
} break;
25472559
case DISPATCH_SYSTEM_UI_VISIBILITY: {
2548-
handleDispatchSystemUiVisibilityChanged(msg.arg1);
2560+
handleDispatchSystemUiVisibilityChanged((SystemUiVisibilityInfo)msg.obj);
25492561
} break;
25502562
case UPDATE_CONFIGURATION: {
25512563
Configuration config = (Configuration)msg.obj;
@@ -3429,12 +3441,27 @@ private void handleDragEvent(DragEvent event) {
34293441
event.recycle();
34303442
}
34313443

3432-
public void handleDispatchSystemUiVisibilityChanged(int visibility) {
3444+
public void handleDispatchSystemUiVisibilityChanged(SystemUiVisibilityInfo args) {
3445+
if (mSeq != args.seq) {
3446+
// The sequence has changed, so we need to update our value and make
3447+
// sure to do a traversal afterward so the window manager is given our
3448+
// most recent data.
3449+
mSeq = args.seq;
3450+
mAttachInfo.mForceReportNewAttributes = true;
3451+
scheduleTraversals();
3452+
}
34333453
if (mView == null) return;
3434-
if (mAttachInfo != null) {
3435-
mAttachInfo.mSystemUiVisibility = visibility;
3454+
if (args.localChanges != 0) {
3455+
if (mAttachInfo != null) {
3456+
mAttachInfo.mSystemUiVisibility =
3457+
(mAttachInfo.mSystemUiVisibility&~args.localChanges)
3458+
| (args.localValue&args.localChanges);
3459+
}
3460+
mView.updateLocalSystemUiVisibility(args.localValue, args.localChanges);
3461+
mAttachInfo.mRecomputeGlobalAttributes = true;
3462+
scheduleTraversals();
34363463
}
3437-
mView.dispatchSystemUiVisibilityChanged(visibility);
3464+
mView.dispatchSystemUiVisibilityChanged(args.globalVisibility);
34383465
}
34393466

34403467
public void getLastTouchPoint(Point outLocation) {
@@ -3493,7 +3520,7 @@ private int relayoutWindow(WindowManager.LayoutParams params, int viewVisibility
34933520
}
34943521
}
34953522
int relayoutResult = sWindowSession.relayout(
3496-
mWindow, params,
3523+
mWindow, mSeq, params,
34973524
(int) (mView.getMeasuredWidth() * appScale + 0.5f),
34983525
(int) (mView.getMeasuredHeight() * appScale + 0.5f),
34993526
viewVisibility, insetsPending, mWinFrame,
@@ -3796,8 +3823,14 @@ public void dispatchDragEvent(DragEvent event) {
37963823
sendMessage(msg);
37973824
}
37983825

3799-
public void dispatchSystemUiVisibilityChanged(int visibility) {
3800-
sendMessage(obtainMessage(DISPATCH_SYSTEM_UI_VISIBILITY, visibility, 0));
3826+
public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility,
3827+
int localValue, int localChanges) {
3828+
SystemUiVisibilityInfo args = new SystemUiVisibilityInfo();
3829+
args.seq = seq;
3830+
args.globalVisibility = globalVisibility;
3831+
args.localValue = localValue;
3832+
args.localChanges = localChanges;
3833+
sendMessage(obtainMessage(DISPATCH_SYSTEM_UI_VISIBILITY, args));
38013834
}
38023835

38033836
/**
@@ -4052,10 +4085,12 @@ public void dispatchDragEvent(DragEvent event) {
40524085
}
40534086
}
40544087

4055-
public void dispatchSystemUiVisibilityChanged(int visibility) {
4088+
public void dispatchSystemUiVisibilityChanged(int seq, int globalVisibility,
4089+
int localValue, int localChanges) {
40564090
final ViewRootImpl viewAncestor = mViewAncestor.get();
40574091
if (viewAncestor != null) {
4058-
viewAncestor.dispatchSystemUiVisibilityChanged(visibility);
4092+
viewAncestor.dispatchSystemUiVisibilityChanged(seq, globalVisibility,
4093+
localValue, localChanges);
40594094
}
40604095
}
40614096
}

core/java/android/view/WindowManagerPolicy.java

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

239+
/**
240+
* Retrieve the current system UI visibility flags associated with
241+
* this window.
242+
*/
243+
public int getSystemUiVisibility();
244+
239245
/**
240246
* Get the layer at which this window's surface will be Z-ordered.
241247
*/

core/java/com/android/internal/view/BaseIWindow.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
public class BaseIWindow extends IWindow.Stub {
2929
private IWindowSession mSession;
30+
public int mSeq;
3031

3132
public void setSession(IWindowSession session) {
3233
mSession = session;
@@ -69,7 +70,9 @@ public void dispatchWallpaperOffsets(float x, float y, float xStep, float yStep,
6970
public void dispatchDragEvent(DragEvent event) {
7071
}
7172

72-
public void dispatchSystemUiVisibilityChanged(int visibility) {
73+
public void dispatchSystemUiVisibilityChanged(int seq, int globalUi,
74+
int localValue, int localChanges) {
75+
mSeq = seq;
7376
}
7477

7578
public void dispatchWallpaperCommand(String action, int x, int y,

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3497,8 +3497,7 @@ private void updateSystemUiVisibility() {
34973497
// If there is no window focused, there will be nobody to handle the events
34983498
// anyway, so just hang on in whatever state we're in until things settle down.
34993499
if (mFocusedWindow != null) {
3500-
final WindowManager.LayoutParams params = mFocusedWindow.getAttrs();
3501-
final int visibility = params.systemUiVisibility | params.subtreeSystemUiVisibility;
3500+
final int visibility = mFocusedWindow.getSystemUiVisibility();
35023501
mHandler.post(new Runnable() {
35033502
public void run() {
35043503
if (mStatusBarService == null) {

0 commit comments

Comments
 (0)