# HostValidator.Builder

# HostValidator.Builder

Artifact:[androidx.car.app:app](https://developer.android.com/jetpack/androidx/releases/car-app)  
[View Source](https://cs.android.com/search?q=file:androidx/car/app/validation/HostValidator.java+class:androidx.car.app.validation.HostValidator.Builder)  
Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/car/app/validation/HostValidator.Builder "View this page in Java")

<br />

```
class HostValidator.Builder
```

<br />

*** ** * ** ***

Builder of[HostValidator](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator).

Allows applications to customize the[HostValidator](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator)that will be used to verify whether a caller is a valid templates host.

## Summary

|                                                                                                                                                                             ### Public constructors                                                                                                                                                                             |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Builder](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator.Builder#Builder(android.content.Context))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`)` Returns an empty[Builder](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator.Builder)instance. |

|                                                   ### Public functions                                                    |
|---------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [HostValidator.Builder](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator.Builder) | [addAllowedHost](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator.Builder#addAllowedHost(java.lang.String,java.lang.String))`(packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`, digest: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Adds a host to the allow list. |
| [HostValidator.Builder](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator.Builder) | [addAllowedHosts](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator.Builder#addAllowedHosts(int))`(allowListedHostsRes: @`[ArrayRes](https://developer.android.com/reference/kotlin/androidx/annotation/ArrayRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Adds a hosts to the allow list.                            |
| [HostValidator](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator)                 | [build](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator.Builder#build())`()` Returns a new[HostValidator](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator)                                                                                                                                                         |

## Public constructors

### Builder

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
Builder(context: Context)
```

Returns an empty[Builder](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator.Builder)instance.  

## Public functions

### addAllowedHost

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
fun addAllowedHost(packageName: String, digest: String): HostValidator.Builder
```

Adds a host to the allow list.  

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `packageName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | host package name (as reported by[PackageManager](https://developer.android.com/reference/android/content/pm/PackageManager.html))                                                                                                                                                                                                                                                                           |
| `digest: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)      | SHA256 digest of the DER encoding of the allow-listed host certificate, formatted as 32 lowercase 2 digits hexadecimal values separated by colon (e.g.:"000102030405060708090a0b0c0d0e0f101112131415 161718191a1b1c1d1e1f"). When using[signature rotation](https://developer.android.com/about/versions/pie/android-9.0#apk-key-rotation), this digest should correspond to the initial signing certificate |

### addAllowedHosts

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
fun addAllowedHosts(allowListedHostsRes: @ArrayRes Int): HostValidator.Builder
```

Adds a hosts to the allow list.

Allow-listed hosts are retrieved from a string-array resource, encoded as \[digest,package-name\] pairs separated by comma. See[addAllowedHost](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator.Builder#addAllowedHost(java.lang.String,java.lang.String))for details on signature digest and package-name formatting.  

|                                                                                          Parameters                                                                                           |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------|
| `allowListedHostsRes: @`[ArrayRes](https://developer.android.com/reference/kotlin/androidx/annotation/ArrayRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | string-array resource identifier |

|                                                        Throws                                                         |
|-----------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|
| [java.lang.IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException.html) | if the provided resource doesn't exist or if the entries in the given resource are not formatted as expected |

### build

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)  

```
fun build(): HostValidator
```

Returns a new[HostValidator](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator)