# 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)

*** ** * ** ***


```
public final class HostValidator
```

<br />

*** ** * ** ***

Validates that the calling package is authorized to connect to a `https://developer.android.com/reference/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 |
|---|---|
| `https://developer.android.com/reference/androidx/car/app/validation/HostValidator.Builder` |   |

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/car/app/validation/HostValidator.Builder` Builder of `https://developer.android.com/reference/androidx/car/app/validation/HostValidator`. |

| ### Constants |
|---|---|
| `static final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/validation/HostValidator` | `https://developer.android.com/reference/androidx/car/app/validation/HostValidator#ALLOW_ALL_HOSTS_VALIDATOR()` A host validator that doesn't block any hosts. |
| `static final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/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 methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/String.html>>` | `https://developer.android.com/reference/androidx/car/app/validation/HostValidator#getAllowedHosts()()` Returns a map from package name to signature digests of each of the allowed hosts. |
| `boolean` | `https://developer.android.com/reference/androidx/car/app/validation/HostValidator#isValidHost(androidx.car.app.HostInfo)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/HostInfo 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)

```
public static final @NonNull HostValidator ALLOW_ALL_HOSTS_VALIDATOR
```

A host validator that doesn't block any hosts.

This is intended to be used only during development.

| See also |
|---|---|
| `https://developer.android.com/reference/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)

```
public static final String 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). Other hosts must be allow-listed using `https://developer.android.com/reference/androidx/car/app/validation/HostValidator.Builder#addAllowedHost(java.lang.String,java.lang.String)` or `https://developer.android.com/reference/androidx/car/app/validation/HostValidator.Builder#addAllowedHosts(int)`

## Public methods

### getAllowedHosts

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

```
public @NonNull Map<String, List<String>> getAllowedHosts()
```

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)

```
public boolean isValidHost(@NonNull HostInfo hostInfo)
```

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