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

Commit b021ef40 authored by Malcolm Chen's avatar Malcolm Chen
Browse files

Update PhoneSwitcher to listen updates from cfgManager.

Number of max active data in PhoneSwitcher should be updated by
PhoneConfigManager.

Bug: 92796390
Test: manual
Change-Id: Id3f651d0328a9f570c67086f577cd4d73984017e
Merged-In: Id3f651d0328a9f570c67086f577cd4d73984017e
parent 9d03c0c8
Loading
Loading
Loading
Loading
+31 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.internal.telephony;

import static android.telephony.PhoneStateListener.LISTEN_PHONE_CAPABILITY_CHANGE;
import static android.telephony.SubscriptionManager.INVALID_PHONE_INDEX;
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;

@@ -35,7 +36,10 @@ import android.os.Message;
import android.os.Registrant;
import android.os.RegistrantList;
import android.os.RemoteException;
import android.telephony.PhoneCapability;
import android.telephony.PhoneStateListener;
import android.telephony.Rlog;
import android.telephony.TelephonyManager;
import android.util.LocalLog;

import com.android.internal.annotations.VisibleForTesting;
@@ -60,7 +64,6 @@ public class PhoneSwitcher extends Handler {
    private final static String LOG_TAG = "PhoneSwitcher";
    private final static boolean VDBG = false;

    private final int mMaxActivePhones;
    private final List<DcRequest> mPrioritizedDcRequests = new ArrayList<DcRequest>();
    private final RegistrantList[] mActivePhoneRegistrants;
    private final SubscriptionController mSubscriptionController;
@@ -71,7 +74,9 @@ public class PhoneSwitcher extends Handler {
    private final int mNumPhones;
    private final Phone[] mPhones;
    private final LocalLog mLocalLog;
    private final PhoneStateListener mPhoneStateListener;

    private int mMaxActivePhones;
    private int mDefaultDataSubscription;

    private final static int EVENT_DEFAULT_SUBSCRIPTION_CHANGED = 101;
@@ -96,6 +101,11 @@ public class PhoneSwitcher extends Handler {
        mLocalLog = null;
        mActivePhoneRegistrants = null;
        mNumPhones = 0;
        mPhoneStateListener = new PhoneStateListener(looper) {
            public void onPhoneCapabilityChanged(PhoneCapability capability) {
                onPhoneCapabilityChangedInternal(capability);
            }
        };
    }

    public PhoneSwitcher(int maxActivePhones, int numPhones, Context context,
@@ -111,6 +121,16 @@ public class PhoneSwitcher extends Handler {

        mSubscriptionController = subscriptionController;

        mPhoneStateListener = new PhoneStateListener(looper) {
            public void onPhoneCapabilityChanged(PhoneCapability capability) {
                onPhoneCapabilityChangedInternal(capability);
            }
        };

        TelephonyManager telephonyManager =
                (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
        telephonyManager.listen(mPhoneStateListener, LISTEN_PHONE_CAPABILITY_CHANGE);

        mActivePhoneRegistrants = new RegistrantList[numPhones];
        mPhoneStates = new PhoneState[numPhones];
        for (int i = 0; i < numPhones; i++) {
@@ -278,7 +298,6 @@ public class PhoneSwitcher extends Handler {
            sb.append(" default ").append(mDefaultDataSubscription).append("->").append(dataSub);
            mDefaultDataSubscription = dataSub;
            diffDetected = true;

        }

        for (int i = 0; i < mNumPhones; i++) {
@@ -374,6 +393,16 @@ public class PhoneSwitcher extends Handler {
        }
    }

    private void onPhoneCapabilityChangedInternal(PhoneCapability capability) {
        int newMaxActivePhones = TelephonyManager.getDefault()
                .getNumberOfModemsWithSimultaneousDataConnections();
        if (mMaxActivePhones != newMaxActivePhones) {
            mMaxActivePhones = newMaxActivePhones;
            log("Max active phones changed to " + mMaxActivePhones);
            onEvaluate(true, "phoneCfgChanged");
        }
    }

    private int phoneIdForRequest(NetworkRequest netRequest) {
        NetworkSpecifier specifier = netRequest.networkCapabilities.getNetworkSpecifier();
        int subId;
+5 −0
Original line number Diff line number Diff line
@@ -499,6 +499,11 @@ public class ContextFixture implements TestFixture<Context> {
        public String getPackageName() {
            return "com.android.internal.telephony";
        }

        @Override
        public Context getApplicationContext() {
            return null;
        }
    }

    private final Multimap<String, ComponentName> mComponentNamesByAction =
+38 −31
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.internal.telephony;

import static org.junit.Assert.fail;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
@@ -28,7 +30,6 @@ import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.telephony.Rlog;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;

import com.android.internal.telephony.mocks.ConnectivityServiceMock;
@@ -36,11 +37,22 @@ import com.android.internal.telephony.mocks.SubscriptionControllerMock;
import com.android.internal.telephony.mocks.TelephonyRegistryMock;
import com.android.internal.telephony.test.SimulatedCommands;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

public class PhoneSwitcherTest extends AndroidTestCase {
    private final static String LOG_TAG = "PhoneSwitcherTest";
public class PhoneSwitcherTest extends TelephonyTest {
    private static final String LOG_TAG = "PhoneSwitcherTest";

    private static final String[] sNetworkAttributes = new String[] {
            "mobile,0,0,0,-1,true", "mobile_mms,2,0,2,60000,true",
            "mobile_supl,3,0,2,60000,true", "mobile_dun,4,0,2,60000,true",
            "mobile_hipri,5,0,3,60000,true", "mobile_fota,10,0,2,60000,true",
            "mobile_ims,11,0,2,60000,true", "mobile_cbs,12,0,2,60000,true",
            "mobile_ia,14,0,2,-1,true", "mobile_emergency,15,0,2,-1,true"};

    static void failAndStack(String str) {
        fail(str + "\n" + SubscriptionMonitorTest.stack());
@@ -169,18 +181,20 @@ public class PhoneSwitcherTest extends AndroidTestCase {
        return cs.requestNetwork(netCap, null, 0, new Binder(), -1);
    }

    private Context makeContext() {
        final ContextFixture contextFixture = new ContextFixture();
        String[] networkConfigString = getContext().getResources().getStringArray(
                com.android.internal.R.array.networkAttributes);
        contextFixture.putStringArrayResource(com.android.internal.R.array.networkAttributes,
                networkConfigString);
        return contextFixture.getTestDouble();
    @Before
    public void setUp() throws Exception {
        super.setUp(getClass().getSimpleName());
    }

    @After
    public void tearDown() throws Exception {
        super.tearDown();
    }

    /**
     * Test that a single phone case results in our phone being active and the RIL called
     */
    @Test
    @SmallTest
    public void testRegister() throws Exception {
        mTestName = "testRegister";
@@ -188,17 +202,14 @@ public class PhoneSwitcherTest extends AndroidTestCase {
        final int maxActivePhones = 1;
        final HandlerThread handlerThread = new HandlerThread("PhoneSwitcherTestThread");
        handlerThread.start();
        final ContextFixture contextFixture = new ContextFixture();
        String[] networkConfigString = getContext().getResources().getStringArray(
                com.android.internal.R.array.networkAttributes);
        contextFixture.putStringArrayResource(com.android.internal.R.array.networkAttributes,
                networkConfigString);
        final Context contextMock = contextFixture.getTestDouble();
        mContextFixture.putStringArrayResource(com.android.internal.R.array.networkAttributes,
                sNetworkAttributes);
        final Context contextMock = mContextFixture.getTestDouble();
        final ConnectivityServiceMock connectivityServiceMock =
                new ConnectivityServiceMock(contextMock);
        final ConnectivityManager cm =
                new ConnectivityManager(contextMock, connectivityServiceMock);
        contextFixture.setSystemService(Context.CONNECTIVITY_SERVICE, cm);
        mContextFixture.setSystemService(Context.CONNECTIVITY_SERVICE, cm);
        final ITelephonyRegistry.Stub telRegistryMock = new TelephonyRegistryMock();
        final SubscriptionControllerMock subControllerMock =
                new SubscriptionControllerMock(contextMock, telRegistryMock, numPhones);
@@ -414,6 +425,7 @@ public class PhoneSwitcherTest extends AndroidTestCase {
     * - bring up low priority phone when sub change causes join
     * - don't switch phones when in emergency mode
     */
    @Test
    @SmallTest
    public void testPrioritization() throws Exception {
        mTestName = "testPrioritization";
@@ -421,17 +433,14 @@ public class PhoneSwitcherTest extends AndroidTestCase {
        final int maxActivePhones = 1;
        final HandlerThread handlerThread = new HandlerThread("PhoneSwitcherTestThread");
        handlerThread.start();
        final ContextFixture contextFixture = new ContextFixture();
        String[] networkConfigString = getContext().getResources().getStringArray(
                com.android.internal.R.array.networkAttributes);
        contextFixture.putStringArrayResource(com.android.internal.R.array.networkAttributes,
                networkConfigString);
        final Context contextMock = contextFixture.getTestDouble();
        mContextFixture.putStringArrayResource(com.android.internal.R.array.networkAttributes,
                sNetworkAttributes);
        final Context contextMock = mContextFixture.getTestDouble();
        final ConnectivityServiceMock connectivityServiceMock =
            new ConnectivityServiceMock(contextMock);
        final ConnectivityManager cm =
                new ConnectivityManager(contextMock, connectivityServiceMock);
        contextFixture.setSystemService(Context.CONNECTIVITY_SERVICE, cm);
        mContextFixture.setSystemService(Context.CONNECTIVITY_SERVICE, cm);
        final ITelephonyRegistry.Stub telRegistryMock = new TelephonyRegistryMock();
        final SubscriptionControllerMock subControllerMock =
                new SubscriptionControllerMock(contextMock, telRegistryMock, numPhones);
@@ -487,6 +496,7 @@ public class PhoneSwitcherTest extends AndroidTestCase {
     * Verify we don't send spurious DATA_ALLOWED calls when another NetworkFactory
     * wins (ie, switch to wifi).
     */
    @Test
    @SmallTest
    public void testHigherPriorityDefault() throws Exception {
        mTestName = "testPrioritization";
@@ -494,17 +504,14 @@ public class PhoneSwitcherTest extends AndroidTestCase {
        final int maxActivePhones = 1;
        final HandlerThread handlerThread = new HandlerThread("PhoneSwitcherTestThread");
        handlerThread.start();
        final ContextFixture contextFixture = new ContextFixture();
        String[] networkConfigString = getContext().getResources().getStringArray(
                com.android.internal.R.array.networkAttributes);
        contextFixture.putStringArrayResource(com.android.internal.R.array.networkAttributes,
                networkConfigString);
        final Context contextMock = contextFixture.getTestDouble();
        mContextFixture.putStringArrayResource(com.android.internal.R.array.networkAttributes,
                sNetworkAttributes);
        final Context contextMock = mContextFixture.getTestDouble();
        final ConnectivityServiceMock connectivityServiceMock =
                new ConnectivityServiceMock(contextMock);
        final ConnectivityManager cm =
                new ConnectivityManager(contextMock, connectivityServiceMock);
        contextFixture.setSystemService(Context.CONNECTIVITY_SERVICE, cm);
        mContextFixture.setSystemService(Context.CONNECTIVITY_SERVICE, cm);
        final ITelephonyRegistry.Stub telRegistryMock = new TelephonyRegistryMock();
        final SubscriptionControllerMock subControllerMock =
                new SubscriptionControllerMock(contextMock, telRegistryMock, numPhones);