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

Commit 37b64e59 authored by Helen Qin's avatar Helen Qin Committed by Android (Google) Code Review
Browse files

Merge "Define all the provider-level info in ProviderData."

parents 958af09b c0b50b7d
Loading
Loading
Loading
Loading
+124 −5
Original line number Diff line number Diff line
@@ -16,8 +16,10 @@

package android.credentials.ui;

import android.annotation.CurrentTimeMillisLong;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.drawable.Icon;
import android.os.Parcel;
import android.os.Parcelable;

@@ -43,29 +45,48 @@ public class ProviderData implements Parcelable {
    @NonNull
    private final String mProviderId;
    @NonNull
    private final String mProviderDisplayName;
    @NonNull
    private final Icon mIcon;
    @NonNull
    private final List<Entry> mCredentialEntries;
    @NonNull
    private final List<Entry> mActionChips;
    @Nullable
    private final Entry mAuthenticationEntry;

    private final @CurrentTimeMillisLong long mLastUsedTimeMillis;

    public ProviderData(
            @NonNull String providerId,
            @NonNull List<Entry> credentialEntries,
            @NonNull List<Entry> actionChips,
            @Nullable Entry authenticationEntry) {
            @NonNull String providerId, @NonNull String providerDisplayName,
            @NonNull Icon icon, @NonNull List<Entry> credentialEntries,
            @NonNull List<Entry> actionChips, @Nullable Entry authenticationEntry,
            @CurrentTimeMillisLong long lastUsedTimeMillis) {
        mProviderId = providerId;
        mProviderDisplayName = providerDisplayName;
        mIcon = icon;
        mCredentialEntries = credentialEntries;
        mActionChips = actionChips;
        mAuthenticationEntry = authenticationEntry;
        mLastUsedTimeMillis = lastUsedTimeMillis;
    }

    /** Returns the provider package name. */
    /** Returns the unique provider id. */
    @NonNull
    public String getProviderId() {
        return mProviderId;
    }

    @NonNull
    public String getProviderDisplayName() {
        return mProviderDisplayName;
    }

    @NonNull
    public Icon getIcon() {
        return mIcon;
    }

    @NonNull
    public List<Entry> getCredentialEntries() {
        return mCredentialEntries;
@@ -81,11 +102,24 @@ public class ProviderData implements Parcelable {
        return mAuthenticationEntry;
    }

    /** Returns the time when the provider was last used. */
    public @CurrentTimeMillisLong long getLastUsedTimeMillis() {
        return mLastUsedTimeMillis;
    }

    protected ProviderData(@NonNull Parcel in) {
        String providerId = in.readString8();
        mProviderId = providerId;
        AnnotationValidations.validate(NonNull.class, null, mProviderId);

        String providerDisplayName = in.readString8();
        mProviderDisplayName = providerDisplayName;
        AnnotationValidations.validate(NonNull.class, null, mProviderDisplayName);

        Icon icon = in.readTypedObject(Icon.CREATOR);
        mIcon = icon;
        AnnotationValidations.validate(NonNull.class, null, mIcon);

        List<Entry> credentialEntries = new ArrayList<>();
        in.readTypedList(credentialEntries, Entry.CREATOR);
        mCredentialEntries = credentialEntries;
@@ -98,14 +132,20 @@ public class ProviderData implements Parcelable {

        Entry authenticationEntry = in.readTypedObject(Entry.CREATOR);
        mAuthenticationEntry = authenticationEntry;

        long lastUsedTimeMillis = in.readLong();
        mLastUsedTimeMillis = lastUsedTimeMillis;
    }

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeString8(mProviderId);
        dest.writeString8(mProviderDisplayName);
        dest.writeTypedObject(mIcon, flags);
        dest.writeTypedList(mCredentialEntries);
        dest.writeTypedList(mActionChips);
        dest.writeTypedObject(mAuthenticationEntry, flags);
        dest.writeLong(mLastUsedTimeMillis);
    }

    @Override
@@ -124,4 +164,83 @@ public class ProviderData implements Parcelable {
            return new ProviderData[size];
        }
    };

    /**
     * Builder for {@link ProviderData}.
     *
     * @hide
     */
    public static class Builder {
        private @NonNull String mProviderId;
        private @NonNull String mProviderDisplayName;
        private @NonNull Icon mIcon;
        private @NonNull List<Entry> mCredentialEntries = new ArrayList<>();
        private @NonNull List<Entry> mActionChips = new ArrayList<>();
        private @Nullable Entry mAuthenticationEntry = null;
        private @CurrentTimeMillisLong long mLastUsedTimeMillis = 0L;

        /** Constructor with required properties. */
        public Builder(@NonNull String providerId, @NonNull String providerDisplayName,
                @NonNull Icon icon) {
            mProviderId = providerId;
            mProviderDisplayName = providerDisplayName;
            mIcon = icon;
        }

        /** Sets the unique provider id. */
        @NonNull
        public Builder setProviderId(@NonNull String providerId) {
            mProviderId = providerId;
            return this;
        }

        /** Sets the provider display name to be displayed to the user. */
        @NonNull
        public Builder setProviderDisplayName(@NonNull String providerDisplayName) {
            mProviderDisplayName = providerDisplayName;
            return this;
        }

        /** Sets the provider icon to be displayed to the user. */
        @NonNull
        public Builder setIcon(@NonNull Icon icon) {
            mIcon = icon;
            return this;
        }

        /** Sets the list of save / get credential entries to be displayed to the user. */
        @NonNull
        public Builder setCredentialEntries(@NonNull List<Entry> credentialEntries) {
            mCredentialEntries = credentialEntries;
            return this;
        }

        /** Sets the list of action chips to be displayed to the user. */
        @NonNull
        public Builder setActionChips(@NonNull List<Entry> actionChips) {
            mActionChips = actionChips;
            return this;
        }

        /** Sets the authentication entry to be displayed to the user. */
        @NonNull
        public Builder setAuthenticationEntry(@Nullable Entry authenticationEntry) {
            mAuthenticationEntry = authenticationEntry;
            return this;
        }

        /** Sets the time when the provider was last used. */
        @NonNull
        public Builder setLastUsedTimeMillis(@CurrentTimeMillisLong long lastUsedTimeMillis) {
            mLastUsedTimeMillis = lastUsedTimeMillis;
            return this;
        }

        /** Builds a {@link ProviderData}. */
        @NonNull
        public ProviderData build() {
            return new ProviderData(mProviderId, mProviderDisplayName, mIcon, mCredentialEntries,
                mActionChips, mAuthenticationEntry, mLastUsedTimeMillis);
        }
    }
}
+34 −38
Original line number Diff line number Diff line
@@ -119,46 +119,42 @@ class CredentialManagerRepo(
  // TODO: below are prototype functionalities. To be removed for productionization.
  private fun testProviderList(): List<ProviderData> {
    return listOf(
      ProviderData(
      ProviderData.Builder(
        "com.google",
        "Google Password Manager",
        Icon.createWithResource(context, R.drawable.ic_launcher_foreground))
        .setCredentialEntries(
          listOf<Entry>(
            newEntry(1, "elisa.beckett@gmail.com", "Elisa Backett",
                     "20 passwords and 7 passkeys saved"),
            newEntry(2, "elisa.work@google.com", "Elisa Backett Work",
                     "20 passwords and 7 passkeys saved"),
        ),
          )
        ).setActionChips(
          listOf<Entry>(
            newEntry(3, "Go to Settings", "",
                     "20 passwords and 7 passkeys saved"),
            newEntry(4, "Switch Account", "",
                     "20 passwords and 7 passkeys saved"),
          ),
        null
      ),
      ProviderData(
        ).build(),
      ProviderData.Builder(
        "com.dashlane",
        "Dashlane",
        Icon.createWithResource(context, R.drawable.ic_launcher_foreground))
        .setCredentialEntries(
          listOf<Entry>(
          newEntry(5, "elisa.beckett@dashlane.com", "Elisa Backett",
            newEntry(1, "elisa.beckett@dashlane.com", "Elisa Backett",
                     "20 passwords and 7 passkeys saved"),
          newEntry(6, "elisa.work@dashlane.com", "Elisa Backett Work",
            "20 passwords and 7 passkeys saved"),
        ),
        listOf<Entry>(
          newEntry(7, "Manage Accounts", "Manage your accounts in the dashlane app",
            newEntry(2, "elisa.work@dashlane.com", "Elisa Backett Work",
                     "20 passwords and 7 passkeys saved"),
        ),
        null
      ),
      ProviderData(
        "com.lastpass",
          )
        ).setActionChips(
          listOf<Entry>(
          newEntry(8, "elisa.beckett@lastpass.com", "Elisa Backett",
            newEntry(3, "Manage Accounts", "Manage your accounts in the dashlane app",
                     "20 passwords and 7 passkeys saved"),
          ),
        listOf<Entry>(),
        null
      )

        ).build(),
    )
  }