TrustedWebActivityServiceConnectionPool
public
final
class
TrustedWebActivityServiceConnectionPool
extends Object
java.lang.Object | |
↳ | androidx.browser.trusted.TrustedWebActivityServiceConnectionPool |
A TrustedWebActivityServiceConnectionPool will be used by a Trusted Web Activity provider and
takes care of connecting to and communicating with TrustedWebActivityService
s.
This is done through the connect(Uri, Set
method.
Multiple Trusted Web Activity client apps may be suitable for a given scope.
These are passed in to connect(Uri, Set
and serviceExistsForScope(Uri, Set
and the most
appropriate one for the scope is chosen.
Summary
Public methods | |
---|---|
ListenableFuture<TrustedWebActivityServiceConnection>
|
connect(Uri scope, Set<Token> possiblePackages, Executor executor)
Connects to the appropriate |
static
TrustedWebActivityServiceConnectionPool
|
create(Context context)
Creates a TrustedWebActivityServiceConnectionPool. |
boolean
|
serviceExistsForScope(Uri scope, Set<Token> possiblePackages)
Checks if a TrustedWebActivityService exists to handle requests for the given scope and origin. |
Inherited methods | |
---|---|
Public methods
connect
public ListenableFuture<TrustedWebActivityServiceConnection> connect (Uri scope, Set<Token> possiblePackages, Executor executor)
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
Intent.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
TrustedWebActivityService.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 |
Set : 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(Uri, Set ).
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
public static TrustedWebActivityServiceConnectionPool create (Context context)
Creates a TrustedWebActivityServiceConnectionPool.
Parameters | |
---|---|
context |
Context : A Context used for accessing SharedPreferences.
|
Returns | |
---|---|
TrustedWebActivityServiceConnectionPool |
serviceExistsForScope
public boolean serviceExistsForScope (Uri scope, Set<Token> possiblePackages)
Checks if a TrustedWebActivityService exists to handle requests for the given scope and
origin.
This method uses the same logic as connect(Uri, Set
.
If this method returns false
, connect(Uri, Set
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 |
Set : 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.
|