Skip to content

Commit df2390a

Browse files
author
Craig Mautner
committed
Don't die(immediate) if from performTraversals.
The Drive application was calling PopupWindow.dismiss from within onMeasure. This caused dispatchDetachedFromWindow to be called from within performTraversals. Since dispatchDetachedFromWindow destroys much of what performTraversals uses this was a disaster waiting to happen. This fix adds a check for seeing if die(immediate=true) is being called from within performTraversals. If it is then die doesn't execute doDie immediately, but instead treats it as a call to die(immediate=false). Fixes bug 6836841. Change-Id: I833289e12c19fd33c17a715b2ed2adcf8388573a
1 parent ac137b3 commit df2390a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

core/java/android/view/ViewRootImpl.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ public final class ViewRootImpl implements ViewParent,
214214
boolean mTraversalScheduled;
215215
int mTraversalBarrier;
216216
boolean mWillDrawSoon;
217+
/** Set to true while in performTraversals for detecting when die(true) is called from internal
218+
* callbacks such as onMeasure, onPreDraw, onDraw and deferring doDie() until later. */
219+
boolean mIsInTraversal;
217220
boolean mFitSystemWindowsRequested;
218221
boolean mLayoutRequested;
219222
boolean mFirst;
@@ -1104,6 +1107,7 @@ private void performTraversals() {
11041107
if (host == null || !mAdded)
11051108
return;
11061109

1110+
mIsInTraversal = true;
11071111
mWillDrawSoon = true;
11081112
boolean windowSizeMayChange = false;
11091113
boolean newSurface = false;
@@ -1842,6 +1846,8 @@ private void performTraversals() {
18421846
mPendingTransitions.clear();
18431847
}
18441848
}
1849+
1850+
mIsInTraversal = false;
18451851
}
18461852

18471853
private void performMeasure(int childWidthMeasureSpec, int childHeightMeasureSpec) {
@@ -3956,7 +3962,9 @@ private static void getGfxInfo(View view, int[] info) {
39563962
}
39573963

39583964
public void die(boolean immediate) {
3959-
if (immediate) {
3965+
// Make sure we do execute immediately if we are in the middle of a traversal or the damage
3966+
// done by dispatchDetachedFromWindow will cause havoc on return.
3967+
if (immediate && !mIsInTraversal) {
39603968
doDie();
39613969
} else {
39623970
if (!mIsDrawing) {

0 commit comments

Comments
 (0)