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

Commit d34750b6 authored by Jack Yu's avatar Jack Yu
Browse files

Fixed deadlock in IccSmsInterfaceManager

The sync call in to RIL should run on a different thread than
IccSmsInterfaceManager's handler thread, otherwise it will
cause deadlock because the RIL response to unlock is also
running on the same thread.

Test: Manual boot up to make sure no ANR occurs.
Bug: 148923425
Change-Id: I1f59f8af2134fb5e8b205dec0f728b29e24cbe5f
parent baa60673
Loading
Loading
Loading
Loading
+28 −6
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.net.Uri;
import android.os.AsyncResult;
import android.os.Binder;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.UserManager;
import android.provider.Telephony;
@@ -199,13 +200,23 @@ public class IccSmsInterfaceManager {
                            if (mPhone.getPhoneId() == intent.getIntExtra(
                                    CarrierConfigManager.EXTRA_SLOT_INDEX,
                                    SubscriptionManager.INVALID_SIM_SLOT_INDEX)) {
                                new Thread(() -> {
                                    log("Carrier config changed. Update ranges.");
                                    mCellBroadcastRangeManager.updateRanges();
                                }).start();
                            }
                        }
                    }
                }, new IntentFilter(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED));
    }

    private void enforceNotOnHandlerThread(String methodName) {
        if (Looper.myLooper() == mHandler.getLooper()) {
            throw new RuntimeException("This method " + methodName + " will deadlock if called from"
                    + " the handler's thread.");
        }
    }

    protected void markMessagesAsRead(ArrayList<byte[]> messages) {
        if (messages == null) {
            return;
@@ -275,6 +286,7 @@ public class IccSmsInterfaceManager {
                "("+ Arrays.toString(pdu) + ")");
        enforceReceiveAndSend("Updating message on Icc");
        enforceAccessMessageOnICC("Updating message on Icc");
        enforceNotOnHandlerThread("updateMessageOnIccEf");
        if (mAppOps.noteOp(AppOpsManager.OPSTR_WRITE_ICC_SMS, Binder.getCallingUid(),
                callingPackage) != AppOpsManager.MODE_ALLOWED) {
            return false;
@@ -334,6 +346,7 @@ public class IccSmsInterfaceManager {
                "pdu=("+ Arrays.toString(pdu) +
                "), smsc=(" + Arrays.toString(smsc) +")");
        enforceReceiveAndSend("Copying message to Icc");
        enforceNotOnHandlerThread("copyMessageToIccEf");
        if (mAppOps.noteOp(AppOpsManager.OPSTR_WRITE_ICC_SMS, Binder.getCallingUid(),
                callingPackage) != AppOpsManager.MODE_ALLOWED) {
            return false;
@@ -373,6 +386,7 @@ public class IccSmsInterfaceManager {
                Manifest.permission.RECEIVE_SMS,
                "Reading messages from Icc");
        enforceAccessMessageOnICC("Reading messages from Icc");
        enforceNotOnHandlerThread("getAllMessagesFromIccEf");
        if (mAppOps.noteOp(AppOpsManager.OPSTR_READ_ICC_SMS, Binder.getCallingUid(),
                callingPackage) != AppOpsManager.MODE_ALLOWED) {
            return new ArrayList<SmsRawData>();
@@ -880,6 +894,7 @@ public class IccSmsInterfaceManager {
                callingPackage, "getSmscAddressFromIccEf")) {
            return null;
        }
        enforceNotOnHandlerThread("getSmscAddressFromIccEf");
        synchronized (mLock) {
            mSmsc = null;
            Message response = mHandler.obtainMessage(EVENT_GET_SMSC_DONE);
@@ -1155,9 +1170,10 @@ public class IccSmsInterfaceManager {

    @UnsupportedAppUsage
    private boolean setCellBroadcastConfig(SmsBroadcastConfigInfo[] configs) {
        if (DBG)
        if (DBG) {
            log("Calling setGsmBroadcastConfig with " + configs.length + " configurations");

        }
        enforceNotOnHandlerThread("setCellBroadcastConfig");
        synchronized (mLock) {
            Message response = mHandler.obtainMessage(EVENT_SET_BROADCAST_CONFIG_DONE);

@@ -1175,9 +1191,11 @@ public class IccSmsInterfaceManager {
    }

    private boolean setCellBroadcastActivation(boolean activate) {
        if (DBG)
        if (DBG) {
            log("Calling setCellBroadcastActivation(" + activate + ')');
        }

        enforceNotOnHandlerThread("setCellBroadcastConfig");
        synchronized (mLock) {
            Message response = mHandler.obtainMessage(EVENT_SET_BROADCAST_ACTIVATION_DONE);

@@ -1196,9 +1214,11 @@ public class IccSmsInterfaceManager {

    @UnsupportedAppUsage
    private boolean setCdmaBroadcastConfig(CdmaSmsBroadcastConfigInfo[] configs) {
        if (DBG)
        if (DBG) {
            log("Calling setCdmaBroadcastConfig with " + configs.length + " configurations");
        }

        enforceNotOnHandlerThread("setCdmaBroadcastConfig");
        synchronized (mLock) {
            Message response = mHandler.obtainMessage(EVENT_SET_BROADCAST_CONFIG_DONE);

@@ -1216,9 +1236,11 @@ public class IccSmsInterfaceManager {
    }

    private boolean setCdmaBroadcastActivation(boolean activate) {
        if (DBG)
        if (DBG) {
            log("Calling setCdmaBroadcastActivation(" + activate + ")");
        }

        enforceNotOnHandlerThread("setCdmaBroadcastActivation");
        synchronized (mLock) {
            Message response = mHandler.obtainMessage(EVENT_SET_BROADCAST_ACTIVATION_DONE);