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

Commit 1dd45a4d authored by Jack Yu's avatar Jack Yu
Browse files

Removed the usage of NetworkInfo in telephony

NetworkInfo has been deprecated. Removed all the usages
in telephony. The APN name (i.e. extra info), network type
(i.e. sub type), and suspended state are still passed
up to connectivity service like before.

Fix: 162789235
Test: Manual & FrameworksTelephonyTests
Merged-In: Ie63972d51f3da6780d43304c18b85ccf646330d6
Change-Id: Ie63972d51f3da6780d43304c18b85ccf646330d6
(cherry picked from commit 1099a0d6)
parent d04f7bb4
Loading
Loading
Loading
Loading
+23 −88
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import android.net.LinkProperties;
import android.net.NetworkAgentConfig;
import android.net.NetworkCapabilities;
import android.net.NetworkFactory;
import android.net.NetworkInfo;
import android.net.NetworkProvider;
import android.net.NetworkRequest;
import android.net.ProxyInfo;
@@ -279,7 +278,6 @@ public class DataConnection extends StateMachine {
    private int mRilRat = ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN;
    private int mDataRegState = Integer.MAX_VALUE;
    private boolean mIsSuspended;
    private NetworkInfo mNetworkInfo;
    private int mDownlinkBandwidth = 14;
    private int mUplinkBandwidth = 14;

@@ -655,9 +653,6 @@ public class DataConnection extends StateMachine {
        mRilRat = ServiceState.networkTypeToRilRadioTechnology(networkType);
        updateLinkBandwidthsFromCarrierConfig(mRilRat);

        mNetworkInfo = new NetworkInfo(ConnectivityManager.TYPE_MOBILE,
                networkType, NETWORK_TYPE, TelephonyManager.getNetworkTypeName(networkType));

        addState(mDefaultState);
            addState(mInactiveState, mDefaultState);
            addState(mActivatingState, mDefaultState);
@@ -859,8 +854,6 @@ public class DataConnection extends StateMachine {
    }

    private void notifyAllWithEvent(ApnContext alreadySent, int event, String reason) {
        mNetworkInfo.setDetailedState(mNetworkInfo.getDetailedState(), reason,
                mNetworkInfo.getExtraInfo());
        for (ConnectionParams cp : mApnContexts.values()) {
            ApnContext apnContext = cp.mApnContext;
            if (apnContext == alreadySent) continue;
@@ -1364,9 +1357,6 @@ public class DataConnection extends StateMachine {
    /**
     * Get the network capabilities for this data connection.
     *
     * Note that this method reads fields from mNetworkInfo, so its output is only as fresh
     * as mNetworkInfo. Call updateNetworkInfoSuspendState before calling this.
     *
     * @return the {@link NetworkCapabilities} of this data connection.
     */
    public NetworkCapabilities getNetworkCapabilities() {
@@ -1484,7 +1474,7 @@ public class DataConnection extends StateMachine {
            result.removeCapability(NetworkCapabilities.NET_CAPABILITY_TEMPORARILY_NOT_METERED);
        }

        updateNetworkInfoSuspendState();
        updateSuspendState();
        result.setCapability(NetworkCapabilities.NET_CAPABILITY_NOT_SUSPENDED, !mIsSuspended);

        result.setAdministratorUids(mAdministratorUids);
@@ -1790,10 +1780,6 @@ public class DataConnection extends StateMachine {
                                + " drs=" + mDataRegState
                                + " mRilRat=" + mRilRat);
                    }
                    if (mNetworkAgent != null) {
                        updateNetworkInfo();
                        mNetworkAgent.sendNetworkInfo(mNetworkInfo, DataConnection.this);
                    }
                    break;
                default:
                    if (DBG) {
@@ -1806,34 +1792,18 @@ public class DataConnection extends StateMachine {
        }
    }

    private void updateNetworkInfo() {
        final ServiceState state = mPhone.getServiceState();

        NetworkRegistrationInfo nri = state.getNetworkRegistrationInfo(
                NetworkRegistrationInfo.DOMAIN_PS, mTransportType);
        int subtype = TelephonyManager.NETWORK_TYPE_UNKNOWN;
        if (nri != null) {
            subtype = nri.getAccessNetworkTechnology();
        }

        mNetworkInfo.setSubtype(subtype, TelephonyManager.getNetworkTypeName(subtype));
    }

    private void updateNetworkInfoSuspendState() {
    private void updateSuspendState() {
        if (mNetworkAgent == null) {
            Rlog.e(getName(), "Setting suspend state without a NetworkAgent");
            Rlog.d(getName(), "Setting suspend state without a NetworkAgent");
        }

        boolean suspended = isSuspended();
        if (mIsSuspended != suspended) {
            mIsSuspended = suspended;

            // If data connection is active, we need to update the suspended state.
            // If data connection is active, we need to notify the new data connection state
            // changed event.
            if (isActive()) {
                mNetworkInfo.setDetailedState(mIsSuspended
                                ? NetworkInfo.DetailedState.SUSPENDED
                                : NetworkInfo.DetailedState.CONNECTED, null,
                        mNetworkInfo.getExtraInfo());
                notifyDataConnectionState();
            }
        }
@@ -1907,15 +1877,8 @@ public class DataConnection extends StateMachine {
                            "Handover failed and dangling agent found.");
                    mHandoverSourceNetworkAgent.acquireOwnership(
                            DataConnection.this, mTransportType);
                    NetworkInfo networkInfo = mHandoverSourceNetworkAgent.getNetworkInfo();
                    if (networkInfo != null) {
                    log("Cleared dangling network agent. " + mHandoverSourceNetworkAgent);
                    mHandoverSourceNetworkAgent.unregister(DataConnection.this);
                    } else {
                        String str = "Failed to get network info.";
                        loge(str);
                        mHandoverLocalLog.log(str);
                    }
                    mHandoverSourceNetworkAgent.releaseOwnership(DataConnection.this);
                }
                mHandoverSourceNetworkAgent = null;
@@ -2163,9 +2126,6 @@ public class DataConnection extends StateMachine {
                    mApnSetting != null ? (long) mApnSetting.getApnTypeBitmask() : 0L,
                    mApnSetting != null
                        ? mApnSetting.canHandleType(ApnSetting.TYPE_DEFAULT) : false);

            updateNetworkInfo();

            // If we were retrying there maybe more than one, otherwise they'll only be one.
            notifyAllWithEvent(null, DctConstants.EVENT_DATA_SETUP_COMPLETE,
                    Phone.REASON_CONNECTED);
@@ -2179,9 +2139,6 @@ public class DataConnection extends StateMachine {
            // if it didn't then this is effectively a NOP.
            mDcController.addActiveDcByCid(DataConnection.this);

            mNetworkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED,
                    mNetworkInfo.getReason(), null);
            mNetworkInfo.setExtraInfo(mApnSetting.getApnName());
            updateTcpBufferSizes(mRilRat);
            updateLinkBandwidthsFromCarrierConfig(mRilRat);

@@ -2241,6 +2198,7 @@ public class DataConnection extends StateMachine {
                    // do it now because connectivity service does not support dynamically removing
                    // immutable capabilities.

                    mNetworkAgent.updateLegacySubtype(DataConnection.this);
                    // Update the capability after handover
                    mNetworkAgent.sendNetworkCapabilities(getNetworkCapabilities(),
                            DataConnection.this);
@@ -2260,9 +2218,8 @@ public class DataConnection extends StateMachine {

                mDisabledApnTypeBitMask |= getDisallowedApnTypes();
                updateLinkPropertiesHttpProxy();
                mNetworkAgent = new DcNetworkAgent(DataConnection.this,
                        mPhone, mNetworkInfo, mScore, configBuilder.build(), provider,
                        mTransportType);
                mNetworkAgent = new DcNetworkAgent(DataConnection.this, mPhone, mScore,
                        configBuilder.build(), provider, mTransportType);
                // All network agents start out in CONNECTING mode, but DcNetworkAgents are
                // created when the network is already connected. Hence, send the connected
                // notification immediately.
@@ -2283,34 +2240,22 @@ public class DataConnection extends StateMachine {
        @Override
        public void exit() {
            if (DBG) log("DcActiveState: exit dc=" + this);
            String reason = mNetworkInfo.getReason();
            if(mDcController.isExecutingCarrierChange()) {
                reason = Phone.REASON_CARRIER_CHANGE;
            } else if (mDisconnectParams != null && mDisconnectParams.mReason != null) {
                reason = mDisconnectParams.mReason;
            } else {
                reason = DataFailCause.toString(mDcFailCause);
            }
            mPhone.getCallTracker().unregisterForVoiceCallStarted(getHandler());
            mPhone.getCallTracker().unregisterForVoiceCallEnded(getHandler());

            // If the data connection is being handover to other transport, we should not notify
            // disconnected to connectivity service.
            if (mHandoverState != HANDOVER_STATE_BEING_TRANSFERRED) {
                mNetworkInfo.setDetailedState(NetworkInfo.DetailedState.DISCONNECTED,
                        reason, mNetworkInfo.getExtraInfo());
            }

            if (mTransportType == AccessNetworkConstants.TRANSPORT_TYPE_WWAN) {
                mPhone.mCi.unregisterForNattKeepaliveStatus(getHandler());
                mPhone.mCi.unregisterForLceInfo(getHandler());
            }

            // If we are still owning this agent, then we should inform connectivity service the
            // data connection is disconnected. If we don't own this agent at this point, that means
            // it has been transferred to the new data connection for IWLAN data handover case.
            // data connection is disconnected. There is one exception that we shouldn't unregister,
            // which is when IWLAN handover is ongoing. Instead of unregistering, the agent will
            // be transferred to the new data connection on the other transport.
            if (mNetworkAgent != null) {
                mNetworkAgent.sendNetworkInfo(mNetworkInfo, DataConnection.this);
                if (mHandoverState != HANDOVER_STATE_BEING_TRANSFERRED) {
                    mNetworkAgent.unregister(DataConnection.this);
                }
                mNetworkAgent.releaseOwnership(DataConnection.this);
            }
            mNetworkAgent = null;
@@ -2418,10 +2363,11 @@ public class DataConnection extends StateMachine {
                                + " mRilRat=" + mRilRat);
                    }
                    if (mNetworkAgent != null) {
                        updateNetworkInfoSuspendState();
                        mNetworkAgent.updateLegacySubtype(DataConnection.this);
                        // The new suspended state will be passed through connectivity service
                        // through NET_CAPABILITY_NOT_SUSPENDED.
                        mNetworkAgent.sendNetworkCapabilities(getNetworkCapabilities(),
                                DataConnection.this);
                        mNetworkAgent.sendNetworkInfo(mNetworkInfo, DataConnection.this);
                        mNetworkAgent.sendLinkProperties(mLinkProperties, DataConnection.this);
                    }
                    retVal = HANDLED;
@@ -2449,12 +2395,13 @@ public class DataConnection extends StateMachine {
                    // fallthrough
                case EVENT_DATA_CONNECTION_ROAM_ON:
                case EVENT_DATA_CONNECTION_ROAM_OFF:
                case EVENT_DATA_CONNECTION_OVERRIDE_CHANGED: {
                case EVENT_DATA_CONNECTION_OVERRIDE_CHANGED:
                case EVENT_DATA_CONNECTION_VOICE_CALL_STARTED:
                case EVENT_DATA_CONNECTION_VOICE_CALL_ENDED: {
                    if (mNetworkAgent != null) {
                        updateNetworkInfo();
                        mNetworkAgent.updateLegacySubtype(DataConnection.this);
                        mNetworkAgent.sendNetworkCapabilities(getNetworkCapabilities(),
                                DataConnection.this);
                        mNetworkAgent.sendNetworkInfo(mNetworkInfo, DataConnection.this);
                    }
                    retVal = HANDLED;
                    break;
@@ -2471,18 +2418,6 @@ public class DataConnection extends StateMachine {
                    retVal = HANDLED;
                    break;
                }
                case EVENT_DATA_CONNECTION_VOICE_CALL_STARTED:
                case EVENT_DATA_CONNECTION_VOICE_CALL_ENDED: {
                    if (mNetworkAgent != null) {
                        updateNetworkInfoSuspendState();
                        updateNetworkInfo();
                        mNetworkAgent.sendNetworkCapabilities(getNetworkCapabilities(),
                                DataConnection.this);
                        mNetworkAgent.sendNetworkInfo(mNetworkInfo, DataConnection.this);
                    }
                    retVal = HANDLED;
                    break;
                }
                case EVENT_KEEPALIVE_START_REQUEST: {
                    KeepalivePacketData pkt = (KeepalivePacketData) msg.obj;
                    int slotId = msg.arg1;
+33 −41
Original line number Diff line number Diff line
@@ -24,14 +24,16 @@ import android.net.NattKeepalivePacketData;
import android.net.NetworkAgent;
import android.net.NetworkAgentConfig;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.NetworkProvider;
import android.net.SocketKeepalive;
import android.net.Uri;
import android.os.Message;
import android.telephony.AccessNetworkConstants;
import android.telephony.AccessNetworkConstants.TransportType;
import android.telephony.Annotation.NetworkType;
import android.telephony.AnomalyReporter;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.util.ArrayMap;
import android.util.LocalLog;
@@ -78,13 +80,11 @@ public class DcNetworkAgent extends NetworkAgent {

    private final LocalLog mNetCapsLocalLog = new LocalLog(50);

    private NetworkInfo mNetworkInfo;

    // For interface duplicate detection. Key is the net id, value is the interface name in string.
    private static Map<Integer, String> sInterfaceNames = new ArrayMap<>();

    DcNetworkAgent(DataConnection dc, Phone phone, NetworkInfo ni, int score,
            NetworkAgentConfig config, NetworkProvider networkProvider, int transportType) {
    DcNetworkAgent(DataConnection dc, Phone phone, int score, NetworkAgentConfig config,
            NetworkProvider networkProvider, int transportType) {
        super(phone.getContext(), dc.getHandler().getLooper(), "DcNetworkAgent",
                dc.getNetworkCapabilities(), dc.getLinkProperties(), score, config,
                networkProvider);
@@ -95,9 +95,9 @@ public class DcNetworkAgent extends NetworkAgent {
        mNetworkCapabilities = dc.getNetworkCapabilities();
        mTransportType = transportType;
        mDataConnection = dc;
        mNetworkInfo = new NetworkInfo(ni);
        setLegacySubtype(ni.getSubtype(), ni.getSubtypeName());
        setLegacyExtraInfo(ni.getExtraInfo());
        int networkType = getNetworkType();
        setLegacySubtype(networkType, TelephonyManager.getNetworkTypeName(networkType));
        setLegacyExtraInfo(dc.getApnSetting().getApnName());
        if (dc.getLinkProperties() != null) {
            checkDuplicateInterface(mId, dc.getLinkProperties().getInterfaceName());
            logd("created for data connection " + dc.getName() + ", "
@@ -107,6 +107,19 @@ public class DcNetworkAgent extends NetworkAgent {
        }
    }

    private @NetworkType int getNetworkType() {
        ServiceState ss = mPhone.getServiceState();
        int networkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;

        NetworkRegistrationInfo nri = ss.getNetworkRegistrationInfo(
                NetworkRegistrationInfo.DOMAIN_PS, mTransportType);
        if (nri != null) {
            networkType = nri.getAccessNetworkTechnology();
        }

        return networkType;
    }

    private void checkDuplicateInterface(int netId, @Nullable String interfaceName) {
        for (Map.Entry<Integer, String> entry: sInterfaceNames.entrySet()) {
            if (Objects.equals(interfaceName, entry.getValue())) {
@@ -222,6 +235,18 @@ public class DcNetworkAgent extends NetworkAgent {
        return true;
    }

    /**
     * Update the legacy sub type (i.e. data network type).
     *
     * @param dc The data connection that invokes this method.
     */
    public synchronized void updateLegacySubtype(DataConnection dc) {
        if (!isOwned(dc, "updateLegacySubtype")) return;

        int networkType = getNetworkType();
        setLegacySubtype(networkType, TelephonyManager.getNetworkTypeName(networkType));
    }

    /**
     * Set the network capabilities.
     *
@@ -293,39 +318,6 @@ public class DcNetworkAgent extends NetworkAgent {
        super.unregister();
    }

    /**
     * Set the network info.
     *
     * @param networkInfo The network info.
     * @param dc The data connection that invokes this method.
     */
    public synchronized void sendNetworkInfo(NetworkInfo networkInfo, DataConnection dc) {
        if (!isOwned(dc, "sendNetworkInfo")) return;
        final NetworkInfo.State oldState = mNetworkInfo.getState();
        final NetworkInfo.State state = networkInfo.getState();
        if (!mNetworkInfo.getExtraInfo().equals(networkInfo.getExtraInfo())) {
            setLegacyExtraInfo(networkInfo.getExtraInfo());
        }
        int subType = networkInfo.getSubtype();
        if (mNetworkInfo.getSubtype() != subType) {
            setLegacySubtype(subType, TelephonyManager.getNetworkTypeName(subType));
        }
        if ((oldState == NetworkInfo.State.SUSPENDED || oldState == NetworkInfo.State.CONNECTED)
                && state == NetworkInfo.State.DISCONNECTED) {
            unregister(dc);
        }
        mNetworkInfo = new NetworkInfo(networkInfo);
    }

    /**
     * Get the latest sent network info.
     *
     * @return network info
     */
    public synchronized NetworkInfo getNetworkInfo() {
        return mNetworkInfo;
    }

    @Override
    public synchronized void onStartSocketKeepalive(int slot, @NonNull Duration interval,
            @NonNull KeepalivePacketData packet) {
+0 −7
Original line number Diff line number Diff line
@@ -47,7 +47,6 @@ import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.NattKeepalivePacketData;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.os.AsyncResult;
import android.os.Handler;
import android.os.HandlerThread;
@@ -554,12 +553,6 @@ public class DataConnectionTest extends TelephonyTest {
        assertEquals(RetryManager.NO_RETRY, getSuggestedRetryDelay(response));
    }

    private NetworkInfo getNetworkInfo() throws Exception {
        Field f = DataConnection.class.getDeclaredField("mNetworkInfo");
        f.setAccessible(true);
        return (NetworkInfo) f.get(mDc);
    }

    private NetworkCapabilities getNetworkCapabilities() throws Exception {
        Method method = DataConnection.class.getDeclaredMethod("getNetworkCapabilities");
        method.setAccessible(true);