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

Commit af559359 authored by Robert Greenwalt's avatar Robert Greenwalt
Browse files

DO NOT MERGE - Create TelephonyNetworkFactory.

It replaces DctController.  Also adds tests.

Change-Id: Ib2dd309bd9f87f9b9d4ca114440e6251c562e925
parent bc2eba90
Loading
Loading
Loading
Loading
+26 −12
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.util.LocalLog;

import com.android.internal.telephony.cdma.CdmaSubscriptionSourceManager;
import com.android.internal.telephony.dataconnection.DctController;
import com.android.internal.telephony.dataconnection.TelephonyNetworkFactory;
import com.android.internal.telephony.imsphone.ImsPhone;
import com.android.internal.telephony.imsphone.ImsPhoneFactory;
import com.android.internal.telephony.sip.SipPhone;
@@ -66,8 +67,8 @@ public class PhoneFactory {

    static private CommandsInterface[] sCommandsInterfaces = null;

    static private ProxyController mProxyController;
    static private UiccController mUiccController;
    static private ProxyController sProxyController;
    static private UiccController sUiccController;

    static private CommandsInterface sCommandsInterface = null;
    static private SubscriptionInfoUpdater sSubInfoRecordUpdater = null;
@@ -75,7 +76,8 @@ public class PhoneFactory {
    static private boolean sMadeDefaults = false;
    static private PhoneNotifier sPhoneNotifier;
    static private Context sContext;
    //static private PhoneSwitcher mPhoneSwitcher;
    static private PhoneSwitcher sPhoneSwitcher;
    static private TelephonyNetworkFactory[] sTelephonyNetworkFactories;

    static private final HashMap<String, LocalLog>sLocalLogs = new HashMap<String, LocalLog>();

@@ -137,6 +139,7 @@ public class PhoneFactory {
                int[] networkModes = new int[numPhones];
                sPhones = new Phone[numPhones];
                sCommandsInterfaces = new RIL[numPhones];
                sTelephonyNetworkFactories = new TelephonyNetworkFactory[numPhones];

                for (int i = 0; i < numPhones; i++) {
                    // reads the system properties and makes commandsinterface
@@ -152,7 +155,7 @@ public class PhoneFactory {

                // Instantiate UiccController so that all other classes can just
                // call getInstance()
                mUiccController = UiccController.make(context, sCommandsInterfaces);
                sUiccController = UiccController.make(context, sCommandsInterfaces);

                for (int i = 0; i < numPhones; i++) {
                    Phone phone = null;
@@ -172,8 +175,6 @@ public class PhoneFactory {

                    sPhones[i] = phone;
                }
                mProxyController = ProxyController.getInstance(context, sPhones,
                        mUiccController, sCommandsInterfaces);

                // Set the default phone in base class.
                // FIXME: This is a first best guess at what the defaults will be. It
@@ -215,9 +216,18 @@ public class PhoneFactory {
                SubscriptionMonitor subscriptionMonitor = new SubscriptionMonitor(tr,
                        sContext, sc, numPhones);

                //mPhoneSwitcher = new PhoneSwitcher(MAX_ACTIVE_PHONES, numPhones,
                //sPhoneSwitcher = new PhoneSwitcher(MAX_ACTIVE_PHONES, numPhones,
                //        sContext, sc, Looper.myLooper(), tr, sCommandsInterfaces,
                //        sPhones);

                sProxyController = ProxyController.getInstance(context, sPhones,
                        sUiccController, sCommandsInterfaces, sPhoneSwitcher);

                //for (int i = 0; i < numPhones; i++) {
                //    sTelephonyNetworkFactories[i] = new TelephonyNetworkFactory(
                //            sPhoneSwitcher, sc, subscriptionMonitor, Looper.myLooper(),
                //            sContext, i, sPhones[i].mDcTracker);
                //}
            }
        }
    }
@@ -464,13 +474,12 @@ public class PhoneFactory {
        pw.println("PhoneFactory:");
        pw.println(" sMadeDefaults=" + sMadeDefaults);

        //mPhoneSwitcher.dump(fd, pw, args);
        //sPhoneSwitcher.dump(fd, pw, args);
        //pw.println();

        Phone[] phones = (Phone[])PhoneFactory.getPhones();
        int i = -1;
        for(Phone phone : phones) {
            i += 1;
        for (int i = 0; i < phones.length; i++) {
            Phone phone = phones[i];

            try {
                phone.dump(fd, pw, args);
@@ -482,6 +491,11 @@ public class PhoneFactory {
            pw.flush();
            pw.println("++++++++++++++++++++++++++++++++");

            sTelephonyNetworkFactories[i].dump(fd, pw, args);

            pw.flush();
            pw.println("++++++++++++++++++++++++++++++++");

            try {
                ((IccCardProxy)phone.getIccCard()).dump(fd, pw, args);
            } catch (Exception e) {
@@ -498,7 +512,7 @@ public class PhoneFactory {
        }

        try {
            mUiccController.dump(fd, pw, args);
            sUiccController.dump(fd, pw, args);
        } catch (Exception e) {
            e.printStackTrace();
        }
+35 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.telephony.Rlog;
import android.text.TextUtils;
import android.util.LocalLog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.IOnSubscriptionsChangedListener;
import com.android.internal.telephony.ITelephonyRegistry;
@@ -81,9 +82,25 @@ public class PhoneSwitcher extends Handler {
    private final static int EVENT_REQUEST_NETWORK              = 103;
    private final static int EVENT_RELEASE_NETWORK              = 104;
    private final static int EVENT_EMERGENCY_TOGGLE             = 105;
    private final static int EVENT_RESEND_DATA_ALLOWED          = 106;

    private final static int MAX_LOCAL_LOG_LINES = 30;

    @VisibleForTesting
    public PhoneSwitcher(Looper looper) {
        super(looper);
        mMaxActivePhones = 0;
        mSubscriptionController = null;
        mPhoneSubscriptions = null;
        mCommandsInterfaces = null;
        mContext = null;
        mPhoneStates = null;
        mPhones = null;
        mLocalLog = null;
        mActivePhoneRegistrants = null;
        mNumPhones = 0;
    }

    public PhoneSwitcher(int maxActivePhones, int numPhones, Context context,
            SubscriptionController subscriptionController, Looper looper, ITelephonyRegistry tr,
            CommandsInterface[] cis, Phone[] phones) {
@@ -181,6 +198,10 @@ public class PhoneSwitcher extends Handler {
                onEvaluate(REQUESTS_CHANGED, "emergencyToggle");
                break;
            }
            case EVENT_RESEND_DATA_ALLOWED: {
                onResendDataAllowed(msg);
                break;
            }
        }
    }

@@ -324,6 +345,20 @@ public class PhoneSwitcher extends Handler {
        mActivePhoneRegistrants[phoneId].notifyRegistrants();
    }

    // used when the modem may have been rebooted and we want to resend
    // setDataAllowed
    public void resendDataAllowed(int phoneId) {
        validatePhoneId(phoneId);
        Message msg = obtainMessage(EVENT_RESEND_DATA_ALLOWED);
        msg.arg1 = phoneId;
        msg.sendToTarget();
    }

    private void onResendDataAllowed(Message msg) {
        final int phoneId = msg.arg1;
        mCommandsInterfaces[phoneId].setDataAllowed(mPhoneStates[phoneId].active, null);
    }

    private int phoneIdForRequest(NetworkRequest netRequest) {
        String specifier = netRequest.networkCapabilities.getNetworkSpecifier();
        int subId;
+11 −3
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.telephony.Rlog;
import android.telephony.TelephonyManager;
import android.util.Log;

import com.android.internal.telephony.PhoneSwitcher;
import com.android.internal.telephony.dataconnection.DctController;
import com.android.internal.telephony.uicc.UiccController;

@@ -71,6 +72,8 @@ public class ProxyController {

    private Context mContext;

    private PhoneSwitcher mPhoneSwitcher;
    // TODO - remove
    private DctController mDctController;

    //UiccPhoneBookController to use proper IccPhoneBookInterfaceManagerProxy object
@@ -107,9 +110,9 @@ public class ProxyController {

    //***** Class Methods
    public static ProxyController getInstance(Context context, Phone[] phone,
            UiccController uiccController, CommandsInterface[] ci) {
            UiccController uiccController, CommandsInterface[] ci, PhoneSwitcher ps) {
        if (sProxyController == null) {
            sProxyController = new ProxyController(context, phone, uiccController, ci);
            sProxyController = new ProxyController(context, phone, uiccController, ci, ps);
        }
        return sProxyController;
    }
@@ -119,14 +122,16 @@ public class ProxyController {
    }

    private ProxyController(Context context, Phone[] phone, UiccController uiccController,
            CommandsInterface[] ci) {
            CommandsInterface[] ci, PhoneSwitcher phoneSwitcher) {
        logd("Constructor - Enter");

        mContext = context;
        mPhones = phone;
        mUiccController = uiccController;
        mCi = ci;
        mPhoneSwitcher = phoneSwitcher;

        // TODO - remove
        mDctController = DctController.makeDctController(phone);
        mUiccPhoneBookController = new UiccPhoneBookController(mPhones);
        mPhoneSubInfoController = new PhoneSubInfoController(mContext, mPhones);
@@ -455,6 +460,8 @@ public class ProxyController {
                logd("onNotificationRadioCapabilityChanged: phoneId=" + id + " status=SUCCESS");
                mSetRadioAccessFamilyStatus[id] = SET_RC_STATUS_SUCCESS;
                // The modems may have been restarted and forgotten this
                // TODO - switch these
//                mPhoneSwitcher.resendDataAllowed(id);
                mDctController.retryAttach(id);
                mPhones[id].radioCapabilityUpdated(rc);
            }
@@ -663,6 +670,7 @@ public class ProxyController {

    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        try {
            // TODO remove
            mDctController.dump(fd, pw, args);
        } catch (Exception e) {
            e.printStackTrace();
+10 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.os.ServiceManager;
import android.telephony.Rlog;
import android.telephony.SubscriptionManager;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.ISub;
import com.android.internal.telephony.IOnSubscriptionsChangedListener;
import com.android.internal.telephony.ITelephonyRegistry;
@@ -88,6 +89,15 @@ public class SubscriptionMonitor {
                new IntentFilter(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED));
    }

    @VisibleForTesting
    public SubscriptionMonitor() {
        mSubscriptionsChangedRegistrants = null;
        mDefaultDataSubChangedRegistrants = null;
        mSubscriptionController = null;
        mContext = null;
        mPhoneSubId = null;
    }

    private final IOnSubscriptionsChangedListener mSubscriptionsChangedListener =
            new IOnSubscriptionsChangedListener.Stub() {
        @Override
+133 −2
Original line number Diff line number Diff line
@@ -19,7 +19,9 @@ package com.android.internal.telephony.dataconnection;
import android.app.PendingIntent;
import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.net.NetworkConfig;
import android.net.NetworkRequest;
import android.telephony.Rlog;
import android.text.TextUtils;
import android.util.LocalLog;
@@ -28,6 +30,7 @@ import android.util.SparseIntArray;
import com.android.internal.R;
import com.android.internal.telephony.DctConstants;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.RetryManager;
import com.android.internal.util.IndentingPrintWriter;

@@ -43,6 +46,7 @@ import java.util.concurrent.atomic.AtomicInteger;
public class ApnContext {

    public final String LOG_TAG;
    private final static String SLOG_TAG = "ApnContext";

    protected static final boolean DBG = false;

@@ -408,7 +412,7 @@ public class ApnContext {
                log.log("ApnContext.incRefCount - " + mRefCount);
            }
            if (mRefCount++ == 0) {
                mDcTracker.setEnabled(mDcTracker.apnTypeToId(mApnType), true);
                mDcTracker.setEnabled(apnIdForApnName(mApnType), true);
            }
        }
    }
@@ -426,7 +430,7 @@ public class ApnContext {
                log.log("ApnContext.decRefCount - 1");
            }
            if (mRefCount-- == 1) {
                mDcTracker.setEnabled(mDcTracker.apnTypeToId(mApnType), false);
                mDcTracker.setEnabled(apnIdForApnName(mApnType), false);
            }
            if (mRefCount < 0) {
                log.log("ApnContext.decRefCount went to " + mRefCount);
@@ -533,6 +537,133 @@ public class ApnContext {
        }
    }

    public static int apnIdForNetworkRequest(NetworkRequest nr) {
        NetworkCapabilities nc = nr.networkCapabilities;
        // For now, ignore the bandwidth stuff
        if (nc.getTransportTypes().length > 0 &&
                nc.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) == false) {
            return DctConstants.APN_INVALID_ID;
        }

        // in the near term just do 1-1 matches.
        // TODO - actually try to match the set of capabilities
        int apnId = DctConstants.APN_INVALID_ID;
        boolean error = false;

        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) {
            apnId = DctConstants.APN_DEFAULT_ID;
        }
        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_MMS)) {
            if (apnId != DctConstants.APN_INVALID_ID) error = true;
            apnId = DctConstants.APN_MMS_ID;
        }
        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_SUPL)) {
            if (apnId != DctConstants.APN_INVALID_ID) error = true;
            apnId = DctConstants.APN_SUPL_ID;
        }
        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_DUN)) {
            if (apnId != DctConstants.APN_INVALID_ID) error = true;
            apnId = DctConstants.APN_DUN_ID;
        }
        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_FOTA)) {
            if (apnId != DctConstants.APN_INVALID_ID) error = true;
            apnId = DctConstants.APN_FOTA_ID;
        }
        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_IMS)) {
            if (apnId != DctConstants.APN_INVALID_ID) error = true;
            apnId = DctConstants.APN_IMS_ID;
        }
        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_CBS)) {
            if (apnId != DctConstants.APN_INVALID_ID) error = true;
            apnId = DctConstants.APN_CBS_ID;
        }
        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_IA)) {
            if (apnId != DctConstants.APN_INVALID_ID) error = true;
            apnId = DctConstants.APN_IA_ID;
        }
        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_RCS)) {
            if (apnId != DctConstants.APN_INVALID_ID) error = true;

            Rlog.d(SLOG_TAG, "RCS APN type not yet supported");
        }
        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_XCAP)) {
            if (apnId != DctConstants.APN_INVALID_ID) error = true;

            Rlog.d(SLOG_TAG, "XCAP APN type not yet supported");
        }
        if (nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_EIMS)) {
            if (apnId != DctConstants.APN_INVALID_ID) error = true;
            apnId = DctConstants.APN_MMS_ID;
        }
        if (error) {
            // TODO: If this error condition is removed, the framework's handling of
            // NET_CAPABILITY_NOT_RESTRICTED will need to be updated so requests for
            // say FOTA and INTERNET are marked as restricted.  This is not how
            // NetworkCapabilities.maybeMarkCapabilitiesRestricted currently works.
            Rlog.d(SLOG_TAG, "Multiple apn types specified in request - result is unspecified!");
        }
        if (apnId == DctConstants.APN_INVALID_ID) {
            Rlog.d(SLOG_TAG, "Unsupported NetworkRequest in Telephony: nr=" + nr);
        }
        return apnId;
    }

    // TODO - kill The use of these strings
    public static int apnIdForApnName(String type) {
        switch (type) {
            case PhoneConstants.APN_TYPE_DEFAULT:
                return DctConstants.APN_DEFAULT_ID;
            case PhoneConstants.APN_TYPE_MMS:
                return DctConstants.APN_MMS_ID;
            case PhoneConstants.APN_TYPE_SUPL:
                return DctConstants.APN_SUPL_ID;
            case PhoneConstants.APN_TYPE_DUN:
                return DctConstants.APN_DUN_ID;
            case PhoneConstants.APN_TYPE_HIPRI:
                return DctConstants.APN_HIPRI_ID;
            case PhoneConstants.APN_TYPE_IMS:
                return DctConstants.APN_IMS_ID;
            case PhoneConstants.APN_TYPE_FOTA:
                return DctConstants.APN_FOTA_ID;
            case PhoneConstants.APN_TYPE_CBS:
                return DctConstants.APN_CBS_ID;
            case PhoneConstants.APN_TYPE_IA:
                return DctConstants.APN_IA_ID;
            case PhoneConstants.APN_TYPE_EMERGENCY:
                return DctConstants.APN_EMERGENCY_ID;
            default:
                return DctConstants.APN_INVALID_ID;
        }
    }

    private static String apnNameForApnId(int id) {
        switch (id) {
            case DctConstants.APN_DEFAULT_ID:
                return PhoneConstants.APN_TYPE_DEFAULT;
            case DctConstants.APN_MMS_ID:
                return PhoneConstants.APN_TYPE_MMS;
            case DctConstants.APN_SUPL_ID:
                return PhoneConstants.APN_TYPE_SUPL;
            case DctConstants.APN_DUN_ID:
                return PhoneConstants.APN_TYPE_DUN;
            case DctConstants.APN_HIPRI_ID:
                return PhoneConstants.APN_TYPE_HIPRI;
            case DctConstants.APN_IMS_ID:
                return PhoneConstants.APN_TYPE_IMS;
            case DctConstants.APN_FOTA_ID:
                return PhoneConstants.APN_TYPE_FOTA;
            case DctConstants.APN_CBS_ID:
                return PhoneConstants.APN_TYPE_CBS;
            case DctConstants.APN_IA_ID:
                return PhoneConstants.APN_TYPE_IA;
            case DctConstants.APN_EMERGENCY_ID:
                return PhoneConstants.APN_TYPE_EMERGENCY;
            default:
                Rlog.d(SLOG_TAG, "Unknown id (" + id + ") in apnIdToType");
                return PhoneConstants.APN_TYPE_DEFAULT;
        }
    }

    @Override
    public synchronized String toString() {
        // We don't print mDataConnection because its recursive.
Loading