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

Commit d4c84aff authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Fix race condition in CarrierTextController

If WakefulnessLifcecycle dispatches to CarrierTextController after the
CarrierTextCallback has been cleared but the observer has not been
removed, there will be an NPE.

This change guards the callback against dispatching to a null object.

Test: build and unlock
Fixes: 142130321
Change-Id: I5da46a0d5c8308870f2b67ae4622daf8e2d53b2f
parent 0cfa8916
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.android.internal.telephony.IccCardConstants;
@@ -66,6 +67,7 @@ public class CarrierTextController {
    private WifiManager mWifiManager;
    private boolean[] mSimErrorState;
    private final int mSimSlotsNumber;
    @Nullable // Check for nullability before dispatching
    private CarrierTextCallback mCarrierTextCallback;
    private Context mContext;
    private CharSequence mSeparator;
@@ -74,12 +76,12 @@ public class CarrierTextController {
            new WakefulnessLifecycle.Observer() {
                @Override
                public void onFinishedWakingUp() {
                    mCarrierTextCallback.finishedWakingUp();
                    if (mCarrierTextCallback != null) mCarrierTextCallback.finishedWakingUp();
                }

                @Override
                public void onStartedGoingToSleep() {
                    mCarrierTextCallback.startedGoingToSleep();
                    if (mCarrierTextCallback != null) mCarrierTextCallback.startedGoingToSleep();
                }
            };