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

Commit c926ab85 authored by Jack Yu's avatar Jack Yu Committed by android-build-merger
Browse files

Merge "Fixed that active sub ids are not sorted by slot index"

am: ef96bb25

Change-Id: I20464e96ac1671a4b6cc5193c72a37bf1652ffcb
parents 9e1f2d0b ef96bb25
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}));
    }
}