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

Commit da50f643 authored by Malcolm Chen's avatar Malcolm Chen
Browse files

Fix bug that setOperatorBrandOverride applies on wrong subId.

Make sure the iccid in SIM record matches the current active subId.

Bug: 155584595
Test: manual
Change-Id: Iae42e60d3f1c4eb7e371567cd868c1d83a7e2202
Merged-In: Iae42e60d3f1c4eb7e371567cd868c1d83a7e2202
parent 0506228d
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Pair;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.MccTable;
import com.android.internal.telephony.util.ArrayUtils;
@@ -119,7 +120,8 @@ public abstract class IccRecords extends Handler implements IccConstants {
    protected boolean mRecordsRequested = false; // true if we've made requests for the sim records
    protected int mLockedRecordsReqReason = LOCKED_RECORDS_REQ_REASON_NONE;

    protected String mIccId;  // Includes only decimals (no hex)
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PROTECTED)
    public String mIccId;  // Includes only decimals (no hex)

    protected String mFullIccId;  // Includes hex characters in ICCID
    protected String mMsisdn = null;  // My mobile number
+19 −0
Original line number Diff line number Diff line
@@ -1677,6 +1677,21 @@ public class UiccProfile extends IccCard {
        }
    }

    /**
     * Make sure the iccid in SIM record matches the current active subId. If not, return false.
     * When SIM switching in eSIM is happening, there are rare cases that setOperatorBrandOverride
     * is called on old subId while new iccid is already loaded on SIM record. For those cases
     * setOperatorBrandOverride would apply to the wrong (new) iccid. This check is to avoid it.
     */
    private boolean checkSubIdAndIccIdMatch(String iccid) {
        if (TextUtils.isEmpty(iccid)) return false;
        SubscriptionInfo subInfo = SubscriptionController.getInstance()
                .getActiveSubscriptionInfoForSimSlotIndex(
                        getPhoneId(), mContext.getOpPackageName(), null);
        return subInfo != null && IccUtils.stripTrailingFs(subInfo.getIccId()).equals(
                IccUtils.stripTrailingFs(iccid));
    }

    /**
     * Sets the overridden operator brand.
     */
@@ -1688,6 +1703,10 @@ public class UiccProfile extends IccCard {
        if (TextUtils.isEmpty(iccId)) {
            return false;
        }
        if (!checkSubIdAndIccIdMatch(iccId)) {
            loge("iccId doesn't match current active subId.");
            return false;
        }

        SharedPreferences.Editor spEditor =
                PreferenceManager.getDefaultSharedPreferences(mContext).edit();
+44 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.atLeast;
@@ -35,6 +37,7 @@ import android.os.Handler;
import android.os.Message;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionInfo;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;

@@ -547,6 +550,47 @@ public class UiccProfileTest extends TelephonyTest {
        assertTrue(carrierFound);
    }

    @Mock
    private SubscriptionInfo mSubscriptionInfo;

    @Test
    public void testSetOperatorBrandOverride() {
        testUpdateUiccProfileApplication();
        String fakeIccId = "1234567";
        String fakeBrand = "operator";

        mUiccProfile.getApplicationIndex(0).getIccRecords().mIccId = fakeIccId;
        doReturn(fakeIccId).when(mSubscriptionInfo).getIccId();
        doReturn(mSubscriptionInfo).when(mSubscriptionController)
                .getActiveSubscriptionInfoForSimSlotIndex(eq(0), any(), any());

        mUiccProfile.setOperatorBrandOverride(fakeBrand);
        String brandInSharedPreference = mContext.getSharedPreferences("file name", 0)
                .getString("operator_branding_" + fakeIccId, null);
        assertEquals(fakeBrand, brandInSharedPreference);
    }

    @Test
    public void testSetOperatorBrandOverrideIccNotMatch() {
        testUpdateUiccProfileApplication();
        String fakeIccId1 = "1234567";
        String fakeIccId2 = "7654321";
        String fakeBrand = "operator";

        mUiccProfile.getApplicationIndex(0).getIccRecords().mIccId = fakeIccId1;
        doReturn(fakeIccId2).when(mSubscriptionInfo).getIccId();
        doReturn(mSubscriptionInfo).when(mSubscriptionController)
                .getActiveSubscriptionInfoForSimSlotIndex(eq(0), any(), any());

        mUiccProfile.setOperatorBrandOverride(fakeBrand);
        String brandInSharedPreference = mContext.getSharedPreferences("file name", 0)
                .getString("operator_branding_" + fakeIccId1, null);
        assertNull(brandInSharedPreference);
        brandInSharedPreference = mContext.getSharedPreferences("file name", 0)
                .getString("operator_branding_" + fakeIccId2, null);
        assertNull(brandInSharedPreference);
    }

    @Test
    @SmallTest
    public void testIsEmptyProfile() {