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

Commit 00399566 authored by Reema Bajwa's avatar Reema Bajwa Committed by Android (Google) Code Review
Browse files

Merge "Basic create flow for credential manager up until pending intent is...

Merge "Basic create flow for credential manager up until pending intent is invoked Test: Built locally & deployed Bug: 253155340"
parents d1dd7947 ed78b791
Loading
Loading
Loading
Loading
+6 −6
Original line number Original line Diff line number Diff line
@@ -173,7 +173,7 @@ public final class CredentialEntry implements Parcelable {
         */
         */
        public @NonNull Builder setPendingIntent(@Nullable PendingIntent pendingIntent) {
        public @NonNull Builder setPendingIntent(@Nullable PendingIntent pendingIntent) {
            if (pendingIntent != null) {
            if (pendingIntent != null) {
                Preconditions.checkState(mCredential != null,
                Preconditions.checkState(mCredential == null,
                        "credential is already set. Cannot set both the pendingIntent "
                        "credential is already set. Cannot set both the pendingIntent "
                                + "and the credential");
                                + "and the credential");
            }
            }
@@ -189,7 +189,7 @@ public final class CredentialEntry implements Parcelable {
         */
         */
        public @NonNull Builder setCredential(@Nullable Credential credential) {
        public @NonNull Builder setCredential(@Nullable Credential credential) {
            if (credential != null) {
            if (credential != null) {
                Preconditions.checkState(mPendingIntent != null,
                Preconditions.checkState(mPendingIntent == null,
                        "pendingIntent is already set. Cannot set both the "
                        "pendingIntent is already set. Cannot set both the "
                                + "pendingIntent and the credential");
                                + "pendingIntent and the credential");
            }
            }
@@ -215,10 +215,10 @@ public final class CredentialEntry implements Parcelable {
         * is set, or if both are set.
         * is set, or if both are set.
         */
         */
        public @NonNull CredentialEntry build() {
        public @NonNull CredentialEntry build() {
            Preconditions.checkState(mPendingIntent == null && mCredential == null,
            Preconditions.checkState(((mPendingIntent != null && mCredential == null)
                    "Either pendingIntent or credential must be set");
                            || (mPendingIntent == null && mCredential != null)),
            Preconditions.checkState(mPendingIntent != null && mCredential != null,
                    "Either pendingIntent or credential must be set, and both cannot"
                    "Cannot set both the pendingIntent and credential");
                            + "be set at the same time");
            return new CredentialEntry(mType, mSlice, mPendingIntent,
            return new CredentialEntry(mType, mSlice, mPendingIntent,
                    mCredential, mAutoSelectAllowed);
                    mCredential, mAutoSelectAllowed);
        }
        }
+2 −1
Original line number Original line Diff line number Diff line
@@ -24,7 +24,6 @@ import android.app.AppGlobals;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.pm.PackageItemInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.pm.ServiceInfo;
@@ -96,6 +95,8 @@ public final class CredentialProviderInfo {
        mLabel = mServiceInfo.loadSafeLabel(
        mLabel = mServiceInfo.loadSafeLabel(
                mContext.getPackageManager(), 0 /* do not ellipsize */,
                mContext.getPackageManager(), 0 /* do not ellipsize */,
                TextUtils.SAFE_STRING_FLAG_FIRST_LINE | TextUtils.SAFE_STRING_FLAG_TRIM);
                TextUtils.SAFE_STRING_FLAG_FIRST_LINE | TextUtils.SAFE_STRING_FLAG_TRIM);
        Log.i(TAG, "mLabel is : " + mLabel + ", for: " + mServiceInfo.getComponentName()
                .flattenToString());
        populateProviderCapabilities(context, serviceInfo);
        populateProviderCapabilities(context, serviceInfo);
    }
    }


+13 −1
Original line number Original line Diff line number Diff line
@@ -41,6 +41,18 @@ import java.util.Objects;
 * @hide
 * @hide
 */
 */
public abstract class CredentialProviderService extends Service {
public abstract class CredentialProviderService extends Service {
    /** Extra to be used by provider to populate the credential when ending the activity started
     * through the {@code pendingIntent} on the selected {@link SaveEntry}. **/
    public static final String EXTRA_SAVE_CREDENTIAL =
            "android.service.credentials.extra.SAVE_CREDENTIAL";

    /**
     * Provider must read the value against this extra to receive the complete create credential
     * request parameters, when a pending intent is launched.
     */
    public static final String EXTRA_CREATE_CREDENTIAL_REQUEST_PARAMS =
            "android.service.credentials.extra.CREATE_CREDENTIAL_REQUEST_PARAMS";

    private static final String TAG = "CredProviderService";
    private static final String TAG = "CredProviderService";


    public static final String CAPABILITY_META_DATA_KEY = "android.credentials.capabilities";
    public static final String CAPABILITY_META_DATA_KEY = "android.credentials.capabilities";
@@ -64,7 +76,7 @@ public abstract class CredentialProviderService extends Service {
    }
    }


    @Override
    @Override
    public final @NonNull IBinder onBind(@NonNull Intent intent) {
    @NonNull public final IBinder onBind(@NonNull Intent intent) {
        if (SERVICE_INTERFACE.equals(intent.getAction())) {
        if (SERVICE_INTERFACE.equals(intent.getAction())) {
            return mInterface.asBinder();
            return mInterface.asBinder();
        }
        }
+2 −2
Original line number Original line Diff line number Diff line
@@ -119,9 +119,9 @@ public final class GetCredentialsRequest implements Parcelable {
         */
         */
        public @NonNull Builder setGetCredentialOptions(
        public @NonNull Builder setGetCredentialOptions(
                @NonNull List<GetCredentialOption> getCredentialOptions) {
                @NonNull List<GetCredentialOption> getCredentialOptions) {
            Preconditions.checkCollectionNotEmpty(mGetCredentialOptions,
            Preconditions.checkCollectionNotEmpty(getCredentialOptions,
                    "getCredentialOptions");
                    "getCredentialOptions");
            Preconditions.checkCollectionElementsNotNull(mGetCredentialOptions,
            Preconditions.checkCollectionElementsNotNull(getCredentialOptions,
                    "getCredentialOptions");
                    "getCredentialOptions");
            mGetCredentialOptions = getCredentialOptions;
            mGetCredentialOptions = getCredentialOptions;
            return this;
            return this;
+75 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.credentials;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.credentials.CreateCredentialRequest;
import android.credentials.CredentialManager;
import android.credentials.ICreateCredentialCallback;
import android.credentials.ui.ProviderData;
import android.credentials.ui.RequestInfo;
import android.service.credentials.CredentialProviderInfo;
import android.util.Log;

import java.util.ArrayList;

/**
 * Central session for a single {@link CredentialManager#executeCreateCredential} request.
 * This class listens to the responses from providers, and the UX app, and updates the
 * provider(s) state maintained in {@link ProviderCreateSession}.
 */
public final class CreateRequestSession extends RequestSession<CreateCredentialRequest,
        ICreateCredentialCallback> {
    private static final String TAG = "CreateRequestSession";

    CreateRequestSession(@NonNull Context context, int userId,
            CreateCredentialRequest request,
            ICreateCredentialCallback callback,
            String callingPackage) {
        super(context, userId, request, callback, RequestInfo.TYPE_CREATE, callingPackage);
    }

    /**
     * Creates a new provider session, and adds it to list of providers that are contributing to
     * this request session.
     *
     * @return the provider session that was started
     */
    @Override
    @Nullable
    public ProviderSession initiateProviderSession(CredentialProviderInfo providerInfo,
            RemoteCredentialService remoteCredentialService) {
        ProviderCreateSession providerCreateSession = ProviderCreateSession
                .createNewSession(mContext, mUserId, providerInfo,
                this, remoteCredentialService);
        if (providerCreateSession != null) {
            Log.i(TAG, "In startProviderSession - provider session created and being added");
            mProviders.put(providerCreateSession.getComponentName().flattenToString(),
                    providerCreateSession);
        }
        return providerCreateSession;
    }

    @Override
    protected void launchUiWithProviderData(ArrayList<ProviderData> providerDataList) {
        mHandler.post(() -> mCredentialManagerUi.show(RequestInfo.newCreateRequestInfo(
                        mRequestId, mClientRequest, mIsFirstUiTurn, mClientCallingPackage),
                providerDataList));
    }
}
Loading