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

Commit 5a5818f2 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Fix loading of toast app icons

We need an application context for icons, and a display
context for layout.

Test: ToastTest (all 5 matches with atest)
Test: InternetDialogDelegateControllerTest
Test: post toast from Settings
Flag: EXEMPT bug fix
Fixes: 372190414
Change-Id: Ia2ad158adb647706342211f13336a29c39c986e6
parent 7fb089df
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1429,7 +1429,7 @@ public class InternetDialogController implements AccessPointController.AccessPoi
    void makeOverlayToast(int stringId) {
        final Resources res = mContext.getResources();

        final SystemUIToast systemUIToast = mToastFactory.createToast(mContext,
        final SystemUIToast systemUIToast = mToastFactory.createToast(mContext, mContext,
                res.getString(stringId), mContext.getPackageName(), UserHandle.myUserId(),
                res.getConfiguration().orientation);
        if (systemUIToast == null) {
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ constructor(
        // Show the brightness warning toast with passing the toast inflation required context,
        // userId and resId from SystemUI package.
        val systemUIToast = toastFactory.createToast(
            viewContext,
            viewContext, viewContext,
            res.getString(resId), viewContext.packageName, viewContext.getUserId(),
            res.configuration.orientation
        )
+11 −9
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import com.android.systemui.plugins.ToastPlugin;
public class SystemUIToast implements ToastPlugin.Toast {
    static final String TAG = "SystemUIToast";
    final Context mContext;
    final Context mDisplayContext;
    final CharSequence mText;
    final ToastPlugin.Toast mPluginToast;

@@ -68,17 +69,18 @@ public class SystemUIToast implements ToastPlugin.Toast {
    @Nullable private final Animator mInAnimator;
    @Nullable private final Animator mOutAnimator;

    SystemUIToast(LayoutInflater layoutInflater, Context context, CharSequence text,
            String packageName, int userId, int orientation) {
        this(layoutInflater, context, text, null, packageName, userId,
    SystemUIToast(LayoutInflater layoutInflater, Context applicationContext, Context displayContext,
            CharSequence text, String packageName, int userId, int orientation) {
        this(layoutInflater, applicationContext, displayContext, text, null, packageName, userId,
                orientation);
    }

    SystemUIToast(LayoutInflater layoutInflater, Context context, CharSequence text,
            ToastPlugin.Toast pluginToast, String packageName, @UserIdInt int userId,
            int orientation) {
    SystemUIToast(LayoutInflater layoutInflater, Context applicationContext, Context displayContext,
            CharSequence text, ToastPlugin.Toast pluginToast, String packageName,
            @UserIdInt int userId, int orientation) {
        mLayoutInflater = layoutInflater;
        mContext = context;
        mContext = applicationContext;
        mDisplayContext = displayContext;
        mText = text;
        mPluginToast = pluginToast;
        mPackageName = packageName;
@@ -221,9 +223,9 @@ public class SystemUIToast implements ToastPlugin.Toast {
            mPluginToast.onOrientationChange(orientation);
        }

        mDefaultY = mContext.getResources().getDimensionPixelSize(R.dimen.toast_y_offset);
        mDefaultY = mDisplayContext.getResources().getDimensionPixelSize(R.dimen.toast_y_offset);
        mDefaultGravity =
                mContext.getResources().getInteger(R.integer.config_toastDefaultGravity);
                mDisplayContext.getResources().getInteger(R.integer.config_toastDefaultGravity);
    }

    private Animator createInAnimator() {
+8 −7
Original line number Diff line number Diff line
@@ -65,16 +65,17 @@ public class ToastFactory implements Dumpable {
    /**
     * Create a toast to be shown by ToastUI.
     */
    public SystemUIToast createToast(Context context, CharSequence text, String packageName,
            int userId, int orientation) {
        LayoutInflater layoutInflater = LayoutInflater.from(context);
    public SystemUIToast createToast(Context applicationContext, Context displayContext,
            CharSequence text, String packageName, int userId, int orientation) {
        LayoutInflater layoutInflater = LayoutInflater.from(displayContext);
        if (isPluginAvailable()) {
            return new SystemUIToast(layoutInflater, context, text, mPlugin.createToast(text,
                    packageName, userId), packageName, userId, orientation);
        }
        return new SystemUIToast(layoutInflater, context, text, packageName, userId,
            return new SystemUIToast(layoutInflater, applicationContext, displayContext, text,
                    mPlugin.createToast(text, packageName, userId), packageName, userId,
                    orientation);
        }
        return new SystemUIToast(layoutInflater, applicationContext, displayContext, text,
                packageName, userId, orientation);
    }

    private boolean isPluginAvailable() {
        return mPlugin != null;
+2 −2
Original line number Diff line number Diff line
@@ -135,8 +135,8 @@ public class ToastUI implements
                return;
            }
            Context displayContext = context.createDisplayContext(display);
            mToast = mToastFactory.createToast(displayContext /* sysuiContext */, text, packageName,
                    userHandle.getIdentifier(), mOrientation);
            mToast = mToastFactory.createToast(mContext, displayContext /* sysuiContext */, text,
                    packageName, userHandle.getIdentifier(), mOrientation);

            if (mToast.getInAnimation() != null) {
                mToast.getInAnimation().start();
Loading