# TrafficStatsCompat

# TrafficStatsCompat

Artifact:[androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core)  
[View Source](https://cs.android.com/search?q=file:androidx/core/net/TrafficStatsCompat.java+class:androidx.core.net.TrafficStatsCompat)  
Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/core/net/TrafficStatsCompat "View this page in Java")

<br />

```
class TrafficStatsCompat
```

<br />

*** ** * ** ***

Helper for accessing features in[TrafficStats](https://developer.android.com/reference/android/net/TrafficStats.html).

## Summary

|                                    ### Public functions                                     |
|---------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | ~~[clearThreadStatsTag](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#clearThreadStatsTag())~~`()` **This function is deprecated.** Use[clearThreadStatsTag](https://developer.android.com/reference/android/net/TrafficStats.html#clearThreadStatsTag())directly. <br />                                                                                                                                                                                                                 |
| `java-static `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)   | ~~[getThreadStatsTag](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#getThreadStatsTag())~~`()` **This function is deprecated.** Use[getThreadStatsTag](https://developer.android.com/reference/android/net/TrafficStats.html#getThreadStatsTag())directly. <br />                                                                                                                                                                                                                         |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | ~~[incrementOperationCount](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#incrementOperationCount(int))~~`(operationCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` **This function is deprecated.** Use[incrementOperationCount](https://developer.android.com/reference/android/net/TrafficStats.html#incrementOperationCount(int))directly. <br />                                                                                              |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | ~~[incrementOperationCount](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#incrementOperationCount(int,int))~~`(tag: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, operationCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` **This function is deprecated.** Use[incrementOperationCount](https://developer.android.com/reference/android/net/TrafficStats.html#incrementOperationCount(int, int))directly. <br /> |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | ~~[setThreadStatsTag](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#setThreadStatsTag(int))~~`(tag: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` **This function is deprecated.** Use[setThreadStatsTag](https://developer.android.com/reference/android/net/TrafficStats.html#setThreadStatsTag(int))directly. <br />                                                                                                                                 |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [tagDatagramSocket](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#tagDatagramSocket(java.net.DatagramSocket))`(socket: `[DatagramSocket](https://developer.android.com/reference/java/net/DatagramSocket.html)`)` Tag the given[DatagramSocket](https://developer.android.com/reference/java/net/DatagramSocket.html)with any statistics parameters active for the current thread.                                                                                                        |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | ~~[tagSocket](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#tagSocket(java.net.Socket))~~`(socket: `[Socket](https://developer.android.com/reference/java/net/Socket.html)`!)` **This function is deprecated.** Use[tagSocket](https://developer.android.com/reference/android/net/TrafficStats.html#tagSocket(java.net.Socket))directly. <br />                                                                                                                                          |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [untagDatagramSocket](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#untagDatagramSocket(java.net.DatagramSocket))`(socket: `[DatagramSocket](https://developer.android.com/reference/java/net/DatagramSocket.html)`)` Remove any statistics parameters from the given[DatagramSocket](https://developer.android.com/reference/java/net/DatagramSocket.html).                                                                                                                              |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | ~~[untagSocket](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#untagSocket(java.net.Socket))~~`(socket: `[Socket](https://developer.android.com/reference/java/net/Socket.html)`!)` **This function is deprecated.** Use[untagSocket](https://developer.android.com/reference/android/net/TrafficStats.html#untagSocket(java.net.Socket))directly. <br />                                                                                                                                  |

## Public functions

### clearThreadStatsTag

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  
Deprecated in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun [clearThreadStatsTag](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#clearThreadStatsTag())(): Unit
```
| **This function is deprecated.**   
|
| Use[clearThreadStatsTag](https://developer.android.com/reference/android/net/TrafficStats.html#clearThreadStatsTag())directly.

Clear active tag used when accounting[Socket](https://developer.android.com/reference/java/net/Socket.html)traffic originating from the current thread.  

### getThreadStatsTag

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  
Deprecated in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun [getThreadStatsTag](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#getThreadStatsTag())(): Int
```
| **This function is deprecated.**   
|
| Use[getThreadStatsTag](https://developer.android.com/reference/android/net/TrafficStats.html#getThreadStatsTag())directly.

Get the active tag used when accounting[Socket](https://developer.android.com/reference/java/net/Socket.html)traffic originating from the current thread. Only one active tag per thread is supported.[tagSocket](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#tagSocket(java.net.Socket)).  

### incrementOperationCount

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  
Deprecated in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun [incrementOperationCount](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#incrementOperationCount(int))(operationCount: Int): Unit
```
| **This function is deprecated.**   
|
| Use[incrementOperationCount](https://developer.android.com/reference/android/net/TrafficStats.html#incrementOperationCount(int))directly.

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: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Number of operations to increment count by. |

### incrementOperationCount

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  
Deprecated in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun [incrementOperationCount](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#incrementOperationCount(int,int))(tag: Int, operationCount: Int): Unit
```
| **This function is deprecated.**   
|
| Use[incrementOperationCount](https://developer.android.com/reference/android/net/TrafficStats.html#incrementOperationCount(int, int))directly.

Increment count of network operations performed under the given accounting tag. This can be used to derive bytes-per-operation.  

|                                          Parameters                                           |
|-----------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|
| `tag: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)            | Accounting tag used in[setThreadStatsTag](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#setThreadStatsTag(int)). |
| `operationCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Number of operations to increment count by.                                                                                                            |

### setThreadStatsTag

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  
Deprecated in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun [setThreadStatsTag](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#setThreadStatsTag(int))(tag: Int): Unit
```
| **This function is deprecated.**   
|
| Use[setThreadStatsTag](https://developer.android.com/reference/android/net/TrafficStats.html#setThreadStatsTag(int))directly.

Set active tag to use when accounting[Socket](https://developer.android.com/reference/java/net/Socket.html)traffic originating from the current thread. Only one active tag per thread is supported.

Changes only take effect during subsequent calls to[tagSocket](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#tagSocket(java.net.Socket)).

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

### tagDatagramSocket

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun tagDatagramSocket(socket: DatagramSocket): Unit
```

Tag the given[DatagramSocket](https://developer.android.com/reference/java/net/DatagramSocket.html)with any statistics parameters active for the current thread. Subsequent calls always replace any existing parameters. When finished, call[untagDatagramSocket](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#untagDatagramSocket(java.net.DatagramSocket))to remove statistics parameters.  

|                                              Throws                                               |
|---------------------------------------------------------------------------------------------------|---|
| [java.net.SocketException](https://developer.android.com/reference/java/net/SocketException.html) |   |

|                                                            See also                                                             |
|---------------------------------------------------------------------------------------------------------------------------------|---|
| [setThreadStatsTag](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#setThreadStatsTag(int)) |   |

### tagSocket

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  
Deprecated in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun [tagSocket](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#tagSocket(java.net.Socket))(socket: Socket!): Unit
```
| **This function is deprecated.**   
|
| Use[tagSocket](https://developer.android.com/reference/android/net/TrafficStats.html#tagSocket(java.net.Socket))directly.

Tag the given[Socket](https://developer.android.com/reference/java/net/Socket.html)with any statistics parameters active for the current thread. Subsequent calls always replace any existing parameters. When finished, call[untagSocket](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#untagSocket(java.net.Socket))to remove statistics parameters.  

|                                              Throws                                               |
|---------------------------------------------------------------------------------------------------|---|
| [java.net.SocketException](https://developer.android.com/reference/java/net/SocketException.html) |   |

|                                                            See also                                                             |
|---------------------------------------------------------------------------------------------------------------------------------|---|
| [setThreadStatsTag](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#setThreadStatsTag(int)) |   |

### untagDatagramSocket

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun untagDatagramSocket(socket: DatagramSocket): Unit
```

Remove any statistics parameters from the given[DatagramSocket](https://developer.android.com/reference/java/net/DatagramSocket.html).  

|                                              Throws                                               |
|---------------------------------------------------------------------------------------------------|---|
| [java.net.SocketException](https://developer.android.com/reference/java/net/SocketException.html) |   |

### untagSocket

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  
Deprecated in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun [untagSocket](https://developer.android.com/reference/kotlin/androidx/core/net/TrafficStatsCompat#untagSocket(java.net.Socket))(socket: Socket!): Unit
```
| **This function is deprecated.**   
|
| Use[untagSocket](https://developer.android.com/reference/android/net/TrafficStats.html#untagSocket(java.net.Socket))directly.

Remove any statistics parameters from the given[Socket](https://developer.android.com/reference/java/net/Socket.html).  

|                                              Throws                                               |
|---------------------------------------------------------------------------------------------------|---|
| [java.net.SocketException](https://developer.android.com/reference/java/net/SocketException.html) |   |