Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 99428a60 authored by Anh Pham's avatar Anh Pham
Browse files

Add APIs for apps to update Contact keys of other apps.

Bug: 290696572
Test: atest CtsContactKeysManagerTestCases CtsContactKeysProviderPrivilegedApp
Change-Id: Ie015135483b19c5ea88c025ff684f12cd66957e2
parent e7f1e7fa
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -11299,6 +11299,12 @@ package android.provider {
    field public static final int ERROR_UNKNOWN = 0; // 0x0
  }
  @FlaggedApi("android.provider.user_keys") public class ContactKeysManager {
    method @RequiresPermission(allOf={android.Manifest.permission.WRITE_VERIFICATION_STATE_E2EE_CONTACT_KEYS, android.Manifest.permission.WRITE_CONTACTS}) public boolean updateContactKeyLocalVerificationState(@NonNull String, @NonNull String, @NonNull String, @NonNull String, int);
    method @RequiresPermission(allOf={android.Manifest.permission.WRITE_VERIFICATION_STATE_E2EE_CONTACT_KEYS, android.Manifest.permission.WRITE_CONTACTS}) public boolean updateContactKeyRemoteVerificationState(@NonNull String, @NonNull String, @NonNull String, @NonNull String, int);
    method @RequiresPermission(allOf={android.Manifest.permission.WRITE_VERIFICATION_STATE_E2EE_CONTACT_KEYS, android.Manifest.permission.WRITE_CONTACTS}) public boolean updateSelfKeyRemoteVerificationState(@NonNull String, @NonNull String, @NonNull String, int);
  }
  @Deprecated public static final class ContactsContract.MetadataSync implements android.provider.BaseColumns android.provider.ContactsContract.MetadataSyncColumns {
    field @Deprecated public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact_metadata";
    field @Deprecated public static final String CONTENT_TYPE = "vnd.android.cursor.dir/contact_metadata";
+115 −2
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.content.Context;
@@ -246,6 +247,44 @@ public class ContactKeysManager {
        return response != null && response.getBoolean(ContactKeys.KEY_UPDATED_ROWS);
    }

    /**
     * Updates a contact key entry's local verification state that belongs to the app identified
     * by ownerPackageName.
     *
     * @param lookupKey the value that references the contact
     * @param deviceId an app-specified identifier for the device
     * @param accountId an app-specified identifier for the account
     * @param ownerPackageName the package name of the app that owns the key
     * @param localVerificationState the new local verification state
     *
     * @return true if the entry was updated, false otherwise.
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(allOf = {
            android.Manifest.permission.WRITE_VERIFICATION_STATE_E2EE_CONTACT_KEYS,
            android.Manifest.permission.WRITE_CONTACTS})
    public boolean updateContactKeyLocalVerificationState(@NonNull String lookupKey,
            @NonNull String deviceId,
            @NonNull String accountId,
            @NonNull String ownerPackageName,
            @VerificationState int localVerificationState) {
        validateVerificationState(localVerificationState);

        final Bundle extras = new Bundle();
        extras.putString(ContactKeys.LOOKUP_KEY, Objects.requireNonNull(lookupKey));
        extras.putString(ContactKeys.DEVICE_ID, Objects.requireNonNull(deviceId));
        extras.putString(ContactKeys.ACCOUNT_ID, Objects.requireNonNull(accountId));
        extras.putString(ContactKeys.OWNER_PACKAGE_NAME, Objects.requireNonNull(ownerPackageName));
        extras.putInt(ContactKeys.LOCAL_VERIFICATION_STATE, localVerificationState);

        final Bundle response = nullSafeCall(mContentResolver,
                ContactKeys.UPDATE_CONTACT_KEY_LOCAL_VERIFICATION_STATE_METHOD, extras);

        return response != null && response.getBoolean(ContactKeys.KEY_UPDATED_ROWS);
    }

    /**
     * Updates a contact key entry's remote verification state that belongs to the caller app.
     *
@@ -275,6 +314,45 @@ public class ContactKeysManager {
        return response != null && response.getBoolean(ContactKeys.KEY_UPDATED_ROWS);
    }

    /**
     * Updates a contact key entry's remote verification state that belongs to the app identified
     * by ownerPackageName.
     *
     * @param lookupKey the value that references the contact
     * @param deviceId an app-specified identifier for the device
     * @param accountId an app-specified identifier for the account
     * @param ownerPackageName the package name of the app that owns the key
     * @param remoteVerificationState the new remote verification state
     *
     * @return true if the entry was updated, false otherwise.
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(allOf = {
            android.Manifest.permission.WRITE_VERIFICATION_STATE_E2EE_CONTACT_KEYS,
            android.Manifest.permission.WRITE_CONTACTS})
    public boolean updateContactKeyRemoteVerificationState(@NonNull String lookupKey,
            @NonNull String deviceId,
            @NonNull String accountId,
            @NonNull String ownerPackageName,
            @VerificationState int remoteVerificationState) {
        validateVerificationState(remoteVerificationState);

        final Bundle extras = new Bundle();
        extras.putString(ContactKeys.LOOKUP_KEY, Objects.requireNonNull(lookupKey));
        extras.putString(ContactKeys.DEVICE_ID, Objects.requireNonNull(deviceId));
        extras.putString(ContactKeys.ACCOUNT_ID, Objects.requireNonNull(accountId));
        extras.putString(ContactKeys.OWNER_PACKAGE_NAME, Objects.requireNonNull(ownerPackageName));
        extras.putInt(ContactKeys.REMOTE_VERIFICATION_STATE, remoteVerificationState);

        final Bundle response = nullSafeCall(mContentResolver,
                ContactKeys.UPDATE_CONTACT_KEY_REMOTE_VERIFICATION_STATE_METHOD, extras);

        return response != null && response.getBoolean(ContactKeys.KEY_UPDATED_ROWS);
    }


    private static void validateVerificationState(int verificationState) {
        if (verificationState != UNVERIFIED
                && verificationState != VERIFICATION_FAILED
@@ -297,12 +375,12 @@ public class ContactKeysManager {
    public boolean removeContactKey(@NonNull String lookupKey,
            @NonNull String deviceId,
            @NonNull String accountId) {
        Bundle extras = new Bundle();
        final Bundle extras = new Bundle();
        extras.putString(ContactKeys.LOOKUP_KEY, Objects.requireNonNull(lookupKey));
        extras.putString(ContactKeys.DEVICE_ID, Objects.requireNonNull(deviceId));
        extras.putString(ContactKeys.ACCOUNT_ID, Objects.requireNonNull(accountId));

        Bundle response = nullSafeCall(mContentResolver,
        final Bundle response = nullSafeCall(mContentResolver,
                ContactKeys.REMOVE_CONTACT_KEY_METHOD, extras);

        return response != null && response.getBoolean(ContactKeys.KEY_UPDATED_ROWS);
@@ -368,6 +446,41 @@ public class ContactKeysManager {
        return response != null && response.getBoolean(ContactKeys.KEY_UPDATED_ROWS);
    }

    /**
     * Updates a self key entry's remote verification state that belongs to the app identified
     * by ownerPackageName.
     *
     * @param deviceId an app-specified identifier for the device
     * @param accountId an app-specified identifier for the account
     * @param ownerPackageName the package name of the app that owns the key
     * @param remoteVerificationState the new remote verification state
     *
     * @return true if the entry was updated, false otherwise.
     *
     * @hide
     */
    @SystemApi
    @RequiresPermission(allOf = {
            android.Manifest.permission.WRITE_VERIFICATION_STATE_E2EE_CONTACT_KEYS,
            android.Manifest.permission.WRITE_CONTACTS})
    public boolean updateSelfKeyRemoteVerificationState(@NonNull String deviceId,
            @NonNull String accountId,
            @NonNull String ownerPackageName,
            @VerificationState int remoteVerificationState) {
        validateVerificationState(remoteVerificationState);

        Bundle extras = new Bundle();
        extras.putString(ContactKeys.DEVICE_ID, Objects.requireNonNull(deviceId));
        extras.putString(ContactKeys.ACCOUNT_ID, Objects.requireNonNull(accountId));
        extras.putString(ContactKeys.OWNER_PACKAGE_NAME, Objects.requireNonNull(ownerPackageName));
        extras.putInt(ContactKeys.REMOTE_VERIFICATION_STATE, remoteVerificationState);

        Bundle response = nullSafeCall(mContentResolver,
                ContactKeys.UPDATE_SELF_KEY_REMOTE_VERIFICATION_STATE_METHOD, extras);

        return response != null && response.getBoolean(ContactKeys.KEY_UPDATED_ROWS);
    }

    /**
     * Maximum size of a contact key.
     */