Loading src/java/com/android/internal/telephony/SubscriptionController.java +24 −0 Original line number Diff line number Diff line Loading @@ -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 Loading src/java/com/android/internal/telephony/uicc/UiccProfile.java +1 −16 Original line number Diff line number Diff line Loading @@ -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. */ Loading @@ -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; } Loading tests/telephonytests/src/com/android/internal/telephony/SubscriptionControllerTest.java +18 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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")); } } tests/telephonytests/src/com/android/internal/telephony/uicc/UiccProfileTest.java +10 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } Loading Loading
src/java/com/android/internal/telephony/SubscriptionController.java +24 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
src/java/com/android/internal/telephony/uicc/UiccProfile.java +1 −16 Original line number Diff line number Diff line Loading @@ -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. */ Loading @@ -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; } Loading
tests/telephonytests/src/com/android/internal/telephony/SubscriptionControllerTest.java +18 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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")); } }
tests/telephonytests/src/com/android/internal/telephony/uicc/UiccProfileTest.java +10 −3 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } Loading