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

Commit 786082c9 authored by Jack Yu's avatar Jack Yu Committed by Grace Jia
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
Merged-In: I1f59f8af2134fb5e8b205dec0f728b29e24cbe5f
parent d7c16538
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;
@@ -266,6 +277,7 @@ public class IccSmsInterfaceManager {
                " status=" + status + " ==> " +
                "("+ Arrays.toString(pdu) + ")");
        enforceReceiveAndSend("Updating message on Icc");
        enforceNotOnHandlerThread("updateMessageOnIccEf");
        if (mAppOps.noteOp(AppOpsManager.OPSTR_WRITE_ICC_SMS, Binder.getCallingUid(),
                callingPackage) != AppOpsManager.MODE_ALLOWED) {
            return false;
@@ -325,6 +337,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;
@@ -363,6 +376,7 @@ public class IccSmsInterfaceManager {
        mContext.enforceCallingOrSelfPermission(
                Manifest.permission.RECEIVE_SMS,
                "Reading messages from Icc");
        enforceNotOnHandlerThread("getAllMessagesFromIccEf");
        if (mAppOps.noteOp(AppOpsManager.OPSTR_READ_ICC_SMS, Binder.getCallingUid(),
                callingPackage) != AppOpsManager.MODE_ALLOWED) {
            return new ArrayList<SmsRawData>();
@@ -859,6 +873,7 @@ public class IccSmsInterfaceManager {
                callingPackage, "getSmscAddressFromIccEf")) {
            return null;
        }
        enforceNotOnHandlerThread("getSmscAddressFromIccEf");
        synchronized (mLock) {
            mSmsc = null;
            Message response = mHandler.obtainMessage(EVENT_GET_SMSC_DONE);
@@ -1134,9 +1149,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);

@@ -1154,9 +1170,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);

@@ -1175,9 +1193,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);

@@ -1195,9 +1215,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);