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

Commit da762f62 authored by Helen Qin's avatar Helen Qin
Browse files

Finish the RequestInfo interface definition.

Test: deployed locally
Bug: 247855226
Bug: 253156958
Change-Id: I1669f66e1d1b4f7107e45521f4d6533f8801cb36
parent 85ec2063
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -29,5 +29,4 @@ public class Constants {
    */
    public static final String EXTRA_RESULT_RECEIVER =
            "android.credentials.ui.extra.RESULT_RECEIVER";

}
+87 −4
Original line number Diff line number Diff line
@@ -17,12 +17,19 @@
package android.credentials.ui;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StringDef;
import android.credentials.CreateCredentialRequest;
import android.credentials.GetCredentialRequest;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;

import com.android.internal.util.AnnotationValidations;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * Contains information about the request that initiated this UX flow.
 *
@@ -42,18 +49,45 @@ public class RequestInfo implements Parcelable {
    /** Type value for an executeCreateCredential request. */
    public static final @NonNull String TYPE_CREATE = "android.credentials.ui.TYPE_CREATE";

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @StringDef(value = { TYPE_GET, TYPE_CREATE })
    public @interface RequestType {}

    @NonNull
    private final IBinder mToken;

    @Nullable
    private final CreateCredentialRequest mCreateCredentialRequest;

    @Nullable
    private final GetCredentialRequest mGetCredentialRequest;

    @NonNull
    @RequestType
    private final String mType;

    private final boolean mIsFirstUsage;

    public RequestInfo(@NonNull IBinder token, @NonNull String type, boolean isFirstUsage) {
        mToken = token;
        mType = type;
        mIsFirstUsage = isFirstUsage;
    @NonNull
    private final String mAppDisplayName;

    /** Creates new {@code RequestInfo} for a create-credential flow. */
    public static RequestInfo newCreateRequestInfo(
            @NonNull IBinder token, @NonNull CreateCredentialRequest createCredentialRequest,
            boolean isFirstUsage, @NonNull String appDisplayName) {
        return new RequestInfo(
                token, TYPE_CREATE, isFirstUsage, appDisplayName,
                createCredentialRequest, null);
    }

    /** Creates new {@code RequestInfo} for a get-credential flow. */
    public static RequestInfo newGetRequestInfo(
            @NonNull IBinder token, @NonNull GetCredentialRequest getCredentialRequest,
            boolean isFirstUsage, @NonNull String appDisplayName) {
        return new RequestInfo(
                token, TYPE_GET, isFirstUsage, appDisplayName,
                null, getCredentialRequest);
    }

    /** Returns the request token matching the user request. */
@@ -64,6 +98,7 @@ public class RequestInfo implements Parcelable {

    /** Returns the request type. */
    @NonNull
    @RequestType
    public String getType() {
        return mType;
    }
@@ -78,16 +113,61 @@ public class RequestInfo implements Parcelable {
        return mIsFirstUsage;
    }

    /** Returns the display name of the app that made this request. */
    @NonNull
    public String getAppDisplayName() {
        return mAppDisplayName;
    }

    /**
     * Returns the non-null CreateCredentialRequest when the type of the request is {@link
     * #TYPE_CREATE}, or null otherwise.
     */
    @Nullable
    public CreateCredentialRequest getCreateCredentialRequest() {
        return mCreateCredentialRequest;
    }

    /**
     * Returns the non-null GetCredentialRequest when the type of the request is {@link
     * #TYPE_GET}, or null otherwise.
     */
    @Nullable
    public GetCredentialRequest getGetCredentialRequest() {
        return mGetCredentialRequest;
    }

    private RequestInfo(@NonNull IBinder token, @NonNull @RequestType String type,
            boolean isFirstUsage, @NonNull String appDisplayName,
            @Nullable CreateCredentialRequest createCredentialRequest,
            @Nullable GetCredentialRequest getCredentialRequest) {
        mToken = token;
        mType = type;
        mIsFirstUsage = isFirstUsage;
        mAppDisplayName = appDisplayName;
        mCreateCredentialRequest = createCredentialRequest;
        mGetCredentialRequest = getCredentialRequest;
    }

    protected RequestInfo(@NonNull Parcel in) {
        IBinder token = in.readStrongBinder();
        String type = in.readString8();
        boolean isFirstUsage = in.readBoolean();
        String appDisplayName = in.readString8();
        CreateCredentialRequest createCredentialRequest =
                in.readTypedObject(CreateCredentialRequest.CREATOR);
        GetCredentialRequest getCredentialRequest =
                in.readTypedObject(GetCredentialRequest.CREATOR);

        mToken = token;
        AnnotationValidations.validate(NonNull.class, null, mToken);
        mType = type;
        AnnotationValidations.validate(NonNull.class, null, mType);
        mIsFirstUsage = isFirstUsage;
        mAppDisplayName = appDisplayName;
        AnnotationValidations.validate(NonNull.class, null, mAppDisplayName);
        mCreateCredentialRequest = createCredentialRequest;
        mGetCredentialRequest = getCredentialRequest;
    }

    @Override
@@ -95,6 +175,9 @@ public class RequestInfo implements Parcelable {
        dest.writeStrongBinder(mToken);
        dest.writeString8(mType);
        dest.writeBoolean(mIsFirstUsage);
        dest.writeString8(mAppDisplayName);
        dest.writeTypedObject(mCreateCredentialRequest, flags);
        dest.writeTypedObject(mGetCredentialRequest, flags);
    }

    @Override
+16 −5
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.slice.Slice
import android.app.slice.SliceSpec
import android.content.Context
import android.content.Intent
import android.credentials.CreateCredentialRequest
import android.credentials.ui.Constants
import android.credentials.ui.Entry
import android.credentials.ui.ProviderData
@@ -50,11 +51,7 @@ class CredentialManagerRepo(
    requestInfo = intent.extras?.getParcelable(
      RequestInfo.EXTRA_REQUEST_INFO,
      RequestInfo::class.java
    ) ?: RequestInfo(
      Binder(),
      RequestInfo.TYPE_CREATE,
      /*isFirstUsage=*/false
    )
    ) ?: testRequestInfo()

    providerList = intent.extras?.getParcelableArrayList(
      ProviderData.EXTRA_PROVIDER_DATA_LIST,
@@ -178,4 +175,18 @@ class CredentialManagerRepo(
      slice
    )
  }

  private fun testRequestInfo(): RequestInfo {
    val data = Bundle()
    return RequestInfo.newCreateRequestInfo(
      Binder(),
      CreateCredentialRequest(
        // TODO: use the jetpack type and utils once defined.
        "androidx.credentials.TYPE_PUBLIC_KEY_CREDENTIAL",
        data
      ),
      /*isFirstUsage=*/false,
      "tribank.us"
    )
  }
}