# CpuHeadroomParams.Builder

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Builder

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/os/CpuHeadroomParams.Builder "View this page in Java")  

```
class Builder
```

|---|------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                               ||
| ↳ | [android.os.CpuHeadroomParams.Builder](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams.Builder#) |

## Summary

|                                                                                                                                                  Public constructors                                                                                                                                                   ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [Builder](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams.Builder#Builder())`()` <br />                                                                                                                                                                                                 |
| [Builder](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams.Builder#Builder(android.os.CpuHeadroomParams))`(`params:` `[CpuHeadroomParams](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams)`)` Returns a new builder copy with the same values as the params. |

|                                                                                                                                                                                                             Public methods                                                                                                                                                                                                             ||
|-------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [CpuHeadroomParams](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams)                  | [build](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams.Builder#build())`()` Builds the[CpuHeadroomParams](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams)object.                                                                                          |
| [CpuHeadroomParams.Builder](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams.Builder#) | [setCalculationType](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams.Builder#setCalculationType(kotlin.Int))`(`calculationType:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Sets the headroom calculation type.                                     |
| [CpuHeadroomParams.Builder](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams.Builder#) | [setCalculationWindowMillis](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams.Builder#setCalculationWindowMillis(kotlin.Int))`(`windowMillis:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Sets the headroom calculation window size in milliseconds. |
| [CpuHeadroomParams.Builder](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams.Builder#) | [setTids](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams.Builder#setTids(kotlin.Int))`(`vararg` `tids:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` Sets the thread TIDs to track.                                                                  |

## Public constructors

### Builder

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Builder()
```  

### Builder

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Builder(params: CpuHeadroomParams)
```

Returns a new builder copy with the same values as the params.

|                                                               Parameters                                                               ||
|----------|------------------------------------------------------------------------------------------------------------------------------|
| `params` | [CpuHeadroomParams](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams):This value cannot be`null`. |

## Public methods

### build

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun build(): CpuHeadroomParams
```

Builds the[CpuHeadroomParams](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams)object.

|                                                            Return                                                             ||
|--------------------------------------------------------------------------------------------------|-----------------------------|
| [CpuHeadroomParams](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams) | This value cannot be`null`. |

### setCalculationType

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun setCalculationType(calculationType: Int): CpuHeadroomParams.Builder
```

Sets the headroom calculation type.

<br />

|                                                                                                                                                                                                                                               Parameters                                                                                                                                                                                                                                               ||
|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `calculationType` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):Value is[android.os.CpuHeadroomParams#CPU_HEADROOM_CALCULATION_TYPE_MIN](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams#CPU_HEADROOM_CALCULATION_TYPE_MIN:kotlin.Int), or[android.os.CpuHeadroomParams#CPU_HEADROOM_CALCULATION_TYPE_AVERAGE](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams#CPU_HEADROOM_CALCULATION_TYPE_AVERAGE:kotlin.Int) |

|                                                                     Return                                                                     ||
|-------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [CpuHeadroomParams.Builder](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams.Builder#) | This value cannot be`null`. |

|                          Exceptions                           ||
|--------------------------------------|-------------------------|
| `java.lang.IllegalArgumentException` | if the type is invalid. |

### setCalculationWindowMillis

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun setCalculationWindowMillis(windowMillis: Int): CpuHeadroomParams.Builder
```

Sets the headroom calculation window size in milliseconds.

<br />

|                                                                                                                                                                                                                                                                                                                                                              Parameters                                                                                                                                                                                                                                                                                                                                                              ||
|----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `windowMillis` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):the window size in milliseconds ranges from[SystemHealthManager.getCpuHeadroomCalculationWindowRange()](https://developer.android.com/reference/kotlin/android/os/health/SystemHealthManager#getCpuHeadroomCalculationWindowRange()). The smaller the window size, the larger fluctuation in the headroom value should be expected. The default value can be retrieved from the[CpuHeadroomParams.getCalculationWindowMillis](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams#getCalculationWindowMillis()). The device will try to use the closest feasible window size to this param. Value is 1 or greater |

|                                                                     Return                                                                     ||
|-------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [CpuHeadroomParams.Builder](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams.Builder#) | This value cannot be`null`. |

|                           Exceptions                            ||
|--------------------------------------|---------------------------|
| `java.lang.IllegalArgumentException` | if the window is invalid. |

### setTids

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun setTids(vararg tids: Int): CpuHeadroomParams.Builder
```

Sets the thread TIDs to track.

The TIDs should belong to the same of the process that will make the headroom call. And they should not have different core affinity.

If not set or set to empty, the headroom will be based on the PID of the process making the call.

|                                                                                                                                                    Parameters                                                                                                                                                     ||
|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `tids` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):non-null list of TIDs, where maximum size can be read from[SystemHealthManager.getMaxCpuHeadroomTidsSize()](https://developer.android.com/reference/kotlin/android/os/health/SystemHealthManager#getMaxCpuHeadroomTidsSize()). |

|                                                                     Return                                                                     ||
|-------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [CpuHeadroomParams.Builder](https://developer.android.com/reference/kotlin/android/os/CpuHeadroomParams.Builder#) | This value cannot be`null`. |

|                            Exceptions                             ||
|--------------------------------------|-----------------------------|
| `java.lang.IllegalArgumentException` | if the TID is not positive. |