public class NetworkStats extends Object implements Parcelable
/proc/
data format. This structure
optimizes for rapid in-memory comparison, but consider using
NetworkStatsHistory
when persisting.Modifier and Type | Class and Description |
---|---|
static class |
NetworkStats.Entry |
static interface |
NetworkStats.NonMonotonicObserver<C> |
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static Parcelable.Creator<NetworkStats> |
CREATOR |
static String |
IFACE_ALL
iface value when interface details unavailable. |
static int |
ROAMING_ALL
set value for all roaming values. |
static int |
ROAMING_NO
set value where native, non-roaming data is accounted. |
static int |
ROAMING_YES
set value where roaming data is accounted. |
static int |
SET_ALL
set value for all sets combined, not including debug sets. |
static int |
SET_DBG_VPN_IN
Debug
set value when the VPN stats are moved in. |
static int |
SET_DBG_VPN_OUT
Debug
set value when the VPN stats are moved out of a vpn UID. |
static int |
SET_DEBUG_START
|
static int |
SET_DEFAULT
set value where background data is accounted. |
static int |
SET_FOREGROUND
set value where foreground data is accounted. |
static int |
TAG_ALL
tag value matching any tag. |
static int |
TAG_NONE
tag value for total data across all tags. |
static int |
UID_ALL
uid value when UID details unavailable. |
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_ELIDE_DUPLICATES, PARCELABLE_WRITE_RETURN_VALUE
Constructor and Description |
---|
NetworkStats(long elapsedRealtime,
int initialSize) |
NetworkStats(Parcel parcel) |
Modifier and Type | Method and Description |
---|---|
NetworkStats |
addIfaceValues(String iface,
long rxBytes,
long rxPackets,
long txBytes,
long txPackets) |
NetworkStats |
addValues(NetworkStats.Entry entry)
Add new stats entry, copying from given
NetworkStats.Entry . |
NetworkStats |
addValues(String iface,
int uid,
int set,
int tag,
int roaming,
long rxBytes,
long rxPackets,
long txBytes,
long txPackets,
long operations) |
NetworkStats |
addValues(String iface,
int uid,
int set,
int tag,
long rxBytes,
long rxPackets,
long txBytes,
long txPackets,
long operations) |
NetworkStats |
clone()
Creates and returns a copy of this object.
|
void |
combineAllValues(NetworkStats another)
Combine all values from another
NetworkStats into this object. |
NetworkStats |
combineValues(NetworkStats.Entry entry)
Combine given values with an existing row, or create a new row if
findIndex(String, int, int, int, int) is unable to find match. |
NetworkStats |
combineValues(String iface,
int uid,
int set,
int tag,
long rxBytes,
long rxPackets,
long txBytes,
long txPackets,
long operations) |
NetworkStats |
combineValues(String iface,
int uid,
int tag,
long rxBytes,
long rxPackets,
long txBytes,
long txPackets,
long operations)
Deprecated.
|
int |
describeContents()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation.
|
void |
dump(String prefix,
PrintWriter pw) |
int |
findIndex(String iface,
int uid,
int set,
int tag,
int roaming)
Find first stats index that matches the requested parameters.
|
int |
findIndexHinted(String iface,
int uid,
int set,
int tag,
int roaming,
int hintIndex)
Find first stats index that matches the requested parameters, starting
search around the hinted index as an optimization.
|
long |
getElapsedRealtime() |
long |
getElapsedRealtimeAge()
Return age of this
NetworkStats object with respect to
SystemClock.elapsedRealtime() . |
NetworkStats.Entry |
getTotal(NetworkStats.Entry recycle)
Return total of all fields represented by this snapshot object.
|
NetworkStats.Entry |
getTotal(NetworkStats.Entry recycle,
HashSet<String> limitIface)
Return total of all fields represented by this snapshot object matching
the requested
iface . |
NetworkStats.Entry |
getTotal(NetworkStats.Entry recycle,
int limitUid)
Return total of all fields represented by this snapshot object matching
the requested
uid . |
long |
getTotalBytes()
Return total bytes represented by this snapshot object, usually used when
checking if a
subtract(NetworkStats) delta passes a threshold. |
NetworkStats.Entry |
getTotalIncludingTags(NetworkStats.Entry recycle) |
long |
getTotalPackets()
Fast path for battery stats.
|
String[] |
getUniqueIfaces()
Return list of unique interfaces known by this data structure.
|
int[] |
getUniqueUids()
Return list of unique UIDs known by this data structure.
|
NetworkStats.Entry |
getValues(int i,
NetworkStats.Entry recycle)
Return specific stats entry.
|
NetworkStats |
groupedByIface()
Return total statistics grouped by
iface ; doesn't mutate the
original structure. |
NetworkStats |
groupedByUid()
Return total statistics grouped by
uid ; doesn't mutate the
original structure. |
int |
internalSize() |
boolean |
migrateTun(int tunUid,
String tunIface,
String underlyingIface)
VPN accounting.
|
static String |
roamingToString(int roaming)
Return text description of
roaming value. |
void |
setElapsedRealtime(long time) |
static boolean |
setMatches(int querySet,
int dataSet) |
static String |
setToCheckinString(int set)
Return text description of
set value. |
static String |
setToString(int set)
Return text description of
set value. |
int |
size() |
void |
spliceOperationsFrom(NetworkStats stats)
|
NetworkStats |
subtract(NetworkStats right)
Subtract the given
NetworkStats , effectively leaving the delta
between two snapshots in time. |
static <C> NetworkStats |
subtract(NetworkStats left,
NetworkStats right,
NetworkStats.NonMonotonicObserver<C> observer,
C cookie)
Subtract the two given
NetworkStats objects, returning the delta
between two snapshots in time. |
static <C> NetworkStats |
subtract(NetworkStats left,
NetworkStats right,
NetworkStats.NonMonotonicObserver<C> observer,
C cookie,
NetworkStats recycle)
Subtract the two given
NetworkStats objects, returning the delta
between two snapshots in time. |
static String |
tagToString(int tag)
Return text description of
tag value. |
String |
toString()
Returns a string representation of the object.
|
NetworkStats |
withoutUids(int[] uids)
Return all rows except those attributed to the requested UID; doesn't
mutate the original structure.
|
void |
writeToParcel(Parcel dest,
int flags)
Flatten this object in to a Parcel.
|
public static final int UID_ALL
uid
value when UID details unavailable.public static final int TAG_ALL
tag
value matching any tag.public static final int SET_ALL
set
value for all sets combined, not including debug sets.public static final int SET_DEFAULT
set
value where background data is accounted.public static final int SET_FOREGROUND
set
value where foreground data is accounted.public static final int SET_DEBUG_START
public static final int SET_DBG_VPN_IN
set
value when the VPN stats are moved in.public static final int SET_DBG_VPN_OUT
set
value when the VPN stats are moved out of a vpn UID.public static final int TAG_NONE
tag
value for total data across all tags.public static final int ROAMING_ALL
set
value for all roaming values.public static final int ROAMING_NO
set
value where native, non-roaming data is accounted.public static final int ROAMING_YES
set
value where roaming data is accounted.public static final Parcelable.Creator<NetworkStats> CREATOR
public NetworkStats(long elapsedRealtime, int initialSize)
public NetworkStats(Parcel parcel)
public void writeToParcel(Parcel dest, int flags)
Parcelable
writeToParcel
in interface Parcelable
dest
- The Parcel in which the object should be written.flags
- Additional flags about how the object should be written.
May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE
.public NetworkStats clone()
Object
x
, the expression:
will be true, and that the expression:x.clone() != x
will bex.clone().getClass() == x.getClass()
true
, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x)
true
, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
super.clone
. If a class and all of its superclasses (except
Object
) obey this convention, it will be the case that
x.clone().getClass() == x.getClass()
.
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by super.clone
before returning it. Typically, this means
copying any mutable objects that comprise the internal "deep structure"
of the object being cloned and replacing the references to these
objects with references to the copies. If a class contains only
primitive fields or references to immutable objects, then it is usually
the case that no fields in the object returned by super.clone
need to be modified.
The method clone
for class Object
performs a
specific cloning operation. First, if the class of this object does
not implement the interface Cloneable
, then a
CloneNotSupportedException
is thrown. Note that all arrays
are considered to implement the interface Cloneable
and that
the return type of the clone
method of an array type T[]
is T[]
where T is any reference or primitive type.
Otherwise, this method creates a new instance of the class of this
object and initializes all its fields with exactly the contents of
the corresponding fields of this object, as if by assignment; the
contents of the fields are not themselves cloned. Thus, this method
performs a "shallow copy" of this object, not a "deep copy" operation.
The class Object
does not itself implement the interface
Cloneable
, so calling the clone
method on an object
whose class is Object
will result in throwing an
exception at run time.
public NetworkStats addIfaceValues(String iface, long rxBytes, long rxPackets, long txBytes, long txPackets)
public NetworkStats addValues(String iface, int uid, int set, int tag, long rxBytes, long rxPackets, long txBytes, long txPackets, long operations)
public NetworkStats addValues(String iface, int uid, int set, int tag, int roaming, long rxBytes, long rxPackets, long txBytes, long txPackets, long operations)
public NetworkStats addValues(NetworkStats.Entry entry)
NetworkStats.Entry
. The NetworkStats.Entry
object can be recycled across multiple calls.public NetworkStats.Entry getValues(int i, NetworkStats.Entry recycle)
public long getElapsedRealtime()
public void setElapsedRealtime(long time)
public long getElapsedRealtimeAge()
NetworkStats
object with respect to
SystemClock.elapsedRealtime()
.public int size()
public int internalSize()
@Deprecated public NetworkStats combineValues(String iface, int uid, int tag, long rxBytes, long rxPackets, long txBytes, long txPackets, long operations)
public NetworkStats combineValues(String iface, int uid, int set, int tag, long rxBytes, long rxPackets, long txBytes, long txPackets, long operations)
public NetworkStats combineValues(NetworkStats.Entry entry)
findIndex(String, int, int, int, int)
is unable to find match. Can
also be used to subtract values from existing rows.public void combineAllValues(NetworkStats another)
NetworkStats
into this object.public int findIndex(String iface, int uid, int set, int tag, int roaming)
public int findIndexHinted(String iface, int uid, int set, int tag, int roaming, int hintIndex)
public void spliceOperationsFrom(NetworkStats stats)
operations
from the given NetworkStats
based
on matching uid
and tag
rows. Ignores iface
,
since operation counts are at data layer.public String[] getUniqueIfaces()
public int[] getUniqueUids()
public long getTotalBytes()
subtract(NetworkStats)
delta passes a threshold.public NetworkStats.Entry getTotal(NetworkStats.Entry recycle)
public NetworkStats.Entry getTotal(NetworkStats.Entry recycle, int limitUid)
uid
.public NetworkStats.Entry getTotal(NetworkStats.Entry recycle, HashSet<String> limitIface)
iface
.public NetworkStats.Entry getTotalIncludingTags(NetworkStats.Entry recycle)
public long getTotalPackets()
public NetworkStats subtract(NetworkStats right)
NetworkStats
, effectively leaving the delta
between two snapshots in time. Assumes that statistics rows collect over
time, and that none of them have disappeared.public static <C> NetworkStats subtract(NetworkStats left, NetworkStats right, NetworkStats.NonMonotonicObserver<C> observer, C cookie)
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 0
and
reported to the given NetworkStats.NonMonotonicObserver
.
public static <C> NetworkStats subtract(NetworkStats left, NetworkStats right, NetworkStats.NonMonotonicObserver<C> observer, C cookie, NetworkStats recycle)
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 0
and
reported to the given NetworkStats.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.
public NetworkStats groupedByIface()
iface
; doesn't mutate the
original structure.public NetworkStats groupedByUid()
uid
; doesn't mutate the
original structure.public NetworkStats withoutUids(int[] uids)
public void dump(String prefix, PrintWriter pw)
public static String setToCheckinString(int set)
set
value.public static boolean setMatches(int querySet, int dataSet)
public static String roamingToString(int roaming)
roaming
value.public String toString()
Object
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
public int describeContents()
Parcelable
Parcelable.writeToParcel(Parcel, int)
,
the return value of this method must include the
Parcelable.CONTENTS_FILE_DESCRIPTOR
bit.describeContents
in interface Parcelable
Parcelable.CONTENTS_FILE_DESCRIPTOR
public boolean migrateTun(int tunUid, String tunIface, String underlyingIface)
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.
It is possible for the VPN software to use multiple underlying networks. This method
only migrates traffic for the primary underlying network.tunUid
- uid of the VPN applicationtunIface
- iface of the vpn tunnelunderlyingIface
- the primary underlying network iface used by the VPN application