Loading src/java/com/android/internal/telephony/SubscriptionController.java +40 −0 Original line number Diff line number Diff line Loading @@ -62,6 +62,7 @@ import com.android.internal.telephony.metrics.TelephonyMetrics; import com.android.internal.telephony.uicc.IccUtils; import com.android.internal.telephony.uicc.UiccCard; import com.android.internal.telephony.uicc.UiccController; import com.android.internal.telephony.uicc.UiccSlot; import com.android.internal.telephony.util.ArrayUtils; import com.android.internal.telephony.util.TelephonyUtils; import com.android.telephony.Rlog; Loading Loading @@ -860,6 +861,12 @@ public class SubscriptionController extends ISub.Stub { selection += " OR " + SubscriptionManager.IS_EMBEDDED + "=1"; } List<String> iccIds = getIccIdsOfInsertedSims(); if (!iccIds.isEmpty()) { selection += " OR (" + getSelectionForIccIdList(iccIds.toArray(new String[0])) + ")"; } List<SubscriptionInfo> subList = getSubInfo(selection, null /* queryKey */); if (subList != null) { Loading @@ -876,6 +883,22 @@ public class SubscriptionController extends ISub.Stub { } } private List<String> getIccIdsOfInsertedSims() { List<String> ret = new ArrayList<>(); UiccSlot[] uiccSlots = UiccController.getInstance().getUiccSlots(); if (uiccSlots == null) return ret; for (UiccSlot uiccSlot : uiccSlots) { if (uiccSlot != null && uiccSlot.getCardState() != null && uiccSlot.getCardState().isCardPresent() && !TextUtils.isEmpty(uiccSlot.getIccId())) { ret.add(uiccSlot.getIccId()); } } return ret; } @Override public List<SubscriptionInfo> getAccessibleSubscriptionInfoList(String callingPackage) { EuiccManager euiccManager = (EuiccManager) mContext.getSystemService(Context.EUICC_SERVICE); Loading Loading @@ -3300,6 +3323,23 @@ public class SubscriptionController extends ISub.Stub { return selection.toString(); } /** * Helper function to create selection argument of a list of subId. * The result should be: "in (iccId1, iccId2, ...)". */ private String getSelectionForIccIdList(String[] iccIds) { StringBuilder selection = new StringBuilder(); selection.append(SubscriptionManager.ICC_ID); selection.append(" IN ("); for (int i = 0; i < iccIds.length - 1; i++) { selection.append("\"" + iccIds[i] + "\", "); } selection.append("\"" + iccIds[iccIds.length - 1] + "\""); selection.append(")"); return selection.toString(); } /** * Get subscriptionInfo list of subscriptions that are in the same group of given subId. * See {@link #createSubscriptionGroup(int[], String)} for more details. Loading tests/telephonytests/src/com/android/internal/telephony/SubscriptionControllerTest.java +39 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,8 @@ */ package com.android.internal.telephony; import static com.android.internal.telephony.uicc.IccCardStatus.CardState.CARDSTATE_PRESENT; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; Loading Loading @@ -45,6 +47,7 @@ import android.test.suitebuilder.annotation.SmallTest; import androidx.test.filters.FlakyTest; import com.android.internal.telephony.uicc.IccCardStatus; import com.android.internal.telephony.uicc.UiccController; import com.android.internal.telephony.uicc.UiccSlot; Loading Loading @@ -1091,4 +1094,40 @@ public class SubscriptionControllerTest extends TelephonyTest { > mSubscriptionControllerUT.getNameSourcePriority( SubscriptionManager.NAME_SOURCE_DEFAULT)); } @Test @SmallTest public void testGetAvailableSubscriptionList() throws Exception { // TODO b/123300875 slot index 1 is not expected to be valid mSubscriptionControllerUT.addSubInfoRecord("123", 1); // sub 1 mSubscriptionControllerUT.addSubInfoRecord("456", 0); // sub 2 List<SubscriptionInfo> infoList = mSubscriptionControllerUT .getAvailableSubscriptionInfoList(mCallingPackage, mCallingFeature); assertEquals(2, infoList.size()); assertEquals("456", infoList.get(0).getIccId()); assertEquals("123", infoList.get(1).getIccId()); // Remove "123" from active sim list but have it inserted. UiccSlot[] uiccSlots = {mUiccSlot}; IccCardStatus.CardState cardState = CARDSTATE_PRESENT; doReturn(uiccSlots).when(mUiccController).getUiccSlots(); doReturn(cardState).when(mUiccSlot).getCardState(); doReturn("123").when(mUiccSlot).getIccId(); mSubscriptionControllerUT.clearSubInfoRecord(1); // Active sub list should return 1 now. infoList = mSubscriptionControllerUT .getActiveSubscriptionInfoList(mCallingPackage, mCallingFeature); assertEquals(1, infoList.size()); assertEquals("456", infoList.get(0).getIccId()); // Available sub list should still return two. infoList = mSubscriptionControllerUT .getAvailableSubscriptionInfoList(mCallingPackage, mCallingFeature); assertEquals(2, infoList.size()); assertEquals("123", infoList.get(0).getIccId()); assertEquals("456", infoList.get(1).getIccId()); } } Loading
src/java/com/android/internal/telephony/SubscriptionController.java +40 −0 Original line number Diff line number Diff line Loading @@ -62,6 +62,7 @@ import com.android.internal.telephony.metrics.TelephonyMetrics; import com.android.internal.telephony.uicc.IccUtils; import com.android.internal.telephony.uicc.UiccCard; import com.android.internal.telephony.uicc.UiccController; import com.android.internal.telephony.uicc.UiccSlot; import com.android.internal.telephony.util.ArrayUtils; import com.android.internal.telephony.util.TelephonyUtils; import com.android.telephony.Rlog; Loading Loading @@ -860,6 +861,12 @@ public class SubscriptionController extends ISub.Stub { selection += " OR " + SubscriptionManager.IS_EMBEDDED + "=1"; } List<String> iccIds = getIccIdsOfInsertedSims(); if (!iccIds.isEmpty()) { selection += " OR (" + getSelectionForIccIdList(iccIds.toArray(new String[0])) + ")"; } List<SubscriptionInfo> subList = getSubInfo(selection, null /* queryKey */); if (subList != null) { Loading @@ -876,6 +883,22 @@ public class SubscriptionController extends ISub.Stub { } } private List<String> getIccIdsOfInsertedSims() { List<String> ret = new ArrayList<>(); UiccSlot[] uiccSlots = UiccController.getInstance().getUiccSlots(); if (uiccSlots == null) return ret; for (UiccSlot uiccSlot : uiccSlots) { if (uiccSlot != null && uiccSlot.getCardState() != null && uiccSlot.getCardState().isCardPresent() && !TextUtils.isEmpty(uiccSlot.getIccId())) { ret.add(uiccSlot.getIccId()); } } return ret; } @Override public List<SubscriptionInfo> getAccessibleSubscriptionInfoList(String callingPackage) { EuiccManager euiccManager = (EuiccManager) mContext.getSystemService(Context.EUICC_SERVICE); Loading Loading @@ -3300,6 +3323,23 @@ public class SubscriptionController extends ISub.Stub { return selection.toString(); } /** * Helper function to create selection argument of a list of subId. * The result should be: "in (iccId1, iccId2, ...)". */ private String getSelectionForIccIdList(String[] iccIds) { StringBuilder selection = new StringBuilder(); selection.append(SubscriptionManager.ICC_ID); selection.append(" IN ("); for (int i = 0; i < iccIds.length - 1; i++) { selection.append("\"" + iccIds[i] + "\", "); } selection.append("\"" + iccIds[iccIds.length - 1] + "\""); selection.append(")"); return selection.toString(); } /** * Get subscriptionInfo list of subscriptions that are in the same group of given subId. * See {@link #createSubscriptionGroup(int[], String)} for more details. Loading
tests/telephonytests/src/com/android/internal/telephony/SubscriptionControllerTest.java +39 −0 Original line number Diff line number Diff line Loading @@ -15,6 +15,8 @@ */ package com.android.internal.telephony; import static com.android.internal.telephony.uicc.IccCardStatus.CardState.CARDSTATE_PRESENT; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; Loading Loading @@ -45,6 +47,7 @@ import android.test.suitebuilder.annotation.SmallTest; import androidx.test.filters.FlakyTest; import com.android.internal.telephony.uicc.IccCardStatus; import com.android.internal.telephony.uicc.UiccController; import com.android.internal.telephony.uicc.UiccSlot; Loading Loading @@ -1091,4 +1094,40 @@ public class SubscriptionControllerTest extends TelephonyTest { > mSubscriptionControllerUT.getNameSourcePriority( SubscriptionManager.NAME_SOURCE_DEFAULT)); } @Test @SmallTest public void testGetAvailableSubscriptionList() throws Exception { // TODO b/123300875 slot index 1 is not expected to be valid mSubscriptionControllerUT.addSubInfoRecord("123", 1); // sub 1 mSubscriptionControllerUT.addSubInfoRecord("456", 0); // sub 2 List<SubscriptionInfo> infoList = mSubscriptionControllerUT .getAvailableSubscriptionInfoList(mCallingPackage, mCallingFeature); assertEquals(2, infoList.size()); assertEquals("456", infoList.get(0).getIccId()); assertEquals("123", infoList.get(1).getIccId()); // Remove "123" from active sim list but have it inserted. UiccSlot[] uiccSlots = {mUiccSlot}; IccCardStatus.CardState cardState = CARDSTATE_PRESENT; doReturn(uiccSlots).when(mUiccController).getUiccSlots(); doReturn(cardState).when(mUiccSlot).getCardState(); doReturn("123").when(mUiccSlot).getIccId(); mSubscriptionControllerUT.clearSubInfoRecord(1); // Active sub list should return 1 now. infoList = mSubscriptionControllerUT .getActiveSubscriptionInfoList(mCallingPackage, mCallingFeature); assertEquals(1, infoList.size()); assertEquals("456", infoList.get(0).getIccId()); // Available sub list should still return two. infoList = mSubscriptionControllerUT .getAvailableSubscriptionInfoList(mCallingPackage, mCallingFeature); assertEquals(2, infoList.size()); assertEquals("123", infoList.get(0).getIccId()); assertEquals("456", infoList.get(1).getIccId()); } }