TrustedWebActivityServiceConnectionPool


class TrustedWebActivityServiceConnectionPool


A TrustedWebActivityServiceConnectionPool will be used by a Trusted Web Activity provider and takes care of connecting to and communicating with TrustedWebActivityServices. This is done through the connect method.

Multiple Trusted Web Activity client apps may be suitable for a given scope. These are passed in to connect and serviceExistsForScope and the most appropriate one for the scope is chosen.

Summary

Public functions

ListenableFuture<TrustedWebActivityServiceConnection!>
@MainThread
connect(
    scope: Uri,
    possiblePackages: (Mutable)Set<Token!>,
    executor: Executor
)

Connects to the appropriate TrustedWebActivityService or uses an existing connection if available and runs code once connected.

java-static TrustedWebActivityServiceConnectionPool
create(context: Context)

Creates a TrustedWebActivityServiceConnectionPool.

Boolean
@MainThread
serviceExistsForScope(scope: Uri, possiblePackages: (Mutable)Set<Token!>)

Checks if a TrustedWebActivityService exists to handle requests for the given scope and origin.

Public functions

connect

Added in 1.2.0
@MainThread
fun connect(
    scope: Uri,
    possiblePackages: (Mutable)Set<Token!>,
    executor: Executor
): ListenableFuture<TrustedWebActivityServiceConnection!>

Connects to the appropriate TrustedWebActivityService or uses an existing connection if available and runs code once connected.

To find a Service to connect to, this method attempts to resolve an ACTION_VIEW Intent with the scope as data. The first of the resolved packages to be contained in the possiblePackages set will be chosen. Finally, an Intent with the action ACTION_TRUSTED_WEB_ACTIVITY_SERVICE will be used to find the Service.

This method should be called on the UI thread.

Parameters
scope: Uri

The scope used in an Intent to find packages that may have a TrustedWebActivityService.

possiblePackages: (Mutable)Set<Token!>

A collection of packages to consider. These would be the packages that have previously launched a Trusted Web Activity for the origin.

executor: Executor

The Executor to connect to the Service on if a new connection is required.

Returns
ListenableFuture<TrustedWebActivityServiceConnection!>

A ListenableFuture for the resulting TrustedWebActivityServiceConnection. This may be set to an IllegalArgumentException if no service exists for the scope (you can check for this beforehand by calling serviceExistsForScope). It may be set to a SecurityException if the Service does not accept connections from this app. It may be set to an IllegalStateException if connecting to the Service fails.

create

Added in 1.2.0
java-static fun create(context: Context): TrustedWebActivityServiceConnectionPool

Creates a TrustedWebActivityServiceConnectionPool.

Parameters
context: Context

A Context used for accessing SharedPreferences.

serviceExistsForScope

Added in 1.2.0
@MainThread
fun serviceExistsForScope(scope: Uri, possiblePackages: (Mutable)Set<Token!>): Boolean

Checks if a TrustedWebActivityService exists to handle requests for the given scope and origin. This method uses the same logic as connect. If this method returns false, connect will return a Future containing an IllegalStateException.

This method should be called on the UI thread.

Parameters
scope: Uri

The scope used in an Intent to find packages that may have a TrustedWebActivityService.

possiblePackages: (Mutable)Set<Token!>

A collection of packages to consider. These would be the packages that have previously launched a Trusted Web Activity for the origin.

Returns
Boolean

Whether a TrustedWebActivityService was found.