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

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

Check for ICCID against all subs belonging to the group.

Earlier the check was only against the current active subId.
As a result if the check was done while active sub was being
switched to another sub in the same group, the check failed.

Test: atest SubscriptionControllerTest
Bug: 182377503
Change-Id: Id639f841412ee84d1378d683225a2af04b57cd77
parent ec0babff
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -3834,6 +3834,30 @@ public class SubscriptionController extends ISub.Stub {

    }

    /**
     * Check if the passed in phoneId has a sub that belongs to the same group as the sub
     * corresponding to the passed in iccid.
     * @param phoneId phone id to check
     * @param iccid ICCID to check
     * @return true if sub/group is the same, false otherwise
     */
    public boolean checkPhoneIdAndIccIdMatch(int phoneId, String iccid) {
        int subId = getSubIdUsingPhoneId(phoneId);
        if (!SubscriptionManager.isUsableSubIdValue(subId)) return false;
        ParcelUuid groupUuid = getGroupUuid(subId);
        List<SubscriptionInfo> subInfoList;
        if (groupUuid != null) {
            subInfoList = getSubInfo(SubscriptionManager.GROUP_UUID
                    + "=\'" + groupUuid.toString() + "\'", null);
        } else {
            subInfoList = getSubInfo(SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID
                    + "=" + subId, null);
        }
        return subInfoList != null && subInfoList.stream().anyMatch(
                subInfo -> IccUtils.stripTrailingFs(subInfo.getIccId()).equals(
                IccUtils.stripTrailingFs(iccid)));
    }

    public ParcelUuid getGroupUuid(int subId) {
        ParcelUuid groupUuid;
        List<SubscriptionInfo> subInfo = getSubInfo(SubscriptionManager.UNIQUE_KEY_SUBSCRIPTION_ID
+1 −16
Original line number Diff line number Diff line
@@ -1754,21 +1754,6 @@ 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.
     */
@@ -1780,7 +1765,7 @@ public class UiccProfile extends IccCard {
        if (TextUtils.isEmpty(iccId)) {
            return false;
        }
        if (!checkSubIdAndIccIdMatch(iccId)) {
        if (!SubscriptionController.getInstance().checkPhoneIdAndIccIdMatch(getPhoneId(), iccId)) {
            loge("iccId doesn't match current active subId.");
            return false;
        }
+18 −1
Original line number Diff line number Diff line
@@ -57,9 +57,9 @@ import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.UiccSlotInfo;
import android.test.mock.MockContentResolver;
import android.test.suitebuilder.annotation.SmallTest;

import androidx.test.filters.FlakyTest;
import androidx.test.filters.SmallTest;

import com.android.internal.telephony.uicc.IccCardStatus;
import com.android.internal.telephony.uicc.UiccController;
@@ -1939,4 +1939,21 @@ public class SubscriptionControllerTest extends TelephonyTest {
                mSubscriptionControllerUT
                        .getAllSubInfoList(mCallingPackage, mCallingFeature).size());
    }

    @Test
    @SmallTest
    public void testCheckPhoneIdAndIccIdMatch() {
        try {
            testSetSubscriptionGroupWithModifyPermission();
        } catch (Exception e) {
            fail("Unexpected exception: " + e);
        }

        mSubscriptionControllerUT.addSubInfoRecord("test3",
                SubscriptionManager.INVALID_SIM_SLOT_INDEX);

        assertTrue(mSubscriptionControllerUT.checkPhoneIdAndIccIdMatch(0, "test"));
        assertTrue(mSubscriptionControllerUT.checkPhoneIdAndIccIdMatch(0, "test2"));
        assertFalse(mSubscriptionControllerUT.checkPhoneIdAndIccIdMatch(0, "test3"));
    }
}
+10 −3
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import static com.android.internal.telephony.TelephonyTestUtils.waitForMs;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
@@ -561,13 +562,19 @@ public class UiccProfileTest extends TelephonyTest {
        String fakeBrand = "operator";

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

        doReturn(false).when(mSubscriptionController)
                .checkPhoneIdAndIccIdMatch(anyInt(), anyString());
        mUiccProfile.setOperatorBrandOverride(fakeBrand);
        String brandInSharedPreference = mContext.getSharedPreferences("file name", 0)
                .getString("operator_branding_" + fakeIccId, null);
        assertNotEquals(fakeBrand, brandInSharedPreference);

        doReturn(true).when(mSubscriptionController)
                .checkPhoneIdAndIccIdMatch(anyInt(), anyString());
        mUiccProfile.setOperatorBrandOverride(fakeBrand);
        brandInSharedPreference = mContext.getSharedPreferences("file name", 0)
                .getString("operator_branding_" + fakeIccId, null);
        assertEquals(fakeBrand, brandInSharedPreference);
    }