ContactKeyClient


interface ContactKeyClient : HasApiKey


A client for the Contact Key API.

Summary

Public functions

Flow<List<E2eeAccountContactKeyParcelable>>
@RequiresPermission(value = "android.permission.READ_CONTACTS")
getAccountContactKeysFlow(accountIds: List<String>)

Returns a flow of account contact keys updates.

Task<E2eeContactKeyListParcelable>
@RequiresPermission(value = "android.permission.READ_CONTACTS")
getAllE2eeContactKeys(lookupKey: String)

Retrieves all end-to-end encryption contact key entries that belong to apps visible to the caller.

Task<E2eeSelfKeyListParcelable>
@RequiresPermission(value = "android.permission.READ_CONTACTS")
getAllE2eeSelfKeys()

Returns all end-to-end encryption self key entries that belong to apps visible to the caller.

Task<ImmutableList<E2eeAccountContactKeyParcelable>>
@RequiresPermission(value = "android.permission.READ_CONTACTS")
getAllOwnerE2eeAccountContactKeys()

Retrieves all end-to-end encryption account contact keys that belong to the caller app, whether they are associated with a contact or not.

Task<E2eeContactKeyListParcelable>
@RequiresPermission(value = "android.permission.READ_CONTACTS")
getAllOwnerE2eeContactKeys()

Retrieves all end-to-end encryption contact keys that belong to the caller app, across all contacts.

Task<ImmutableList<E2eeAccountContactKeyParcelable>>
@RequiresPermission(value = "android.permission.READ_CONTACTS")
getE2eeAccountKeysForAccount(accountId: String)

Retrieves all end-to-end encryption contact key entries that belong to the caller app and the caller's account, across all contacts.

Task<E2eeContactKeyParcelable?>
@RequiresPermission(value = "android.permission.READ_CONTACTS")
getE2eeContactKey(lookupKey: String, deviceId: String, accountId: String)

Retrieves an end-to-end encryption contact key entry given the lookupKey, deviceId, accountId and inferred caller package name.

Task<E2eeSelfKeyParcelable?>
@RequiresPermission(value = "android.permission.READ_CONTACTS")
getE2eeSelfKey(deviceId: String, accountId: String)

Returns an end-to-end encryption self key entry given the deviceId, accountId and the inferred package name of the caller.

Task<Int>

Returns the maximum allowed size of a key in bytes.

Task<PendingIntent>
getOnboardingIntent(
    nextActivity: OnboardingNextActivity,
    lookupKey: String?,
    packageName: String?
)

Returns an intent to show the Onboarding activity, and marks that the Onboarding has been shown on this device.

Task<E2eeContactKeyListParcelable>
@RequiresPermission(value = "android.permission.READ_CONTACTS")
getOwnerE2eeContactKeys(lookupKey: String)

Retrieves all end-to-end encryption contact key entries for a given lookupKey that belong to the caller app.

Task<E2eeSelfKeyListParcelable>
@RequiresPermission(value = "android.permission.READ_CONTACTS")
getOwnerE2eeSelfKeys()

Returns all end-to-end encryption self key entries that are owned by the caller app.

Task<PendingIntent>
getScanQrCodeIntent(lookupKey: String, skipOnboarding: Boolean)

Returns an intent to the "Scan QR Code" activity.

Task<PendingIntent>
getScanQrCodeIntentForAccount(packageName: String, accountId: String)

Returns an intent to the "Scan QR Code" activity for a specific account.

Task<PendingIntent>
getShowQrCodeIntent(packageName: String?, skipOnboarding: Boolean)

Returns an intent to the "Show QR Code" activity.

Task<Boolean>

Returns a Task that completes successfully whether the API is available or not.

Task<Void>
@RequiresPermission(value = "android.permission.READ_CONTACTS")
registerAccountContactKeysListener(
    accountIds: List<String>,
    listener: OnAccountContactKeysUpdatedListener
)

Registers a listener for account contact keys updates.

Task<Void>
@RequiresPermission(value = "android.permission.WRITE_CONTACTS")
removeE2eeAccountContactKey(deviceId: String, accountId: String)

Removes an end-to-end encryption account contact key entry that belongs to the caller app.

Task<Void>
@RequiresPermission(value = "android.permission.WRITE_CONTACTS")
removeE2eeContactKey(
    lookupKey: String,
    deviceId: String,
    accountId: String
)

Removes an end-to-end encryption contact key entry that belongs to the caller app.

Task<Void>
@RequiresPermission(value = "android.permission.WRITE_CONTACTS")
removeE2eeSelfKey(deviceId: String, accountId: String)

Removes an end-to-end encryption self key entry given the deviceId and the inferred package name of the caller.

Task<Boolean>

Unregisters a listener for account contact keys updates.

Task<Void>
@RequiresPermission(allOf = ["android.permission.READ_CONTACTS", "android.permission.WRITE_CONTACTS"])
updateAllE2eeAccountKeys(accountKeyInfos: List<E2eeAccountKeyInfo>)

Inserts a batch of account contact keys.

Task<Void>
@RequiresPermission(allOf = ["android.permission.READ_CONTACTS", "android.permission.WRITE_CONTACTS"])
updateOrInsertE2eeContactKey(
    lookupKey: String,
    deviceId: String,
    accountId: String,
    keyValue: ByteArray
)

Inserts a new entry into the end-to-end encryption contact keys table or updates one if it already exists.

Task<Void>
@RequiresPermission(allOf = ["android.permission.READ_CONTACTS", "android.permission.WRITE_CONTACTS"])
updateOrInsertE2eeContactKey(
    lookupKeys: List<String>,
    deviceId: String,
    accountId: String,
    keyValue: ByteArray
)

Inserts a new entry into the end-to-end encryption contact keys table or updates one if it already exists.

Task<Void>
@RequiresPermission(value = "android.permission.WRITE_CONTACTS")
updateOrInsertE2eeSelfKey(
    deviceId: String,
    accountId: String,
    keyValue: ByteArray
)

Inserts a new entry into the end-to-end encryption self keys table or updates one if it already exists.

Public functions

getAccountContactKeysFlow

@RequiresPermission(value = "android.permission.READ_CONTACTS")
fun getAccountContactKeysFlow(accountIds: List<String>): Flow<List<E2eeAccountContactKeyParcelable>>

Returns a flow of account contact keys updates.

The flow will emit when any key for any accountId provided is updated, added, or removed. It will emit the list of all keys for the provided accountIds, not just the ones that were updated.

Parameters
accountIds: List<String>

the list of account ids to listen for updates on.

Returns
Flow<List<E2eeAccountContactKeyParcelable>>

a flow emitting the lists of E2eeAccountContactKeyParcelable for the provided accountIds whenever any key is updated, added or removed.

Throws
com.google.android.libraries.sdkcoroutines.flow.CallbackChannelFullException

if the callback events are processed too slowly.

getAllE2eeContactKeys

@RequiresPermission(value = "android.permission.READ_CONTACTS")
fun getAllE2eeContactKeys(lookupKey: String): Task<E2eeContactKeyListParcelable>

Retrieves all end-to-end encryption contact key entries that belong to apps visible to the caller. The keys will be stripped of deviceId, timeUpdated and keyValue data.

Parameters
lookupKey: String

the value that references the contact

Returns
Task<E2eeContactKeyListParcelable>

a E2eeContactKeyListParcelable containing a list of the end-to-end encryption contact key information, or an empty list if no keys are found.

getAllE2eeSelfKeys

@RequiresPermission(value = "android.permission.READ_CONTACTS")
fun getAllE2eeSelfKeys(): Task<E2eeSelfKeyListParcelable>

Returns all end-to-end encryption self key entries that belong to apps visible to the caller. The keys will be stripped of deviceId, timeUpdated and keyValue data.

Returns
Task<E2eeSelfKeyListParcelable>

a E2eeSelfKeyListParcelable containing a list of the end-to-end encryption self key information, or an empty list if no self keys are found.

getAllOwnerE2eeAccountContactKeys

@RequiresPermission(value = "android.permission.READ_CONTACTS")
fun getAllOwnerE2eeAccountContactKeys(): Task<ImmutableList<E2eeAccountContactKeyParcelable>>

Retrieves all end-to-end encryption account contact keys that belong to the caller app, whether they are associated with a contact or not.

Returns
Task<ImmutableList<E2eeAccountContactKeyParcelable>>

a list of E2eeAccountContactKeyParcelable objects containing the end-to-end encryption contact key information, or an empty list if no keys are found.

getAllOwnerE2eeContactKeys

@RequiresPermission(value = "android.permission.READ_CONTACTS")
fun getAllOwnerE2eeContactKeys(): Task<E2eeContactKeyListParcelable>

Retrieves all end-to-end encryption contact keys that belong to the caller app, across all contacts.

This method should be used to only retrieve keys that have at least one contact associated with them. If you need to retrieve keys that are not associated with any contacts, use getAllOwnerE2eeAccountContactKeys instead.

Returns
Task<E2eeContactKeyListParcelable>

a E2eeContactKeyListParcelable containing a list of the end-to-end encryption contact key information, or an empty list if no keys are found.

getE2eeAccountKeysForAccount

@RequiresPermission(value = "android.permission.READ_CONTACTS")
fun getE2eeAccountKeysForAccount(accountId: String): Task<ImmutableList<E2eeAccountContactKeyParcelable>>

Retrieves all end-to-end encryption contact key entries that belong to the caller app and the caller's account, across all contacts. Includes keys not associated with any contact.

Returns
Task<ImmutableList<E2eeAccountContactKeyParcelable>>

a list of E2eeAccountContactKeyParcelable objects containing the end-to-end encryption contact key information, or an empty list if no keys are found.

getE2eeContactKey

@RequiresPermission(value = "android.permission.READ_CONTACTS")
fun getE2eeContactKey(lookupKey: String, deviceId: String, accountId: String): Task<E2eeContactKeyParcelable?>

Retrieves an end-to-end encryption contact key entry given the lookupKey, deviceId, accountId and inferred caller package name.

Parameters
lookupKey: String

the value that references the contact

deviceId: String

an app-specified identifier for the device

accountId: String

an app-specified identifier for the account

Returns
Task<E2eeContactKeyParcelable?>

an E2eeContactKeyParcelable containing the contact key information, or null if no contact key is found.

getE2eeSelfKey

@RequiresPermission(value = "android.permission.READ_CONTACTS")
fun getE2eeSelfKey(deviceId: String, accountId: String): Task<E2eeSelfKeyParcelable?>

Returns an end-to-end encryption self key entry given the deviceId, accountId and the inferred package name of the caller.

Parameters
deviceId: String

an app-specified identifier for the device

accountId: String

an app-specified identifier for the account

Returns
Task<E2eeSelfKeyParcelable?>

an E2eeSelfKeyParcelable containing the end-to-end encryption self key information, or null if no self key is found.

getMaxKeySizeBytes

fun getMaxKeySizeBytes(): Task<Int>

Returns the maximum allowed size of a key in bytes.

getOnboardingIntent

fun getOnboardingIntent(
    nextActivity: OnboardingNextActivity,
    lookupKey: String?,
    packageName: String?
): Task<PendingIntent>

Returns an intent to show the Onboarding activity, and marks that the Onboarding has been shown on this device. This requires a nextActivity, which can be either the string show or scan. If scan, the lookupKey of the contact to scan for is required.

Parameters
nextActivity: OnboardingNextActivity

the next activity to show after the Onboarding activity. Must be either show or scan.

lookupKey: String?

the value that references the contact. Required if nextActivity is scan.

packageName: String?

the package name associated with the app whose keys are needed (optional).

getOwnerE2eeContactKeys

@RequiresPermission(value = "android.permission.READ_CONTACTS")
fun getOwnerE2eeContactKeys(lookupKey: String): Task<E2eeContactKeyListParcelable>

Retrieves all end-to-end encryption contact key entries for a given lookupKey that belong to the caller app.

Parameters
lookupKey: String

the value that references the contact

Returns
Task<E2eeContactKeyListParcelable>

an E2eeContactKeyListParcelable containing a list of the end-to-end encryption contact key information, or an empty list if no keys are found.

getOwnerE2eeSelfKeys

@RequiresPermission(value = "android.permission.READ_CONTACTS")
fun getOwnerE2eeSelfKeys(): Task<E2eeSelfKeyListParcelable>

Returns all end-to-end encryption self key entries that are owned by the caller app.

Returns
Task<E2eeSelfKeyListParcelable>

a E2eeSelfKeyListParcelable containing the end-to-end encryption self key information, or an empty list if no self keys are found.

getScanQrCodeIntent

fun getScanQrCodeIntent(lookupKey: String, skipOnboarding: Boolean = false): Task<PendingIntent>

Returns an intent to the "Scan QR Code" activity.

Parameters
lookupKey: String

the value that references the contact

skipOnboarding: Boolean = false

Currently unused.

getScanQrCodeIntentForAccount

fun getScanQrCodeIntentForAccount(packageName: String, accountId: String): Task<PendingIntent>

Returns an intent to the "Scan QR Code" activity for a specific account.

Parameters
packageName: String

the package name associated with the account the user wishes to verify

accountId: String

the account id associated with the account the user wishes to verify

getShowQrCodeIntent

fun getShowQrCodeIntent(packageName: String?, skipOnboarding: Boolean = false): Task<PendingIntent>

Returns an intent to the "Show QR Code" activity.

Parameters
packageName: String?

the package name associated with the app whose keys are needed (optional)

skipOnboarding: Boolean = false

Currently unused.

isEnabled

fun isEnabled(): Task<Boolean>

Returns a Task that completes successfully whether the API is available or not.

If the API is available, the returned task will have a true result, and false otherwise.

Exceptions typically thrown when the API is unavailable will be caught and a task successfully returning false will be returned instead.

registerAccountContactKeysListener

@RequiresPermission(value = "android.permission.READ_CONTACTS")
fun registerAccountContactKeysListener(
    accountIds: List<String>,
    listener: OnAccountContactKeysUpdatedListener
): Task<Void>

Registers a listener for account contact keys updates.

The listener will be called when any key for any accountId provided is updated, added, or removed. It will be called with the list of all keys for the provided accountIds, not just the ones that were updated.

Parameters
accountIds: List<String>

the list of account ids to register the listener for.

listener: OnAccountContactKeysUpdatedListener

the listener to register.

removeE2eeAccountContactKey

@RequiresPermission(value = "android.permission.WRITE_CONTACTS")
fun removeE2eeAccountContactKey(deviceId: String, accountId: String): Task<Void>

Removes an end-to-end encryption account contact key entry that belongs to the caller app.

Parameters
deviceId: String

an app-specified identifier for the device

accountId: String

an app-specified identifier for the account

removeE2eeContactKey

@RequiresPermission(value = "android.permission.WRITE_CONTACTS")
fun removeE2eeContactKey(
    lookupKey: String,
    deviceId: String,
    accountId: String
): Task<Void>

Removes an end-to-end encryption contact key entry that belongs to the caller app.

Parameters
lookupKey: String

the value that references the contact

deviceId: String

an app-specified identifier for the device

accountId: String

an app-specified identifier for the account

removeE2eeSelfKey

@RequiresPermission(value = "android.permission.WRITE_CONTACTS")
fun removeE2eeSelfKey(deviceId: String, accountId: String): Task<Void>

Removes an end-to-end encryption self key entry given the deviceId and the inferred package name of the caller.

Parameters
deviceId: String

an app-specified identifier for the device

accountId: String

an app-specified identifier for the account

unregisterAccountContactKeysListener

@CanIgnoreReturnValue
fun unregisterAccountContactKeysListener(
    listener: OnAccountContactKeysUpdatedListener
): Task<Boolean>

Unregisters a listener for account contact keys updates.

Parameters
listener: OnAccountContactKeysUpdatedListener

the listener to unregister.

updateAllE2eeAccountKeys

@RequiresPermission(allOf = ["android.permission.READ_CONTACTS", "android.permission.WRITE_CONTACTS"])
fun updateAllE2eeAccountKeys(accountKeyInfos: List<E2eeAccountKeyInfo>): Task<Void>

Inserts a batch of account contact keys.

Behaves similarly to updateOrInsertE2eeContactKey, but allows for multiple keys to be inserted/updated at once. Each key is inserted in its own transaction, so some keys may be inserted even if the task throws an exception.

Clients may choose to handle temporary failures by resending the whole batch, as this API will not affect the status of already-inserted keys.

For each key, if a lookupKey is provided but the contact basic info (displayName, phoneNumber, emailAddress)is not, this API will also attempt to retrieve the contact's name, phone number, and email address from the Contacts Provider. When retrieving the key, contact management apps should use this information to make sure that the key is only used for the contact that it was intended for.

The Android Key Verification app stores this information on-device and only exposes it to API callers that hold the READ_CONTACTS permission.

If no lookupKey is provided for a key, this API will store a key that is not tied to any contact.

Parameters
accountKeyInfos: List<E2eeAccountKeyInfo>

the list of E2eeAccountKeyInfo objects containing the end-to-end encryption contact key information.

updateOrInsertE2eeContactKey

@RequiresPermission(allOf = ["android.permission.READ_CONTACTS", "android.permission.WRITE_CONTACTS"])
fun updateOrInsertE2eeContactKey(
    lookupKey: String,
    deviceId: String,
    accountId: String,
    keyValue: ByteArray
): Task<Void>

Inserts a new entry into the end-to-end encryption contact keys table or updates one if it already exists. The inserted/updated end-to-end encryption contact key is owned by the caller app.

This API will also store the contact's name, phone number, and email address from the Contacts Provider, alongside the key. When retrieving the key, contact management apps should use this information to make sure that the key is only used for the contact that it was intended for.

The Android Key Verification app stores this information on-device and only exposes it to API callers that hold the READ_CONTACTS permission.

Parameters
lookupKey: String

value that references the contact

deviceId: String

an app-specified identifier for the device

accountId: String

an app-specified identifier for the account

keyValue: ByteArray

the raw bytes for the key (max size is getMaxKeySizeBytes bytes)

updateOrInsertE2eeContactKey

@RequiresPermission(allOf = ["android.permission.READ_CONTACTS", "android.permission.WRITE_CONTACTS"])
fun updateOrInsertE2eeContactKey(
    lookupKeys: List<String>,
    deviceId: String,
    accountId: String,
    keyValue: ByteArray
): Task<Void>

Inserts a new entry into the end-to-end encryption contact keys table or updates one if it already exists. The inserted/updated end-to-end encryption contact key is owned by the caller app.

For each provided lookup key, this API will also store the contact's name, phone number, and email address from the Contacts Provider, alongside the key. When retrieving the key, contact management apps should use this information to make sure that the key is only used for the contact that it was intended for.

The Android Key Verification app stores this information on-device and only exposes it to API callers that hold the READ_CONTACTS permission.

If the list of lookup keys is empty, this API will store a key that is not associated with any contact.

Calling this API with one or more lookup keys will update the key metadata to associate it with the provided contacts, but will not remove any existing associations for contacts that are not provided in the list. To remove an association between a contact and a key, call removeE2eeContactKey with the appropriate lookup key.

Parameters
lookupKeys: List<String>

potentially empty list of CP2 lookup keys referencing contacts that the key is associated with

deviceId: String

an app-specified identifier for the device

accountId: String

an app-specified identifier for the account

keyValue: ByteArray

the raw bytes for the key (max size is getMaxKeySizeBytes bytes)

updateOrInsertE2eeSelfKey

@RequiresPermission(value = "android.permission.WRITE_CONTACTS")
fun updateOrInsertE2eeSelfKey(
    deviceId: String,
    accountId: String,
    keyValue: ByteArray
): Task<Void>

Inserts a new entry into the end-to-end encryption self keys table or updates one if it already exists.

Parameters
deviceId: String

an app-specified identifier for the device

accountId: String

an app-specified identifier for the account

keyValue: ByteArray

the raw bytes for the key (max size is getMaxKeySizeBytes bytes)