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

Commit 4d6b4815 authored by Jack Yu's avatar Jack Yu Committed by Gerrit Code Review
Browse files

Merge "Generate bugreport for IMS reaping issue"

parents 874bc936 44e01ac9
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ 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;
@@ -47,6 +48,9 @@ import com.android.telephony.Rlog;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * This class represents a network agent which is communication channel between
@@ -75,6 +79,11 @@ public class DcNetworkAgent extends NetworkAgent {

    private NetworkInfo mNetworkInfo;

    // For debugging IMS redundant network agent issue.
    private static List<DcNetworkAgent> sNetworkAgents = new ArrayList<>();

    private static int sRedundantTimes = 0;

    DcNetworkAgent(DataConnection dc, Phone phone, NetworkInfo ni, int score,
            NetworkAgentConfig config, NetworkProvider networkProvider, int transportType) {
        super(phone.getContext(), dc.getHandler().getLooper(), "DcNetworkAgent",
@@ -90,9 +99,31 @@ public class DcNetworkAgent extends NetworkAgent {
        setLegacyExtraInfo(dc.getApnSetting().getApnName());
        int subType = getNetworkType();
        setLegacySubtype(subType, TelephonyManager.getNetworkTypeName(subType));
        // TODO: Remove after b/151487565 is fixed.
        sNetworkAgents.add(this);
        checkRedundantIms();
        logd(mTag + " created for data connection " + dc.getName());
    }

    // This is a temp code to catch the multiple IMS network agents issue.
    // TODO: Remove after b/151487565 is fixed.
    private void checkRedundantIms() {
        if (sNetworkAgents.stream()
                .filter(n -> n.mNetworkCapabilities.hasCapability(
                        NetworkCapabilities.NET_CAPABILITY_IMS))
                .count() > 1) {
            sRedundantTimes++;
            if (sRedundantTimes == 5) { // When it occurs 5 times.
                String message = "Multiple IMS network agents detected.";
                log(message);
                // Using fixed UUID to avoid duplicate bugreport notification
                AnomalyReporter.reportAnomaly(
                        UUID.fromString("a5cf4881-75ae-4129-a25d-71bc4293f493"),
                        message);
            }
        }
    }

    /**
     * @return The tag
     */
@@ -269,6 +300,7 @@ public class DcNetworkAgent extends NetworkAgent {
        if ((oldState == NetworkInfo.State.SUSPENDED || oldState == NetworkInfo.State.CONNECTED)
                && state == NetworkInfo.State.DISCONNECTED) {
            logd("Unregister from connectivity service");
            sNetworkAgents.remove(this);
            unregister();
        }
        mNetworkInfo = new NetworkInfo(networkInfo);