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