Loading src/java/com/android/internal/telephony/subscription/SubscriptionManagerService.java +30 −11 Original line number Diff line number Diff line Loading @@ -141,6 +141,8 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executor; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; Loading @@ -157,9 +159,6 @@ public class SubscriptionManagerService extends ISub.Stub { private static final int CHECK_BOOTSTRAP_TIMER_IN_MS = 20 * 60 * 1000; // 20 minutes private static CountDownTimer bootstrapProvisioningTimer; /** Whether enabling verbose debugging message or not. */ private static final boolean VDBG = false; /** * The columns in {@link SimInfo} table that can be directly accessed through * {@link #getSubscriptionProperty(int, String, String, String)} or Loading Loading @@ -235,6 +234,11 @@ public class SubscriptionManagerService extends ISub.Stub { @NonNull private static final BinderWrapper BINDER_WRAPPER = new BinderWrapper(); /** Regular expression to determine if a string is in MAC address format. */ private static final Pattern MAC_ADDRESS_PATTERN = Pattern.compile( // Matches formats like 00:1B:44:11:3A:B7 or 00-1B-44-11-3A-B7 "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$"); /** Instance of subscription manager service. */ @NonNull private static SubscriptionManagerService sInstance; Loading Loading @@ -869,6 +873,22 @@ public class SubscriptionManagerService extends ISub.Stub { return result.build(); } /** * Get the stripped ICCID, which sometimes ended with 'F'. Also not doing this if the ICCID * is MAC address (used by texting through bluetooth). * * @param iccId The original ICCID. * @return The fixed ICCID. */ @VisibleForTesting @NonNull public static String getStrippedIccid(@NonNull String iccId) { Matcher matcher = MAC_ADDRESS_PATTERN.matcher(iccId); if (matcher.matches()) return iccId; return TextUtils.emptyIfNull(IccUtils.stripTrailingFs(iccId)); } /** * @return The list of ICCIDs from the inserted physical SIMs. */ Loading @@ -884,7 +904,7 @@ public class SubscriptionManagerService extends ISub.Stub { // Non euicc slots will have single port, so use default port index. String iccId = uiccSlot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); if (!TextUtils.isEmpty(iccId)) { iccidList.add(IccUtils.stripTrailingFs(iccId)); iccidList.add(getStrippedIccid(iccId)); } } } Loading Loading @@ -1393,7 +1413,7 @@ public class SubscriptionManagerService extends ISub.Stub { } SubscriptionInfoInternal subInfo = mSubscriptionDatabaseManager .getSubscriptionInfoInternalByIccId(IccUtils.stripTrailingFs(iccId)); .getSubscriptionInfoInternalByIccId(getStrippedIccid(iccId)); return subInfo != null && subInfo.areUiccApplicationsEnabled(); } Loading @@ -1407,8 +1427,7 @@ public class SubscriptionManagerService extends ISub.Stub { @NonNull private String getIccId(int phoneId) { UiccPort port = mUiccController.getUiccPort(phoneId); return (port == null) ? "" : TextUtils.emptyIfNull( IccUtils.stripTrailingFs(port.getIccId())); return (port == null) ? "" : getStrippedIccid(port.getIccId()); } /** Loading Loading @@ -2018,7 +2037,7 @@ public class SubscriptionManagerService extends ISub.Stub { final long identity = Binder.clearCallingIdentity(); try { iccId = IccUtils.stripTrailingFs(iccId); iccId = getStrippedIccid(iccId); SubscriptionInfoInternal subInfo = mSubscriptionDatabaseManager .getSubscriptionInfoInternalByIccId(iccId); Loading Loading @@ -2352,7 +2371,7 @@ public class SubscriptionManagerService extends ISub.Stub { return -1; } iccId = IccUtils.stripTrailingFs(iccId); iccId = getStrippedIccid(iccId); SubscriptionInfoInternal subInfo = mSubscriptionDatabaseManager .getSubscriptionInfoInternalByIccId(iccId); Loading Loading @@ -4457,7 +4476,7 @@ public class SubscriptionManagerService extends ISub.Stub { // When port is inactive, sometimes valid iccid is present in the slot status, // hence update the portIndex. (Pre-U behavior) SubscriptionInfoInternal subInfo = mSubscriptionDatabaseManager .getSubscriptionInfoInternalByIccId(IccUtils.stripTrailingFs(iccId)); .getSubscriptionInfoInternalByIccId(getStrippedIccid(iccId)); int subId; if (subInfo != null) { subId = subInfo.getSubscriptionId(); Loading @@ -4466,7 +4485,7 @@ public class SubscriptionManagerService extends ISub.Stub { } else { // If iccId is new, add a subscription record in the database so it can be // activated later. (Pre-U behavior) subId = insertSubscriptionInfo(IccUtils.stripTrailingFs(iccId), subId = insertSubscriptionInfo(getStrippedIccid(iccId), SubscriptionManager.INVALID_SIM_SLOT_INDEX, "", SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM); mSubscriptionDatabaseManager.setDisplayName(subId, Loading tests/telephonytests/src/com/android/internal/telephony/subscription/SubscriptionDatabaseManagerTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -75,6 +75,10 @@ public class SubscriptionDatabaseManagerTest extends TelephonyTest { static final String FAKE_DEFAULT_CARD_NAME = "CARD %d"; static final String FAKE_ICCID1 = "123456"; static final String FAKE_ICCID2 = "456789"; static final String FAKE_ICCID3 = "12345F"; static final String FAKE_ICCID4 = "00:1A:2B:3C:4D:5F"; static final String FAKE_PHONE_NUMBER1 = "9995551234"; static final String FAKE_PHONE_NUMBER2 = "9998887777"; static final String FAKE_CARRIER_NAME1 = "A-Mobile"; Loading tests/telephonytests/src/com/android/internal/telephony/subscription/SubscriptionManagerServiceTest.java +11 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,8 @@ import static com.android.internal.telephony.subscription.SubscriptionDatabaseMa import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_HPLMNS1; import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_ICCID1; import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_ICCID2; import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_ICCID3; import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_ICCID4; import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_IMSI1; import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_MAC_ADDRESS1; import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_MAC_ADDRESS2; Loading Loading @@ -3742,4 +3744,13 @@ public class SubscriptionManagerServiceTest extends TelephonyTest { assertThat(mSubscriptionManagerServiceUT.getActiveSubscriptionInfoList( CALLING_PACKAGE, CALLING_FEATURE, true)).isEmpty(); } @Test @EnableCompatChanges({TelephonyManager.ENABLE_FEATURE_MAPPING}) public void testIccIdStripping() { assertThat(SubscriptionManagerService.getStrippedIccid(FAKE_ICCID1)).isEqualTo(FAKE_ICCID1); assertThat(SubscriptionManagerService.getStrippedIccid(FAKE_ICCID2)).isEqualTo(FAKE_ICCID2); assertThat(SubscriptionManagerService.getStrippedIccid(FAKE_ICCID3)).isEqualTo("12345"); assertThat(SubscriptionManagerService.getStrippedIccid(FAKE_ICCID4)).isEqualTo(FAKE_ICCID4); } } Loading
src/java/com/android/internal/telephony/subscription/SubscriptionManagerService.java +30 −11 Original line number Diff line number Diff line Loading @@ -141,6 +141,8 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executor; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; Loading @@ -157,9 +159,6 @@ public class SubscriptionManagerService extends ISub.Stub { private static final int CHECK_BOOTSTRAP_TIMER_IN_MS = 20 * 60 * 1000; // 20 minutes private static CountDownTimer bootstrapProvisioningTimer; /** Whether enabling verbose debugging message or not. */ private static final boolean VDBG = false; /** * The columns in {@link SimInfo} table that can be directly accessed through * {@link #getSubscriptionProperty(int, String, String, String)} or Loading Loading @@ -235,6 +234,11 @@ public class SubscriptionManagerService extends ISub.Stub { @NonNull private static final BinderWrapper BINDER_WRAPPER = new BinderWrapper(); /** Regular expression to determine if a string is in MAC address format. */ private static final Pattern MAC_ADDRESS_PATTERN = Pattern.compile( // Matches formats like 00:1B:44:11:3A:B7 or 00-1B-44-11-3A-B7 "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$"); /** Instance of subscription manager service. */ @NonNull private static SubscriptionManagerService sInstance; Loading Loading @@ -869,6 +873,22 @@ public class SubscriptionManagerService extends ISub.Stub { return result.build(); } /** * Get the stripped ICCID, which sometimes ended with 'F'. Also not doing this if the ICCID * is MAC address (used by texting through bluetooth). * * @param iccId The original ICCID. * @return The fixed ICCID. */ @VisibleForTesting @NonNull public static String getStrippedIccid(@NonNull String iccId) { Matcher matcher = MAC_ADDRESS_PATTERN.matcher(iccId); if (matcher.matches()) return iccId; return TextUtils.emptyIfNull(IccUtils.stripTrailingFs(iccId)); } /** * @return The list of ICCIDs from the inserted physical SIMs. */ Loading @@ -884,7 +904,7 @@ public class SubscriptionManagerService extends ISub.Stub { // Non euicc slots will have single port, so use default port index. String iccId = uiccSlot.getIccId(TelephonyManager.DEFAULT_PORT_INDEX); if (!TextUtils.isEmpty(iccId)) { iccidList.add(IccUtils.stripTrailingFs(iccId)); iccidList.add(getStrippedIccid(iccId)); } } } Loading Loading @@ -1393,7 +1413,7 @@ public class SubscriptionManagerService extends ISub.Stub { } SubscriptionInfoInternal subInfo = mSubscriptionDatabaseManager .getSubscriptionInfoInternalByIccId(IccUtils.stripTrailingFs(iccId)); .getSubscriptionInfoInternalByIccId(getStrippedIccid(iccId)); return subInfo != null && subInfo.areUiccApplicationsEnabled(); } Loading @@ -1407,8 +1427,7 @@ public class SubscriptionManagerService extends ISub.Stub { @NonNull private String getIccId(int phoneId) { UiccPort port = mUiccController.getUiccPort(phoneId); return (port == null) ? "" : TextUtils.emptyIfNull( IccUtils.stripTrailingFs(port.getIccId())); return (port == null) ? "" : getStrippedIccid(port.getIccId()); } /** Loading Loading @@ -2018,7 +2037,7 @@ public class SubscriptionManagerService extends ISub.Stub { final long identity = Binder.clearCallingIdentity(); try { iccId = IccUtils.stripTrailingFs(iccId); iccId = getStrippedIccid(iccId); SubscriptionInfoInternal subInfo = mSubscriptionDatabaseManager .getSubscriptionInfoInternalByIccId(iccId); Loading Loading @@ -2352,7 +2371,7 @@ public class SubscriptionManagerService extends ISub.Stub { return -1; } iccId = IccUtils.stripTrailingFs(iccId); iccId = getStrippedIccid(iccId); SubscriptionInfoInternal subInfo = mSubscriptionDatabaseManager .getSubscriptionInfoInternalByIccId(iccId); Loading Loading @@ -4457,7 +4476,7 @@ public class SubscriptionManagerService extends ISub.Stub { // When port is inactive, sometimes valid iccid is present in the slot status, // hence update the portIndex. (Pre-U behavior) SubscriptionInfoInternal subInfo = mSubscriptionDatabaseManager .getSubscriptionInfoInternalByIccId(IccUtils.stripTrailingFs(iccId)); .getSubscriptionInfoInternalByIccId(getStrippedIccid(iccId)); int subId; if (subInfo != null) { subId = subInfo.getSubscriptionId(); Loading @@ -4466,7 +4485,7 @@ public class SubscriptionManagerService extends ISub.Stub { } else { // If iccId is new, add a subscription record in the database so it can be // activated later. (Pre-U behavior) subId = insertSubscriptionInfo(IccUtils.stripTrailingFs(iccId), subId = insertSubscriptionInfo(getStrippedIccid(iccId), SubscriptionManager.INVALID_SIM_SLOT_INDEX, "", SubscriptionManager.SUBSCRIPTION_TYPE_LOCAL_SIM); mSubscriptionDatabaseManager.setDisplayName(subId, Loading
tests/telephonytests/src/com/android/internal/telephony/subscription/SubscriptionDatabaseManagerTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -75,6 +75,10 @@ public class SubscriptionDatabaseManagerTest extends TelephonyTest { static final String FAKE_DEFAULT_CARD_NAME = "CARD %d"; static final String FAKE_ICCID1 = "123456"; static final String FAKE_ICCID2 = "456789"; static final String FAKE_ICCID3 = "12345F"; static final String FAKE_ICCID4 = "00:1A:2B:3C:4D:5F"; static final String FAKE_PHONE_NUMBER1 = "9995551234"; static final String FAKE_PHONE_NUMBER2 = "9998887777"; static final String FAKE_CARRIER_NAME1 = "A-Mobile"; Loading
tests/telephonytests/src/com/android/internal/telephony/subscription/SubscriptionManagerServiceTest.java +11 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,8 @@ import static com.android.internal.telephony.subscription.SubscriptionDatabaseMa import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_HPLMNS1; import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_ICCID1; import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_ICCID2; import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_ICCID3; import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_ICCID4; import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_IMSI1; import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_MAC_ADDRESS1; import static com.android.internal.telephony.subscription.SubscriptionDatabaseManagerTest.FAKE_MAC_ADDRESS2; Loading Loading @@ -3742,4 +3744,13 @@ public class SubscriptionManagerServiceTest extends TelephonyTest { assertThat(mSubscriptionManagerServiceUT.getActiveSubscriptionInfoList( CALLING_PACKAGE, CALLING_FEATURE, true)).isEmpty(); } @Test @EnableCompatChanges({TelephonyManager.ENABLE_FEATURE_MAPPING}) public void testIccIdStripping() { assertThat(SubscriptionManagerService.getStrippedIccid(FAKE_ICCID1)).isEqualTo(FAKE_ICCID1); assertThat(SubscriptionManagerService.getStrippedIccid(FAKE_ICCID2)).isEqualTo(FAKE_ICCID2); assertThat(SubscriptionManagerService.getStrippedIccid(FAKE_ICCID3)).isEqualTo("12345"); assertThat(SubscriptionManagerService.getStrippedIccid(FAKE_ICCID4)).isEqualTo(FAKE_ICCID4); } }