Token
class 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:
<code>Token token = Token.create(packageName, packageManager);
byte[] serialized = token.serialize();
// Persist serialized.
// Some time later...
Token verified = Token.deserialize(serialized);
verified.matches(packageName, packageManager);
</code>
Summary
Public methods |
static Token? |
Creates a Token for the given package, taking into account the package name and its signing signature.
|
static Token |
Reconstructs a Token from the output of its serialize .
|
Boolean |
Whether the given package matches the package that was used to create the original Token.
|
ByteArray |
Serializes the Token to a form that can later be restored by the deserialize method.
|
Public methods
create
@Nullable static fun create(
@NonNull packageName: String,
@NonNull packageManager: PackageManager
): Token?
Creates a Token
for the given package, taking into account the package name and its signing signature.
Return |
Token? |
A Token . null if the provided package cannot be found (the app is not installed). |
deserialize
@NonNull static fun deserialize(@NonNull serialized: ByteArray): Token
Reconstructs a Token
from the output of its serialize
.
Return |
Token |
The deserialized Token. |
matches
fun matches(
@NonNull packageName: String,
@NonNull packageManager: PackageManager
): Boolean
Whether the given package matches the package that was used to create the original Token.
Return |
Boolean |
Whether the given package currently is the same as the one used to create the Token. |
serialize
@NonNull fun serialize(): ByteArray
Serializes the Token
to a form that can later be restored by the deserialize
method.