Loading src/com/android/settings/network/telephony/SubscriptionRepository.kt +9 −1 Original line number Diff line number Diff line Loading @@ -124,6 +124,14 @@ fun Context.getSelectableSubscriptionInfoList(): List<SubscriptionInfo> { } } // Matching the sorting order in SubscriptionManagerService.getAvailableSubscriptionInfoList .sortedWith(compareBy({ it.simSlotIndex }, { it.subscriptionId })) .sortedWith(compareBy({ it.sortableSimSlotIndex }, { it.subscriptionId })) .also { Log.d(TAG, "getSelectableSubscriptionInfoList: $it") } } /** Subscription with invalid sim slot index has lowest sort order. */ private val SubscriptionInfo.sortableSimSlotIndex: Int get() = if (simSlotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { simSlotIndex } else { Int.MAX_VALUE } tests/spa_unit/src/com/android/settings/network/telephony/SubscriptionRepositoryTest.kt +21 −0 Original line number Diff line number Diff line Loading @@ -115,6 +115,27 @@ class SubscriptionRepositoryTest { .containsExactly(SIM_SLOT_INDEX_0, SIM_SLOT_INDEX_1).inOrder() } @Test fun getSelectableSubscriptionInfoList_oneNotInSlot_inSlotSortedFirst() { mockSubscriptionManager.stub { on { getAvailableSubscriptionInfoList() } doReturn listOf( SubscriptionInfo.Builder().apply { setSimSlotIndex(SubscriptionManager.INVALID_SIM_SLOT_INDEX) setId(SUB_ID_3_NOT_IN_SLOT) }.build(), SubscriptionInfo.Builder().apply { setSimSlotIndex(SIM_SLOT_INDEX_1) setId(SUB_ID_IN_SLOT_1) }.build(), ) } val subInfos = context.getSelectableSubscriptionInfoList() assertThat(subInfos.map { it.simSlotIndex }) .containsExactly(SIM_SLOT_INDEX_1, SubscriptionManager.INVALID_SIM_SLOT_INDEX).inOrder() } @Test fun getSelectableSubscriptionInfoList_sameGroupAndOneHasSlot_returnTheOneWithSimSlotIndex() { mockSubscriptionManager.stub { Loading Loading
src/com/android/settings/network/telephony/SubscriptionRepository.kt +9 −1 Original line number Diff line number Diff line Loading @@ -124,6 +124,14 @@ fun Context.getSelectableSubscriptionInfoList(): List<SubscriptionInfo> { } } // Matching the sorting order in SubscriptionManagerService.getAvailableSubscriptionInfoList .sortedWith(compareBy({ it.simSlotIndex }, { it.subscriptionId })) .sortedWith(compareBy({ it.sortableSimSlotIndex }, { it.subscriptionId })) .also { Log.d(TAG, "getSelectableSubscriptionInfoList: $it") } } /** Subscription with invalid sim slot index has lowest sort order. */ private val SubscriptionInfo.sortableSimSlotIndex: Int get() = if (simSlotIndex != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { simSlotIndex } else { Int.MAX_VALUE }
tests/spa_unit/src/com/android/settings/network/telephony/SubscriptionRepositoryTest.kt +21 −0 Original line number Diff line number Diff line Loading @@ -115,6 +115,27 @@ class SubscriptionRepositoryTest { .containsExactly(SIM_SLOT_INDEX_0, SIM_SLOT_INDEX_1).inOrder() } @Test fun getSelectableSubscriptionInfoList_oneNotInSlot_inSlotSortedFirst() { mockSubscriptionManager.stub { on { getAvailableSubscriptionInfoList() } doReturn listOf( SubscriptionInfo.Builder().apply { setSimSlotIndex(SubscriptionManager.INVALID_SIM_SLOT_INDEX) setId(SUB_ID_3_NOT_IN_SLOT) }.build(), SubscriptionInfo.Builder().apply { setSimSlotIndex(SIM_SLOT_INDEX_1) setId(SUB_ID_IN_SLOT_1) }.build(), ) } val subInfos = context.getSelectableSubscriptionInfoList() assertThat(subInfos.map { it.simSlotIndex }) .containsExactly(SIM_SLOT_INDEX_1, SubscriptionManager.INVALID_SIM_SLOT_INDEX).inOrder() } @Test fun getSelectableSubscriptionInfoList_sameGroupAndOneHasSlot_returnTheOneWithSimSlotIndex() { mockSubscriptionManager.stub { Loading