Methods Summary |
---|
public static void | clearThreadStatsTag()Clear any active tag set to account {@link Socket} traffic originating
from the current thread.
NetworkManagementSocketTagger.setThreadSocketStatsTag(-1);
|
public static void | clearThreadStatsUid(){@hide}
NetworkManagementSocketTagger.setThreadSocketStatsUid(-1);
|
public static void | closeQuietly(INetworkStatsSession session){@hide}
// TODO: move to NetworkStatsService once it exists
if (session != null) {
try {
session.close();
} catch (RuntimeException rethrown) {
throw rethrown;
} catch (Exception ignored) {
}
}
|
private static NetworkStats | getDataLayerSnapshotForUid(android.content.Context context)Return detailed {@link NetworkStats} for the current UID. Requires no
special permission.
// TODO: take snapshot locally, since proc file is now visible
final int uid = android.os.Process.myUid();
try {
return getStatsService().getDataLayerSnapshotForUid(uid);
} catch (RemoteException e) {
throw new RuntimeException(e);
}
|
private static java.lang.String[] | getMobileIfaces()Return set of any ifaces associated with mobile networks since boot.
Interfaces are never removed from this list, so counters should always be
monotonic.
try {
return getStatsService().getMobileIfaces();
} catch (RemoteException e) {
throw new RuntimeException(e);
}
|
public static long | getMobileRxBytes()Return number of bytes received across mobile networks since device boot.
Counts packets across all mobile network interfaces, and always increases
monotonically since device boot. Statistics are measured at the network
layer, so they include both TCP and UDP usage.
Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may
return {@link #UNSUPPORTED} on devices where statistics aren't available.
long total = 0;
for (String iface : getMobileIfaces()) {
total += getRxBytes(iface);
}
return total;
|
public static long | getMobileRxPackets()Return number of packets received across mobile networks since device
boot. Counts packets across all mobile network interfaces, and always
increases monotonically since device boot. Statistics are measured at the
network layer, so they include both TCP and UDP usage.
Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may
return {@link #UNSUPPORTED} on devices where statistics aren't available.
long total = 0;
for (String iface : getMobileIfaces()) {
total += getRxPackets(iface);
}
return total;
|
public static long | getMobileTcpRxPackets(){@hide}
long total = 0;
for (String iface : getMobileIfaces()) {
final long stat = nativeGetIfaceStat(iface, TYPE_TCP_RX_PACKETS);
if (stat != UNSUPPORTED) {
total += stat;
}
}
return total;
|
public static long | getMobileTcpTxPackets(){@hide}
long total = 0;
for (String iface : getMobileIfaces()) {
final long stat = nativeGetIfaceStat(iface, TYPE_TCP_TX_PACKETS);
if (stat != UNSUPPORTED) {
total += stat;
}
}
return total;
|
public static long | getMobileTxBytes()Return number of bytes transmitted across mobile networks since device
boot. Counts packets across all mobile network interfaces, and always
increases monotonically since device boot. Statistics are measured at the
network layer, so they include both TCP and UDP usage.
Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may
return {@link #UNSUPPORTED} on devices where statistics aren't available.
long total = 0;
for (String iface : getMobileIfaces()) {
total += getTxBytes(iface);
}
return total;
|
public static long | getMobileTxPackets()Return number of packets transmitted across mobile networks since device
boot. Counts packets across all mobile network interfaces, and always
increases monotonically since device boot. Statistics are measured at the
network layer, so they include both TCP and UDP usage.
Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may
return {@link #UNSUPPORTED} on devices where statistics aren't available.
long total = 0;
for (String iface : getMobileIfaces()) {
total += getTxPackets(iface);
}
return total;
|
public static long | getRxBytes(java.lang.String iface){@hide}
return nativeGetIfaceStat(iface, TYPE_RX_BYTES);
|
public static long | getRxPackets(java.lang.String iface){@hide}
return nativeGetIfaceStat(iface, TYPE_RX_PACKETS);
|
private static synchronized INetworkStatsService | getStatsService()
if (sStatsService == null) {
sStatsService = INetworkStatsService.Stub.asInterface(
ServiceManager.getService(Context.NETWORK_STATS_SERVICE));
}
return sStatsService;
|
public static int | getThreadStatsTag()Get the active tag used when accounting {@link Socket} traffic originating
from the current thread. Only one active tag per thread is supported.
{@link #tagSocket(Socket)}.
return NetworkManagementSocketTagger.getThreadSocketStatsTag();
|
public static long | getTotalRxBytes()Return number of bytes received since device boot. Counts packets across
all network interfaces, and always increases monotonically since device
boot. Statistics are measured at the network layer, so they include both
TCP and UDP usage.
Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may
return {@link #UNSUPPORTED} on devices where statistics aren't available.
return nativeGetTotalStat(TYPE_RX_BYTES);
|
public static long | getTotalRxPackets()Return number of packets received since device boot. Counts packets
across all network interfaces, and always increases monotonically since
device boot. Statistics are measured at the network layer, so they
include both TCP and UDP usage.
Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may
return {@link #UNSUPPORTED} on devices where statistics aren't available.
return nativeGetTotalStat(TYPE_RX_PACKETS);
|
public static long | getTotalTxBytes()Return number of bytes transmitted since device boot. Counts packets
across all network interfaces, and always increases monotonically since
device boot. Statistics are measured at the network layer, so they
include both TCP and UDP usage.
Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may
return {@link #UNSUPPORTED} on devices where statistics aren't available.
return nativeGetTotalStat(TYPE_TX_BYTES);
|
public static long | getTotalTxPackets()Return number of packets transmitted since device boot. Counts packets
across all network interfaces, and always increases monotonically since
device boot. Statistics are measured at the network layer, so they
include both TCP and UDP usage.
Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may
return {@link #UNSUPPORTED} on devices where statistics aren't available.
return nativeGetTotalStat(TYPE_TX_PACKETS);
|
public static long | getTxBytes(java.lang.String iface){@hide}
return nativeGetIfaceStat(iface, TYPE_TX_BYTES);
|
public static long | getTxPackets(java.lang.String iface){@hide}
return nativeGetIfaceStat(iface, TYPE_TX_PACKETS);
|
public static long | getUidRxBytes(int uid)Return number of bytes received by the given UID since device boot.
Counts packets across all network interfaces, and always increases
monotonically since device boot. Statistics are measured at the network
layer, so they include both TCP and UDP usage.
Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may return
{@link #UNSUPPORTED} on devices where statistics aren't available.
return nativeGetUidStat(uid, TYPE_RX_BYTES);
|
public static long | getUidRxPackets(int uid)Return number of packets received by the given UID since device boot.
Counts packets across all network interfaces, and always increases
monotonically since device boot. Statistics are measured at the network
layer, so they include both TCP and UDP usage.
Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may return
{@link #UNSUPPORTED} on devices where statistics aren't available.
return nativeGetUidStat(uid, TYPE_RX_PACKETS);
|
public static long | getUidTcpRxBytes(int uid)
return UNSUPPORTED;
|
public static long | getUidTcpRxSegments(int uid)
return UNSUPPORTED;
|
public static long | getUidTcpTxBytes(int uid)
return UNSUPPORTED;
|
public static long | getUidTcpTxSegments(int uid)
return UNSUPPORTED;
|
public static long | getUidTxBytes(int uid)Return number of bytes transmitted by the given UID since device boot.
Counts packets across all network interfaces, and always increases
monotonically since device boot. Statistics are measured at the network
layer, so they include both TCP and UDP usage.
Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may return
{@link #UNSUPPORTED} on devices where statistics aren't available.
return nativeGetUidStat(uid, TYPE_TX_BYTES);
|
public static long | getUidTxPackets(int uid)Return number of packets transmitted by the given UID since device boot.
Counts packets across all network interfaces, and always increases
monotonically since device boot. Statistics are measured at the network
layer, so they include both TCP and UDP usage.
Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may return
{@link #UNSUPPORTED} on devices where statistics aren't available.
return nativeGetUidStat(uid, TYPE_TX_PACKETS);
|
public static long | getUidUdpRxBytes(int uid)
return UNSUPPORTED;
|
public static long | getUidUdpRxPackets(int uid)
return UNSUPPORTED;
|
public static long | getUidUdpTxBytes(int uid)
return UNSUPPORTED;
|
public static long | getUidUdpTxPackets(int uid)
return UNSUPPORTED;
|
public static void | incrementOperationCount(int operationCount)Increment count of network operations performed under the accounting tag
currently active on the calling thread. This can be used to derive
bytes-per-operation.
final int tag = getThreadStatsTag();
incrementOperationCount(tag, operationCount);
|
public static void | incrementOperationCount(int tag, int operationCount)Increment count of network operations performed under the given
accounting tag. This can be used to derive bytes-per-operation.
final int uid = android.os.Process.myUid();
try {
getStatsService().incrementOperationCount(uid, tag, operationCount);
} catch (RemoteException e) {
throw new RuntimeException(e);
}
|
private static native long | nativeGetIfaceStat(java.lang.String iface, int type)
|
private static native long | nativeGetTotalStat(int type)
|
private static native long | nativeGetUidStat(int uid, int type)
|
public static void | setThreadStatsTag(int tag)Set active tag to use when accounting {@link Socket} traffic originating
from the current thread. Only one active tag per thread is supported.
Changes only take effect during subsequent calls to
{@link #tagSocket(Socket)}.
Tags between {@code 0xFFFFFF00} and {@code 0xFFFFFFFF} are reserved and
used internally by system services like {@link DownloadManager} when
performing traffic on behalf of an application.
NetworkManagementSocketTagger.setThreadSocketStatsTag(tag);
|
public static void | setThreadStatsTagBackup()System API for backup-related support components to tag network traffic
appropriately.
setThreadStatsTag(TAG_SYSTEM_BACKUP);
|
public static void | setThreadStatsUid(int uid)Set specific UID to use when accounting {@link Socket} traffic
originating from the current thread. Designed for use when performing an
operation on behalf of another application.
Changes only take effect during subsequent calls to
{@link #tagSocket(Socket)}.
To take effect, caller must hold
{@link android.Manifest.permission#UPDATE_DEVICE_STATS} permission.
NetworkManagementSocketTagger.setThreadSocketStatsUid(uid);
|
public static void | startDataProfiling(android.content.Context context)Start profiling data usage for current UID. Only one profiling session
can be active at a time.
synchronized (sProfilingLock) {
if (sActiveProfilingStart != null) {
throw new IllegalStateException("already profiling data");
}
// take snapshot in time; we calculate delta later
sActiveProfilingStart = getDataLayerSnapshotForUid(context);
}
|
public static NetworkStats | stopDataProfiling(android.content.Context context)Stop profiling data usage for current UID.
synchronized (sProfilingLock) {
if (sActiveProfilingStart == null) {
throw new IllegalStateException("not profiling data");
}
// subtract starting values and return delta
final NetworkStats profilingStop = getDataLayerSnapshotForUid(context);
final NetworkStats profilingDelta = NetworkStats.subtract(
profilingStop, sActiveProfilingStart, null, null);
sActiveProfilingStart = null;
return profilingDelta;
}
|
public static void | tagSocket(java.net.Socket socket)Tag the given {@link Socket} with any statistics parameters active for
the current thread. Subsequent calls always replace any existing
parameters. When finished, call {@link #untagSocket(Socket)} to remove
statistics parameters.
SocketTagger.get().tag(socket);
|
public static void | untagSocket(java.net.Socket socket)Remove any statistics parameters from the given {@link Socket}.
SocketTagger.get().untag(socket);
|