diff --git a/core/java/android/credentials/ui/Entry.java b/core/java/android/credentials/ui/Entry.java new file mode 100644 index 0000000000000..122c54ad81442 --- /dev/null +++ b/core/java/android/credentials/ui/Entry.java @@ -0,0 +1,116 @@ +/* + * Copyright 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 android.credentials.ui; + +import android.annotation.NonNull; +import android.app.slice.Slice; +import android.net.Uri; +import android.os.Parcel; +import android.os.Parcelable; + +import com.android.internal.util.AnnotationValidations; + +/** + * A credential, save, or action entry to be rendered. + * + * @hide + */ +public class Entry implements Parcelable { + // TODO: move to jetpack. + public static final String VERSION = "v1"; + public static final Uri CREDENTIAL_MANAGER_ENTRY_URI = Uri.parse("credentialmanager.slice"); + public static final String HINT_TITLE = "hint_title"; + public static final String HINT_SUBTITLE = "hint_subtitle"; + public static final String HINT_ICON = "hint_icon"; + + /** + * The intent extra key for the action chip {@code Entry} list when launching the UX activities. + */ + public static final String EXTRA_ENTRY_LIST_ACTION_CHIP = + "android.credentials.ui.extra.ENTRY_LIST_ACTION_CHIP"; + /** + * The intent extra key for the credential / save {@code Entry} list when launching the UX + * activities. + */ + public static final String EXTRA_ENTRY_LIST_CREDENTIAL = + "android.credentials.ui.extra.ENTRY_LIST_CREDENTIAL"; + /** + * The intent extra key for the authentication action {@code Entry} when launching the UX + * activities. + */ + public static final String EXTRA_ENTRY_AUTHENTICATION_ACTION = + "android.credentials.ui.extra.ENTRY_AUTHENTICATION_ACTION"; + + // TODO: may be changed to other type depending on the service implementation. + private final int mId; + + @NonNull + private final Slice mSlice; + + protected Entry(@NonNull Parcel in) { + int entryId = in.readInt(); + Slice slice = Slice.CREATOR.createFromParcel(in); + + mId = entryId; + mSlice = slice; + AnnotationValidations.validate(NonNull.class, null, mSlice); + } + + public Entry(int id, @NonNull Slice slice) { + mId = id; + mSlice = slice; + } + + /** + * Returns the id of this entry that's unique within the context of the CredentialManager + * request. + */ + public int getEntryId() { + return mId; + } + + /** + * Returns the Slice to be rendered. + */ + @NonNull + public Slice getSlice() { + return mSlice; + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeInt(mId); + mSlice.writeToParcel(dest, flags); + } + + @Override + public int describeContents() { + return 0; + } + + public static final @NonNull Creator CREATOR = new Creator() { + @Override + public Entry createFromParcel(@NonNull Parcel in) { + return new Entry(in); + } + + @Override + public Entry[] newArray(int size) { + return new Entry[size]; + } + }; +} diff --git a/core/java/android/credentials/ui/ProviderData.java b/core/java/android/credentials/ui/ProviderData.java index 49e5e49c2450e..18e6ba4305893 100644 --- a/core/java/android/credentials/ui/ProviderData.java +++ b/core/java/android/credentials/ui/ProviderData.java @@ -17,11 +17,15 @@ package android.credentials.ui; import android.annotation.NonNull; +import android.annotation.Nullable; import android.os.Parcel; import android.os.Parcelable; import com.android.internal.util.AnnotationValidations; +import java.util.ArrayList; +import java.util.List; + /** * Holds metadata and credential entries for a single provider. * @@ -36,13 +40,24 @@ public class ProviderData implements Parcelable { public static final String EXTRA_PROVIDER_DATA_LIST = "android.credentials.ui.extra.PROVIDER_DATA_LIST"; - // TODO: add entry data. - @NonNull private final String mPackageName; + @NonNull + private final List mCredentialEntries; + @NonNull + private final List mActionChips; + @Nullable + private final Entry mAuthenticationEntry; - public ProviderData(@NonNull String packageName) { + public ProviderData( + @NonNull String packageName, + @NonNull List credentialEntries, + @NonNull List actionChips, + @Nullable Entry authenticationEntry) { mPackageName = packageName; + mCredentialEntries = credentialEntries; + mActionChips = actionChips; + mAuthenticationEntry = authenticationEntry; } /** Returns the provider package name. */ @@ -51,15 +66,46 @@ public class ProviderData implements Parcelable { return mPackageName; } + @NonNull + public List getCredentialEntries() { + return mCredentialEntries; + } + + @NonNull + public List getActionChips() { + return mActionChips; + } + + @Nullable + public Entry getAuthenticationEntry() { + return mAuthenticationEntry; + } + protected ProviderData(@NonNull Parcel in) { String packageName = in.readString8(); mPackageName = packageName; AnnotationValidations.validate(NonNull.class, null, mPackageName); + + List credentialEntries = new ArrayList<>(); + in.readTypedList(credentialEntries, Entry.CREATOR); + mCredentialEntries = credentialEntries; + AnnotationValidations.validate(NonNull.class, null, mCredentialEntries); + + List actionChips = new ArrayList<>(); + in.readTypedList(actionChips, Entry.CREATOR); + mActionChips = actionChips; + AnnotationValidations.validate(NonNull.class, null, mActionChips); + + Entry authenticationEntry = in.readTypedObject(Entry.CREATOR); + mAuthenticationEntry = authenticationEntry; } @Override public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeString8(mPackageName); + dest.writeTypedList(mCredentialEntries); + dest.writeTypedList(mActionChips); + dest.writeTypedObject(mAuthenticationEntry, flags); } @Override