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

Commit b6ee2a24 authored by Craig Mautner's avatar Craig Mautner
Browse files

Use correct WindowManager for Toast.

The WindowManager retrieved from the activity Context with
getSystemService is incorrect for a Toast. Because it contains
a parent window when addView is called its LayoutParams.token
is set to the value of the parent window. Then when an Activity
is dismissed WindowManagerGlobal.closeAll() sees the incorrect
token and incorrectly closes the Toast.

This fix uses the application Context instead of the activity
Context to retrieve a WindowManager with no parent window. This
leaves the token unchanged and keeps from dismissing the toast when
the activity is closed.

Fixes bug 7048792.

Change-Id: I92c3095d8fabd6e9e4206e9bc8e917885ab322a9
parent ac137b32
Loading
Loading
Loading
Loading
+7 −2
Original line number Original line Diff line number Diff line
@@ -305,12 +305,14 @@ public class Toast {


    private static class TN extends ITransientNotification.Stub {
    private static class TN extends ITransientNotification.Stub {
        final Runnable mShow = new Runnable() {
        final Runnable mShow = new Runnable() {
            @Override
            public void run() {
            public void run() {
                handleShow();
                handleShow();
            }
            }
        };
        };


        final Runnable mHide = new Runnable() {
        final Runnable mHide = new Runnable() {
            @Override
            public void run() {
            public void run() {
                handleHide();
                handleHide();
                // Don't do this in handleHide() because it is also invoked by handleShow()
                // Don't do this in handleHide() because it is also invoked by handleShow()
@@ -350,6 +352,7 @@ public class Toast {
        /**
        /**
         * schedule handleShow into the right thread
         * schedule handleShow into the right thread
         */
         */
        @Override
        public void show() {
        public void show() {
            if (localLOGV) Log.v(TAG, "SHOW: " + this);
            if (localLOGV) Log.v(TAG, "SHOW: " + this);
            mHandler.post(mShow);
            mHandler.post(mShow);
@@ -358,6 +361,7 @@ public class Toast {
        /**
        /**
         * schedule handleHide into the right thread
         * schedule handleHide into the right thread
         */
         */
        @Override
        public void hide() {
        public void hide() {
            if (localLOGV) Log.v(TAG, "HIDE: " + this);
            if (localLOGV) Log.v(TAG, "HIDE: " + this);
            mHandler.post(mHide);
            mHandler.post(mHide);
@@ -370,7 +374,8 @@ public class Toast {
                // remove the old view if necessary
                // remove the old view if necessary
                handleHide();
                handleHide();
                mView = mNextView;
                mView = mNextView;
                mWM = (WindowManager)mView.getContext().getSystemService(Context.WINDOW_SERVICE);
                mWM = (WindowManager)mView.getContext().getApplicationContext()
                        .getSystemService(Context.WINDOW_SERVICE);
                // We can resolve the Gravity here by using the Locale for getting
                // We can resolve the Gravity here by using the Locale for getting
                // the layout direction
                // the layout direction
                final Configuration config = mView.getContext().getResources().getConfiguration();
                final Configuration config = mView.getContext().getResources().getConfiguration();