# HostValidator

# HostValidator

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)  
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 "View this page in Java")

<br />

```
class HostValidator
```

<br />

*** ** * ** ***

Validates that the calling package is authorized to connect to a[CarAppService](https://developer.android.com/reference/kotlin/androidx/car/app/CarAppService).

Host are expected to either hold`android.car.permission.TEMPLATE_RENDERER`privileged permission, or be included in the allow-listed set of hosts, identified by their signatures.  

|                                                         See also                                                          |
|---------------------------------------------------------------------------------------------------------------------------|---|
| [HostValidator.Builder](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator.Builder) |   |

## Summary

|                                                                                                                    ### Nested types                                                                                                                    |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `class `[HostValidator.Builder](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator.Builder) Builder of[HostValidator](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator). |

|                                                   ### Constants                                                   |
|-------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[HostValidator](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator) | [ALLOW_ALL_HOSTS_VALIDATOR](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator#ALLOW_ALL_HOSTS_VALIDATOR()) A host validator that doesn't block any hosts.                                                                                                                     |
| `const `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!`                      | [TEMPLATE_RENDERER_PERMISSION](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator#TEMPLATE_RENDERER_PERMISSION())` = "android.car.permission.TEMPLATE_RENDERER"` System permission used to identify valid hosts (only used by hosts running on Android API level 31 or later). |

|                                                                                                                                                                                                                                                                                 ### Public functions                                                                                                                                                                                                                                                                                 |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `(`[Mutable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)`)`[Map](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!, (`[Mutable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)`)`[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!>!>` | [getAllowedHosts](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator#getAllowedHosts())`()` Returns a map from package name to signature digests of each of the allowed hosts.                                                                                                 |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  | [isValidHost](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator#isValidHost(androidx.car.app.HostInfo))`(hostInfo: `[HostInfo](https://developer.android.com/reference/kotlin/androidx/car/app/HostInfo)`)` Returns whether the given host is allowed to bind to this client. |

## Constants

### ALLOW_ALL_HOSTS_VALIDATOR

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

```
const val ALLOW_ALL_HOSTS_VALIDATOR: HostValidator
```

A host validator that doesn't block any hosts.

This is intended to be used only during development.  

|                                                          See also                                                          |
|----------------------------------------------------------------------------------------------------------------------------|---|
| [createHostValidator](https://developer.android.com/reference/kotlin/androidx/car/app/CarAppService#createHostValidator()) |   |

### TEMPLATE_RENDERER_PERMISSION

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

```
const val TEMPLATE_RENDERER_PERMISSION = "android.car.permission.TEMPLATE_RENDERER": String!
```

System permission used to identify valid hosts (only used by hosts running on Android API level 31 or later). Other hosts must be allow-listed using[addAllowedHost](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator.Builder#addAllowedHost(java.lang.String,java.lang.String))or[addAllowedHosts](https://developer.android.com/reference/kotlin/androidx/car/app/validation/HostValidator.Builder#addAllowedHosts(int))  

## Public functions

### getAllowedHosts

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

```
fun getAllowedHosts(): (Mutable)Map<String!, (Mutable)List<String!>!>
```

Returns a map from package name to signature digests of each of the allowed hosts.  

### isValidHost

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

```
fun isValidHost(hostInfo: HostInfo): Boolean
```

Returns whether the given host is allowed to bind to this client.