Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 73de6529 authored by Jack Yu's avatar Jack Yu
Browse files

Fixed that active sub ids are not sorted by slot index

Test: Unit tests
Bug: 119223420
Merged-In: Ife0f41762b471a0d22a9dab442a6d844ade1f093
Change-Id: Ife0f41762b471a0d22a9dab442a6d844ade1f093
(cherry picked from commit 6f1e11c1)
parent 62932ba3
Loading
Loading
Loading
Loading
+7 −12
Original line number Diff line number Diff line
@@ -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;
@@ -1917,20 +1918,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;
    }
+12 −0
Original line number Diff line number Diff line
@@ -45,6 +45,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 {
@@ -522,4 +523,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}));
    }
}