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

Commit 748f585e authored by Helen Qin's avatar Helen Qin
Browse files

Update cross section (entries grouped by entryGroupId) ranking logic

Now cross sections are ranked by the latest timestamp (rather than front
entry timestamp) within each section.

Test: see screenshots attached to bug
Bug: 280085288
Change-Id: I778208c13c5101650131b85908e376907ec5cec4
parent df61b513
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.credentialmanager.model.get.AuthenticationEntryInfo
import com.android.credentialmanager.model.get.CredentialEntryInfo
import com.android.credentialmanager.model.get.RemoteEntryInfo
import com.android.internal.util.Preconditions
import java.time.Instant

data class GetCredentialUiState(
    val isRequestForAllOptions: Boolean,
@@ -156,11 +157,17 @@ fun toProviderDisplayInfo(
    userNameToCredentialEntryMap.values.forEach {
        it.sortWith(comparator)
    }
    // Transform to list of PerUserNameCredentialEntryLists and then sort across usernames
    // Transform to list of PerUserNameCredentialEntryLists and then sort the outer list (of
    // entries grouped by username / entryGroupId) based on the latest timestamp within that
    // PerUserNameCredentialEntryList
    val sortedUserNameToCredentialEntryList = userNameToCredentialEntryMap.map {
        PerUserNameCredentialEntryList(it.key, it.value)
    }.sortedWith(
        compareByDescending { it.sortedCredentialEntryList.first().lastUsedTimeMillis }
        compareByDescending {
            it.sortedCredentialEntryList.maxByOrNull{ entry ->
                entry.lastUsedTimeMillis ?: Instant.MIN
            }?.lastUsedTimeMillis ?: Instant.MIN
        }
    )

    return ProviderDisplayInfo(
@@ -211,7 +218,7 @@ internal class CredentialEntryInfoComparatorByTypeThenTimestamp(
        val typePriorityMap: Map<String, Int>,
) : Comparator<CredentialEntryInfo> {
    override fun compare(p0: CredentialEntryInfo, p1: CredentialEntryInfo): Int {
        // First prefer passkey type for its security benefits
        // First rank by priorities of each credential type.
        if (p0.rawCredentialType != p1.rawCredentialType) {
            val p0Priority = typePriorityMap.getOrDefault(
                    p0.rawCredentialType, PriorityHints.PRIORITY_DEFAULT
@@ -225,6 +232,7 @@ internal class CredentialEntryInfoComparatorByTypeThenTimestamp(
                return 1
            }
        }
        // Then rank by last used timestamps.
        val p0LastUsedTimeMillis = p0.lastUsedTimeMillis
        val p1LastUsedTimeMillis = p1.lastUsedTimeMillis
        // Then order by last used timestamp