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

Commit 60aa3c07 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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

parents 4b11a165 6f1e11c1
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;
@@ -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;
    }
+12 −0
Original line number Diff line number Diff line
@@ -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 {
@@ -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}));
    }
}