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

Commit 55ed8a0e authored by Daniel's avatar Daniel
Browse files

Refactor credman for autofill methods

Refactor existing method overloads that are used jointly for autofill
flows. Clean up the method overloads so that there is a distinct flow
within credman for autofill. Additionally, clean up
isRequestForAllOptions.

Bug: 323552850
Test: tested e2e with addressbook
Change-Id: I31cc094f2232b718351b5b371c2d09a6b98296aa
parent f9f1b66b
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -29,13 +29,6 @@ public class Constants {
    public static final String EXTRA_RESULT_RECEIVER =
            "android.credentials.selection.extra.RESULT_RECEIVER";

    /**
     * The intent extra key for indicating whether the bottom sheet should be started directly
     * on the 'All Options' screen.
     */
    public static final String EXTRA_REQ_FOR_ALL_OPTIONS =
            "android.credentials.selection.extra.REQ_FOR_ALL_OPTIONS";

    /**
     * The intent extra key for the final result receiver object
     */
+9 −22
Original line number Diff line number Diff line
@@ -48,41 +48,28 @@ import java.util.ArrayList;
public class IntentFactory {

    /**
     * Generate a new launch intent to the Credential Selector UI for auto-filling.
     * Generate a new launch intent to the Credential Selector UI for auto-filling. This intent is
     * invoked from the Autofill flow, when the user requests to bring up the 'All Options' page of
     * the credential bottom-sheet. When the user clicks on the pinned entry, the intent will bring
     * up the 'All Options' page of the bottom-sheet. The provider data list is processed by the
     * credential autofill service for each autofill id and passed in as an auth extra.
     *
     * @hide
     */
    @NonNull
    // TODO(b/323552850) - clean up method overloads
    public static Intent createCredentialSelectorIntent(
    public static Intent createCredentialSelectorIntentForAutofill(
            @NonNull Context context,
            @NonNull RequestInfo requestInfo,
            @SuppressLint("ConcreteCollection") // Concrete collection needed for marshalling.
            @Nullable
            ArrayList<ProviderData> enabledProviderDataList,
            @SuppressLint("ConcreteCollection") // Concrete collection needed for marshalling.
            @NonNull
            ArrayList<DisabledProviderData> disabledProviderDataList,
            @NonNull ResultReceiver resultReceiver,
            boolean isRequestForAllOptions) {

        Intent intent;
        if (enabledProviderDataList != null) {
            intent = createCredentialSelectorIntent(context, requestInfo, enabledProviderDataList,
                    disabledProviderDataList, resultReceiver);
        } else {
            intent = createCredentialSelectorIntent(context, requestInfo,
            @NonNull ResultReceiver resultReceiver) {
        return createCredentialSelectorIntent(context, requestInfo,
                disabledProviderDataList, resultReceiver);
    }
        intent.putExtra(Constants.EXTRA_REQ_FOR_ALL_OPTIONS, isRequestForAllOptions);

        return intent;
    }

    /**
     * Generate a new launch intent to the Credential Selector UI.
     *
     * @hide
     */
    @NonNull
    private static Intent createCredentialSelectorIntent(
+1 −5
Original line number Diff line number Diff line
@@ -111,11 +111,7 @@ class CredentialManagerRepo(
                ResultReceiver::class.java
        )

        isReqForAllOptions = intent.getBooleanExtra(
                Constants.EXTRA_REQ_FOR_ALL_OPTIONS,
                /*defaultValue=*/ false
        ) || (requestInfo?.isShowAllOptionsRequested ?: false) // TODO(b/323552850) - Remove
        // usage on Constants.EXTRA_REQ_FOR_ALL_OPTIONS once it is deprecated.
        isReqForAllOptions = requestInfo?.isShowAllOptionsRequested ?: false

        val cancellationRequest = getCancelUiRequest(intent)
        val cancelUiRequestState = cancellationRequest?.let {
+2 −3
Original line number Diff line number Diff line
@@ -104,7 +104,6 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
                flattenedPrimaryProviders.add(cn.flattenToString());
            }

            final boolean isShowAllOptionsRequested = false;
            mPendingIntent = mCredentialManagerUi.createPendingIntent(
                    RequestInfo.newCreateRequestInfo(
                            mRequestId, mClientRequest,
@@ -112,8 +111,8 @@ public final class CreateRequestSession extends RequestSession<CreateCredentialR
                            PermissionUtils.hasPermission(mContext, mClientAppInfo.getPackageName(),
                                    Manifest.permission.CREDENTIAL_MANAGER_SET_ALLOWED_PROVIDERS),
                            /*defaultProviderId=*/flattenedPrimaryProviders,
                            isShowAllOptionsRequested),
                    providerDataList, /*isRequestForAllOptions=*/ isShowAllOptionsRequested);
                            /*isShowAllOptionsRequested=*/ false),
                    providerDataList);
            mClientCallback.onPendingIntent(mPendingIntent);
        } catch (RemoteException e) {
            mRequestSessionMetric.collectUiReturnedFinalPhase(/*uiReturned=*/ false);
+35 −10
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.credentials;
import static android.credentials.selection.Constants.EXTRA_FINAL_RESPONSE_RECEIVER;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
@@ -152,16 +153,34 @@ public class CredentialManagerUi {

    /**
     * Creates a {@link PendingIntent} to be used to invoke the credential manager selector UI,
     * by the calling app process.
     * by the calling app process. The bottom-sheet navigates to the default page when the intent
     * is invoked.
     *
     * @param requestInfo            the information about the request
     * @param providerDataList       the list of provider data from remote providers
     * @param isRequestForAllOptions whether the bottom sheet should directly navigate to the
     *                               all options page
     */
    public PendingIntent createPendingIntent(
            RequestInfo requestInfo, ArrayList<ProviderData> providerDataList,
            boolean isRequestForAllOptions) {
            RequestInfo requestInfo, ArrayList<ProviderData> providerDataList) {
        return createPendingIntent(requestInfo, providerDataList, /*forAutofill=*/ false);
    }

    /**
     * Creates a {@link PendingIntent} to be used to invoke the credential manager selector UI,
     * by the calling app process. This intent is invoked from the Autofill flow, when the user
     * requests to bring up the 'All Options' page of the credential bottom-sheet. When the user
     * clicks on the pinned entry, the intent will bring up the 'All Options' page of the
     * bottom-sheet. The provider data list is processed by the credential autofill service for
     * each autofill id and passed in as an auth extra.
     *
     * @param requestInfo            the information about the request
     */
    public PendingIntent createPendingIntentForAutofill(RequestInfo requestInfo) {
        return createPendingIntent(requestInfo, /*providerDataList=*/ null, /*forAutofill=*/ true);
    }

    private PendingIntent createPendingIntent(
            RequestInfo requestInfo, @Nullable ArrayList<ProviderData> providerDataList,
            boolean forAutofill) {
        List<CredentialProviderInfo> allProviders =
                CredentialProviderInfoFactory.getCredentialProviderServices(
                        mContext,
@@ -176,11 +195,17 @@ public class CredentialManagerUi {
                .map(disabledProvider -> new DisabledProviderData(
                        disabledProvider.getComponentName().flattenToString())).toList();

        Intent intent = IntentFactory.createCredentialSelectorIntent(mContext, requestInfo,
                        providerDataList,
                        new ArrayList<>(disabledProviderDataList), mResultReceiver,
                        isRequestForAllOptions)
                .setAction(UUID.randomUUID().toString());
        Intent intent;
        if (forAutofill) {
            intent = IntentFactory.createCredentialSelectorIntentForAutofill(
                    mContext, requestInfo, new ArrayList<>(disabledProviderDataList),
                    mResultReceiver);
        } else {
            intent = IntentFactory.createCredentialSelectorIntent(
                    mContext, requestInfo, providerDataList,
                    new ArrayList<>(disabledProviderDataList), mResultReceiver);
        }
        intent.setAction(UUID.randomUUID().toString());
        //TODO: Create unique pending intent using request code and cancel any pre-existing pending
        // intents
        return PendingIntent.getActivityAsUser(
Loading