public interface ProviderEventsManager


Provides APIs for credential providers to participate in provider events, such as same-device credential transfer.

This manager supports two primary roles for credential transfer:

  • Importing (Client Role): A provider can initiate a flow to import credentials by calling importCredentials. This will display a UI allowing the user to select another provider to import from.

  • Exporting (Source Role): A provider must first register its ability to export credentials by calling registerExport. Once registered, it will appear in the UI when other providers initiate an import flow.

Summary

Public methods

default static final @NonNull ProviderEventsManager

Creates a ProviderEventsManager based on the given context.

default @NonNull ProviderImportCredentialsResponse

Initiates a flow to import credentials from another credential provider.

abstract void

Initiates a flow to import credentials from another credential provider.

default @NonNull RegisterExportResponse

Registers the calling credential provider as a source for exporting credentials.

abstract void

Registers the calling credential provider as a source for exporting credentials.

Public methods

create

Added in 1.0.0-alpha03
default static final @NonNull ProviderEventsManager create(@NonNull Context context)

Creates a ProviderEventsManager based on the given context.

Parameters
@NonNull Context context

the context with which the ProviderEventsManager should be associated

importCredentials

default @NonNull ProviderImportCredentialsResponse importCredentials(
    @NonNull Context context,
    @NonNull ImportCredentialsRequest request
)

Initiates a flow to import credentials from another credential provider.

This method launches a provider selector UI, allowing the user to choose a source provider from a list of those registered via registerExport. The request is then forwarded to the selected provider.

Under the hood, this API facilitates the transfer by creating a temporary file in the caller's cache directory. The framework handles the file I/O, permissions, and cleanup, providing a seamless transfer medium between the two providers.

Parameters
@NonNull Context context

the activity context required to launch the UI.

@NonNull ImportCredentialsRequest request

the request detailing the credentials to be imported.

Returns
@NonNull ProviderImportCredentialsResponse

a ProviderImportCredentialsResponse with the imported credential data.

Throws
androidx.credentials.providerevents.exception.ImportCredentialsException

on failure, with a subclass indicating the error type.

importCredentialsAsync

Added in 1.0.0-alpha03
abstract void importCredentialsAsync(
    @NonNull Context context,
    @NonNull ImportCredentialsRequest request,
    CancellationSignal cancellationSignal,
    @NonNull Executor executor,
    @NonNull CredentialManagerCallback<@NonNull ProviderImportCredentialsResponse, @NonNull ImportCredentialsException> callback
)

Initiates a flow to import credentials from another credential provider.

This method launches a provider selector UI, allowing the user to choose a source provider from a list of those registered via registerExport. The request is then forwarded to the selected provider.

Under the hood, this API facilitates the transfer by creating a temporary file in the caller's cache directory. The framework handles the file I/O, permissions, and cleanup, providing a seamless transfer medium between the two providers.

Parameters
@NonNull Context context

the activity context required to launch the UI.

@NonNull ImportCredentialsRequest request

request the request detailing the credentials to be imported.

CancellationSignal cancellationSignal

an optional signal that allows for cancelling this call

@NonNull Executor executor

the callback will take place on this executor

@NonNull CredentialManagerCallback<@NonNull ProviderImportCredentialsResponse, @NonNull ImportCredentialsException> callback

the callback invoked when the request succeeds or fails

registerExport

default @NonNull RegisterExportResponse registerExport(@NonNull RegisterExportRequest request)

Registers the calling credential provider as a source for exporting credentials.

Once registered, the provider's ExportEntry will be displayed in the provider selector UI when another provider initiates an importCredentials flow.

In addition to calling this method, a provider that wishes to export credentials must declare an [Activity] in its manifest that can handle the transfer request. This activity must have an intent filter configured with the following:

  • An intent action of "androidx.identitycredentials.action.IMPORT_CREDENTIALS"
  • A data element with a "content" scheme

The framework will invoke this activity with an intent containing a content URI, which serves as the medium for transferring the credential data. The activity can retrieve the request from the intent by calling IntentHandler.retrieveProviderImportCredentialsRequest. In addition to the ImportCredentialsRequest, the ProviderImportCredentialsRequest contains a few security measures. The importer's CallingAppInfo is provided to verify the importer. The 'credId' is provided to validate the selected ExportEntry.

After the activity processes the request, the activity should return the ImportCredentialsResponse through the 'uri' of ProviderImportCredentialsRequest to successfully return the credentials or set an exception by calling IntentHandler.setImportCredentialsException.

Parameters
@NonNull RegisterExportRequest request

the request containing the provider data to register

Returns
@NonNull RegisterExportResponse

a RegisterExportResponse on successful registration.

registerExportAsync

Added in 1.0.0-alpha03
abstract void registerExportAsync(
    @NonNull RegisterExportRequest request,
    CancellationSignal cancellationSignal,
    @NonNull Executor executor,
    @NonNull CredentialManagerCallback<@NonNull RegisterExportResponse, @NonNull RegisterExportException> callback
)

Registers the calling credential provider as a source for exporting credentials.

Once registered, the provider's ExportEntry will be displayed in the provider selector UI when another provider initiates an importCredentials flow.

In addition to calling this method, a provider that wishes to export credentials must declare an [Activity] in its manifest that can handle the transfer request. This activity must have an intent filter configured with the following:

  • An intent action of "androidx.identitycredentials.action.IMPORT_CREDENTIALS"
  • A data element with a "content" scheme

The framework will invoke this activity with an intent containing a content URI, which serves as the medium for transferring the credential data. The activity can retrieve the request from the intent by calling IntentHandler.retrieveProviderImportCredentialsRequest. In addition to the ImportCredentialsRequest, the ProviderImportCredentialsRequest contains a few security measures. The importer's CallingAppInfo is provided to verify the importer. The 'credId' is provided to validate the selected ExportEntry.

After the activity processes the request, the activity should return the ImportCredentialsResponse through the 'uri' of ProviderImportCredentialsRequest to successfully return the credentials or set an exception by calling IntentHandler.setImportCredentialsException.

Parameters
@NonNull RegisterExportRequest request

the request containing the provider data to register

CancellationSignal cancellationSignal

an optional signal that allows for cancelling this call

@NonNull Executor executor

the callback will take place on this executor

@NonNull CredentialManagerCallback<@NonNull RegisterExportResponse, @NonNull RegisterExportException> callback

the callback invoked when the request succeeds or fails