ContactKeyClient


public interface ContactKeyClient extends HasApiKey


A client for the Contact Key API.

Summary

Public methods

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

Returns a flow of account contact keys updates.

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

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

abstract @NonNull Task<@NonNull 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.

abstract @NonNull Task<@NonNull ImmutableList<@NonNull 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.

abstract @NonNull Task<@NonNull 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.

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

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

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

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

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

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

abstract @NonNull Task<@NonNull Integer>

Returns the maximum allowed size of a key in bytes.

abstract @NonNull Task<@NonNull PendingIntent>
getOnboardingIntent(
    @NonNull OnboardingNextActivity nextActivity,
    String lookupKey,
    String packageName
)

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

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

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

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

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

abstract @NonNull Task<@NonNull PendingIntent>
getScanQrCodeIntent(@NonNull String lookupKey, boolean skipOnboarding)

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

abstract @NonNull Task<@NonNull PendingIntent>
getScanQrCodeIntentForAccount(
    @NonNull String packageName,
    @NonNull String accountId
)

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

abstract @NonNull Task<@NonNull PendingIntent>
getShowQrCodeIntent(String packageName, boolean skipOnboarding)

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

abstract @NonNull Task<@NonNull Boolean>

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

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

Registers a listener for account contact keys updates.

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

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

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

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

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

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

abstract @NonNull Task<@NonNull Boolean>

Unregisters a listener for account contact keys updates.

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

Inserts a batch of account contact keys.

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

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

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

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

abstract @NonNull Task<@NonNull Void>
@RequiresPermission(value = "android.permission.WRITE_CONTACTS")
updateOrInsertE2eeSelfKey(
    @NonNull String deviceId,
    @NonNull String accountId,
    @NonNull byte[] keyValue
)

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

Public methods

getAccountContactKeysFlow

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

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
@NonNull List<@NonNull String> accountIds

the list of account ids to listen for updates on.

Returns
@NonNull Flow<@NonNull List<@NonNull 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")
abstract @NonNull Task<@NonNull E2eeContactKeyListParcelablegetAllE2eeContactKeys(@NonNull String lookupKey)

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
@NonNull String lookupKey

the value that references the contact

Returns
@NonNull Task<@NonNull 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")
abstract @NonNull Task<@NonNull E2eeSelfKeyListParcelablegetAllE2eeSelfKeys()

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
@NonNull Task<@NonNull 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")
abstract @NonNull Task<@NonNull ImmutableList<@NonNull E2eeAccountContactKeyParcelable>> 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.

Returns
@NonNull Task<@NonNull ImmutableList<@NonNull 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")
abstract @NonNull Task<@NonNull E2eeContactKeyListParcelablegetAllOwnerE2eeContactKeys()

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
@NonNull Task<@NonNull 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")
abstract @NonNull Task<@NonNull ImmutableList<@NonNull E2eeAccountContactKeyParcelable>> getE2eeAccountKeysForAccount(@NonNull String accountId)

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
@NonNull Task<@NonNull ImmutableList<@NonNull 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")
abstract @NonNull Task<E2eeContactKeyParcelablegetE2eeContactKey(
    @NonNull String lookupKey,
    @NonNull String deviceId,
    @NonNull String accountId
)

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

Parameters
@NonNull String lookupKey

the value that references the contact

@NonNull String deviceId

an app-specified identifier for the device

@NonNull String accountId

an app-specified identifier for the account

Returns
@NonNull Task<E2eeContactKeyParcelable>

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

getE2eeSelfKey

@RequiresPermission(value = "android.permission.READ_CONTACTS")
abstract @NonNull Task<E2eeSelfKeyParcelablegetE2eeSelfKey(@NonNull String deviceId, @NonNull String accountId)

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

Parameters
@NonNull String deviceId

an app-specified identifier for the device

@NonNull String accountId

an app-specified identifier for the account

Returns
@NonNull Task<E2eeSelfKeyParcelable>

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

getMaxKeySizeBytes

abstract @NonNull Task<@NonNull IntegergetMaxKeySizeBytes()

Returns the maximum allowed size of a key in bytes.

getOnboardingIntent

abstract @NonNull Task<@NonNull PendingIntentgetOnboardingIntent(
    @NonNull OnboardingNextActivity nextActivity,
    String lookupKey,
    String packageName
)

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
@NonNull OnboardingNextActivity nextActivity

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

String lookupKey

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

String packageName

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

getOwnerE2eeContactKeys

@RequiresPermission(value = "android.permission.READ_CONTACTS")
abstract @NonNull Task<@NonNull E2eeContactKeyListParcelablegetOwnerE2eeContactKeys(@NonNull String lookupKey)

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

Parameters
@NonNull String lookupKey

the value that references the contact

Returns
@NonNull Task<@NonNull 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")
abstract @NonNull Task<@NonNull E2eeSelfKeyListParcelablegetOwnerE2eeSelfKeys()

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

Returns
@NonNull Task<@NonNull E2eeSelfKeyListParcelable>

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

getScanQrCodeIntent

abstract @NonNull Task<@NonNull PendingIntentgetScanQrCodeIntent(@NonNull String lookupKey, boolean skipOnboarding)

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

Parameters
@NonNull String lookupKey

the value that references the contact

boolean skipOnboarding

Currently unused.

getScanQrCodeIntentForAccount

abstract @NonNull Task<@NonNull PendingIntentgetScanQrCodeIntentForAccount(
    @NonNull String packageName,
    @NonNull String accountId
)

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

Parameters
@NonNull String packageName

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

@NonNull String accountId

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

getShowQrCodeIntent

abstract @NonNull Task<@NonNull PendingIntentgetShowQrCodeIntent(String packageName, boolean skipOnboarding)

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

Parameters
String packageName

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

boolean skipOnboarding

Currently unused.

isEnabled

abstract @NonNull Task<@NonNull BooleanisEnabled()

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")
abstract @NonNull Task<@NonNull VoidregisterAccountContactKeysListener(
    @NonNull List<@NonNull String> accountIds,
    @NonNull OnAccountContactKeysUpdatedListener listener
)

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
@NonNull List<@NonNull String> accountIds

the list of account ids to register the listener for.

@NonNull OnAccountContactKeysUpdatedListener listener

the listener to register.

removeE2eeAccountContactKey

@RequiresPermission(value = "android.permission.WRITE_CONTACTS")
abstract @NonNull Task<@NonNull VoidremoveE2eeAccountContactKey(
    @NonNull String deviceId,
    @NonNull String accountId
)

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

Parameters
@NonNull String deviceId

an app-specified identifier for the device

@NonNull String accountId

an app-specified identifier for the account

removeE2eeContactKey

@RequiresPermission(value = "android.permission.WRITE_CONTACTS")
abstract @NonNull Task<@NonNull VoidremoveE2eeContactKey(
    @NonNull String lookupKey,
    @NonNull String deviceId,
    @NonNull String accountId
)

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

Parameters
@NonNull String lookupKey

the value that references the contact

@NonNull String deviceId

an app-specified identifier for the device

@NonNull String accountId

an app-specified identifier for the account

removeE2eeSelfKey

@RequiresPermission(value = "android.permission.WRITE_CONTACTS")
abstract @NonNull Task<@NonNull VoidremoveE2eeSelfKey(@NonNull String deviceId, @NonNull String accountId)

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

Parameters
@NonNull String deviceId

an app-specified identifier for the device

@NonNull String accountId

an app-specified identifier for the account

unregisterAccountContactKeysListener

@CanIgnoreReturnValue
abstract @NonNull Task<@NonNull BooleanunregisterAccountContactKeysListener(
    @NonNull OnAccountContactKeysUpdatedListener listener
)

Unregisters a listener for account contact keys updates.

Parameters
@NonNull OnAccountContactKeysUpdatedListener listener

the listener to unregister.

updateAllE2eeAccountKeys

@RequiresPermission(allOf = ["android.permission.READ_CONTACTS", "android.permission.WRITE_CONTACTS"])
abstract @NonNull Task<@NonNull VoidupdateAllE2eeAccountKeys(
    @NonNull List<@NonNull E2eeAccountKeyInfo> accountKeyInfos
)

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
@NonNull List<@NonNull E2eeAccountKeyInfo> accountKeyInfos

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"])
abstract @NonNull Task<@NonNull VoidupdateOrInsertE2eeContactKey(
    @NonNull String lookupKey,
    @NonNull String deviceId,
    @NonNull String accountId,
    @NonNull byte[] keyValue
)

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
@NonNull String lookupKey

value that references the contact

@NonNull String deviceId

an app-specified identifier for the device

@NonNull String accountId

an app-specified identifier for the account

@NonNull byte[] keyValue

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

updateOrInsertE2eeContactKey

@RequiresPermission(allOf = ["android.permission.READ_CONTACTS", "android.permission.WRITE_CONTACTS"])
abstract @NonNull Task<@NonNull VoidupdateOrInsertE2eeContactKey(
    @NonNull List<@NonNull String> lookupKeys,
    @NonNull String deviceId,
    @NonNull String accountId,
    @NonNull byte[] keyValue
)

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
@NonNull List<@NonNull String> lookupKeys

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

@NonNull String deviceId

an app-specified identifier for the device

@NonNull String accountId

an app-specified identifier for the account

@NonNull byte[] keyValue

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

updateOrInsertE2eeSelfKey

@RequiresPermission(value = "android.permission.WRITE_CONTACTS")
abstract @NonNull Task<@NonNull VoidupdateOrInsertE2eeSelfKey(
    @NonNull String deviceId,
    @NonNull String accountId,
    @NonNull byte[] keyValue
)

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

Parameters
@NonNull String deviceId

an app-specified identifier for the device

@NonNull String accountId

an app-specified identifier for the account

@NonNull byte[] keyValue

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