android.net.NetworkStats Maven / Gradle / Ivy
Show all versions of androidstub Show documentation
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.net;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.SystemClock;
import com.android.internal.annotations.VisibleForTesting;
import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
/**
* Collection of active network statistics. Can contain summary details across
* all interfaces, or details with per-UID granularity. Internally stores data
* as a large table, closely matching {@code /proc/} data format. This structure
* optimizes for rapid in-memory comparison, but consider using
* {@link NetworkStatsHistory} when persisting.
*
* @hide
*/
// @NotThreadSafe
@SystemApi
public final class NetworkStats implements Parcelable, Iterable {
private static final String TAG = "NetworkStats";
/**
* {@link #iface} value when interface details unavailable.
*
* @hide
*/
@Nullable
public static final String IFACE_ALL = null;
/**
* Virtual network interface for video telephony. This is for VT data usage counting
* purpose.
*/
public static final String IFACE_VT = "vt_data0";
/**
* {@link #uid} value when UID details unavailable.
*/
public static final int UID_ALL = -1;
/**
* Special UID value for data usage by tethering.
*/
public static final int UID_TETHERING = -5;
/**
* {@link #tag} value matching any tag.
*
* @hide
*/
// TODO: Rename TAG_ALL to TAG_ANY.
public static final int TAG_ALL = -1;
/**
* {@link #set} value for all sets combined, not including debug sets.
*/
public static final int SET_ALL = -1;
/**
* {@link #set} value where background data is accounted.
*/
public static final int SET_DEFAULT = 0;
/**
* {@link #set} value where foreground data is accounted.
*/
public static final int SET_FOREGROUND = 1;
/**
* All {@link #set} value greater than SET_DEBUG_START are debug {@link #set} values.
*
* @hide
*/
public static final int SET_DEBUG_START = 1000;
/**
* Debug {@link #set} value when the VPN stats are moved in.
*
* @hide
*/
public static final int SET_DBG_VPN_IN = 1001;
/**
* Debug {@link #set} value when the VPN stats are moved out of a vpn UID.
*
* @hide
*/
public static final int SET_DBG_VPN_OUT = 1002;
/**
* @hide
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = {"SET_"}, value = {
SET_ALL,
SET_DEFAULT,
SET_FOREGROUND,
})
public @interface State {
}
/**
* Include all interfaces when filtering
*
* @hide
*/
public @Nullable
static final String[] INTERFACES_ALL = null;
/**
* {@link #tag} value for total data across all tags.
*/
// TODO: Rename TAG_NONE to TAG_ALL.
public static final int TAG_NONE = 0;
/**
* {@link #metered} value to account for all metered states.
*/
public static final int METERED_ALL = -1;
/**
* {@link #metered} value where native, unmetered data is accounted.
*/
public static final int METERED_NO = 0;
/**
* {@link #metered} value where metered data is accounted.
*/
public static final int METERED_YES = 1;
/**
* @hide
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = {"METERED_"}, value = {
METERED_ALL,
METERED_NO,
METERED_YES
})
public @interface Meteredness {
}
/**
* {@link #roaming} value to account for all roaming states.
*/
public static final int ROAMING_ALL = -1;
/**
* {@link #roaming} value where native, non-roaming data is accounted.
*/
public static final int ROAMING_NO = 0;
/**
* {@link #roaming} value where roaming data is accounted.
*/
public static final int ROAMING_YES = 1;
/**
* @hide
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = {"ROAMING_"}, value = {
ROAMING_ALL,
ROAMING_NO,
ROAMING_YES
})
public @interface Roaming {
}
public static final int DEFAULT_NETWORK_ALL = -1;
public static final int DEFAULT_NETWORK_NO = 0;
public static final int DEFAULT_NETWORK_YES = 1;
/**
* @hide
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = {"DEFAULT_NETWORK_"}, value = {
DEFAULT_NETWORK_ALL,
DEFAULT_NETWORK_NO,
DEFAULT_NETWORK_YES
})
public @interface DefaultNetwork {
}
/**
* Denotes a request for stats at the interface level.
*
* @hide
*/
public static final int STATS_PER_IFACE = 0;
/**
* Denotes a request for stats at the interface and UID level.
*
* @hide
*/
public static final int STATS_PER_UID = 1;
/**
* @hide
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = {"STATS_PER_"}, value = {
STATS_PER_IFACE,
STATS_PER_UID
})
public @interface StatsType {
}
private static final String CLATD_INTERFACE_PREFIX = "v4-";
// Delta between IPv4 header (20b) and IPv6 header (40b).
// Used for correct stats accounting on clatd interfaces.
private static final int IPV4V6_HEADER_DELTA = 20;
// TODO: move fields to "mVariable" notation
/**
* {@link SystemClock#elapsedRealtime()} timestamp in milliseconds when this data was
* generated.
* It's a timestamps delta when {@link #subtract()},
* {@code INetworkStatsSession#getSummaryForAllUid()} methods are used.
*/
private long elapsedRealtime;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
private int size;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
private int capacity;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
private String[] iface;
@UnsupportedAppUsage
private int[] uid;
@UnsupportedAppUsage
private int[] set;
@UnsupportedAppUsage
private int[] tag;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
private int[] metered;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
private int[] roaming;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
private int[] defaultNetwork;
@UnsupportedAppUsage
private long[] rxBytes;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
private long[] rxPackets;
@UnsupportedAppUsage
private long[] txBytes;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
private long[] txPackets;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
private long[] operations;
/**
* Basic element of network statistics. Contains the number of packets and number of bytes
* transferred on both directions in a given set of conditions. See
* {@link Entry#Entry(String, int, int, int, int, int, int, long, long, long, long, long)}.
*
* @hide
*/
@SystemApi
public static class Entry {
/**
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public String iface;
/**
* @hide
*/
@UnsupportedAppUsage
public int uid;
/**
* @hide
*/
@UnsupportedAppUsage
public int set;
/**
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public int tag;
/**
* Note that this is only populated w/ the default value when read from /proc or written
* to disk. We merge in the correct value when reporting this value to clients of
* getSummary().
*
* @hide
*/
public int metered;
/**
* Note that this is only populated w/ the default value when read from /proc or written
* to disk. We merge in the correct value when reporting this value to clients of
* getSummary().
*
* @hide
*/
public int roaming;
/**
* Note that this is only populated w/ the default value when read from /proc or written
* to disk. We merge in the correct value when reporting this value to clients of
* getSummary().
*
* @hide
*/
public int defaultNetwork;
/**
* @hide
*/
@UnsupportedAppUsage
public long rxBytes;
/**
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public long rxPackets;
/**
* @hide
*/
@UnsupportedAppUsage
public long txBytes;
/**
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public long txPackets;
/**
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public long operations;
/**
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public Entry() {
throw new IllegalStateException("STUB");
}
/**
* @hide
*/
public Entry(long rxBytes, long rxPackets, long txBytes, long txPackets, long operations) {
throw new IllegalStateException("STUB");
}
/**
* @hide
*/
public Entry(String iface, int uid, int set, int tag, long rxBytes, long rxPackets,
long txBytes, long txPackets, long operations) {
throw new IllegalStateException("STUB");
}
/**
* Construct a {@link Entry} object by giving statistics of packet and byte transferred on
* both direction, and associated with a set of given conditions.
*
* @param iface interface name of this {@link Entry}. Or null if not specified.
* @param uid uid of this {@link Entry}. {@link #UID_TETHERING} if this {@link Entry} is
* for tethering. Or {@link #UID_ALL} if this {@link NetworkStats} is only
* counting iface stats.
* @param set usage state of this {@link Entry}. Should be one of the following
* values: {@link #SET_DEFAULT}, {@link #SET_FOREGROUND}.
* @param tag tag of this {@link Entry}.
* @param metered metered state of this {@link Entry}. Should be one of the following
* values: {link #METERED_YES}, {link #METERED_NO}.
* @param roaming roaming state of this {@link Entry}. Should be one of the following
* values: {link #ROAMING_YES}, {link #ROAMING_NO}.
* @param defaultNetwork default network status of this {@link Entry}. Should be one
* of the following values: {link #DEFAULT_NETWORK_YES},
* {link #DEFAULT_NETWORK_NO}.
* @param rxBytes Number of bytes received for this {@link Entry}. Statistics should
* represent the contents of IP packets, including IP headers.
* @param rxPackets Number of packets received for this {@link Entry}. Statistics should
* represent the contents of IP packets, including IP headers.
* @param txBytes Number of bytes transmitted for this {@link Entry}. Statistics should
* represent the contents of IP packets, including IP headers.
* @param txPackets Number of bytes transmitted for this {@link Entry}. Statistics should
* represent the contents of IP packets, including IP headers.
* @param operations count of network operations performed for this {@link Entry}. This can
* be used to derive bytes-per-operation.
*/
public Entry(@Nullable String iface, int uid, @State int set, int tag,
@Meteredness int metered, @Roaming int roaming, @DefaultNetwork int defaultNetwork,
long rxBytes, long rxPackets, long txBytes, long txPackets, long operations) {
throw new IllegalStateException("STUB");
}
/**
* @hide
*/
public boolean isNegative() {
return rxBytes < 0 || rxPackets < 0 || txBytes < 0 || txPackets < 0 || operations < 0;
}
/**
* @hide
*/
public boolean isEmpty() {
return rxBytes == 0 && rxPackets == 0 && txBytes == 0 && txPackets == 0
&& operations == 0;
}
/**
* @hide
*/
public void add(Entry another) {
this.rxBytes += another.rxBytes;
this.rxPackets += another.rxPackets;
this.txBytes += another.txBytes;
this.txPackets += another.txPackets;
this.operations += another.operations;
}
/**
* @return interface name of this entry.
* @hide
*/
@Nullable
public String getIface() {
return iface;
}
/**
* @return the uid of this entry.
*/
public int getUid() {
return uid;
}
/**
* @return the set state of this entry. Should be one of the following
* values: {@link #SET_DEFAULT}, {@link #SET_FOREGROUND}.
*/
@State
public int getSet() {
return set;
}
/**
* @return the tag value of this entry.
*/
public int getTag() {
return tag;
}
/**
* @return the metered state. Should be one of the following
* values: {link #METERED_YES}, {link #METERED_NO}.
*/
@Meteredness
public int getMetered() {
return metered;
}
/**
* @return the roaming state. Should be one of the following
* values: {link #ROAMING_YES}, {link #ROAMING_NO}.
*/
@Roaming
public int getRoaming() {
return roaming;
}
/**
* @return the default network state. Should be one of the following
* values: {link #DEFAULT_NETWORK_YES}, {link #DEFAULT_NETWORK_NO}.
*/
@DefaultNetwork
public int getDefaultNetwork() {
throw new IllegalStateException("STUB");
}
/**
* @return the number of received bytes.
*/
public long getRxBytes() {
throw new IllegalStateException("STUB");
}
/**
* @return the number of received packets.
*/
public long getRxPackets() {
throw new IllegalStateException("STUB");
}
/**
* @return the number of transmitted bytes.
*/
public long getTxBytes() {
throw new IllegalStateException("STUB");
}
/**
* @return the number of transmitted packets.
*/
public long getTxPackets() {
throw new IllegalStateException("STUB");
}
/**
* @return the count of network operations performed for this entry.
*/
public long getOperations() {
throw new IllegalStateException("STUB");
}
@Override
public String toString() {
throw new IllegalStateException("STUB");
}
/**
* @hide
*/
@Override
public boolean equals(@Nullable Object o) {
throw new IllegalStateException("STUB");
}
/**
* @hide
*/
@Override
public int hashCode() {
throw new IllegalStateException("STUB");
}
}
public NetworkStats(long elapsedRealtime, int initialSize) {
throw new IllegalStateException("STUB");
}
/**
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public NetworkStats(Parcel parcel) {
throw new IllegalStateException("STUB");
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
throw new IllegalStateException("STUB");
}
/**
* @hide
*/
@Override
public NetworkStats clone() {
throw new IllegalStateException("STUB");
}
/**
* Clear all data stored in this object.
*
* @hide
*/
public void clear() {
throw new IllegalStateException("STUB");
}
/**
* @hide
*/
@VisibleForTesting
public NetworkStats insertEntry(
String iface, long rxBytes, long rxPackets, long txBytes, long txPackets) {
throw new IllegalStateException("STUB");
}
/**
* @hide
*/
@VisibleForTesting
public NetworkStats insertEntry(String iface, int uid, int set, int tag, long rxBytes,
long rxPackets, long txBytes, long txPackets, long operations) {
throw new IllegalStateException("STUB");
}
/**
* @hide
*/
@VisibleForTesting
public NetworkStats insertEntry(String iface, int uid, int set, int tag, int metered,
int roaming, int defaultNetwork, long rxBytes, long rxPackets, long txBytes,
long txPackets, long operations) {
throw new IllegalStateException("STUB");
}
/**
* Add new stats entry, copying from given {@link Entry}. The {@link Entry}
* object can be recycled across multiple calls.
*
* @hide
*/
public NetworkStats insertEntry(Entry entry) {
throw new IllegalStateException("STUB");
}
private void setValues(int i, Entry entry) {
throw new IllegalStateException("STUB");
}
/**
* Iterate over Entry objects.
*
* Return an iterator of this object that will iterate through all contained Entry objects.
*
* This iterator does not support concurrent modification and makes no guarantee of fail-fast
* behavior. If any method that can mutate the contents of this object is called while
* iteration is in progress, either inside the loop or in another thread, then behavior is
* undefined.
* The remove() method is not implemented and will throw UnsupportedOperationException.
*
* @hide
*/
@SystemApi
@NonNull
public Iterator iterator() {
throw new IllegalStateException("STUB");
}
/**
* Return specific stats entry.
*
* @hide
*/
@UnsupportedAppUsage
public Entry getValues(int i, @Nullable Entry recycle) {
throw new IllegalStateException("STUB");
}
/**
* If @{code dest} is not equal to @{code src}, copy entry from index @{code src} to index
*
* @{code dest}.
*/
private void maybeCopyEntry(int dest, int src) {
if (dest == src) return;
iface[dest] = iface[src];
uid[dest] = uid[src];
set[dest] = set[src];
tag[dest] = tag[src];
metered[dest] = metered[src];
roaming[dest] = roaming[src];
defaultNetwork[dest] = defaultNetwork[src];
rxBytes[dest] = rxBytes[src];
rxPackets[dest] = rxPackets[src];
txBytes[dest] = txBytes[src];
txPackets[dest] = txPackets[src];
operations[dest] = operations[src];
}
/**
* @hide
*/
public long getElapsedRealtime() {
return elapsedRealtime;
}
/**
* @hide
*/
public void setElapsedRealtime(long time) {
elapsedRealtime = time;
}
/**
* Return age of this {@link NetworkStats} object with respect to
* {@link SystemClock#elapsedRealtime()}.
*
* @hide
*/
public long getElapsedRealtimeAge() {
return SystemClock.elapsedRealtime() - elapsedRealtime;
}
/**
* @hide
*/
@UnsupportedAppUsage
public int size() {
return size;
}
/**
* @hide
*/
@VisibleForTesting
public int internalSize() {
return capacity;
}
/**
* @hide
*/
@Deprecated
public NetworkStats combineValues(String iface, int uid, int tag, long rxBytes, long rxPackets,
long txBytes, long txPackets, long operations) {
throw new IllegalStateException("STUB");
}
/**
* @hide
*/
public NetworkStats combineValues(String iface, int uid, int set, int tag,
long rxBytes, long rxPackets, long txBytes, long txPackets, long operations) {
throw new IllegalStateException("STUB");
}
/**
* Combine given values with an existing row, or create a new row if
* {@link #findIndex(String, int, int, int, int, int, int)} is unable to find match. Can
* also be used to subtract values from existing rows. This method mutates the referencing
* {@link NetworkStats} object.
*
* @param entry the {@link Entry} to combine.
* @return a reference to this mutated {@link NetworkStats} object.
* @hide
*/
public @NonNull
NetworkStats combineValues(@NonNull Entry entry) {
throw new IllegalStateException("STUB");
}
/**
* Add given values with an existing row, or create a new row if
* {@link #findIndex(String, int, int, int, int, int, int)} is unable to find match. Can
* also be used to subtract values from existing rows.
*
* @param entry the {@link Entry} to add.
* @return a new constructed {@link NetworkStats} object that contains the result.
*/
public @NonNull
NetworkStats addEntry(@NonNull Entry entry) {
throw new IllegalStateException("STUB");
}
/**
* Add the given {@link NetworkStats} objects.
*
* @return the sum of two objects.
*/
public @NonNull
NetworkStats add(@NonNull NetworkStats another) {
throw new IllegalStateException("STUB");
}
/**
* Combine all values from another {@link NetworkStats} into this object.
*
* @hide
*/
public void combineAllValues(@NonNull NetworkStats another) {
throw new IllegalStateException("STUB");
}
/**
* Find first stats index that matches the requested parameters.
*
* @hide
*/
public int findIndex(String iface, int uid, int set, int tag, int metered, int roaming,
int defaultNetwork) {
throw new IllegalStateException("STUB");
}
/**
* Find first stats index that matches the requested parameters, starting
* search around the hinted index as an optimization.
*
* @hide
*/
@VisibleForTesting
public int findIndexHinted(String iface, int uid, int set, int tag, int metered, int roaming,
int defaultNetwork, int hintIndex) {
throw new IllegalStateException("STUB");
}
/**
* Splice in {@link #operations} from the given {@link NetworkStats} based
* on matching {@link #uid} and {@link #tag} rows. Ignores {@link #iface},
* since operation counts are at data layer.
*
* @hide
*/
public void spliceOperationsFrom(NetworkStats stats) {
throw new IllegalStateException("STUB");
}
/**
* Return list of unique interfaces known by this data structure.
*
* @hide
*/
public String[] getUniqueIfaces() {
throw new IllegalStateException("STUB");
}
/**
* Return list of unique UIDs known by this data structure.
*
* @hide
*/
@UnsupportedAppUsage
public int[] getUniqueUids() {
throw new IllegalStateException("STUB");
}
/**
* Return total bytes represented by this snapshot object, usually used when
* checking if a {@link #subtract(NetworkStats)} delta passes a threshold.
*
* @hide
*/
@UnsupportedAppUsage
public long getTotalBytes() {
final Entry entry = getTotal(null);
return entry.rxBytes + entry.txBytes;
}
/**
* Return total of all fields represented by this snapshot object.
*
* @hide
*/
@UnsupportedAppUsage
public Entry getTotal(Entry recycle) {
return getTotal(recycle, null, UID_ALL, false);
}
/**
* Return total of all fields represented by this snapshot object matching
* the requested {@link #uid}.
*
* @hide
*/
@UnsupportedAppUsage
public Entry getTotal(Entry recycle, int limitUid) {
return getTotal(recycle, null, limitUid, false);
}
/**
* Return total of all fields represented by this snapshot object matching
* the requested {@link #iface}.
*
* @hide
*/
public Entry getTotal(Entry recycle, HashSet limitIface) {
return getTotal(recycle, limitIface, UID_ALL, false);
}
/**
* @hide
*/
@UnsupportedAppUsage
public Entry getTotalIncludingTags(Entry recycle) {
return getTotal(recycle, null, UID_ALL, true);
}
/**
* Return total of all fields represented by this snapshot object matching
* the requested {@link #iface} and {@link #uid}.
*
* @param limitIface Set of {@link #iface} to include in total; or {@code
* null} to include all ifaces.
*/
private Entry getTotal(
Entry recycle, HashSet limitIface, int limitUid, boolean includeTags) {
throw new IllegalStateException("STUB");
}
/**
* Fast path for battery stats.
*
* @hide
*/
public long getTotalPackets() {
throw new IllegalStateException("STUB");
}
/**
* Subtract the given {@link NetworkStats}, effectively leaving the delta
* between two snapshots in time. Assumes that statistics rows collect over
* time, and that none of them have disappeared. This method does not mutate
* the referencing object.
*
* @return the delta between two objects.
*/
public @NonNull
NetworkStats subtract(@NonNull NetworkStats right) {
throw new IllegalStateException("STUB");
}
/**
* Subtract the two given {@link NetworkStats} objects, returning the delta
* between two snapshots in time. Assumes that statistics rows collect over
* time, and that none of them have disappeared.
*
* If counters have rolled backwards, they are clamped to {@code 0} and
* reported to the given {@link NonMonotonicObserver}.
*
* @hide
*/
public static NetworkStats subtract(NetworkStats left, NetworkStats right,
NonMonotonicObserver observer, C cookie) {
throw new IllegalStateException("STUB");
}
/**
* Subtract the two given {@link NetworkStats} objects, returning the delta
* between two snapshots in time. Assumes that statistics rows collect over
* time, and that none of them have disappeared.
*
* If counters have rolled backwards, they are clamped to {@code 0} and
* reported to the given {@link NonMonotonicObserver}.
*
* If recycle is supplied, this NetworkStats object will be
* reused (and returned) as the result if it is large enough to contain
* the data.
*
* @hide
*/
public static NetworkStats subtract(NetworkStats left, NetworkStats right,
NonMonotonicObserver observer, C cookie, NetworkStats recycle) {
throw new IllegalStateException("STUB");
}
/**
* Calculate and apply adjustments to captured statistics for 464xlat traffic.
*
* This mutates stacked traffic stats, to account for IPv4/IPv6 header size difference.
*
*
UID stats, which are only accounted on the stacked interface, need to be increased
* by 20 bytes/packet to account for translation overhead.
*
*
The potential additional overhead of 8 bytes/packet for ip fragments is ignored.
*
*
Interface stats need to sum traffic on both stacked and base interface because:
* - eBPF offloaded packets appear only on the stacked interface
* - Non-offloaded ingress packets appear only on the stacked interface
* (due to iptables raw PREROUTING drop rules)
* - Non-offloaded egress packets appear only on the stacked interface
* (due to ignoring traffic from clat daemon by uid match)
* (and of course the 20 bytes/packet overhead needs to be applied to stacked interface stats)
*
*
This method will behave fine if {@code stackedIfaces} is an non-synchronized but add-only
* {@code ConcurrentHashMap}
*
* @param baseTraffic Traffic on the base interfaces. Will be mutated.
* @param stackedTraffic Stats with traffic stacked on top of our ifaces. Will also be mutated.
* @param stackedIfaces Mapping ipv6if -> ipv4if interface where traffic is counted on both.
* @hide
*/
public static void apply464xlatAdjustments(NetworkStats baseTraffic,
NetworkStats stackedTraffic, Map stackedIfaces) {
throw new IllegalStateException("STUB");
}
/**
* Calculate and apply adjustments to captured statistics for 464xlat traffic counted twice.
*
* This mutates the object this method is called on. Equivalent to calling
* {@link #apply464xlatAdjustments(NetworkStats, NetworkStats, Map)} with {@code this} as
* base and stacked traffic.
*
* @param stackedIfaces Mapping ipv6if -> ipv4if interface where traffic is counted on both.
* @hide
*/
public void apply464xlatAdjustments(Map stackedIfaces) {
apply464xlatAdjustments(this, this, stackedIfaces);
}
/**
* Return total statistics grouped by {@link #iface}; doesn't mutate the
* original structure.
*
* @hide
*/
public NetworkStats groupedByIface() {
throw new IllegalStateException("STUB");
}
/**
* Return total statistics grouped by {@link #uid}; doesn't mutate the
* original structure.
*
* @hide
*/
public NetworkStats groupedByUid() {
throw new IllegalStateException("STUB");
}
/**
* Remove all rows that match one of specified UIDs.
* This mutates the original structure in place.
*
* @hide
*/
public void removeUids(int[] uids) {
throw new IllegalStateException("STUB");
}
/**
* Remove all rows that match one of specified UIDs.
*
* @return the result object.
* @hide
*/
@NonNull
public NetworkStats removeEmptyEntries() {
throw new IllegalStateException("STUB");
}
/**
* Only keep entries that match all specified filters.
*
* This mutates the original structure in place. After this method is called,
* size is the number of matching entries, and capacity is the previous capacity.
*
* @param limitUid UID to filter for, or {@link #UID_ALL}.
* @param limitIfaces Interfaces to filter for, or {@link #INTERFACES_ALL}.
* @param limitTag Tag to filter for, or {@link #TAG_ALL}.
* @hide
*/
public void filter(int limitUid, String[] limitIfaces, int limitTag) {
throw new IllegalStateException("STUB");
}
/**
* Only keep entries with {@link #set} value less than {@link #SET_DEBUG_START}.
*
*
This mutates the original structure in place.
*
* @hide
*/
public void filterDebugEntries() {
throw new IllegalStateException("STUB");
}
private void filter(Predicate predicate) {
throw new IllegalStateException("STUB");
}
/**
* @hide
*/
public void dump(String prefix, PrintWriter pw) {
throw new IllegalStateException("STUB");
}
/**
* Return text description of {@link #set} value.
*
* @hide
*/
public static String setToString(int set) {
throw new IllegalStateException("STUB");
}
/**
* Return text description of {@link #set} value.
*
* @hide
*/
public static String setToCheckinString(int set) {
throw new IllegalStateException("STUB");
}
/**
* @return true if the querySet matches the dataSet.
* @hide
*/
public static boolean setMatches(int querySet, int dataSet) {
throw new IllegalStateException("STUB");
}
/**
* Return text description of {@link #tag} value.
*
* @hide
*/
public static String tagToString(int tag) {
throw new IllegalStateException("STUB");
}
/**
* Return text description of {@link #metered} value.
*
* @hide
*/
public static String meteredToString(int metered) {
throw new IllegalStateException("STUB");
}
/**
* Return text description of {@link #roaming} value.
*
* @hide
*/
public static String roamingToString(int roaming) {
throw new IllegalStateException("STUB");
}
/**
* Return text description of {@link #defaultNetwork} value.
*
* @hide
*/
public static String defaultNetworkToString(int defaultNetwork) {
throw new IllegalStateException("STUB");
}
/**
* @hide
*/
@Override
public String toString() {
throw new IllegalStateException("STUB");
}
@Override
public int describeContents() {
throw new IllegalStateException("STUB");
}
public static final @NonNull
Creator CREATOR = new Creator() {
@Override
public NetworkStats createFromParcel(Parcel in) {
return new NetworkStats(in);
}
@Override
public NetworkStats[] newArray(int size) {
return new NetworkStats[size];
}
};
/**
* @hide
*/
public interface NonMonotonicObserver {
public void foundNonMonotonic(
NetworkStats left, int leftIndex, NetworkStats right, int rightIndex, C cookie);
public void foundNonMonotonic(
NetworkStats stats, int statsIndex, C cookie);
}
/**
* VPN accounting. Move some VPN's underlying traffic to other UIDs that use tun0 iface.
*
* This method should only be called on delta NetworkStats. Do not call this method on a
* snapshot {@link NetworkStats} object because the tunUid and/or the underlyingIface may change
* over time.
*
*
This method performs adjustments for one active VPN package and one VPN iface at a time.
*
* @param tunUid uid of the VPN application
* @param tunIface iface of the vpn tunnel
* @param underlyingIfaces underlying network ifaces used by the VPN application
* @hide
*/
public void migrateTun(int tunUid, @NonNull String tunIface,
@NonNull List underlyingIfaces) {
throw new IllegalStateException("STUB");
}
/**
* Initializes the data used by the migrateTun() method.
*
* This is the first pass iteration which does the following work:
*
*
* - Adds up all the traffic through the tunUid's underlyingIfaces (both foreground and
* background).
*
- Adds up all the traffic through tun0 excluding traffic from the vpn app itself.
*
*
* @param tunUid uid of the VPN application
* @param tunIface iface of the vpn tunnel
* @param underlyingIfaces underlying network ifaces used by the VPN application
* @param tunIfaceTotal output parameter; combined data usage by all apps using VPN
* @param perInterfaceTotal output parameter; data usage by VPN app, grouped by its {@code
* underlyingIfaces}
* @param underlyingIfacesTotal output parameter; data usage by VPN, summed across all of its
* {@code underlyingIfaces}
*/
private void tunAdjustmentInit(int tunUid, @NonNull String tunIface,
@NonNull List underlyingIfaces, @NonNull Entry tunIfaceTotal,
@NonNull Entry[] perInterfaceTotal, @NonNull Entry underlyingIfacesTotal) {
throw new IllegalStateException("STUB");
}
/**
* Distributes traffic across apps that are using given {@code tunIface}, and returns the total
* traffic that should be moved off of {@code tunUid} grouped by {@code underlyingIfaces}.
*
* @param tunUid uid of the VPN application
* @param tunIface iface of the vpn tunnel
* @param underlyingIfaces underlying network ifaces used by the VPN application
* @param tunIfaceTotal combined data usage across all apps using {@code tunIface}
* @param perInterfaceTotal data usage by VPN app, grouped by its {@code underlyingIfaces}
* @param underlyingIfacesTotal data usage by VPN, summed across all of its {@code
* underlyingIfaces}
*/
private Entry[] addTrafficToApplications(int tunUid, @NonNull String tunIface,
@NonNull List underlyingIfaces, @NonNull Entry tunIfaceTotal,
@NonNull Entry[] perInterfaceTotal, @NonNull Entry underlyingIfacesTotal) {
throw new IllegalStateException("STUB");
}
private void deductTrafficFromVpnApp(
int tunUid,
@NonNull List underlyingIfaces,
@NonNull Entry[] moved) {
throw new IllegalStateException("STUB");
}
private static void tunSubtract(int i, @NonNull NetworkStats left, @NonNull Entry right) {
throw new IllegalStateException("STUB");
}
}