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

Commit 9855d41d authored by Chalard Jean's avatar Chalard Jean
Browse files

Use the factory serial number.

Test: atest frameworks/opt/telephony/tests/telephonytests
      also, tested that cellular connectivity works.
Bug: 29030667

Change-Id: Id6852f513283c923464ea499fff659fb8196f81e
parent c81c3275
Loading
Loading
Loading
Loading
+31 −1
Original line number Diff line number Diff line
@@ -63,7 +63,7 @@ public class PhoneFactory {

    //***** Class Variables

    // lock sLockProxyPhones protects both sPhones and sPhone
    // lock sLockProxyPhones protects sPhones, sPhone and sTelephonyNetworkFactories
    final static Object sLockProxyPhones = new Object();
    static private Phone[] sPhones = null;
    static private Phone sPhone = null;
@@ -321,6 +321,36 @@ public class PhoneFactory {
        return sImsResolver;
    }

    /**
     * Get the network factory associated with a given phone ID.
     * @param phoneId the phone id
     * @return a factory for this phone ID, or null if none.
     */
    public static TelephonyNetworkFactory getNetworkFactory(int phoneId) {
        synchronized (sLockProxyPhones) {
            if (!sMadeDefaults) {
                throw new IllegalStateException("Default phones haven't been made yet!");
            }
            final String dbgInfo;
            if (phoneId == SubscriptionManager.DEFAULT_PHONE_INDEX) {
                dbgInfo = "getNetworkFactory with DEFAULT_PHONE_ID => factory for sPhone";
                phoneId = sPhone.getSubId();
            } else {
                dbgInfo = "getNetworkFactory with non-default, return factory for passed id";
            }
            // sTelephonyNetworkFactories is null in tests because in tests makeDefaultPhones()
            // is not called.
            final TelephonyNetworkFactory factory = (sTelephonyNetworkFactories != null
                            && (phoneId >= 0 && phoneId < sTelephonyNetworkFactories.length))
                            ? sTelephonyNetworkFactories[phoneId] : null;
            if (DBG) {
                Rlog.d(LOG_TAG, "getNetworkFactory:-" + dbgInfo + " phoneId=" + phoneId
                        + " factory=" + factory);
            }
            return factory;
        }
    }

    /**
     * Makes a {@link SipPhone} object.
     * @param sipUri the local SIP URI the phone runs on
+9 −3
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.net.LinkProperties;
import android.net.NattKeepalivePacketData;
import android.net.NetworkAgent;
import android.net.NetworkCapabilities;
import android.net.NetworkFactory;
import android.net.NetworkInfo;
import android.net.NetworkMisc;
import android.net.NetworkRequest;
@@ -68,6 +69,7 @@ import com.android.internal.telephony.DctConstants;
import com.android.internal.telephony.LinkCapacityEstimate;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.RILConstants;
import com.android.internal.telephony.RetryManager;
import com.android.internal.telephony.ServiceStateTracker;
@@ -1895,9 +1897,12 @@ public class DataConnection extends StateMachine {
                }
            } else {
                mScore = calculateScore();
                final NetworkFactory factory = PhoneFactory.getNetworkFactory(mPhone.getPhoneId());
                final int factorySerialNumber = (null == factory)
                        ? NetworkFactory.SerialNumber.NONE : factory.getSerialNumber();
                mNetworkAgent = new DcNetworkAgent(getHandler().getLooper(), mPhone.getContext(),
                        "DcNetworkAgent" + mTagSuffix, mNetworkInfo, getNetworkCapabilities(),
                        mLinkProperties, mScore, misc);
                        mLinkProperties, mScore, misc, factorySerialNumber);
            }
            if (mDataServiceManager.getTransportType()
                    == AccessNetworkConstants.TRANSPORT_TYPE_WWAN) {
@@ -2344,8 +2349,9 @@ public class DataConnection extends StateMachine {
        public final DcKeepaliveTracker keepaliveTracker = new DcKeepaliveTracker();

        public DcNetworkAgent(Looper l, Context c, String TAG, NetworkInfo ni,
                NetworkCapabilities nc, LinkProperties lp, int score, NetworkMisc misc) {
            super(l, c, TAG, ni, nc, lp, score, misc);
                NetworkCapabilities nc, LinkProperties lp, int score, NetworkMisc misc,
                int factorySerialNumber) {
            super(l, c, TAG, ni, nc, lp, score, misc, factorySerialNumber);
            mNetCapsLocalLog.log("New network agent created. capabilities=" + nc);
            mNetworkCapabilities = nc;
            mTransportType = new AtomicInteger(mDataServiceManager.getTransportType());
+9 −2
Original line number Diff line number Diff line
@@ -16,12 +16,13 @@

package com.android.internal.telephony;

import static org.junit.Assert.fail;

import android.net.NetworkFactory;
import android.test.suitebuilder.annotation.SmallTest;

import org.junit.Test;

import static org.junit.Assert.fail;

public class PhoneFactoryTest {
    @Test
    @SmallTest
@@ -43,6 +44,12 @@ public class PhoneFactoryTest {
            fail("Expecting IllegalStateException");
        } catch (IllegalStateException e) {
        }

        try {
            NetworkFactory factory = PhoneFactory.getNetworkFactory(0);
            fail("Expecting IllegalStateException");
        } catch (IllegalStateException e) {
        }
    }

    //todo: add test for makeDefaultPhone(). will need some refactoring in PhoneFactory.