Loading src/java/com/android/internal/telephony/uicc/IccRecords.java +3 −1 Original line number Original line Diff line number Diff line Loading @@ -30,6 +30,7 @@ import android.telephony.TelephonyManager; import android.text.TextUtils; import android.text.TextUtils; import android.util.Pair; import android.util.Pair; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.telephony.CommandsInterface; import com.android.internal.telephony.CommandsInterface; import com.android.internal.telephony.MccTable; import com.android.internal.telephony.MccTable; import com.android.internal.telephony.util.ArrayUtils; import com.android.internal.telephony.util.ArrayUtils; Loading Loading @@ -112,7 +113,8 @@ public abstract class IccRecords extends Handler implements IccConstants { protected boolean mRecordsRequested = false; // true if we've made requests for the sim records protected boolean mRecordsRequested = false; // true if we've made requests for the sim records protected int mLockedRecordsReqReason = LOCKED_RECORDS_REQ_REASON_NONE; 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 mFullIccId; // Includes hex characters in ICCID protected String mMsisdn = null; // My mobile number protected String mMsisdn = null; // My mobile number Loading src/java/com/android/internal/telephony/uicc/UiccProfile.java +19 −0 Original line number Original line Diff line number Diff line Loading @@ -1665,6 +1665,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. * Sets the overridden operator brand. */ */ Loading @@ -1676,6 +1691,10 @@ public class UiccProfile extends IccCard { if (TextUtils.isEmpty(iccId)) { if (TextUtils.isEmpty(iccId)) { return false; return false; } } if (!checkSubIdAndIccIdMatch(iccId)) { loge("iccId doesn't match current active subId."); return false; } SharedPreferences.Editor spEditor = SharedPreferences.Editor spEditor = PreferenceManager.getDefaultSharedPreferences(mContext).edit(); PreferenceManager.getDefaultSharedPreferences(mContext).edit(); Loading tests/telephonytests/src/com/android/internal/telephony/uicc/UiccProfileTest.java +44 −0 Original line number Original line Diff line number Diff line Loading @@ -21,6 +21,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; 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.anyInt; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.atLeast; Loading @@ -35,6 +37,7 @@ import android.os.Handler; import android.os.Message; import android.os.Message; import android.os.PersistableBundle; import android.os.PersistableBundle; import android.telephony.CarrierConfigManager; import android.telephony.CarrierConfigManager; import android.telephony.SubscriptionInfo; import android.testing.AndroidTestingRunner; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.testing.TestableLooper; Loading Loading @@ -547,6 +550,47 @@ public class UiccProfileTest extends TelephonyTest { assertTrue(carrierFound); 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 @Test @SmallTest @SmallTest public void testIsEmptyProfile() { public void testIsEmptyProfile() { Loading Loading
src/java/com/android/internal/telephony/uicc/IccRecords.java +3 −1 Original line number Original line Diff line number Diff line Loading @@ -30,6 +30,7 @@ import android.telephony.TelephonyManager; import android.text.TextUtils; import android.text.TextUtils; import android.util.Pair; import android.util.Pair; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.telephony.CommandsInterface; import com.android.internal.telephony.CommandsInterface; import com.android.internal.telephony.MccTable; import com.android.internal.telephony.MccTable; import com.android.internal.telephony.util.ArrayUtils; import com.android.internal.telephony.util.ArrayUtils; Loading Loading @@ -112,7 +113,8 @@ public abstract class IccRecords extends Handler implements IccConstants { protected boolean mRecordsRequested = false; // true if we've made requests for the sim records protected boolean mRecordsRequested = false; // true if we've made requests for the sim records protected int mLockedRecordsReqReason = LOCKED_RECORDS_REQ_REASON_NONE; 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 mFullIccId; // Includes hex characters in ICCID protected String mMsisdn = null; // My mobile number protected String mMsisdn = null; // My mobile number Loading
src/java/com/android/internal/telephony/uicc/UiccProfile.java +19 −0 Original line number Original line Diff line number Diff line Loading @@ -1665,6 +1665,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. * Sets the overridden operator brand. */ */ Loading @@ -1676,6 +1691,10 @@ public class UiccProfile extends IccCard { if (TextUtils.isEmpty(iccId)) { if (TextUtils.isEmpty(iccId)) { return false; return false; } } if (!checkSubIdAndIccIdMatch(iccId)) { loge("iccId doesn't match current active subId."); return false; } SharedPreferences.Editor spEditor = SharedPreferences.Editor spEditor = PreferenceManager.getDefaultSharedPreferences(mContext).edit(); PreferenceManager.getDefaultSharedPreferences(mContext).edit(); Loading
tests/telephonytests/src/com/android/internal/telephony/uicc/UiccProfileTest.java +44 −0 Original line number Original line Diff line number Diff line Loading @@ -21,6 +21,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; 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.anyInt; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.atLeast; Loading @@ -35,6 +37,7 @@ import android.os.Handler; import android.os.Message; import android.os.Message; import android.os.PersistableBundle; import android.os.PersistableBundle; import android.telephony.CarrierConfigManager; import android.telephony.CarrierConfigManager; import android.telephony.SubscriptionInfo; import android.testing.AndroidTestingRunner; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.testing.TestableLooper; Loading Loading @@ -547,6 +550,47 @@ public class UiccProfileTest extends TelephonyTest { assertTrue(carrierFound); 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 @Test @SmallTest @SmallTest public void testIsEmptyProfile() { public void testIsEmptyProfile() { Loading