Android 12 Developer Preview is here! Try it out, and give us your feedback!

HostValidator

public final class HostValidator
extends Object

java.lang.Object
   ↳ androidx.car.app.validation.HostValidator


Validates that the calling package is authorized to connect to a 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.

Summary

Nested classes

class HostValidator.Builder

Builder of HostValidator

Constants

String TEMPLATE_RENDERER_PERMISSION

System permission used to identify valid hosts (only used by hosts running on Android API level 31 or later).

Fields

public static final HostValidator ALLOW_ALL_HOSTS_VALIDATOR

A host validator that doesn't block any hosts.

Public methods

Map<String, List<String>> getAllowedHosts()

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

boolean isValidHost(HostInfo hostInfo)

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

Inherited methods

Constants

TEMPLATE_RENDERER_PERMISSION

public static final String TEMPLATE_RENDERER_PERMISSION

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 HostValidator.Builder.addAllowedHost(String, String) or HostValidator.Builder.addAllowedHosts(int)

Constant Value: "android.car.permission.TEMPLATE_RENDERER"

Fields

ALLOW_ALL_HOSTS_VALIDATOR

public static final HostValidator ALLOW_ALL_HOSTS_VALIDATOR

A host validator that doesn't block any hosts.

This is intended to be used only during development.

Public methods

getAllowedHosts

public Map<String, List<String>> getAllowedHosts ()

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

Returns
Map<String, List<String>>

isValidHost

public boolean isValidHost (HostInfo hostInfo)

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

Parameters
hostInfo HostInfo

Returns
boolean