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

Commit b1ec286a authored by Amit Mahajan's avatar Amit Mahajan
Browse files

Share lock object between UiccSlot, UiccCard and UiccProfile.

Prior to P, there was a single class UiccCard that had the lock. Now
it's split between these 3 classes, but if each has a separate lock
there can be a deadlock if they call each other's APIs which they do.
The solution is to use a single lock between them which is equivalent
to how the locking mechanism was earlier.

Test: Basic telephony sanity.
Bug: 80317780
Change-Id: Iadecb726dc3bf85dcde76c70a54e191f1a55007c
parent 95141432
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -104,8 +104,8 @@ public class TelephonyComponentFactory {
     * Create a new UiccProfile object.
     */
    public UiccProfile makeUiccProfile(Context context, CommandsInterface ci, IccCardStatus ics,
                                       int phoneId, UiccCard uiccCard) {
        return new UiccProfile(context, ci, ics, phoneId, uiccCard);
                                       int phoneId, UiccCard uiccCard, Object lock) {
        return new UiccProfile(context, ci, ics, phoneId, uiccCard, lock);
    }

    public EriManager makeEriManager(Phone phone, Context context, int eriFileSource) {
+6 −3
Original line number Diff line number Diff line
@@ -46,7 +46,9 @@ public class UiccCard {
    public static final String EXTRA_ICC_CARD_ADDED =
            "com.android.internal.telephony.uicc.ICC_CARD_ADDED";

    private final Object mLock = new Object();
    // The lock object is created by UiccSlot that owns this UiccCard - this is to share the lock
    // between UiccSlot, UiccCard and UiccProfile for now.
    private final Object mLock;
    private CardState mCardState;
    private String mIccid;
    protected String mCardId;
@@ -55,10 +57,11 @@ public class UiccCard {
    private CommandsInterface mCi;
    private final int mPhoneId;

    public UiccCard(Context c, CommandsInterface ci, IccCardStatus ics, int phoneId) {
    public UiccCard(Context c, CommandsInterface ci, IccCardStatus ics, int phoneId, Object lock) {
        if (DBG) log("Creating");
        mCardState = ics.mCardState;
        mPhoneId = phoneId;
        mLock = lock;
        update(c, ci, ics);
    }

@@ -83,7 +86,7 @@ public class UiccCard {
            if (mCardState != CardState.CARDSTATE_ABSENT) {
                if (mUiccProfile == null) {
                    mUiccProfile = TelephonyComponentFactory.getInstance().makeUiccProfile(
                            mContext, mCi, ics, mPhoneId, this);
                            mContext, mCi, ics, mPhoneId, this, mLock);
                } else {
                    mUiccProfile.update(mContext, mCi, ics);
                }
+5 −2
Original line number Diff line number Diff line
@@ -88,7 +88,9 @@ public class UiccProfile extends IccCard {

    private static final String OPERATOR_BRAND_OVERRIDE_PREFIX = "operator_branding_";

    private final Object mLock = new Object();
    // The lock object is created by UiccSlot that owns the UiccCard that owns this UiccProfile.
    // This is to share the lock between UiccSlot, UiccCard and UiccProfile for now.
    private final Object mLock;
    private PinState mUniversalPinState;
    private int mGsmUmtsSubscriptionAppIndex;
    private int mCdmaSubscriptionAppIndex;
@@ -214,8 +216,9 @@ public class UiccProfile extends IccCard {
    };

    public UiccProfile(Context c, CommandsInterface ci, IccCardStatus ics, int phoneId,
            UiccCard uiccCard) {
            UiccCard uiccCard, Object lock) {
        if (DBG) log("Creating profile");
        mLock = lock;
        mUiccCard = uiccCard;
        mPhoneId = phoneId;
        // set current app type based on phone type - do this before calling update() as that
+2 −2
Original line number Diff line number Diff line
@@ -112,9 +112,9 @@ public class UiccSlot extends Handler {
                }

                if (!mIsEuicc) {
                    mUiccCard = new UiccCard(mContext, mCi, ics, mPhoneId);
                    mUiccCard = new UiccCard(mContext, mCi, ics, mPhoneId, mLock);
                } else {
                    mUiccCard = new EuiccCard(mContext, mCi, ics, phoneId);
                    mUiccCard = new EuiccCard(mContext, mCi, ics, phoneId, mLock);
                }
            } else {
                if (mUiccCard != null) {
+2 −2
Original line number Diff line number Diff line
@@ -116,8 +116,8 @@ public class EuiccCard extends UiccCard {
    private EuiccSpecVersion mSpecVersion;
    private volatile String mEid;

    public EuiccCard(Context c, CommandsInterface ci, IccCardStatus ics, int phoneId) {
        super(c, ci, ics, phoneId);
    public EuiccCard(Context c, CommandsInterface ci, IccCardStatus ics, int phoneId, Object lock) {
        super(c, ci, ics, phoneId, lock);
        // TODO: Set supportExtendedApdu based on ATR.
        mApduSender = new ApduSender(ci, ISD_R_AID, false /* supportExtendedApdu */);

Loading