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

Commit 4683a7b1 authored by Grant Menke's avatar Grant Menke Committed by Brad Ebinger
Browse files

Update PhoneConfigurationManager to support SimultaneousCallingRestrictionsTest.

This CL makes minor updates to PhoneConfigurationmanager in order to support
the implementation of SCRT:
1) Fixes a bug a PhoneConfigurationManagerTest and SimultaneeousCallingTrackerTest
where we were sending an int[] instead of an ArrayList for the enabledLogicalSlots.
2) Fixes a bug where the PhoneCapability was not being updated properly when the
modem moves from unavailable -> available, which would cause CTS flakiness. We
now re-requery the modem once when the modem moves to available state.

Test: atest SimultaneousCallingRestrictionsTest
Bug: 328293858
Change-Id: I1113ecd76807da6aa6b982880fac0c68e808e8bb
parent cb91ac09
Loading
Loading
Loading
Loading
+44 −22
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import com.android.telephony.Rlog;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
@@ -97,7 +98,9 @@ public class PhoneConfigurationManager {

    private static PhoneConfigurationManager sInstance = null;
    private final Context mContext;
    private PhoneCapability mStaticCapability;
    // Static capability retrieved from the modem - may be null in the case where no info has been
    // retrieved yet.
    private PhoneCapability mStaticCapability = null;
    private final Set<Integer> mSlotsSupportingSimultaneousCellularCalls = new HashSet<>(3);
    private final Set<Integer> mSubIdsSupportingSimultaneousCellularCalls = new HashSet<>(3);
    private final HashSet<Consumer<Set<Integer>>> mSimultaneousCellularCallingListeners =
@@ -151,8 +154,6 @@ public class PhoneConfigurationManager {
        mFeatureFlags = featureFlags;
        // TODO: send commands to modem once interface is ready.
        mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        //initialize with default, it'll get updated when RADIO is ON/AVAILABLE
        mStaticCapability = getDefaultCapability();
        mRadioConfig = RadioConfig.getInstance();
        mHandler = new ConfigManagerHandler();
        mPhoneStatusMap = new HashMap<>();
@@ -256,7 +257,8 @@ public class PhoneConfigurationManager {
        boolean halSupportSimulCalling = mRadioConfig != null
                && mRadioConfig.getRadioConfigProxy(null).getVersion().greaterOrEqual(
                        RIL.RADIO_HAL_VERSION_2_2)
                && getPhoneCount() > 1 && mStaticCapability.getMaxActiveVoiceSubscriptions() > 1;
                && getPhoneCount() > 1
                && getCellularStaticPhoneCapability().getMaxActiveVoiceSubscriptions() > 1;
        // Register for simultaneous calling support changes in the modem if the HAL supports it
        if (halSupportSimulCalling) {
            updateSimultaneousCallingSupport();
@@ -318,7 +320,7 @@ public class PhoneConfigurationManager {
                        log("Unable to add phoneStatus to cache. "
                                + "No phone object provided for event " + msg.what);
                    }
                    getStaticPhoneCapability();
                    updateRadioCapability();
                    break;
                case EVENT_SWITCH_DSDS_CONFIG_DONE:
                    ar = (AsyncResult) msg.obj;
@@ -343,7 +345,7 @@ public class PhoneConfigurationManager {
                case EVENT_GET_PHONE_CAPABILITY_DONE:
                    ar = (AsyncResult) msg.obj;
                    if (ar != null && ar.exception == null) {
                        mStaticCapability = (PhoneCapability) ar.result;
                        setStaticPhoneCapability((PhoneCapability) ar.result);
                        notifyCapabilityChanged();
                        for (Listener l : mListeners) {
                            l.onPhoneCapabilityChanged();
@@ -376,12 +378,12 @@ public class PhoneConfigurationManager {
                    }
                    ar = (AsyncResult) msg.obj;
                    if (ar != null && ar.exception == null) {
                        int[] returnedIntArray = (int[]) ar.result;
                        List<Integer> returnedArrayList = (List<Integer>) ar.result;
                        if (!mSlotsSupportingSimultaneousCellularCalls.isEmpty()) {
                            mSlotsSupportingSimultaneousCellularCalls.clear();
                        }
                        int maxValidPhoneSlot = getPhoneCount() - 1;
                        for (int i : returnedIntArray) {
                        for (int i : returnedArrayList) {
                            if (i < 0 || i > maxValidPhoneSlot) {
                                loge("Invalid slot supporting DSDA =" + i + ". Disabling DSDA.");
                                mSlotsSupportingSimultaneousCellularCalls.clear();
@@ -534,20 +536,42 @@ public class PhoneConfigurationManager {
    }

    /**
     * get static overall phone capabilities for all phones.
     * @return static overall phone capabilities for all phones, including voice overrides.
     */
    public synchronized PhoneCapability getStaticPhoneCapability() {
        if (getDefaultCapability().equals(mStaticCapability)) {
            log("getStaticPhoneCapability: sending the request for getting PhoneCapability");
            Message callback = Message.obtain(
                    mHandler, EVENT_GET_PHONE_CAPABILITY_DONE);
            mRadioConfig.getPhoneCapability(callback);
        boolean isDefault = mStaticCapability == null;
        PhoneCapability caps = isDefault ? getDefaultCapability() : mStaticCapability;
        caps = maybeOverrideMaxActiveVoiceSubscriptions(caps);
        log("getStaticPhoneCapability: isDefault=" + isDefault + ", caps=" + caps);
        return caps;
    }
        mStaticCapability = maybeOverrideMaxActiveVoiceSubscriptions(mStaticCapability);
        log("getStaticPhoneCapability: mStaticCapability " + mStaticCapability);

    /**
     * @return untouched capabilities returned from the modem
     */
    private synchronized PhoneCapability getCellularStaticPhoneCapability() {
        log("getCellularStaticPhoneCapability: mStaticCapability " + mStaticCapability);
        return mStaticCapability;
    }

    /**
     * Caches the static PhoneCapability returned by the modem
     */
    public synchronized void setStaticPhoneCapability(PhoneCapability capability) {
        log("setStaticPhoneCapability: mStaticCapability " + capability);
        mStaticCapability = capability;
    }

    /**
     * Query the modem to return its static PhoneCapability and cache it
     */
    @VisibleForTesting
    public void updateRadioCapability() {
        log("updateRadioCapability: sending the request for getting PhoneCapability");
        Message callback = Message.obtain(mHandler, EVENT_GET_PHONE_CAPABILITY_DONE);
        mRadioConfig.getPhoneCapability(callback);
    }

    /**
     * get configuration related status of each phone.
     */
@@ -556,12 +580,11 @@ public class PhoneConfigurationManager {
    }

    public int getNumberOfModemsWithSimultaneousDataConnections() {
        return mStaticCapability.getMaxActiveDataSubscriptions();
        return getStaticPhoneCapability().getMaxActiveDataSubscriptions();
    }

    public int getNumberOfModemsWithSimultaneousVoiceConnections() {
        return maybeOverrideMaxActiveVoiceSubscriptions(mStaticCapability)
                .getMaxActiveVoiceSubscriptions();
        return getStaticPhoneCapability().getMaxActiveVoiceSubscriptions();
    }

    public boolean isVirtualDsdaEnabled() {
@@ -591,8 +614,7 @@ public class PhoneConfigurationManager {
    }

    private void notifyCapabilityChanged() {
        mNotifier.notifyPhoneCapabilityChanged(maybeOverrideMaxActiveVoiceSubscriptions(
                mStaticCapability));
        mNotifier.notifyPhoneCapabilityChanged(getStaticPhoneCapability());
    }

    /**
+5 −3
Original line number Diff line number Diff line
@@ -17,14 +17,14 @@
package com.android.internal.telephony;

import android.os.AsyncResult;
import android.os.RemoteException;
import android.os.Trace;

import com.android.internal.telephony.uicc.IccSlotStatus;
import com.android.telephony.Rlog;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * This class is the AIDL implementation of IRadioConfigIndication interface.
@@ -58,9 +58,11 @@ public class RadioConfigIndicationAidl extends
     */
    @Override
    public void onSimultaneousCallingSupportChanged(int[] enabledLogicalSlots) {
        ArrayList<Integer> ret = RILUtils.primitiveArrayToArrayList(enabledLogicalSlots);
        List<Integer> ret = (enabledLogicalSlots == null) ? Collections.emptyList() :
                RILUtils.primitiveArrayToArrayList(enabledLogicalSlots);
        logd("onSimultaneousCallingSupportChanged: enabledLogicalSlots = " + ret);
        if (mRadioConfig.mSimultaneousCallingSupportStatusRegistrant != null) {
            logd("onSimultaneousCallingSupportChanged: notifying registrant");
            mRadioConfig.mSimultaneousCallingSupportStatusRegistrant.notifyRegistrant(
                    new AsyncResult(null, ret, null));
        }
+11 −8
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -157,6 +158,7 @@ public class PhoneConfigurationManagerTest extends TelephonyTest {
        init(1);
        assertEquals(PhoneCapability.DEFAULT_SSSS_CAPABILITY, mPcm.getStaticPhoneCapability());

        mPcm.updateRadioCapability();
        setAndVerifyStaticCapability(PhoneCapability.DEFAULT_DSDS_CAPABILITY);
    }

@@ -171,6 +173,7 @@ public class PhoneConfigurationManagerTest extends TelephonyTest {
                .setMaxActiveVoiceSubscriptions(2)
                .build();

        mPcm.updateRadioCapability();
        ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
        verify(mMockRadioConfig).getPhoneCapability(captor.capture());
        Message msg = captor.getValue();
@@ -188,7 +191,7 @@ public class PhoneConfigurationManagerTest extends TelephonyTest {
        init(2);
        mPcm.updateSimultaneousCallingSupport();

        int[] enabledLogicalSlots = {0, 1};
        List<Integer> enabledLogicalSlots = Arrays.asList(0, 1);
        ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
        verify(mMockRadioConfig).updateSimultaneousCallingSupport(captor.capture());
        Message msg = captor.getValue();
@@ -209,7 +212,7 @@ public class PhoneConfigurationManagerTest extends TelephonyTest {
        mPcm.updateSimultaneousCallingSupport();

        // Have the modem send invalid phone slots -1 and 5:
        int[] invalidEnabledLogicalSlots = {-1, 5};
        List<Integer> invalidEnabledLogicalSlots = Arrays.asList(-1, 5);
        ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
        verify(mMockRadioConfig).updateSimultaneousCallingSupport(captor.capture());
        Message msg = captor.getValue();
@@ -245,14 +248,14 @@ public class PhoneConfigurationManagerTest extends TelephonyTest {
        mPcm.registerForSimultaneousCellularCallingSlotsChanged(newSlots ->
                cachedSimultaneousCallingSlots[0] = newSlots);

        mPcm.getStaticPhoneCapability();
        mPcm.updateRadioCapability();
        setAndVerifyStaticCapability(STATIC_DSDA_CAPABILITY);
        ArgumentCaptor<SubscriptionManager.OnSubscriptionsChangedListener> cBCaptor =
                ArgumentCaptor.forClass(SubscriptionManager.OnSubscriptionsChangedListener.class);
        verify(mMockRegistryManager).addOnSubscriptionsChangedListener(cBCaptor.capture(), any());
        processAllMessages();

        int[] enabledLogicalSlots = {0, 1};
        List<Integer> enabledLogicalSlots = Arrays.asList(0, 1);
        HashSet<Integer> expectedSlots = new HashSet<>(2);
        for (int i : enabledLogicalSlots) {
            expectedSlots.add(i);
@@ -296,7 +299,7 @@ public class PhoneConfigurationManagerTest extends TelephonyTest {

        // Simultaneous calling enabled
        mPcm.updateSimultaneousCallingSupport();
        int[] enabledLogicalSlots = {0, 1};
        List<Integer> enabledLogicalSlots = Arrays.asList(0, 1);
        ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
        verify(mMockRadioConfig).updateSimultaneousCallingSupport(captor.capture());
        Message msg = captor.getValue();
@@ -318,7 +321,7 @@ public class PhoneConfigurationManagerTest extends TelephonyTest {

        // Simultaneous Calling Disabled
        mPcm.updateSimultaneousCallingSupport();
        int[] disabled = {};
        List<Integer> disabled = List.of();
        captor = ArgumentCaptor.forClass(Message.class);
        verify(mMockRadioConfig, times(2)).updateSimultaneousCallingSupport(captor.capture());
        msg = captor.getAllValues().get(1);
@@ -346,13 +349,13 @@ public class PhoneConfigurationManagerTest extends TelephonyTest {

        // Set the capability to DSDA mode to register listener, which will also trigger
        // simultaneous calling evaluation
        mPcm.getCurrentPhoneCapability();
        mPcm.updateRadioCapability();
        setAndVerifyStaticCapability(STATIC_DSDA_CAPABILITY);
        ArgumentCaptor<SubscriptionManager.OnSubscriptionsChangedListener> cBCaptor =
                ArgumentCaptor.forClass(SubscriptionManager.OnSubscriptionsChangedListener.class);
        verify(mMockRegistryManager).addOnSubscriptionsChangedListener(cBCaptor.capture(), any());

        int[] enabledLogicalSlots = {0, 1};
        List<Integer> enabledLogicalSlots = Arrays.asList(0, 1);
        ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
        verify(mMockRadioConfig).updateSimultaneousCallingSupport(captor.capture());
        Message msg = captor.getValue();
+11 −10
Original line number Diff line number Diff line
@@ -172,7 +172,7 @@ public class SimultaneousCallingTrackerTest extends TelephonyTest {
    }

    private void setAndVerifyStaticCapability(PhoneCapability capability) {
        mPcm.getCurrentPhoneCapability();
        mPcm.updateRadioCapability();
        ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
        verify(mMockRadioConfig).getPhoneCapability(captor.capture());
        Message msg = captor.getValue();
@@ -185,7 +185,8 @@ public class SimultaneousCallingTrackerTest extends TelephonyTest {

    }

    private void setAndVerifySlotsSupportingSimultaneousCellularCalling(int[] enabledLogicalSlots) {
    private void setAndVerifySlotsSupportingSimultaneousCellularCalling(
            List<Integer> enabledLogicalSlots) {
        ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
        verify(mMockRadioConfig).updateSimultaneousCallingSupport(captor.capture());
        Message msg = captor.getValue();
@@ -241,7 +242,7 @@ public class SimultaneousCallingTrackerTest extends TelephonyTest {
        init(2);
        setAndVerifyStaticCapability(STATIC_DSDA_CAPABILITY);

        int[] enabledLogicalSlots = {0, 1};
        List<Integer> enabledLogicalSlots = Arrays.asList(0, 1);
        setAndVerifySlotsSupportingSimultaneousCellularCalling(enabledLogicalSlots);

        // Trigger onSubscriptionsChanged by updating the subscription ID of a phone slot:
@@ -264,7 +265,7 @@ public class SimultaneousCallingTrackerTest extends TelephonyTest {
        setAndVerifyStaticCapability(STATIC_DSDA_CAPABILITY);

        // Have the modem inform telephony that only phone slot 0 supports DSDA:
        int[] enabledLogicalSlots = {0};
        List<Integer> enabledLogicalSlots = List.of(0);
        setAndVerifySlotsSupportingSimultaneousCellularCalling(enabledLogicalSlots);

        // Trigger onSubscriptionsChanged by updating the subscription ID of a phone slot:
@@ -286,7 +287,7 @@ public class SimultaneousCallingTrackerTest extends TelephonyTest {
        init(2);
        setAndVerifyStaticCapability(STATIC_DSDA_CAPABILITY);

        int[] enabledLogicalSlots = {0, 1};
        List<Integer> enabledLogicalSlots = Arrays.asList(0, 1);
        setAndVerifySlotsSupportingSimultaneousCellularCalling(enabledLogicalSlots);

        // Trigger onSubscriptionsChanged by updating the subscription ID of a phone slot:
@@ -309,7 +310,7 @@ public class SimultaneousCallingTrackerTest extends TelephonyTest {
        init(2);
        setAndVerifyStaticCapability(STATIC_DSDA_CAPABILITY);

        int[] enabledLogicalSlots = {0, 1};
        List<Integer> enabledLogicalSlots = Arrays.asList(0, 1);
        setAndVerifySlotsSupportingSimultaneousCellularCalling(enabledLogicalSlots);

        // Trigger onSubscriptionsChanged by updating the subscription ID of a phone slot:
@@ -356,7 +357,7 @@ public class SimultaneousCallingTrackerTest extends TelephonyTest {
        init(2);
        setAndVerifyStaticCapability(STATIC_DSDA_CAPABILITY);

        int[] enabledLogicalSlots = {0, 1};
        List<Integer> enabledLogicalSlots = Arrays.asList(0, 1);
        setAndVerifySlotsSupportingSimultaneousCellularCalling(enabledLogicalSlots);

        // Trigger onSubscriptionsChanged by updating the subscription ID of a phone slot:
@@ -384,7 +385,7 @@ public class SimultaneousCallingTrackerTest extends TelephonyTest {
        init(2);
        setAndVerifyStaticCapability(STATIC_DSDA_CAPABILITY);

        int[] enabledLogicalSlots = {0};
        List<Integer> enabledLogicalSlots = List.of(0);
        setAndVerifySlotsSupportingSimultaneousCellularCalling(enabledLogicalSlots);

        // Trigger onSubscriptionsChanged by updating the subscription ID of a phone slot:
@@ -416,7 +417,7 @@ public class SimultaneousCallingTrackerTest extends TelephonyTest {
        init(2);
        setAndVerifyStaticCapability(STATIC_DSDA_CAPABILITY);

        int[] enabledLogicalSlots = {0, 1};
        List<Integer> enabledLogicalSlots = Arrays.asList(0, 1);
        setAndVerifySlotsSupportingSimultaneousCellularCalling(enabledLogicalSlots);

        // Trigger onSubscriptionsChanged by updating the subscription ID of a phone slot:
@@ -449,7 +450,7 @@ public class SimultaneousCallingTrackerTest extends TelephonyTest {
        init(3);
        setAndVerifyStaticCapability(STATIC_DSDA_CAPABILITY);

        int[] enabledLogicalSlots = {0, 1};
        List<Integer> enabledLogicalSlots = Arrays.asList(0, 1);
        setAndVerifySlotsSupportingSimultaneousCellularCalling(enabledLogicalSlots);

        // Trigger onSubscriptionsChanged by updating the subscription ID of a phone slot: