Skip to content

Commit

Permalink
Android Crash: java.lang.OutOfMemoryError - com.duckduckgo.autofill.i…
Browse files Browse the repository at this point in the history
…mpl.configuration.RealAutofillRuntimeConfigProvider.getRuntimeConfiguration (#5433)

Task/Issue URL:
https://app.asana.com/0/1200905986587319/1209069285792741/f

### Description
Optimized string manipulation within getRuntimeConfiguration function.

### Steps to test this PR

Smoke test for autofill.

### NO UI changes
  • Loading branch information
anikiki authored Jan 6, 2025
1 parent 70d0aa8 commit 01076f6
Showing 1 changed file with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,19 @@ class RealAutofillRuntimeConfigProvider @Inject constructor(
)
val availableInputTypes = generateAvailableInputTypes(url)

return rawJs
.replace("// INJECT contentScope HERE", contentScope)
.replace("// INJECT userUnprotectedDomains HERE", userUnprotectedDomains)
.replace("// INJECT userPreferences HERE", userPreferences)
.replace("// INJECT availableInputTypes HERE", availableInputTypes)
return StringBuilder(rawJs).apply {
replacePlaceholder(this, TAG_INJECT_CONTENT_SCOPE, contentScope)
replacePlaceholder(this, TAG_INJECT_USER_UNPROTECTED_DOMAINS, userUnprotectedDomains)
replacePlaceholder(this, TAG_INJECT_USER_PREFERENCES, userPreferences)
replacePlaceholder(this, TAG_INJECT_AVAILABLE_INPUT_TYPES, availableInputTypes)
}.toString()
}

private fun replacePlaceholder(builder: StringBuilder, placeholder: String, replacement: String) {
val index = builder.indexOf(placeholder)
if (index != -1) {
builder.replace(index, index + placeholder.length, replacement)
}
}

private suspend fun generateAvailableInputTypes(url: String?): String {
Expand Down Expand Up @@ -139,4 +147,11 @@ class RealAutofillRuntimeConfigProvider @Inject constructor(
}

private fun determineIfEmailAvailable(): Boolean = emailManager.isSignedIn()

companion object {
private const val TAG_INJECT_CONTENT_SCOPE = "// INJECT contentScope HERE"
private const val TAG_INJECT_USER_UNPROTECTED_DOMAINS = "// INJECT userUnprotectedDomains HERE"
private const val TAG_INJECT_USER_PREFERENCES = "// INJECT userPreferences HERE"
private const val TAG_INJECT_AVAILABLE_INPUT_TYPES = "// INJECT availableInputTypes HERE"
}
}

0 comments on commit 01076f6

Please sign in to comment.