# TokenStore

Artifact: [androidx.browser:browser](https://developer.android.com/jetpack/androidx/releases/browser) [View Source](https://cs.android.com/search?q=file:androidx/browser/trusted/TokenStore.java+class:androidx.browser.trusted.TokenStore) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

*** ** * ** ***


```
public interface TokenStore
```

<br />

*** ** * ** ***

Users should implement this interface to persist the given `https://developer.android.com/reference/androidx/browser/trusted/Token` (across app restarts). Once implemented, they should override `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityService#getTokenStore()` to return an instance. Finally, they should execute the following code themselves to set the verified provider:

```rust
TokenStore tokenStore  = ... // Instantiate the implemented class.
String packageName = ... // Package name of the Trusted Web Activity provider.

tokenStore.store(Token.create(packageName, getPackageManager());
```
There is only a single `https://developer.android.com/reference/androidx/browser/trusted/Token` stored at a time. Note that `https://developer.android.com/reference/androidx/browser/trusted/TokenStore#load()` will be called by `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityService` on a binder thread. Whereas `https://developer.android.com/reference/androidx/browser/trusted/TokenStore#store(androidx.browser.trusted.Token)` can be called by the user on whichever thread they like.

## Summary

| ### Public methods |
|---|---|
| `abstract @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/browser/trusted/Token` | `@https://developer.android.com/reference/androidx/annotation/BinderThread https://developer.android.com/reference/androidx/browser/trusted/TokenStore#load()()` This method returns the `https://developer.android.com/reference/androidx/browser/trusted/Token` previously persisted by a call to `https://developer.android.com/reference/androidx/browser/trusted/TokenStore#store(androidx.browser.trusted.Token)`. |
| `abstract void` | `@https://developer.android.com/reference/androidx/annotation/WorkerThread https://developer.android.com/reference/androidx/browser/trusted/TokenStore#store(androidx.browser.trusted.Token)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/browser/trusted/Token token)` This method should persist the given `https://developer.android.com/reference/androidx/browser/trusted/Token`. |

## Public methods

### load

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
@BinderThread
abstract @Nullable Token load()
```

This method returns the `https://developer.android.com/reference/androidx/browser/trusted/Token` previously persisted by a call to `https://developer.android.com/reference/androidx/browser/trusted/TokenStore#store(androidx.browser.trusted.Token)`.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/browser/trusted/Token` | The previously persisted `https://developer.android.com/reference/androidx/browser/trusted/Token`, or `null` if none exist. This method will be called on a binder thread by `https://developer.android.com/reference/androidx/browser/trusted/TrustedWebActivityService`. |

### store

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
@WorkerThread
abstract void store(@Nullable Token token)
```

This method should persist the given `https://developer.android.com/reference/androidx/browser/trusted/Token`. Subsequent calls will overwrite the previously given `https://developer.android.com/reference/androidx/browser/trusted/Token`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/browser/trusted/Token token` | The token to persist. It may be `null` to clear the storage. |