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

Commit 429f58c5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add anomaly report for excessive unwanted network in the new data...

Merge "Add anomaly report for excessive unwanted network in the new data stack" into tm-dev am: 3c7d7621

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

Change-Id: I328407486d6830b3ee68886c9210543b31a083be
parents e64fc6ec 3c7d7621
Loading
Loading
Loading
Loading
+39 −0
Original line number Original line Diff line number Diff line
@@ -22,24 +22,29 @@ import android.annotation.Nullable;
import android.net.KeepalivePacketData;
import android.net.KeepalivePacketData;
import android.net.NetworkAgent;
import android.net.NetworkAgent;
import android.net.NetworkAgentConfig;
import android.net.NetworkAgentConfig;
import android.net.NetworkCapabilities;
import android.net.NetworkProvider;
import android.net.NetworkProvider;
import android.net.NetworkScore;
import android.net.NetworkScore;
import android.net.QosFilter;
import android.net.QosFilter;
import android.net.QosSessionAttributes;
import android.net.QosSessionAttributes;
import android.net.Uri;
import android.net.Uri;
import android.os.Looper;
import android.os.Looper;
import android.telephony.AnomalyReporter;
import android.util.ArraySet;
import android.util.ArraySet;
import android.util.IndentingPrintWriter;
import android.util.IndentingPrintWriter;
import android.util.LocalLog;
import android.util.LocalLog;


import com.android.internal.telephony.Phone;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.SlidingWindowEventCounter;
import com.android.telephony.Rlog;
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.Set;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Executor;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;


/**
/**
 * TelephonyNetworkAgent class represents a single PDN (Packet Data Network). It is an agent
 * TelephonyNetworkAgent class represents a single PDN (Packet Data Network). It is an agent
@@ -51,6 +56,13 @@ public class TelephonyNetworkAgent extends NetworkAgent implements NotifyQosSess
    private final Phone mPhone;
    private final Phone mPhone;
    private final LocalLog mLocalLog = new LocalLog(128);
    private final LocalLog mLocalLog = new LocalLog(128);


    /** Event counter for unwanted network within time window, is used to trigger anomaly report. */
    private static final long NETWORK_UNWANTED_ANOMALY_WINDOW_MS = TimeUnit.MINUTES.toMillis(5);
    private static final int NETWORK_UNWANTED_ANOMALY_NUM_OCCURRENCES =  12;
    private static final SlidingWindowEventCounter sNetworkUnwantedCounter =
            new SlidingWindowEventCounter(NETWORK_UNWANTED_ANOMALY_WINDOW_MS,
                    NETWORK_UNWANTED_ANOMALY_NUM_OCCURRENCES);

    /** The parent data network. */
    /** The parent data network. */
    private final @NonNull DataNetwork mDataNetwork;
    private final @NonNull DataNetwork mDataNetwork;


@@ -172,9 +184,36 @@ public class TelephonyNetworkAgent extends NetworkAgent implements NotifyQosSess
            log("The agent is already abandoned. Ignored onNetworkUnwanted.");
            log("The agent is already abandoned. Ignored onNetworkUnwanted.");
            return;
            return;
        }
        }

        NetworkCapabilities capabilities = mDataNetwork.getNetworkCapabilities();
        if (capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_IMS)
                || capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) {
            trackNetworkUnwanted();
        }

        mDataNetwork.tearDown(DataNetwork.TEAR_DOWN_REASON_CONNECTIVITY_SERVICE_UNWANTED);
        mDataNetwork.tearDown(DataNetwork.TEAR_DOWN_REASON_CONNECTIVITY_SERVICE_UNWANTED);
    }
    }


    /**
     * There have been several bugs where a RECONNECT loop kicks off where a DataConnection
     * connects to the Network, ConnectivityService indicates that the Network is unwanted,
     * and then the DataConnection reconnects. By the time we get the bug report it's too late
     * because there have already been hundreds of RECONNECTS.  This is meant to capture the issue
     * when it first starts.
     *
     * The unwanted counter is configured to only take an anomaly report in extreme cases.
     * This is to avoid having the anomaly message show up on several devices.
     *
     */
    private void trackNetworkUnwanted() {
        if (sNetworkUnwantedCounter.addOccurrence()) {
            AnomalyReporter.reportAnomaly(
                    UUID.fromString("9f3bc55b-bfa6-4e26-afaa-5031426a66d1"),
                    "Network Unwanted called 12 times in 5 minutes.");
        }
    }


    /**
    /**
     * @return The unique id of the agent.
     * @return The unique id of the agent.
     */
     */