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

Commit 2dfb68ac authored by Pawit Pornkitprasan's avatar Pawit Pornkitprasan
Browse files

Toast: fix force close if called from system service

If a toast is created from a system service, an application context
will not be available, use the service context instead.

Fixes
http://code.google.com/p/android/issues/detail?id=40058
http://code.google.com/p/android/issues/detail?id=40075

Change-Id: Ic643f4557fa04476819cd2c3ee640b735eeae429
parent f9cd515f
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -374,8 +374,13 @@ public class Toast {
                // remove the old view if necessary
                handleHide();
                mView = mNextView;
                mWM = (WindowManager)mView.getContext().getApplicationContext()
                        .getSystemService(Context.WINDOW_SERVICE);
                Context context = mView.getContext();
                if (context.getApplicationContext() != null) {
                    // Use application context, except when called from system
                    // service where there is no application context.
                    context = context.getApplicationContext();
                }
                mWM = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
                // We can resolve the Gravity here by using the Locale for getting
                // the layout direction
                final Configuration config = mView.getContext().getResources().getConfiguration();