From 151778998ae6087c17cae4916a2c02eb59558daa Mon Sep 17 00:00:00 2001 From: Vadim Tryshev Date: Fri, 18 Dec 2015 08:01:00 -0800 Subject: [PATCH] Fixing crash in D&D due to race conditions during drag end. *** MERGING TO MASTER *** Drag-end event processing for a child view can remove the GroupView, Which will synchronously call dispatchDetachedFromWindow(), which will null mChildrenInterestedInDrag. This causes a crash when trying to clear the map. Fixing by introducing a local variable. Bug: 25433279 Change-Id: I2ef88f7f97935dbafda54634831fbbff747b8f2e (cherry picked from commit 2e2f1066ad89110365cdb504bf6568569d94da58) --- core/java/android/view/ViewGroup.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index cd93dab0c48bc..1c243929fa49d 100644 --- a/core/java/android/view/ViewGroup.java +++ b/core/java/android/view/ViewGroup.java @@ -1419,8 +1419,9 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager case DragEvent.ACTION_DRAG_ENDED: { // Release the bookkeeping now that the drag lifecycle has ended - if (mChildrenInterestedInDrag != null) { - for (View child : mChildrenInterestedInDrag) { + final HashSet childrenInterestedInDrag = mChildrenInterestedInDrag; + if (childrenInterestedInDrag != null) { + for (View child : childrenInterestedInDrag) { // If a child was interested in the ongoing drag, it's told that it's over if (child.dispatchDragEvent(event)) { retval = true; @@ -1428,12 +1429,11 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager child.mPrivateFlags2 &= ~View.DRAG_MASK; child.refreshDrawableState(); } - - mChildrenInterestedInDrag.clear(); - if (mCurrentDragStartEvent != null) { - mCurrentDragStartEvent.recycle(); - mCurrentDragStartEvent = null; - } + childrenInterestedInDrag.clear(); + } + if (mCurrentDragStartEvent != null) { + mCurrentDragStartEvent.recycle(); + mCurrentDragStartEvent = null; } if (mIsInterestedInDrag) {