-
Notifications
You must be signed in to change notification settings - Fork 942
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dedup credentials suggestions and sort them by latest usage (#5675)
Task/Issue URL: https://app.asana.com/0/488551667048375/1209453476472067 ### Description We introduce the same logic to dedup credentials and sorting for Autofill Service. That includes updating last used timestamp when we autofill outside our app, to improve UX. ### Steps to test this PR _Feature 1_ - [x] install this branch - [x] Select DDG as autofill provider - [x] Create a bunch of logins (same username and passwords) for mlb.mlb.com, securea.mlb.com and www.mlb.com - [x] Create another login for www.mlb.com with a different username - [x] Visit www.mlb.com in our browser - [x] You will see 2 logins suggested - [x] Now go to another browser and visit the same site - [x] Ensure you only get 2 logins, same order from the autofill provider - [x] Select the second one - [x] Now go back to our browser - [x] Trigger again the suggestions prompt - [x] Ensure the order has changed now (since you selected the second one in the previous step) ### UI changes | Before | After | | ------ | ----- | !(Upload before screenshot)|(Upload after screenshot)|
- Loading branch information
1 parent
79b0e9a
commit 449975a
Showing
26 changed files
with
575 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...l/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/service/AutofillSuggestions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2025 DuckDuckGo | ||
* | ||
* 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 com.duckduckgo.autofill.impl.service | ||
|
||
import com.duckduckgo.autofill.api.domain.app.LoginCredentials | ||
import com.duckduckgo.autofill.api.store.AutofillStore | ||
import com.duckduckgo.autofill.impl.deduper.AutofillLoginDeduplicator | ||
import com.duckduckgo.autofill.impl.service.mapper.AppCredentialProvider | ||
import com.duckduckgo.autofill.impl.ui.credential.selecting.AutofillSelectCredentialsGrouper | ||
import com.duckduckgo.common.utils.DispatcherProvider | ||
import com.duckduckgo.di.scopes.AppScope | ||
import com.squareup.anvil.annotations.ContributesBinding | ||
import dagger.SingleInstanceIn | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.withContext | ||
import timber.log.Timber | ||
|
||
interface AutofillSuggestions { | ||
suspend fun getSiteSuggestions(website: String): List<LoginCredentials> | ||
suspend fun getAppSuggestions(packageId: String): List<LoginCredentials> | ||
} | ||
|
||
@SingleInstanceIn(AppScope::class) | ||
@ContributesBinding(AppScope::class) | ||
class AutofillServiceSuggestions @Inject constructor( | ||
private val autofillStore: AutofillStore, | ||
private val loginDeduplicator: AutofillLoginDeduplicator, | ||
private val grouper: AutofillSelectCredentialsGrouper, | ||
private val appCredentialProvider: AppCredentialProvider, | ||
private val dispatcherProvider: DispatcherProvider, | ||
) : AutofillSuggestions { | ||
|
||
override suspend fun getSiteSuggestions(website: String): List<LoginCredentials> { | ||
return withContext(dispatcherProvider.io()) { | ||
val credentials = autofillStore.getCredentials(website) | ||
loginDeduplicator.deduplicate(website, credentials).let { dedupLogins -> | ||
grouper.group(website, dedupLogins).let { groups -> | ||
groups.perfectMatches | ||
.plus(groups.partialMatches.values.flatten()) | ||
.plus(groups.shareableCredentials.values.flatten()) | ||
} | ||
}.also { | ||
Timber.v("DDGAutofillService credentials for domain: $it") | ||
} | ||
} | ||
} | ||
|
||
override suspend fun getAppSuggestions(packageId: String): List<LoginCredentials> { | ||
return withContext(dispatcherProvider.io()) { | ||
appCredentialProvider.getCredentials(packageId).also { | ||
Timber.v("DDGAutofillService credentials for package: $it") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/AutofillStoreFixtures.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (c) 2025 DuckDuckGo | ||
* | ||
* 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 com.duckduckgo.autofill | ||
|
||
import com.duckduckgo.autofill.api.AutofillFeature | ||
import com.duckduckgo.autofill.api.domain.app.LoginCredentials | ||
import com.duckduckgo.autofill.impl.FakePasswordStoreEventPlugin | ||
import com.duckduckgo.autofill.impl.SecureStoreBackedAutofillStore | ||
import com.duckduckgo.autofill.impl.deduper.AutofillLoginDeduplicator | ||
import com.duckduckgo.autofill.impl.encoding.TestUrlUnicodeNormalizer | ||
import com.duckduckgo.autofill.impl.securestorage.SecureStorage | ||
import com.duckduckgo.autofill.impl.ui.credential.selecting.AutofillSelectCredentialsGrouper | ||
import com.duckduckgo.autofill.impl.ui.credential.selecting.AutofillSelectCredentialsGrouper.Groups | ||
import com.duckduckgo.autofill.impl.urlmatcher.AutofillDomainNameUrlMatcher | ||
import com.duckduckgo.autofill.impl.urlmatcher.AutofillUrlMatcher | ||
import com.duckduckgo.autofill.store.AutofillPrefsStore | ||
import com.duckduckgo.autofill.store.LastUpdatedTimeProvider | ||
import com.duckduckgo.autofill.sync.CredentialsSyncMetadata | ||
import com.duckduckgo.autofill.sync.SyncCredentialsListener | ||
import com.duckduckgo.autofill.sync.inMemoryAutofillDatabase | ||
import com.duckduckgo.common.utils.DispatcherProvider | ||
import kotlinx.coroutines.CoroutineScope | ||
|
||
fun fakeAutofillStore( | ||
secureStorage: SecureStorage = fakeStorage(), | ||
lastUpdatedTimeProvider: LastUpdatedTimeProvider = lastUpdatedTimeProvider(), | ||
autofillPrefsStore: AutofillPrefsStore, | ||
autofillUrlMatcher: AutofillUrlMatcher = autofillDomainNameUrlMatcher(), | ||
autofillFeature: AutofillFeature, | ||
dispatcherProvider: DispatcherProvider, | ||
coroutineScope: CoroutineScope, | ||
) = SecureStoreBackedAutofillStore( | ||
secureStorage = secureStorage, | ||
lastUpdatedTimeProvider = lastUpdatedTimeProvider, | ||
autofillPrefsStore = autofillPrefsStore, | ||
dispatcherProvider = dispatcherProvider, | ||
autofillUrlMatcher = autofillUrlMatcher, | ||
passwordStoreEventListenersPlugins = FakePasswordStoreEventPlugin(), | ||
syncCredentialsListener = SyncCredentialsListener( | ||
CredentialsSyncMetadata(inMemoryAutofillDatabase().credentialsSyncDao()), | ||
dispatcherProvider, | ||
coroutineScope, | ||
), | ||
autofillFeature = autofillFeature, | ||
) | ||
|
||
fun fakeStorage( | ||
canAccessSecureStorage: Boolean = true, | ||
urlMatcher: AutofillUrlMatcher = autofillDomainNameUrlMatcher(), | ||
) = FakeSecureStore( | ||
canAccessSecureStorage = canAccessSecureStorage, | ||
urlMatcher = urlMatcher, | ||
) | ||
|
||
fun lastUpdatedTimeProvider() = object : LastUpdatedTimeProvider { | ||
override fun getInMillis(): Long = 10000L | ||
} | ||
|
||
fun autofillDomainNameUrlMatcher() = AutofillDomainNameUrlMatcher(TestUrlUnicodeNormalizer()) | ||
|
||
fun noopDeduplicator() = object : AutofillLoginDeduplicator { | ||
override fun deduplicate( | ||
originalUrl: String, | ||
logins: List<LoginCredentials>, | ||
): List<LoginCredentials> = logins | ||
} | ||
|
||
fun noopGroupBuilder() = object : AutofillSelectCredentialsGrouper { | ||
override fun group( | ||
originalUrl: String, | ||
unsortedCredentials: List<LoginCredentials>, | ||
): Groups { | ||
return Groups(unsortedCredentials, emptyMap(), emptyMap()) | ||
} | ||
} |
Oops, something went wrong.