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

Commit 1bf852b1 authored by Helen Qin's avatar Helen Qin
Browse files

Change the entry id to key + subkey.

Test: deployed locally
Bug: 247855226
Bug: 253156958
Change-Id: I514c26a7db6c1ca77cadf5f214f165d26ec2fc24
parent e363a3fe
Loading
Loading
Loading
Loading
+25 −10
Original line number Diff line number Diff line
@@ -82,32 +82,46 @@ public class Entry implements Parcelable {
    public static final String EXTRA_ENTRY_AUTHENTICATION_ACTION =
            "android.credentials.ui.extra.ENTRY_AUTHENTICATION_ACTION";

    // TODO: change to string key + string subkey.
    private final int mId;
    @NonNull private final String mKey;
    @NonNull private final String mSubkey;

    @NonNull
    private final Slice mSlice;

    protected Entry(@NonNull Parcel in) {
        int entryId = in.readInt();
        String key = in.readString8();
        String subkey = in.readString8();
        Slice slice = Slice.CREATOR.createFromParcel(in);

        mId = entryId;
        mKey = key;
        AnnotationValidations.validate(NonNull.class, null, mKey);
        mSubkey = subkey;
        AnnotationValidations.validate(NonNull.class, null, mSubkey);
        mSlice = slice;
        AnnotationValidations.validate(NonNull.class, null, mSlice);
    }

    public Entry(int id, @NonNull Slice slice) {
        mId = id;
    public Entry(@NonNull String key, @NonNull String subkey, @NonNull Slice slice) {
        mKey = key;
        mSubkey = subkey;
        mSlice = slice;
    }

    /**
    * Returns the id of this entry that's unique within the context of the CredentialManager
    * Returns the identifier of this entry that's unique within the context of the CredentialManager
    * request.
    */
    public int getEntryId() {
        return mId;
    @NonNull
    public String getKey() {
        return mKey;
    }

    /**
     * Returns the sub-identifier of this entry that's unique within the context of the {@code key}.
     */
    @NonNull
    public String getSubkey() {
        return mSubkey;
    }

    /**
@@ -120,7 +134,8 @@ public class Entry implements Parcelable {

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeInt(mId);
        dest.writeString8(mKey);
        dest.writeString8(mSubkey);
        mSlice.writeToParcel(dest, flags);
    }

+24 −13
Original line number Diff line number Diff line
@@ -54,18 +54,17 @@ public class UserSelectionDialogResult extends BaseDialogResult implements Parce
    private static final String EXTRA_USER_SELECTION_RESULT =
            "android.credentials.ui.extra.USER_SELECTION_RESULT";

    @NonNull
    private final String mProviderId;

    // TODO: consider switching to string or other types, depending on the service implementation.
    private final int mEntryId;
    @NonNull private final String mProviderId;
    @NonNull private final String mEntryKey;
    @NonNull private final String mEntrySubkey;

    public UserSelectionDialogResult(
            @NonNull IBinder requestToken, @NonNull String providerId,
            int entryId) {
            @NonNull String entryKey, @NonNull String entrySubkey) {
        super(requestToken);
        mProviderId = providerId;
        mEntryId = entryId;
        mEntryKey = entryKey;
        mEntrySubkey = entrySubkey;
    }

    /** Returns provider package name whose entry was selected by the user. */
@@ -74,26 +73,38 @@ public class UserSelectionDialogResult extends BaseDialogResult implements Parce
        return mProviderId;
    }

    /** Returns the id of the visual entry that the user selected. */
    public int getEntryId() {
        return mEntryId;
    /** Returns the key of the visual entry that the user selected. */
    @NonNull
    public String getEntryKey() {
        return mEntryKey;
    }

    /** Returns the subkey of the visual entry that the user selected. */
    @NonNull
    public String getEntrySubkey() {
        return mEntrySubkey;
    }

    protected UserSelectionDialogResult(@NonNull Parcel in) {
        super(in);
        String providerId = in.readString8();
        int entryId = in.readInt();
        String entryKey = in.readString8();
        String entrySubkey = in.readString8();

        mProviderId = providerId;
        AnnotationValidations.validate(NonNull.class, null, mProviderId);
        mEntryId = entryId;
        mEntryKey = entryKey;
        AnnotationValidations.validate(NonNull.class, null, mEntryKey);
        mEntrySubkey = entrySubkey;
        AnnotationValidations.validate(NonNull.class, null, mEntrySubkey);
    }

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeString8(mProviderId);
        dest.writeInt(mEntryId);
        dest.writeString8(mEntryKey);
        dest.writeString8(mEntrySubkey);
    }

    @Override
+24 −15
Original line number Diff line number Diff line
@@ -71,11 +71,12 @@ class CredentialManagerRepo(
    resultReceiver?.send(BaseDialogResult.RESULT_CODE_DIALOG_CANCELED, resultData)
  }

  fun onOptionSelected(providerPackageName: String, entryId: Int) {
  fun onOptionSelected(providerPackageName: String, entryKey: String, entrySubkey: String) {
    val userSelectionDialogResult = UserSelectionDialogResult(
      requestInfo.token,
      providerPackageName,
      entryId
      entryKey,
      entrySubkey
    )
    val resultData = Bundle()
    UserSelectionDialogResult.addToBundle(userSelectionDialogResult, resultData)
@@ -137,16 +138,16 @@ class CredentialManagerRepo(
        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"),
            newEntry("key1", "subkey-1", "elisa.beckett@gmail.com",
              "Elisa Backett", "20 passwords and 7 passkeys saved"),
            newEntry("key1", "subkey-2", "elisa.work@google.com",
              "Elisa Backett Work", "20 passwords and 7 passkeys saved"),
          )
        ).setActionChips(
          listOf<Entry>(
            newEntry(3, "Go to Settings", "",
            newEntry("key2", "subkey-1", "Go to Settings", "",
                     "20 passwords and 7 passkeys saved"),
            newEntry(4, "Switch Account", "",
            newEntry("key2", "subkey-2", "Switch Account", "",
                     "20 passwords and 7 passkeys saved"),
          ),
        ).build(),
@@ -156,21 +157,28 @@ class CredentialManagerRepo(
        Icon.createWithResource(context, R.drawable.ic_launcher_foreground))
        .setCredentialEntries(
          listOf<Entry>(
            newEntry(1, "elisa.beckett@dashlane.com", "Elisa Backett",
                     "20 passwords and 7 passkeys saved"),
            newEntry(2, "elisa.work@dashlane.com", "Elisa Backett Work",
                     "20 passwords and 7 passkeys saved"),
            newEntry("key1", "subkey-3", "elisa.beckett@dashlane.com",
              "Elisa Backett", "20 passwords and 7 passkeys saved"),
            newEntry("key1", "subkey-4", "elisa.work@dashlane.com",
              "Elisa Backett Work", "20 passwords and 7 passkeys saved"),
          )
        ).setActionChips(
          listOf<Entry>(
            newEntry(3, "Manage Accounts", "Manage your accounts in the dashlane app",
            newEntry("key2", "subkey-3", "Manage Accounts",
              "Manage your accounts in the dashlane app",
                     "20 passwords and 7 passkeys saved"),
          ),
        ).build(),
    )
  }

  private fun newEntry(id: Int, title: String, subtitle: String, usageData: String): Entry {
  private fun newEntry(
    key: String,
    subkey: String,
    title: String,
    subtitle: String,
    usageData: String
  ): Entry {
    val slice = Slice.Builder(
      Entry.CREDENTIAL_MANAGER_ENTRY_URI, SliceSpec(Entry.VERSION, 1)
    )
@@ -183,7 +191,8 @@ class CredentialManagerRepo(
      .addText(usageData, Slice.SUBTYPE_MESSAGE, listOf(Entry.HINT_SUBTITLE))
      .build()
    return Entry(
      id,
      key,
      subkey,
      slice
    )
  }
+4 −2
Original line number Diff line number Diff line
@@ -59,7 +59,8 @@ class GetFlowUtils {
            ?: context.getDrawable(R.drawable.ic_passkey)!!,
          title = credentialEntryUi.userName.toString(),
          subtitle = credentialEntryUi.displayName?.toString() ?: "Unknown display name",
          id = it.entryId,
          entryKey = it.key,
          entrySubkey = it.subkey,
          usageData = credentialEntryUi.usageData?.toString() ?: "Unknown usageData",
        )
      }
@@ -99,7 +100,8 @@ class CreateFlowUtils {
            ?: context.getDrawable(R.drawable.ic_passkey)!!,
          title = saveEntryUi.title.toString(),
          subtitle = saveEntryUi.subTitle?.toString() ?: "Unknown subtitle",
          id = it.entryId,
          entryKey = it.key,
          entrySubkey = it.subkey,
          usageData = saveEntryUi.usageData?.toString() ?: "Unknown usageData",
        )
      }
+2 −1
Original line number Diff line number Diff line
@@ -30,7 +30,8 @@ data class CreateOptionInfo(
  val icon: Drawable,
  val title: String,
  val subtitle: String,
  val id: Int,
  val entryKey: String,
  val entrySubkey: String,
  val usageData: String
)

Loading