Loading src/java/com/android/internal/telephony/SubscriptionController.java +7 −12 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.internal.telephony; import static android.content.pm.PackageManager.PERMISSION_GRANTED; import android.Manifest; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.AppOpsManager; import android.app.PendingIntent; Loading Loading @@ -1968,20 +1969,14 @@ public class SubscriptionController extends ISub.Stub { * @return the list of subId's that are active, is never null but the length maybe 0. */ @Override public int[] getActiveSubIdList() { Set<Entry<Integer, Integer>> simInfoSet = new HashSet<>(sSlotIndexToSubId.entrySet()); int[] subIdArr = new int[simInfoSet.size()]; int i = 0; for (Entry<Integer, Integer> entry: simInfoSet) { int sub = entry.getValue(); subIdArr[i] = sub; i++; } public @NonNull int[] getActiveSubIdList() { int[] subIdArr = sSlotIndexToSubId.keySet().stream() .sorted() .mapToInt(slotId -> sSlotIndexToSubId.get(slotId)) .toArray(); if (VDBG) { logdl("[getActiveSubIdList] simInfoSet=" + simInfoSet + " subIdArr.length=" + subIdArr.length); logdl("[getActiveSubIdList] subIdArr=" + Arrays.toString(subIdArr)); } return subIdArr; } Loading tests/telephonytests/src/com/android/internal/telephony/SubscriptionControllerTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import java.util.Arrays; import java.util.List; public class SubscriptionControllerTest extends TelephonyTest { Loading Loading @@ -585,4 +586,15 @@ public class SubscriptionControllerTest extends TelephonyTest { doReturn(mTelephonyRegisteryMock).when(mTelephonyRegisteryMock) .queryLocalInterface(anyString()); } @Test @SmallTest public void testGetActiveSubIdList() throws Exception { mSubscriptionControllerUT.addSubInfoRecord("123", 1); // sub 1 mSubscriptionControllerUT.addSubInfoRecord("456", 0); // sub 2 // Make sure the return sub ids are sorted by slot index assertTrue("active sub ids = " + mSubscriptionControllerUT.getActiveSubIdList(), Arrays.equals(mSubscriptionControllerUT.getActiveSubIdList(), new int[]{2, 1})); } } Loading
src/java/com/android/internal/telephony/SubscriptionController.java +7 −12 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.internal.telephony; import static android.content.pm.PackageManager.PERMISSION_GRANTED; import android.Manifest; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.AppOpsManager; import android.app.PendingIntent; Loading Loading @@ -1968,20 +1969,14 @@ public class SubscriptionController extends ISub.Stub { * @return the list of subId's that are active, is never null but the length maybe 0. */ @Override public int[] getActiveSubIdList() { Set<Entry<Integer, Integer>> simInfoSet = new HashSet<>(sSlotIndexToSubId.entrySet()); int[] subIdArr = new int[simInfoSet.size()]; int i = 0; for (Entry<Integer, Integer> entry: simInfoSet) { int sub = entry.getValue(); subIdArr[i] = sub; i++; } public @NonNull int[] getActiveSubIdList() { int[] subIdArr = sSlotIndexToSubId.keySet().stream() .sorted() .mapToInt(slotId -> sSlotIndexToSubId.get(slotId)) .toArray(); if (VDBG) { logdl("[getActiveSubIdList] simInfoSet=" + simInfoSet + " subIdArr.length=" + subIdArr.length); logdl("[getActiveSubIdList] subIdArr=" + Arrays.toString(subIdArr)); } return subIdArr; } Loading
tests/telephonytests/src/com/android/internal/telephony/SubscriptionControllerTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import java.util.Arrays; import java.util.List; public class SubscriptionControllerTest extends TelephonyTest { Loading Loading @@ -585,4 +586,15 @@ public class SubscriptionControllerTest extends TelephonyTest { doReturn(mTelephonyRegisteryMock).when(mTelephonyRegisteryMock) .queryLocalInterface(anyString()); } @Test @SmallTest public void testGetActiveSubIdList() throws Exception { mSubscriptionControllerUT.addSubInfoRecord("123", 1); // sub 1 mSubscriptionControllerUT.addSubInfoRecord("456", 0); // sub 2 // Make sure the return sub ids are sorted by slot index assertTrue("active sub ids = " + mSubscriptionControllerUT.getActiveSubIdList(), Arrays.equals(mSubscriptionControllerUT.getActiveSubIdList(), new int[]{2, 1})); } }