Merge "Exposes a new CredentialEntry constructor that takes in raw Id" into udc-dev

This commit is contained in:
Reema Bajwa
2023-03-07 07:17:21 +00:00
committed by Android (Google) Code Review
3 changed files with 50 additions and 15 deletions

View File

@@ -40640,9 +40640,10 @@ package android.service.credentials {
} }
public class CredentialEntry implements android.os.Parcelable { public class CredentialEntry implements android.os.Parcelable {
ctor public CredentialEntry(@NonNull String, @NonNull String, @NonNull android.app.slice.Slice);
ctor public CredentialEntry(@NonNull android.service.credentials.BeginGetCredentialOption, @NonNull android.app.slice.Slice); ctor public CredentialEntry(@NonNull android.service.credentials.BeginGetCredentialOption, @NonNull android.app.slice.Slice);
method public int describeContents(); method public int describeContents();
method @NonNull public android.service.credentials.BeginGetCredentialOption getBeginGetCredentialOption(); method @NonNull public String getBeginGetCredentialOptionId();
method @NonNull public android.app.slice.Slice getSlice(); method @NonNull public android.app.slice.Slice getSlice();
method @NonNull public String getType(); method @NonNull public String getType();
method public void writeToParcel(@NonNull android.os.Parcel, int); method public void writeToParcel(@NonNull android.os.Parcel, int);

View File

@@ -27,6 +27,8 @@ import android.credentials.GetCredentialResponse;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import com.android.internal.util.Preconditions;
/** /**
* A credential entry that is to be displayed on the account selector that is presented to the * A credential entry that is to be displayed on the account selector that is presented to the
* user. * user.
@@ -56,7 +58,7 @@ import android.os.Parcelable;
@SuppressLint("ParcelNotFinal") @SuppressLint("ParcelNotFinal")
public class CredentialEntry implements Parcelable { public class CredentialEntry implements Parcelable {
/** The request option that corresponds to this entry. **/ /** The request option that corresponds to this entry. **/
private final @Nullable BeginGetCredentialOption mBeginGetCredentialOption; private final @Nullable String mBeginGetCredentialOptionId;
/** The type of the credential entry to be shown on the UI. */ /** The type of the credential entry to be shown on the UI. */
private final @NonNull String mType; private final @NonNull String mType;
@@ -66,6 +68,35 @@ public class CredentialEntry implements Parcelable {
* on the UI. */ * on the UI. */
private final @NonNull Slice mSlice; private final @NonNull Slice mSlice;
/**
* Creates an entry that is associated with a {@link BeginGetCredentialOption} request.
* Providers must use this constructor when they extend from {@link CredentialProviderService}
* to respond to query phase {@link CredentialProviderService#onBeginGetCredential}
* credential retrieval requests.
*
* @param beginGetCredentialOptionId the beginGetCredentialOptionId to be retrieved from
* {@link BeginGetCredentialOption#getId()} - the request option for which this CredentialEntry
* is being constructed This helps maintain an association
* such that when the user selects this entry, providers can
* receive the complete corresponding
* {@link GetCredentialRequest}.
* @param type the type of the credential for which this credential entry is being created
* @param slice the slice containing the metadata to be shown on the UI. Must be
* constructed through the androidx.credentials jetpack library.
*
* @throws IllegalArgumentException If {@code beginGetCredentialOptionId} or {@code type}
* is null, or empty
*/
public CredentialEntry(@NonNull String beginGetCredentialOptionId, @NonNull String type,
@NonNull Slice slice) {
mBeginGetCredentialOptionId = Preconditions.checkStringNotEmpty(
beginGetCredentialOptionId, "beginGetCredentialOptionId must not be "
+ "null, or empty");
mType = Preconditions.checkStringNotEmpty(type, "type must not be null, or "
+ "empty");
mSlice = requireNonNull(slice, "slice must not be null");
}
/** /**
* Creates an entry that is associated with a {@link BeginGetCredentialOption} request. * Creates an entry that is associated with a {@link BeginGetCredentialOption} request.
* Providers must use this constructor when they extend from {@link CredentialProviderService} * Providers must use this constructor when they extend from {@link CredentialProviderService}
@@ -75,16 +106,19 @@ public class CredentialEntry implements Parcelable {
* @param beginGetCredentialOption the request option for which this credential entry is * @param beginGetCredentialOption the request option for which this credential entry is
* being constructed This helps maintain an association, * being constructed This helps maintain an association,
* such that when the user selects this entry, providers * such that when the user selects this entry, providers
* can receive the conmplete corresponding request. * can receive the complete corresponding request.
* @param slice the slice containing the metadata to be shown on the UI. Must be * @param slice the slice containing the metadata to be shown on the UI. Must be
* constructed through the androidx.credentials jetpack library. * constructed through the androidx.credentials jetpack library.
*/ */
public CredentialEntry(@NonNull BeginGetCredentialOption beginGetCredentialOption, public CredentialEntry(@NonNull BeginGetCredentialOption beginGetCredentialOption,
@NonNull Slice slice) { @NonNull Slice slice) {
mBeginGetCredentialOption = requireNonNull(beginGetCredentialOption, requireNonNull(beginGetCredentialOption, "beginGetCredentialOption must not"
"beginGetCredentialOption must not be null"); + " be null");
mType = requireNonNull(mBeginGetCredentialOption.getType(), mBeginGetCredentialOptionId = Preconditions.checkStringNotEmpty(
"type must not be null"); beginGetCredentialOption.getId(), "Id in beginGetCredentialOption "
+ "must not be null");
mType = Preconditions.checkStringNotEmpty(beginGetCredentialOption.getType(),
"type in beginGetCredentialOption must not be null");
mSlice = requireNonNull(slice, "slice must not be null"); mSlice = requireNonNull(slice, "slice must not be null");
} }
@@ -101,7 +135,7 @@ public class CredentialEntry implements Parcelable {
*/ */
// TODO: Unhide this constructor when the registry APIs are stable // TODO: Unhide this constructor when the registry APIs are stable
public CredentialEntry(@NonNull String type, @NonNull Slice slice) { public CredentialEntry(@NonNull String type, @NonNull Slice slice) {
mBeginGetCredentialOption = null; mBeginGetCredentialOptionId = null;
mType = requireNonNull(type, "type must not be null"); mType = requireNonNull(type, "type must not be null");
mSlice = requireNonNull(slice, "slice must not be null"); mSlice = requireNonNull(slice, "slice must not be null");
} }
@@ -110,7 +144,7 @@ public class CredentialEntry implements Parcelable {
requireNonNull(in, "parcel must not be null"); requireNonNull(in, "parcel must not be null");
mType = in.readString8(); mType = in.readString8();
mSlice = in.readTypedObject(Slice.CREATOR); mSlice = in.readTypedObject(Slice.CREATOR);
mBeginGetCredentialOption = in.readTypedObject(BeginGetCredentialOption.CREATOR); mBeginGetCredentialOptionId = in.readString8();
} }
@NonNull @NonNull
@@ -136,15 +170,16 @@ public class CredentialEntry implements Parcelable {
public void writeToParcel(@NonNull Parcel dest, int flags) { public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeString8(mType); dest.writeString8(mType);
dest.writeTypedObject(mSlice, flags); dest.writeTypedObject(mSlice, flags);
dest.writeTypedObject(mBeginGetCredentialOption, flags); dest.writeString8(mBeginGetCredentialOptionId);
} }
/** /**
* Returns the request option for which this credential entry has been constructed. * Returns the id of the {@link BeginGetCredentialOption} for which this credential
* entry has been constructed.
*/ */
@NonNull @NonNull
public BeginGetCredentialOption getBeginGetCredentialOption() { public String getBeginGetCredentialOptionId() {
return mBeginGetCredentialOption; return mBeginGetCredentialOptionId;
} }
/** /**

View File

@@ -502,8 +502,7 @@ public final class ProviderGetSession extends ProviderSession<BeginGetCredential
String id = generateUniqueId(); String id = generateUniqueId();
Entry entry = new Entry(CREDENTIAL_ENTRY_KEY, Entry entry = new Entry(CREDENTIAL_ENTRY_KEY,
id, credentialEntry.getSlice(), id, credentialEntry.getSlice(),
setUpFillInIntent(credentialEntry setUpFillInIntent(credentialEntry.getBeginGetCredentialOptionId()));
.getBeginGetCredentialOption().getId()));
mUiCredentialEntries.put(id, new Pair<>(credentialEntry, entry)); mUiCredentialEntries.put(id, new Pair<>(credentialEntry, entry));
} }