@@ -103,6 +103,8 @@ import com.duckduckgo.sync.api.engine.SyncEngine
103103import com.duckduckgo.sync.api.engine.SyncEngine.SyncTrigger.FEATURE_READ
104104import com.squareup.anvil.annotations.ContributesBinding
105105import kotlinx.coroutines.Job
106+ import kotlinx.coroutines.currentCoroutineContext
107+ import kotlinx.coroutines.ensureActive
106108import kotlinx.coroutines.flow.MutableStateFlow
107109import kotlinx.coroutines.flow.StateFlow
108110import kotlinx.coroutines.flow.combine
@@ -324,7 +326,15 @@ class AutofillPasswordsManagementViewModel @Inject constructor(
324326 return
325327 }
326328
327- val credentialCount = autofillStore.getCredentialCount().firstOrNull()
329+ val credentialCount = runCatching {
330+ autofillStore.getCredentialCount().firstOrNull()
331+ }.getOrElse {
332+ currentCoroutineContext().ensureActive()
333+ logcat { " Error accessing secure storage so can't offer autofill functionality" }
334+ deviceUnsupported()
335+ return
336+ }
337+
328338 val shouldAskAuth = credentialCount == null || credentialCount == 0
329339 if (shouldAskAuth) {
330340 logcat(VERBOSE ) { " No credentials; can skip showing device auth" }
@@ -433,17 +443,23 @@ class AutofillPasswordsManagementViewModel @Inject constructor(
433443 prioritizeDomainMatchesOnSearch = autofillFeature.prioritizeDomainMatchesOnSearch().isEnabled(),
434444 )
435445
436- val allCredentials = autofillStore.getAllCredentials().distinctUntilChanged()
437- val combined = allCredentials.combine(searchQueryFilter) { credentials, filter ->
438- credentialListFilter.filter(credentials, filter)
439- }
440- combined.collect { credentials ->
441- val updatedBreakageState = _viewState .value.reportBreakageState.copy(allowBreakageReporting = isBreakageReportingAllowed())
442- _viewState .value = _viewState .value.copy(
443- logins = credentials,
444- reportBreakageState = updatedBreakageState,
445- )
446- showPromotionIfEligible()
446+ runCatching {
447+ val allCredentials = autofillStore.getAllCredentials().distinctUntilChanged()
448+ val combined = allCredentials.combine(searchQueryFilter) { credentials, filter ->
449+ credentialListFilter.filter(credentials, filter)
450+ }
451+ combined.collect { credentials ->
452+ val updatedBreakageState = _viewState .value.reportBreakageState.copy(allowBreakageReporting = isBreakageReportingAllowed())
453+ _viewState .value = _viewState .value.copy(
454+ logins = credentials,
455+ reportBreakageState = updatedBreakageState,
456+ )
457+ showPromotionIfEligible()
458+ }
459+ }.getOrElse {
460+ logcat { " Error accessing secure storage so can't offer autofill functionality" }
461+ deviceUnsupported()
462+ return @launch
447463 }
448464 }
449465
@@ -681,10 +697,17 @@ class AutofillPasswordsManagementViewModel @Inject constructor(
681697 logcat(VERBOSE ) { " Opened autofill management screen from from $launchSource " }
682698
683699 val source = launchSource.asString()
684- val hasCredentialsSaved = (autofillStore.getCredentialCount().firstOrNull() ? : 0 ) > 0
685- pixel.fire(AUTOFILL_MANAGEMENT_SCREEN_OPENED , mapOf (" source" to source, " has_credentials_saved" to hasCredentialsSaved.toBinaryString()))
686- pixel.fire(AutofillPixelNames .PRODUCT_TELEMETRY_SURFACE_PASSWORDS_OPENED )
687- pixel.fire(AutofillPixelNames .PRODUCT_TELEMETRY_SURFACE_PASSWORDS_OPENED_DAILY , type = Pixel .PixelType .Daily ())
700+ runCatching {
701+ val hasCredentialsSaved = (autofillStore.getCredentialCount().firstOrNull() ? : 0 ) > 0
702+ pixel.fire(
703+ AUTOFILL_MANAGEMENT_SCREEN_OPENED ,
704+ mapOf (" source" to source, " has_credentials_saved" to hasCredentialsSaved.toBinaryString()),
705+ )
706+ pixel.fire(AutofillPixelNames .PRODUCT_TELEMETRY_SURFACE_PASSWORDS_OPENED )
707+ pixel.fire(AutofillPixelNames .PRODUCT_TELEMETRY_SURFACE_PASSWORDS_OPENED_DAILY , type = Pixel .PixelType .Daily ())
708+ }.getOrElse {
709+ logcat { " Couldn't get credential count" }
710+ }
688711 }
689712 }
690713
0 commit comments