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

Commit 2cbded1c authored by Xiangyu/Malcolm Chen's avatar Xiangyu/Malcolm Chen Committed by android-build-merger
Browse files

Merge "Update PhoneSwitcher to listen updates from cfgManager."

am: c13b7a25

Change-Id: I0a171e1d3ab803ba4575da7e018d243227012e5e
parents f74563c1 c13b7a25
Loading
Loading
Loading
Loading
+31 −2
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.internal.telephony;
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_PHONE_INDEX;
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;
import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID;


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


import com.android.internal.annotations.VisibleForTesting;
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 String LOG_TAG = "PhoneSwitcher";
    private final static boolean VDBG = false;
    private final static boolean VDBG = false;


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


    private int mMaxActivePhones;
    private int mDefaultDataSubscription;
    private int mDefaultDataSubscription;


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


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


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

        }
        }


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

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


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


package com.android.internal.telephony;
package com.android.internal.telephony;


import static org.junit.Assert.fail;

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


import com.android.internal.telephony.mocks.ConnectivityServiceMock;
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.mocks.TelephonyRegistryMock;
import com.android.internal.telephony.test.SimulatedCommands;
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.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicReference;


public class PhoneSwitcherTest extends AndroidTestCase {
public class PhoneSwitcherTest extends TelephonyTest {
    private final static String LOG_TAG = "PhoneSwitcherTest";
    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) {
    static void failAndStack(String str) {
        fail(str + "\n" + SubscriptionMonitorTest.stack());
        fail(str + "\n" + SubscriptionMonitorTest.stack());
@@ -169,18 +181,20 @@ public class PhoneSwitcherTest extends AndroidTestCase {
        return cs.requestNetwork(netCap, null, 0, new Binder(), -1);
        return cs.requestNetwork(netCap, null, 0, new Binder(), -1);
    }
    }


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

                networkConfigString);
    @After
        return contextFixture.getTestDouble();
    public void tearDown() throws Exception {
        super.tearDown();
    }
    }


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