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

Commit 499be28e authored by Joy Babafemi's avatar Joy Babafemi Committed by Android (Google) Code Review
Browse files

Merge "Add action chips for Credman-Autofill inline and dropdown presentation" into main

parents 33d0203e 6cd52640
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package android.credentials;

import android.annotation.Hide;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.ComponentName;
import android.content.Intent;
import android.credentials.selection.GetCredentialProviderData;
import android.os.Parcel;
@@ -39,6 +41,9 @@ public final class GetCandidateCredentialsResponse implements Parcelable {
    @NonNull
    private final List<GetCredentialProviderData> mCandidateProviderDataList;

    @Nullable
    private final ComponentName mPrimaryProviderComponentName;

    @NonNull
    private final Intent mIntent;

@@ -48,13 +53,15 @@ public final class GetCandidateCredentialsResponse implements Parcelable {
    @Hide
    public GetCandidateCredentialsResponse(
            @NonNull List<GetCredentialProviderData> candidateProviderDataList,
            @NonNull Intent intent
            @NonNull Intent intent,
            @Nullable ComponentName primaryProviderComponentName
    ) {
        Preconditions.checkCollectionNotEmpty(
                candidateProviderDataList,
                /*valueName=*/ "candidateProviderDataList");
        mCandidateProviderDataList = new ArrayList<>(candidateProviderDataList);
        mIntent = intent;
        mPrimaryProviderComponentName = primaryProviderComponentName;
    }

    /**
@@ -66,6 +73,16 @@ public final class GetCandidateCredentialsResponse implements Parcelable {
        return mCandidateProviderDataList;
    }

    /**
     * Returns the primary provider component name.
     *
     * @hide
     */
    @Nullable
    public ComponentName getPrimaryProviderComponentName() {
        return mPrimaryProviderComponentName;
    }

    /**
     * Returns candidate provider data list.
     *
@@ -83,12 +100,15 @@ public final class GetCandidateCredentialsResponse implements Parcelable {

        AnnotationValidations.validate(NonNull.class, null, mCandidateProviderDataList);
        mIntent = in.readTypedObject(Intent.CREATOR);

        mPrimaryProviderComponentName = in.readTypedObject(ComponentName.CREATOR);
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeTypedList(mCandidateProviderDataList);
        dest.writeTypedObject(mIntent, flags);
        dest.writeTypedObject(mPrimaryProviderComponentName, flags);
    }

    @Override
+3 −2
Original line number Diff line number Diff line
@@ -86,7 +86,8 @@ public final class CredentialProviderInfoFactory {
            @NonNull Context context,
            @NonNull ComponentName serviceComponent,
            int userId,
            boolean isSystemProvider)
            boolean isSystemProvider,
            boolean isPrimary)
            throws PackageManager.NameNotFoundException {
        return create(
                context,
@@ -94,7 +95,7 @@ public final class CredentialProviderInfoFactory {
                isSystemProvider,
                /* disableSystemAppVerificationForTests= */ false,
                /* isEnabled= */ false,
                /* isPrimary= */ false);
                isPrimary);
    }

    /**
+336 −150

File changed.

Preview size limit exceeded, changes collapsed.

+31 −20
Original line number Diff line number Diff line
@@ -21,8 +21,9 @@ import android.util.Log
import com.android.credentialmanager.common.Constants
import android.widget.RemoteViews
import androidx.core.content.ContextCompat
import com.android.credentialmanager.model.get.ActionEntryInfo
import com.android.credentialmanager.model.get.CredentialEntryInfo
import com.android.credentialmanager.model.CredentialType
import com.android.credentialmanager.model.EntryInfo
import android.graphics.drawable.Icon

class RemoteViewsFactory {
@@ -39,37 +40,47 @@ class RemoteViewsFactory {
        fun createDropdownPresentation(
            context: Context,
            icon: Icon,
            credentialEntryInfo: CredentialEntryInfo,
            entryInfo: EntryInfo,
            isFirstEntry: Boolean,
            isLastEntry: Boolean,
        ): RemoteViews {
            var layoutId: Int = com.android.credentialmanager.R.layout
                    .credman_dropdown_presentation_layout
            val remoteViews = RemoteViews(context.packageName, layoutId)
            val displayName = credentialEntryInfo.displayName ?: credentialEntryInfo.userName
            if (entryInfo is CredentialEntryInfo) {
                val displayName = entryInfo.displayName ?: entryInfo.userName
                remoteViews.setTextViewText(android.R.id.text1, displayName)
            val secondaryText = getSecondaryText(credentialEntryInfo)
                val secondaryText = getSecondaryText(entryInfo)
                if (secondaryText.isNullOrBlank()) {
                Log.w(Constants.LOG_TAG, "Secondary text for dropdown is null")
                    Log.w(Constants.LOG_TAG, "Secondary text for dropdown credential entry is null")
                } else {
                    remoteViews.setTextViewText(android.R.id.text2, secondaryText)
                }
            remoteViews.setImageViewIcon(android.R.id.icon1, icon);
                remoteViews.setContentDescription(
                    android.R.id.icon1, entryInfo
                        .providerDisplayName
                )
            } else if (entryInfo is ActionEntryInfo) {
                remoteViews.setTextViewText(android.R.id.text1, entryInfo.title)
                remoteViews.setTextViewText(android.R.id.text2, entryInfo.subTitle)
            }
            remoteViews.setImageViewIcon(android.R.id.icon1, icon)
            remoteViews.setBoolean(
                android.R.id.icon1, SET_ADJUST_VIEW_BOUNDS_METHOD_NAME, true);
                android.R.id.icon1, SET_ADJUST_VIEW_BOUNDS_METHOD_NAME, true
            )
            remoteViews.setInt(
                android.R.id.icon1,
                SET_MAX_HEIGHT_METHOD_NAME,
                context.resources.getDimensionPixelSize(
                    com.android.credentialmanager.R.dimen.autofill_icon_size));
            remoteViews.setContentDescription(android.R.id.icon1, credentialEntryInfo
                    .providerDisplayName);
                    com.android.credentialmanager.R.dimen.autofill_icon_size
                )
            )
            val drawableId =
                if (isFirstEntry)
                    com.android.credentialmanager.R.drawable.fill_dialog_dynamic_list_item_one else
                    com.android.credentialmanager.R.drawable.fill_dialog_dynamic_list_item_middle
            remoteViews.setInt(
                android.R.id.content, SET_BACKGROUND_RESOURCE_METHOD_NAME, drawableId);
                android.R.id.content, SET_BACKGROUND_RESOURCE_METHOD_NAME, drawableId)
            if (isFirstEntry) remoteViews.setViewPadding(
                com.android.credentialmanager.R.id.credential_card,
                /* left=*/0,
@@ -94,8 +105,8 @@ class RemoteViewsFactory {
         * providerDisplayName. Both credential type and provider display name should not be empty.
         */
        private fun getSecondaryText(credentialEntryInfo: CredentialEntryInfo): String? {
            return listOf(if (credentialEntryInfo.displayName != null
                && (credentialEntryInfo.displayName != credentialEntryInfo.userName))
            return listOf(if (credentialEntryInfo.displayName != null &&
                (credentialEntryInfo.displayName != credentialEntryInfo.userName))
                (credentialEntryInfo.userName) else null,
                credentialEntryInfo.credentialTypeDisplayName,
                credentialEntryInfo.providerDisplayName).filterNot { it.isNullOrBlank() }
@@ -113,16 +124,16 @@ class RemoteViewsFactory {
                com.android.credentialmanager
                        .R.string.dropdown_presentation_more_sign_in_options_text))
            remoteViews.setBoolean(
                android.R.id.icon1, SET_ADJUST_VIEW_BOUNDS_METHOD_NAME, true);
                android.R.id.icon1, SET_ADJUST_VIEW_BOUNDS_METHOD_NAME, true)
            remoteViews.setInt(
                android.R.id.icon1,
                SET_MAX_HEIGHT_METHOD_NAME,
                context.resources.getDimensionPixelSize(
                    com.android.credentialmanager.R.dimen.autofill_icon_size));
                    com.android.credentialmanager.R.dimen.autofill_icon_size))
            val drawableId =
                com.android.credentialmanager.R.drawable.more_options_list_item
            remoteViews.setInt(
                android.R.id.content, SET_BACKGROUND_RESOURCE_METHOD_NAME, drawableId);
                android.R.id.content, SET_BACKGROUND_RESOURCE_METHOD_NAME, drawableId)
            return remoteViews
        }
    }
+2 −2
Original line number Diff line number Diff line
@@ -292,12 +292,12 @@ private fun toGetScreenState(
        providerDisplayInfo.remoteEntry == null &&
        providerDisplayInfo.authenticationEntryList.all { it.isUnlockedAndEmpty })
        GetScreenState.UNLOCKED_AUTH_ENTRIES_ONLY
    else if (isRequestForAllOptions)
        GetScreenState.ALL_SIGN_IN_OPTIONS_ONLY
    else if (providerDisplayInfo.sortedUserNameToCredentialEntryList.isEmpty() &&
        providerDisplayInfo.authenticationEntryList.isEmpty() &&
        providerDisplayInfo.remoteEntry != null)
        GetScreenState.REMOTE_ONLY
    else if (isRequestForAllOptions)
        GetScreenState.ALL_SIGN_IN_OPTIONS_ONLY
    else if (isBiometricFlow(providerDisplayInfo, isFlowAutoSelectable(providerDisplayInfo)))
        GetScreenState.BIOMETRIC_SELECTION
    else GetScreenState.PRIMARY_SELECTION
Loading