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.

default void
@RequiresApi(value = 34)
onGetCredential(
    @NonNull Context context,
    @NonNull PrepareGetCredentialResponse.PendingGetCredentialHandle pendingGetCredentialHandle,
    CancellationSignal cancellationSignal,
    @NonNull Executor executor,
    @NonNull CredentialManagerCallback<@NonNull GetCredentialResponse, @NonNull GetCredentialException> callback
)

Complete on a request to get a credential represented by the pendingGetCredentialHandle.

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

Invoked on a request to get a credential.

default void

Invoked on a request to prepare for a get-credential operation

Public methods

isAvailableOnDevice

Added in 1.2.0
abstract boolean isAvailableOnDevice()

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

onClearCredential

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

Added in 1.2.0
abstract void onCreateCredential(
    @NonNull Context context,
    @NonNull CreateCredentialRequest request,
    CancellationSignal cancellationSignal,
    @NonNull Executor executor,
    @NonNull CredentialManagerCallback<@NonNull CreateCredentialResponse, @NonNull CreateCredentialException> callback
)

Invoked on a request to create a credential.

Parameters
@NonNull Context context

the client calling context used to potentially launch any UI needed

@NonNull CreateCredentialRequest request

the request for creating the credential

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

Added in 1.2.0
@RequiresApi(value = 34)
default void onGetCredential(
    @NonNull Context context,
    @NonNull PrepareGetCredentialResponse.PendingGetCredentialHandle pendingGetCredentialHandle,
    CancellationSignal cancellationSignal,
    @NonNull Executor executor,
    @NonNull CredentialManagerCallback<@NonNull GetCredentialResponse, @NonNull GetCredentialException> callback
)

Complete on a request to get a credential represented by the pendingGetCredentialHandle.

Parameters
@NonNull Context context

the client calling context used to potentially launch any UI needed

@NonNull PrepareGetCredentialResponse.PendingGetCredentialHandle pendingGetCredentialHandle

the handle representing the pending operation to resume

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

onGetCredential

Added in 1.2.0
abstract void onGetCredential(
    @NonNull Context context,
    @NonNull GetCredentialRequest request,
    CancellationSignal cancellationSignal,
    @NonNull Executor executor,
    @NonNull CredentialManagerCallback<@NonNull GetCredentialResponse, @NonNull GetCredentialException> callback
)

Invoked on a request to get a credential.

Parameters
@NonNull Context context

the client calling context used to potentially launch any UI needed

@NonNull GetCredentialRequest request

the request for getting the credential

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

onPrepareCredential

Added in 1.2.0
@RequiresApi(value = 34)
default void onPrepareCredential(
    @NonNull GetCredentialRequest request,
    CancellationSignal cancellationSignal,
    @NonNull Executor executor,
    @NonNull CredentialManagerCallback<@NonNull PrepareGetCredentialResponse, @NonNull GetCredentialException> callback
)

Invoked on a request to prepare for a get-credential operation

Parameters
@NonNull GetCredentialRequest request

the request for getting the credential

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

the callback invoked when the request succeeds or fails