Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c4996bd8 authored by Svet Ganov's avatar Svet Ganov Committed by android-build-merger
Browse files

Merge "Fixes crash (race cond) when using toast that is immediately cancelled" into oc-dev

am: 2df0155a

Change-Id: I6cb947b8c42298c7cff1932031faec362b99a354
parents 36d913c7 2df0155a
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -449,6 +449,11 @@ public class Toast {
        public void handleShow(IBinder windowToken) {
            if (localLOGV) Log.v(TAG, "HANDLE SHOW: " + this + " mView=" + mView
                    + " mNextView=" + mNextView);
            // If a cancel/hide is pending - no need to show - at this point
            // the window token is already invalid and no need to do any work.
            if (mHandler.hasMessages(CANCEL) || mHandler.hasMessages(HIDE)) {
                return;
            }
            if (mView != mNextView) {
                // remove the old view if necessary
                handleHide();
@@ -483,8 +488,16 @@ public class Toast {
                    mWM.removeView(mView);
                }
                if (localLOGV) Log.v(TAG, "ADD! " + mView + " in " + this);
                // Since the notification manager service cancels the token right
                // after it notifies us to cancel the toast there is an inherent
                // race and we may attempt to add a window after the token has been
                // invalidated. Let us hedge against that.
                try {
                    mWM.addView(mView, mParams);
                    trySendAccessibilityEvent();
                } catch (WindowManager.BadTokenException e) {
                    /* ignore */
                }
            }
        }