public interface

TokenStore

 androidx.browser.trusted.TokenStore

Gradle dependencies

compile group: 'androidx.browser', name: 'browser', version: '1.8.0'

  • groupId: androidx.browser
  • artifactId: browser
  • version: 1.8.0

Artifact androidx.browser:browser:1.8.0 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.browser:browser com.android.support:customtabs

Overview

Users should implement this interface to persist the given Token (across app restarts). Once implemented, they should override TrustedWebActivityService.getTokenStore() to return an instance. Finally, they should execute the following code themselves to set the verified provider:

 
 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 Token stored at a time. Note that TokenStore.load() will be called by TrustedWebActivityService on a binder thread. Whereas TokenStore.store(Token) can be called by the user on whichever thread they like.

Summary

Methods
public Tokenload()

This method returns the Token previously persisted by a call to TokenStore.store(Token).

public voidstore(Token token)

This method should persist the given Token.

Methods

public void store(Token token)

This method should persist the given Token. Subsequent calls will overwrite the previously given Token.

Parameters:

token: The token to persist. It may be null to clear the storage.

public Token load()

This method returns the Token previously persisted by a call to TokenStore.store(Token).

Returns:

The previously persisted Token, or null if none exist. This method will be called on a binder thread by TrustedWebActivityService.

Source

/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.browser.trusted;

import androidx.annotation.BinderThread;
import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;

/**
 * Users should implement this interface to persist the given {@link Token} (across app
 * restarts).
 * Once implemented, they should override {@link TrustedWebActivityService#getTokenStore()} to
 * return an instance.
 * Finally, they should execute the following code themselves to set the verified provider:
 * <pre>
 * {@code
 * TokenStore tokenStore  = ... // Instantiate the implemented class.
 * String packageName = ... // Package name of the Trusted Web Activity provider.
 *
 * tokenStore.store(Token.create(packageName, getPackageManager());
 * }
 * </pre>
 *
 * There is only a single {@link Token} stored at a time.
 *
 * Note that {@link #load} will be called by {@link TrustedWebActivityService} on a binder thread.
 * Whereas {@link #store} can be called by the user on whichever thread they like.
 */
public interface TokenStore {
    /**
     * This method should persist the given {@link Token}.
     * Subsequent calls will overwrite the previously given {@link Token}.
     *
     * @param token The token to persist. It may be {@code null} to clear the storage.
     */
    @WorkerThread
    void store(@Nullable Token token);

    /**
     * This method returns the {@link Token} previously persisted by a call to {@link #store}.
     * @return The previously persisted {@link Token}, or {@code null} if none exist.
     *
     * This method will be called on a binder thread by {@link TrustedWebActivityService}.
     */
    @BinderThread
    @Nullable
    Token load();
}