The Android Developer Challenge is back! Submit your idea before December 2.

Token

public final class Token
extends Object

java.lang.Object
   ↳ androidx.browser.trusted.Token


Stores a package's identity, a combination of its package name and signing certificate. It is designed to be persistable as a byte[], so you can do this:

     Token token = Token.create(packageName, packageManager);
     byte[] serialized = token.serialize();
     // Persist serialized.

     // Some time later...
     Token verified = Token.deserialize(serialized);
     verified.matches(packageName, packageManager);
 

Summary

Public methods

static Token create(String packageName, PackageManager packageManager)

Creates a Token for the given package, taking into account the package name and its signing signature.

static Token deserialize(byte[] serialized)

Reconstructs a Token from the output of its serialize().

boolean matches(String packageName, PackageManager packageManager)

Whether the given package matches the package that was used to create the original Token.

byte[] serialize()

Serializes the Token to a form that can later be restored by the deserialize(byte[]) method.

Inherited methods

Public methods

create

public static Token create (String packageName, 
                PackageManager packageManager)

Creates a Token for the given package, taking into account the package name and its signing signature.

Parameters
packageName String: The name of the package.

packageManager PackageManager: A PackageManager to determine the signing information.

Returns
Token A Token. null if the provided package cannot be found (the app is not installed).

deserialize

public static Token deserialize (byte[] serialized)

Reconstructs a Token from the output of its serialize().

Parameters
serialized byte: The result of a serialize() call.

Returns
Token The deserialized Token.

matches

public boolean matches (String packageName, 
                PackageManager packageManager)

Whether the given package matches the package that was used to create the original Token.

Parameters
packageName String: The name of the package.

packageManager PackageManager: A PackageManager to get information about the package.

Returns
boolean Whether the given package currently is the same as the one used to create the Token.

serialize

public byte[] serialize ()

Serializes the Token to a form that can later be restored by the deserialize(byte[]) method.

Returns
byte[] A serialization of the Token.