Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/security/ConfirmationPrompt#nestedclasses) \| [Methods](https://developer.android.com/reference/android/security/ConfirmationPrompt#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/security/ConfirmationPrompt#inhmethods)

# ConfirmationPrompt

*** ** * ** ***

` public class ConfirmationPrompt `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.security.ConfirmationPrompt |

<br />

*** ** * ** ***

Class used for displaying confirmation prompts.

Confirmation prompts are prompts shown to the user to confirm a given text and are implemented in a way that a positive response indicates with high confidence that the user has seen the given text, even if the Android framework (including the kernel) was compromised. Implementing confirmation prompts with these guarantees requires dedicated hardware-support and may not always be available.

Confirmation prompts are typically used with an external entity - the *Relying Party* - in the following way. The setup steps are as follows:

- Before first use, the application generates a key-pair with the `https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.Builder#setUserConfirmationRequired(boolean)` set. AndroidKeyStore key attestation, e.g., `https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.Builder#setAttestationChallenge(byte[])` is used to generate a certificate chain that includes the public key (`Kpub` in the following) of the newly generated key.
- The application sends `Kpub` and the certificate chain resulting from device attestation to the *Relying Party*.
- The *Relying Party* validates the certificate chain which involves checking the root certificate is what is expected (e.g. a certificate from Google), each certificate signs the next one in the chain, ending with `Kpub`, and that the attestation certificate asserts that `Kpub` has the `https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.Builder#setUserConfirmationRequired(boolean)` set. Additionally the relying party stores `Kpub` and associates it with the device it was received from.

The *Relying Party* is typically an external device (for example connected via Bluetooth) or application server.

Before executing a transaction which requires a high assurance of user content, the application does the following:

- The application gets a cryptographic nonce from the *Relying Party* and passes this as the `extraData` (via the Builder helper class) to the `https://developer.android.com/reference/android/security/ConfirmationPrompt#presentPrompt(java.util.concurrent.Executor,%20android.security.ConfirmationCallback)` method. The *Relying Party* stores the nonce locally since it'll use it in a later step.
- If the user approves the prompt a *Confirmation Response* is returned in the `https://developer.android.com/reference/android/security/ConfirmationCallback#onConfirmed(byte[])` callback as the `dataThatWasConfirmed` parameter. This blob contains the text that was shown to the user, the `extraData` parameter, and possibly other data.
- The application signs the *Confirmation Response* with the previously created key and sends the blob and the signature to the *Relying Party*.
- The *Relying Party* checks that the signature was made with `Kpub` and then extracts `promptText` matches what is expected and `extraData` matches the previously created nonce. If all checks passes, the transaction is executed.

Note: It is vital to check the `promptText` because this is the only part that the user has approved. To avoid writing parsers for all of the possible locales, it is recommended that the *Relying Party* uses the same string generator as used on the device and performs a simple string comparison.

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/security/ConfirmationPrompt.Builder` A builder that collects arguments, to be shown on the system-provided confirmation prompt. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/security/ConfirmationPrompt#cancelPrompt()() ` Cancels a prompt currently being displayed. |
| ` static boolean` | ` https://developer.android.com/reference/android/security/ConfirmationPrompt#isSupported(android.content.Context)(https://developer.android.com/reference/android/content/Context context) ` Checks if the device supports confirmation prompts. |
| ` void` | ` https://developer.android.com/reference/android/security/ConfirmationPrompt#presentPrompt(java.util.concurrent.Executor,%20android.security.ConfirmationCallback)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/security/ConfirmationCallback callback) ` Requests a confirmation prompt to be presented to the user. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Public methods

### cancelPrompt

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void cancelPrompt ()
```

Cancels a prompt currently being displayed. On success, the `https://developer.android.com/reference/android/security/ConfirmationCallback#onCanceled()` method on the supplied callback object will be called asynchronously.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if no prompt is currently being presented. |

### isSupported

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static boolean isSupported (Context context)
```

Checks if the device supports confirmation prompts.

<br />

| Parameters ||
|---|---|
| `context` | `Context`: the application context. <br /> |

| Returns ||
|---|---|
| `boolean` | true if confirmation prompts are supported by the device. <br /> |

### presentPrompt

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void presentPrompt (Executor executor, 
                ConfirmationCallback callback)
```

Requests a confirmation prompt to be presented to the user. When the prompt is no longer being presented, one of the methods in `https://developer.android.com/reference/android/security/ConfirmationCallback` is called on the supplied callback object. Confirmation prompts may not be available when accessibility services are running so this may fail with a `https://developer.android.com/reference/android/security/ConfirmationNotAvailableException` exception even if `https://developer.android.com/reference/android/security/ConfirmationPrompt#isSupported(android.content.Context)` returns `true`.

<br />

| Parameters ||
|---|---|
| `executor` | `Executor`: the executor identifying the thread that will receive the callback. This value cannot be `null`. <br /> |
| `callback` | `ConfirmationCallback`: the callback to use when the prompt is done showing. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/security/ConfirmationAlreadyPresentingException` | if another prompt is being presented. |
| `https://developer.android.com/reference/android/security/ConfirmationNotAvailableException` | if confirmation prompts are not supported. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if the prompt text is too long or malfomed. |