CredentialProviderService


public abstract class CredentialProviderService
extends Service

java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.Service
         ↳ android.service.credentials.CredentialProviderService


Service to be extended by credential providers, in order to return user credentials to the framework.

Summary

Constants

String EXTRA_BEGIN_GET_CREDENTIAL_REQUEST

Intent extra: The BeginGetCredentialRequest attached with the pendingIntent that is invoked when the user selects an authentication entry (intending to unlock the provider app) on the UI.

String EXTRA_BEGIN_GET_CREDENTIAL_RESPONSE

Intent extra: The result of an authentication flow, to be set on finish of the Activity invoked through the PendingIntent set on an authentication Action, as part of the original BeginGetCredentialResponse.

String EXTRA_CREATE_CREDENTIAL_EXCEPTION

Intent extra: The failure exception set at the final stage of a create flow.

String EXTRA_CREATE_CREDENTIAL_REQUEST

Intent extra: The CreateCredentialRequest attached with the pendingIntent that is invoked when the user selects a CreateEntry returned as part of the BeginCreateCredentialResponse

Type: CreateCredentialRequest

String EXTRA_CREATE_CREDENTIAL_RESPONSE

Intent extra: The result of a create flow operation, to be set on finish of the Activity invoked through the pendingIntent set on a CreateEntry.

String EXTRA_GET_CREDENTIAL_EXCEPTION

Intent extra: The failure exception set at the final stage of a get flow.

String EXTRA_GET_CREDENTIAL_REQUEST

Intent extra: The GetCredentialRequest attached with the pendingIntent that is invoked when the user selects a CredentialEntry returned as part of the BeginGetCredentialResponse

Type: GetCredentialRequest

String EXTRA_GET_CREDENTIAL_RESPONSE

Intent extra: The result of a get credential flow operation, to be set on finish of the Activity invoked through the pendingIntent set on a CredentialEntry.

String SERVICE_INTERFACE

The Intent that must be declared as handled by the service.

String SERVICE_META_DATA

Name under which a Credential Provider service component publishes information about itself.

Inherited constants

Public constructors

CredentialProviderService()

Public methods

abstract void onBeginCreateCredential(BeginCreateCredentialRequest request, CancellationSignal cancellationSignal, OutcomeReceiver<BeginCreateCredentialResponseCreateCredentialException> callback)

Called by the android system to create a credential.

abstract void onBeginGetCredential(BeginGetCredentialRequest request, CancellationSignal cancellationSignal, OutcomeReceiver<BeginGetCredentialResponseGetCredentialException> callback)

Called by the android system to retrieve user credentials from the connected provider service.

final IBinder onBind(Intent intent)

Return the communication channel to the service.

abstract void onClearCredentialState(ClearCredentialStateRequest request, CancellationSignal cancellationSignal, OutcomeReceiver<VoidClearCredentialStateException> callback)

Called by the android system to clear the credential state.

void onCreate()

Called by the system when the service is first created. If you override this method you must call through to the superclass implementation.

Inherited methods

Constants

EXTRA_BEGIN_GET_CREDENTIAL_REQUEST

Added in API level 34
public static final String EXTRA_BEGIN_GET_CREDENTIAL_REQUEST

Intent extra: The BeginGetCredentialRequest attached with the pendingIntent that is invoked when the user selects an authentication entry (intending to unlock the provider app) on the UI.

When a provider app receives a BeginGetCredentialRequest through the CredentialProviderService.onBeginGetCredential call, it can construct the BeginGetCredentialResponse with either an authentication Action (if the app is locked), or a BeginGetCredentialResponse (if the app is unlocked). In the former case, i.e. the app is locked, user will be shown the authentication action. When selected, the underlying PendingIntent will be invoked which will lead the user to provider's unlock activity. This pending intent will also contain the original BeginGetCredentialRequest to be retrieved and processed after the unlock flow is complete.

After the app is unlocked, the BeginGetCredentialResponse must be constructed using a BeginGetCredentialResponse, which must be set on an Intent as an intent extra against CredentialProviderService#EXTRA_CREDENTIALS_RESPONSE_CONTENT}. This intent should then be set as a result through Activity.setResult(int) before finishing the activity.

Type: BeginGetCredentialRequest

Constant Value: "android.service.credentials.extra.BEGIN_GET_CREDENTIAL_REQUEST"

EXTRA_BEGIN_GET_CREDENTIAL_RESPONSE

Added in API level 34
public static final String EXTRA_BEGIN_GET_CREDENTIAL_RESPONSE

Intent extra: The result of an authentication flow, to be set on finish of the Activity invoked through the PendingIntent set on an authentication Action, as part of the original BeginGetCredentialResponse. This result should contain the actual content, including credential entries and action entries, to be shown on the selector.

Type: BeginGetCredentialResponse

Constant Value: "android.service.credentials.extra.BEGIN_GET_CREDENTIAL_RESPONSE"

EXTRA_CREATE_CREDENTIAL_EXCEPTION

Added in API level 34
public static final String EXTRA_CREATE_CREDENTIAL_EXCEPTION

Intent extra: The failure exception set at the final stage of a create flow. This exception is set at the finishing result of the Activity invoked by the PendingIntent , when a user selects the CreateEntry that contained the PendingIntent in question.

Type: CreateCredentialException

Constant Value: "android.service.credentials.extra.CREATE_CREDENTIAL_EXCEPTION"

EXTRA_CREATE_CREDENTIAL_REQUEST

Added in API level 34
public static final String EXTRA_CREATE_CREDENTIAL_REQUEST

Intent extra: The CreateCredentialRequest attached with the pendingIntent that is invoked when the user selects a CreateEntry returned as part of the BeginCreateCredentialResponse

Type: CreateCredentialRequest

Constant Value: "android.service.credentials.extra.CREATE_CREDENTIAL_REQUEST"

EXTRA_CREATE_CREDENTIAL_RESPONSE

Added in API level 34
public static final String EXTRA_CREATE_CREDENTIAL_RESPONSE

Intent extra: The result of a create flow operation, to be set on finish of the Activity invoked through the pendingIntent set on a CreateEntry.

Type: CreateCredentialResponse

Constant Value: "android.service.credentials.extra.CREATE_CREDENTIAL_RESPONSE"

EXTRA_GET_CREDENTIAL_EXCEPTION

Added in API level 34
public static final String EXTRA_GET_CREDENTIAL_EXCEPTION

Intent extra: The failure exception set at the final stage of a get flow. This exception is set at the finishing result of the Activity invoked by the PendingIntent , when a user selects the CredentialEntry that contained the PendingIntent in question.

The result must be set through Activity.setResult(int) as an intent extra

Type: GetCredentialException

Constant Value: "android.service.credentials.extra.GET_CREDENTIAL_EXCEPTION"

EXTRA_GET_CREDENTIAL_REQUEST

Added in API level 34
public static final String EXTRA_GET_CREDENTIAL_REQUEST

Intent extra: The GetCredentialRequest attached with the pendingIntent that is invoked when the user selects a CredentialEntry returned as part of the BeginGetCredentialResponse

Type: GetCredentialRequest

Constant Value: "android.service.credentials.extra.GET_CREDENTIAL_REQUEST"

EXTRA_GET_CREDENTIAL_RESPONSE

Added in API level 34
public static final String EXTRA_GET_CREDENTIAL_RESPONSE

Intent extra: The result of a get credential flow operation, to be set on finish of the Activity invoked through the pendingIntent set on a CredentialEntry.

Type: GetCredentialResponse

Constant Value: "android.service.credentials.extra.GET_CREDENTIAL_RESPONSE"

SERVICE_INTERFACE

Added in API level 34
public static final String SERVICE_INTERFACE

The Intent that must be declared as handled by the service. The service must also require the {android.Manifest.permission#BIND_CREDENTIAL_PROVIDER_SERVICE} permission so that only the system can bind to it.

Constant Value: "android.service.credentials.CredentialProviderService"

SERVICE_META_DATA

Added in API level 34
public static final String SERVICE_META_DATA

Name under which a Credential Provider service component publishes information about itself. This meta-data must reference an XML resource containing an <credential-provider> tag. For example (AndroidManifest.xml): For example (xml/provider.xml): @string/passwords @string/passkeys

Constant Value: "android.credentials.provider"

Public constructors

CredentialProviderService

public CredentialProviderService ()

Public methods

onBeginCreateCredential

Added in API level 34
public abstract void onBeginCreateCredential (BeginCreateCredentialRequest request, 
                CancellationSignal cancellationSignal, 
                OutcomeReceiver<BeginCreateCredentialResponseCreateCredentialException> callback)

Called by the android system to create a credential.

Parameters
request BeginCreateCredentialRequest: The credential creation request for the provider to handle. This value cannot be null.

cancellationSignal CancellationSignal: Signal for providers to listen to any cancellation requests from the android system. This value cannot be null.

callback OutcomeReceiver: Object used to relay the response of the credential creation request. This value cannot be null.

onBeginGetCredential

Added in API level 34
public abstract void onBeginGetCredential (BeginGetCredentialRequest request, 
                CancellationSignal cancellationSignal, 
                OutcomeReceiver<BeginGetCredentialResponseGetCredentialException> callback)

Called by the android system to retrieve user credentials from the connected provider service.

This API denotes a query stage request for getting user's credentials from a given credential provider. The request contains a list of BeginGetCredentialOption that have parameters to be used for populating candidate credentials, as a list of CredentialEntry to be set on the BeginGetCredentialResponse. This list is then shown to the user on a selector.

If a PendingIntent is set on a CredentialEntry, and the user selects that entry, a GetCredentialRequest with all parameters needed to get the actual Credential will be sent as part of the Intent fired through the PendingIntent.

Parameters
request BeginGetCredentialRequest: the request for the provider to handle This value cannot be null.

cancellationSignal CancellationSignal: signal for providers to listen to any cancellation requests from the android system This value cannot be null.

callback OutcomeReceiver: object used to relay the response of the credentials request This value cannot be null.

onBind

Added in API level 34
public final IBinder onBind (Intent intent)

Return the communication channel to the service. May return null if clients can not bind to the service. The returned IBinder is usually for a complex interface that has been described using aidl.

Note that unlike other application components, calls on to the IBinder interface returned here may not happen on the main thread of the process. More information about the main thread can be found in Processes and Threads.

Parameters
intent Intent: This value cannot be null.

Returns
IBinder This value cannot be null.

onClearCredentialState

Added in API level 34
public abstract void onClearCredentialState (ClearCredentialStateRequest request, 
                CancellationSignal cancellationSignal, 
                OutcomeReceiver<VoidClearCredentialStateException> callback)

Called by the android system to clear the credential state. This api isinvoked by developers after users sign out of an app, with an intention to clear any stored credential session that providers have retained. As a provider, you must clear any credential state, if maintained. For e.g. a provider may have stored an active credential session that is used to limit or rank sign-in options for future credential retrieval flows. When a user signs out of the app, such state should be cleared and an exhaustive list of credentials must be presented to the user on subsequent credential retrieval flows.

Parameters
request ClearCredentialStateRequest: The clear credential request for the provider to handle. This value cannot be null.

cancellationSignal CancellationSignal: Signal for providers to listen to any cancellation requests from the android system. This value cannot be null.

callback OutcomeReceiver: Object used to relay the result of the request. This value cannot be null.

onCreate

Added in API level 34
public void onCreate ()

Called by the system when the service is first created. Do not call this method directly. If you override this method you must call through to the superclass implementation.