Stay organized with collections Save and categorize content based on your preferences.

CredentialProvider

public interface CredentialProvider


Provider interface to be implemented by system credential providers that will fulfill Credential Manager requests. The implementation must have a constructor that takes in a context.

Note that for SDK version 33 and below, this interface can be implemented by any OEM provider that wishes to return credentials. The implementation must have a constructor with a context parameter. A provider must :

  1. Release a dedicated provider library that developers can add as a dependency.
  2. Include an empty CredentialProviderService in the provider library for the purposes of exposing a meta-data tag in the Android Manifest file.
  3. Add the name of the class that is implementing this interface, as a value to the meta-data tag described above.
  4. Make sure that there is only one provider implementation on the device. If the device already has a provider installed, and the developer specifies more than one provider dependencies, credential manager will error out.

For SDK version 34 and above, this interface will only be implemented by an internal class that will route all requests to the android framework. Providers will need to register directly with the framework to provide credentials.

Summary

Public methods

abstract boolean

Determines whether the provider is available on this device, or not.

abstract void

Invoked on a request to clear a credential.

abstract void

Invoked on a request to create a credential.

abstract void
onGetCredential(
    @NonNull GetCredentialRequest request,
    @NonNull Activity activity,
    CancellationSignal cancellationSignal,
    @NonNull Executor executor,
    @NonNull CredentialManagerCallback<@NonNull GetCredentialResponse, @NonNull GetCredentialException> callback
)

Invoked on a request to get a credential.

Public methods

isAvailableOnDevice

abstract boolean isAvailableOnDevice()

Determines whether the provider is available on this device, or not.

onClearCredential

abstract void onClearCredential(
    @NonNull ClearCredentialStateRequest request,
    CancellationSignal cancellationSignal,
    @NonNull Executor executor,
    @NonNull CredentialManagerCallback<Void, @NonNull ClearCredentialException> callback
)

Invoked on a request to clear a credential.

Parameters
@NonNull ClearCredentialStateRequest request

the request for clearing the app user's credential state

CancellationSignal cancellationSignal

an optional signal that allows for cancelling this call

@NonNull Executor executor

the callback will take place on this executor

@NonNull CredentialManagerCallback<Void, @NonNull ClearCredentialException> callback

the callback invoked when the request succeeds or fails

onCreateCredential

abstract void onCreateCredential(
    @NonNull CreateCredentialRequest request,
    @NonNull Activity activity,
    CancellationSignal cancellationSignal,
    @NonNull Executor executor,
    @NonNull CredentialManagerCallback<@NonNull CreateCredentialResponse, @NonNull CreateCredentialException> callback
)

Invoked on a request to create a credential.

Parameters
@NonNull CreateCredentialRequest request

the request for creating the credential

@NonNull Activity activity

the client calling activity used to potentially launch any UI needed

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 CreateCredentialResponse, @NonNull CreateCredentialException> callback

the callback invoked when the request succeeds or fails

onGetCredential

abstract void onGetCredential(
    @NonNull GetCredentialRequest request,
    @NonNull Activity activity,
    CancellationSignal cancellationSignal,
    @NonNull Executor executor,
    @NonNull CredentialManagerCallback<@NonNull GetCredentialResponse, @NonNull GetCredentialException> callback
)

Invoked on a request to get a credential.

Parameters
@NonNull GetCredentialRequest request

the request for getting the credential

@NonNull Activity activity

the client calling activity used to potentially launch any UI needed

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 GetCredentialResponse, @NonNull GetCredentialException> callback

the callback invoked when the request succeeds or fails