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

Commit b5ff3536 authored by Jack Yu's avatar Jack Yu Committed by Automerger Merge Worker
Browse files

Merge changes I7b0f20bb,I6fcf1895 am: e31de851

Original change: https://android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/1369565

Change-Id: I4d6c90c4e0d0b5d47ef75ffb60ee4a8db3bc3884
parents 760317aa e31de851
Loading
Loading
Loading
Loading
+39 −30
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.telephony.dataconnection;
package com.android.internal.telephony.dataconnection;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.net.KeepalivePacketData;
import android.net.KeepalivePacketData;
import android.net.LinkProperties;
import android.net.LinkProperties;
import android.net.NattKeepalivePacketData;
import android.net.NattKeepalivePacketData;
@@ -32,7 +33,7 @@ import android.telephony.AccessNetworkConstants;
import android.telephony.AccessNetworkConstants.TransportType;
import android.telephony.AccessNetworkConstants.TransportType;
import android.telephony.AnomalyReporter;
import android.telephony.AnomalyReporter;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.LocalLog;
import android.util.LocalLog;
import android.util.SparseArray;
import android.util.SparseArray;


@@ -46,8 +47,8 @@ import com.android.telephony.Rlog;
import java.io.FileDescriptor;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.time.Duration;
import java.time.Duration;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.Objects;
import java.util.UUID;
import java.util.UUID;


/**
/**
@@ -63,6 +64,8 @@ import java.util.UUID;
public class DcNetworkAgent extends NetworkAgent {
public class DcNetworkAgent extends NetworkAgent {
    private final String mTag;
    private final String mTag;


    private final int mId;

    private Phone mPhone;
    private Phone mPhone;


    private int mTransportType;
    private int mTransportType;
@@ -77,8 +80,8 @@ public class DcNetworkAgent extends NetworkAgent {


    private NetworkInfo mNetworkInfo;
    private NetworkInfo mNetworkInfo;


    // For debugging duplicate interface issue. Remove before R released.
    // For interface duplicate detection. Key is the net id, value is the interface name in string.
    private static Set<String> sInterfaceNames = new HashSet<>();
    private static Map<Integer, String> sInterfaceNames = new ArrayMap<>();


    DcNetworkAgent(DataConnection dc, Phone phone, NetworkInfo ni, int score,
    DcNetworkAgent(DataConnection dc, Phone phone, NetworkInfo ni, int score,
            NetworkAgentConfig config, NetworkProvider networkProvider, int transportType) {
            NetworkAgentConfig config, NetworkProvider networkProvider, int transportType) {
@@ -86,33 +89,38 @@ public class DcNetworkAgent extends NetworkAgent {
                dc.getNetworkCapabilities(), dc.getLinkProperties(), score, config,
                dc.getNetworkCapabilities(), dc.getLinkProperties(), score, config,
                networkProvider);
                networkProvider);
        register();
        register();
        mTag = "DcNetworkAgent" + "-" + getNetwork().netId;
        mId = getNetwork().netId;
        mTag = "DcNetworkAgent" + "-" + mId;
        mPhone = phone;
        mPhone = phone;
        mNetworkCapabilities = dc.getNetworkCapabilities();
        mNetworkCapabilities = dc.getNetworkCapabilities();
        mTransportType = transportType;
        mTransportType = transportType;
        mDataConnection = dc;
        mDataConnection = dc;
        mNetworkInfo = new NetworkInfo(ni);
        mNetworkInfo = new NetworkInfo(ni);
        setLegacyExtraInfo(ni.getExtraInfo());
        setLegacyExtraInfo(ni.getExtraInfo());
        // TODO: Remove before R is released.
        if (dc.getLinkProperties() != null) {
        if (dc.getLinkProperties() != null
            checkDuplicateInterface(mId, dc.getLinkProperties().getInterfaceName());
                && !TextUtils.isEmpty(dc.getLinkProperties().getInterfaceName())) {
            logd("created for data connection " + dc.getName() + ", "
            checkDuplicateInterface(dc.getLinkProperties().getInterfaceName());
                    + dc.getLinkProperties().getInterfaceName());
        } else {
            loge("The connection does not have a valid link properties.");
        }
        }
        logd(mTag + " created for data connection " + dc.getName());
    }
    }


    // This is a temp code to catch the duplicate network interface issue.
    private void checkDuplicateInterface(int netId, @Nullable String interfaceName) {
    // TODO: Remove before R is released.
        for (Map.Entry<Integer, String> entry: sInterfaceNames.entrySet()) {
    private void checkDuplicateInterface(String interfaceName) {
            if (Objects.equals(interfaceName, entry.getValue())) {
        if (sInterfaceNames.contains(interfaceName)) {
                String message = "Duplicate interface " + interfaceName
            String message = "Duplicate interface " + interfaceName + " is detected.";
                        + " is detected. DcNetworkAgent-" + entry.getKey()
            log(message);
                        + " already used this interface name.";
                loge(message);
                // Using fixed UUID to avoid duplicate bugreport notification
                // Using fixed UUID to avoid duplicate bugreport notification
                AnomalyReporter.reportAnomaly(
                AnomalyReporter.reportAnomaly(
                        UUID.fromString("02f3d3f6-4613-4415-b6cb-8d92c8a938a6"),
                        UUID.fromString("02f3d3f6-4613-4415-b6cb-8d92c8a938a6"),
                        message);
                        message);
                return;
            }
            }
        sInterfaceNames.add(interfaceName);
        }
        sInterfaceNames.put(netId, interfaceName);
    }
    }


    /**
    /**
@@ -143,7 +151,7 @@ public class DcNetworkAgent extends NetworkAgent {
            loge("releaseOwnership called on no-owner DcNetworkAgent!");
            loge("releaseOwnership called on no-owner DcNetworkAgent!");
            return;
            return;
        } else if (mDataConnection != dc) {
        } else if (mDataConnection != dc) {
            log("releaseOwnership: This agent belongs to "
            loge("releaseOwnership: This agent belongs to "
                    + mDataConnection.getName() + ", ignored the request from " + dc.getName());
                    + mDataConnection.getName() + ", ignored the request from " + dc.getName());
            return;
            return;
        }
        }
@@ -252,9 +260,11 @@ public class DcNetworkAgent extends NetworkAgent {
     * @param linkProperties The link properties
     * @param linkProperties The link properties
     * @param dc The data connection that invokes this method.
     * @param dc The data connection that invokes this method.
     */
     */
    public synchronized void sendLinkProperties(LinkProperties linkProperties,
    public synchronized void sendLinkProperties(@NonNull LinkProperties linkProperties,
                                                DataConnection dc) {
                                                DataConnection dc) {
        if (!isOwned(dc, "sendLinkProperties")) return;
        if (!isOwned(dc, "sendLinkProperties")) return;

        sInterfaceNames.put(mId, dc.getLinkProperties().getInterfaceName());
        sendLinkProperties(linkProperties);
        sendLinkProperties(linkProperties);
    }
    }


@@ -277,11 +287,8 @@ public class DcNetworkAgent extends NetworkAgent {
    public synchronized void unregister(DataConnection dc) {
    public synchronized void unregister(DataConnection dc) {
        if (!isOwned(dc, "unregister")) return;
        if (!isOwned(dc, "unregister")) return;


        if (dc.getLinkProperties() != null
        logd("Unregister from connectivity service. " + sInterfaceNames.get(mId) + " removed.");
                && !TextUtils.isEmpty(dc.getLinkProperties().getInterfaceName())) {
        sInterfaceNames.remove(mId);
            sInterfaceNames.remove(dc.getLinkProperties().getInterfaceName());
        }
        logd("Unregister from connectivity service");
        super.unregister();
        super.unregister();
    }
    }


@@ -347,11 +354,13 @@ public class DcNetworkAgent extends NetworkAgent {


    @Override
    @Override
    public String toString() {
    public String toString() {
        return "DcNetworkAgent:"
        return "DcNetworkAgent-"
                + mId
                + " mDataConnection="
                + " mDataConnection="
                + ((mDataConnection != null) ? mDataConnection.getName() : null)
                + ((mDataConnection != null) ? mDataConnection.getName() : null)
                + " mTransportType="
                + " mTransportType="
                + AccessNetworkConstants.transportTypeToString(mTransportType)
                + AccessNetworkConstants.transportTypeToString(mTransportType)
                + " " + ((mDataConnection != null) ? mDataConnection.getLinkProperties() : null)
                + " mNetworkCapabilities=" + mNetworkCapabilities;
                + " mNetworkCapabilities=" + mNetworkCapabilities;
    }
    }