android.support.v4.net
Class TrafficStatsCompat

java.lang.Object
  extended by android.support.v4.net.TrafficStatsCompat

public class TrafficStatsCompat
extends Object

Helper for accessing features in TrafficStats introduced after API level 14 in a backwards compatible fashion.


Constructor Summary
TrafficStatsCompat()
           
 
Method Summary
static void clearThreadStatsTag()
          Clear active tag used when accounting Socket traffic originating from the current thread.
static int getThreadStatsTag()
          Get the active tag used when accounting Socket traffic originating from the current thread.
static void incrementOperationCount(int operationCount)
          Increment count of network operations performed under the accounting tag currently active on the calling thread.
static void incrementOperationCount(int tag, int operationCount)
          Increment count of network operations performed under the given accounting tag.
static void setThreadStatsTag(int tag)
          Set active tag to use when accounting Socket traffic originating from the current thread.
static void tagSocket(Socket socket)
          Tag the given Socket with any statistics parameters active for the current thread.
static void untagSocket(Socket socket)
          Remove any statistics parameters from the given Socket.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TrafficStatsCompat

public TrafficStatsCompat()
Method Detail

clearThreadStatsTag

public static void clearThreadStatsTag()
Clear active tag used when accounting Socket traffic originating from the current thread.


getThreadStatsTag

public static int getThreadStatsTag()
Get the active tag used when accounting Socket traffic originating from the current thread. Only one active tag per thread is supported. tagSocket(Socket).


incrementOperationCount

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.

Parameters:
operationCount - Number of operations to increment count by.

incrementOperationCount

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.

Parameters:
tag - Accounting tag used in setThreadStatsTag(int).
operationCount - Number of operations to increment count by.

setThreadStatsTag

public static void setThreadStatsTag(int tag)
Set active tag to use when accounting Socket traffic originating from the current thread. Only one active tag per thread is supported.

Changes only take effect during subsequent calls to tagSocket(Socket).

Tags between 0xFFFFFF00 and 0xFFFFFFFF are reserved and used internally by system services like DownloadManager when performing traffic on behalf of an application.


tagSocket

public static void tagSocket(Socket socket)
                      throws SocketException
Tag the given Socket with any statistics parameters active for the current thread. Subsequent calls always replace any existing parameters. When finished, call untagSocket(Socket) to remove statistics parameters.

Throws:
SocketException
See Also:
setThreadStatsTag(int)

untagSocket

public static void untagSocket(Socket socket)
                        throws SocketException
Remove any statistics parameters from the given Socket.

Throws:
SocketException


Copyright © 2013 Marek Kedzierski. All Rights Reserved.