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

Commit dd0dd5dc authored by Pranav Madapurmath's avatar Pranav Madapurmath
Browse files

Create toast on main thread executor.

With the recent mainline changes to resolve the hidden reference to
Toast#makeText, the new method tries to use Looper#myLooper in creating
the toast. However, this ends up throwing an NPE because we are running
this off of a binder thread. Instead, we need to explicitly run this
command in an exeuctor running on the main thread.

Bug: 330526426
Test: Manual (tested that the new method isn't causing crashes and the
toasts are successfully created)

Change-Id: Iea1223e9c5cdaef7afd456b2605474eb00aaf623
parent 32260704
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3432,7 +3432,7 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
            Log.w(this, "pullExternalCall = pullExternalCall - call %s is external but can not be"
                    + " pulled while an emergency call is in progress.", mId);
            mToastFactory.makeText(mContext, R.string.toast_emergency_can_not_pull_call,
                    Toast.LENGTH_LONG).show();
                    Toast.LENGTH_LONG);
            return;
        }

+3 −2
Original line number Diff line number Diff line
@@ -174,8 +174,9 @@ public class CallIntentProcessor {
            // profile.
            if (fixedInitiatingUser) {
                if (featureFlags.telecomResolveHiddenDependencies()) {
                    Toast.makeText(context, context.getString(R.string.toast_personal_call_msg),
                            Toast.LENGTH_LONG).show();
                    context.getMainExecutor().execute(() ->
                            Toast.makeText(context, context.getString(
                                    R.string.toast_personal_call_msg), Toast.LENGTH_LONG).show());
                } else {
                    Toast.makeText(context, Looper.getMainLooper(),
                            context.getString(R.string.toast_personal_call_msg),
+0 −1
Original line number Diff line number Diff line
@@ -2675,7 +2675,6 @@ public class TelecomServiceImpl {
    private final FeatureFlags mFeatureFlags;
    private final com.android.internal.telephony.flags.FeatureFlags mTelephonyFeatureFlags;


    public TelecomServiceImpl(
            Context context,
            CallsManager callsManager,
+9 −9
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ import android.net.Uri;
import android.os.BugreportManager;
import android.os.DropBoxManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.telecom.Log;
import android.telecom.PhoneAccountHandle;
import android.telephony.AnomalyReporter;
@@ -349,22 +348,23 @@ public class TelecomSystem {

            ToastFactory toastFactory = new ToastFactory() {
                @Override
                public Toast makeText(Context context, int resId, int duration) {
                public void makeText(Context context, int resId, int duration) {
                    if (mFeatureFlags.telecomResolveHiddenDependencies()) {
                        return Toast.makeText(context, resId, duration);
                        context.getMainExecutor().execute(() ->
                                Toast.makeText(context, resId, duration).show());
                    } else {
                        return Toast.makeText(context, context.getMainLooper(),
                                context.getString(resId),
                                duration);
                        Toast.makeText(context, context.getMainLooper(),
                                context.getString(resId), duration).show();
                    }
                }

                @Override
                public Toast makeText(Context context, CharSequence text, int duration) {
                public void makeText(Context context, CharSequence text, int duration) {
                    if (mFeatureFlags.telecomResolveHiddenDependencies()) {
                        return Toast.makeText(context, text, duration);
                        context.getMainExecutor().execute(() ->
                                Toast.makeText(context, text, duration).show());
                    } else {
                        return Toast.makeText(context, context.getMainLooper(), text, duration);
                        Toast.makeText(context, context.getMainLooper(), text, duration).show();
                    }
                }
            };
+2 −2
Original line number Diff line number Diff line
@@ -21,6 +21,6 @@ import android.content.Context;
import android.widget.Toast;

public interface ToastFactory {
    Toast makeText(Context context, @StringRes int resId, int duration);
    Toast makeText(Context context, CharSequence text, int duration);
    void makeText(Context context, @StringRes int resId, int duration);
    void makeText(Context context, CharSequence text, int duration);
}
Loading