HostValidator


public final class HostValidator


Validates that the calling package is authorized to connect to a CarAppService.

On automotive devices, hosts 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. On non-automotive devices, the android.car.permission.TEMPLATE_RENDERER permission is not checked, and hosts must be allow-listed by signatures using addAllowedHost or addAllowedHosts.

Summary

Nested types

public final class HostValidator.Builder

Builder of HostValidator.

Constants

static final @NonNull HostValidator

A host validator that doesn't block any hosts.

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 on automotive devices).

Public methods

@NonNull Map<StringList<String>>

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

boolean

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

Constants

ALLOW_ALL_HOSTS_VALIDATOR

Added in 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.

TEMPLATE_RENDERER_PERMISSION

Added in 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 on automotive devices). Other hosts must be allow-listed using addAllowedHost or addAllowedHosts.

Public methods

getAllowedHosts

Added in 1.0.0
public @NonNull Map<StringList<String>> getAllowedHosts()

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

isValidHost

Added in 1.0.0
public boolean isValidHost(@NonNull HostInfo hostInfo)

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