CredentialProvider


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 functions

Boolean

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

Unit
onClearCredential(
    request: ClearCredentialStateRequest,
    cancellationSignal: CancellationSignal?,
    executor: Executor,
    callback: CredentialManagerCallback<Void?, ClearCredentialException>
)

Invoked on a request to clear a credential.

Unit
onCreateCredential(
    context: Context,
    request: CreateCredentialRequest,
    cancellationSignal: CancellationSignal?,
    executor: Executor,
    callback: CredentialManagerCallback<CreateCredentialResponseCreateCredentialException>
)

Invoked on a request to create a credential.

open Unit
@RequiresApi(value = 34)
onGetCredential(
    context: Context,
    pendingGetCredentialHandle: PrepareGetCredentialResponse.PendingGetCredentialHandle,
    cancellationSignal: CancellationSignal?,
    executor: Executor,
    callback: CredentialManagerCallback<GetCredentialResponseGetCredentialException>
)

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

Unit
onGetCredential(
    context: Context,
    request: GetCredentialRequest,
    cancellationSignal: CancellationSignal?,
    executor: Executor,
    callback: CredentialManagerCallback<GetCredentialResponseGetCredentialException>
)

Invoked on a request to get a credential.

open Unit
@RequiresApi(value = 34)
onPrepareCredential(
    request: GetCredentialRequest,
    cancellationSignal: CancellationSignal?,
    executor: Executor,
    callback: CredentialManagerCallback<PrepareGetCredentialResponseGetCredentialException>
)

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

Public functions

isAvailableOnDevice

Added in 1.2.0
fun isAvailableOnDevice(): Boolean

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

onClearCredential

Added in 1.2.0
fun onClearCredential(
    request: ClearCredentialStateRequest,
    cancellationSignal: CancellationSignal?,
    executor: Executor,
    callback: CredentialManagerCallback<Void?, ClearCredentialException>
): Unit

Invoked on a request to clear a credential.

Parameters
request: ClearCredentialStateRequest

the request for clearing the app user's credential state

cancellationSignal: CancellationSignal?

an optional signal that allows for cancelling this call

executor: Executor

the callback will take place on this executor

callback: CredentialManagerCallback<Void?, ClearCredentialException>

the callback invoked when the request succeeds or fails

onCreateCredential

Added in 1.2.0
fun onCreateCredential(
    context: Context,
    request: CreateCredentialRequest,
    cancellationSignal: CancellationSignal?,
    executor: Executor,
    callback: CredentialManagerCallback<CreateCredentialResponseCreateCredentialException>
): Unit

Invoked on a request to create a credential.

Parameters
context: Context

the client calling context used to potentially launch any UI needed

request: CreateCredentialRequest

the request for creating the credential

cancellationSignal: CancellationSignal?

an optional signal that allows for cancelling this call

executor: Executor

the callback will take place on this executor

callback: CredentialManagerCallback<CreateCredentialResponseCreateCredentialException>

the callback invoked when the request succeeds or fails

onGetCredential

Added in 1.2.0
@RequiresApi(value = 34)
open fun onGetCredential(
    context: Context,
    pendingGetCredentialHandle: PrepareGetCredentialResponse.PendingGetCredentialHandle,
    cancellationSignal: CancellationSignal?,
    executor: Executor,
    callback: CredentialManagerCallback<GetCredentialResponseGetCredentialException>
): Unit

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

Parameters
context: Context

the client calling context used to potentially launch any UI needed

pendingGetCredentialHandle: PrepareGetCredentialResponse.PendingGetCredentialHandle

the handle representing the pending operation to resume

cancellationSignal: CancellationSignal?

an optional signal that allows for cancelling this call

executor: Executor

the callback will take place on this executor

callback: CredentialManagerCallback<GetCredentialResponseGetCredentialException>

the callback invoked when the request succeeds or fails

onGetCredential

Added in 1.2.0
fun onGetCredential(
    context: Context,
    request: GetCredentialRequest,
    cancellationSignal: CancellationSignal?,
    executor: Executor,
    callback: CredentialManagerCallback<GetCredentialResponseGetCredentialException>
): Unit

Invoked on a request to get a credential.

Parameters
context: Context

the client calling context used to potentially launch any UI needed

request: GetCredentialRequest

the request for getting the credential

cancellationSignal: CancellationSignal?

an optional signal that allows for cancelling this call

executor: Executor

the callback will take place on this executor

callback: CredentialManagerCallback<GetCredentialResponseGetCredentialException>

the callback invoked when the request succeeds or fails

onPrepareCredential

Added in 1.2.0
@RequiresApi(value = 34)
open fun onPrepareCredential(
    request: GetCredentialRequest,
    cancellationSignal: CancellationSignal?,
    executor: Executor,
    callback: CredentialManagerCallback<PrepareGetCredentialResponseGetCredentialException>
): Unit

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

Parameters
request: GetCredentialRequest

the request for getting the credential

cancellationSignal: CancellationSignal?

an optional signal that allows for cancelling this call

executor: Executor

the callback will take place on this executor

callback: CredentialManagerCallback<PrepareGetCredentialResponseGetCredentialException>

the callback invoked when the request succeeds or fails