Skip to content

Commit

Permalink
Fix leaking webview in DFPProvider (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaven-stytch authored Jan 23, 2025
1 parent c4ee08a commit 83ec8e3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ ktlint = "12.1.0"
detekt = "1.23.6"
ksp = "2.1.0-1.0.29"
kotlinCompilerExtension="1.5.15"
leakCanary = "2.14"

[libraries]
activity = { module = "androidx.activity:activity", version.ref = "activityKtx" }
Expand Down Expand Up @@ -134,6 +135,7 @@ flowRedux-jvm = { module = "com.freeletics.flowredux:flowredux-jvm", version.ref
flowRedux-compose = { module = "com.freeletics.flowredux:compose", version.ref = "flowRedux" }
coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil" }
coil-network = { module = "io.coil-kt.coil3:coil-network-okhttp", version.ref = "coil" }
leakCanary = { module = "com.squareup.leakcanary:leakcanary-android", version.ref = "leakCanary"}

[plugins]
androidApplication = { id = "com.android.application", version.ref = "gradle" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ internal class DFPProviderImpl(
object {
@JavascriptInterface
fun reportTelemetryId(telemetryId: String) {
activityProvider.currentActivity?.let {
it.runOnUiThread {
(webview.parent as? ViewGroup)?.removeView(webview)
activityProvider.currentActivity?.let { currentActivity ->
webview?.let {
currentActivity.runOnUiThread {
(it.parent as? ViewGroup)?.removeView(it)
}
}
}
webview = null
if (continuation.isActive) {
continuation.resume(telemetryId, null)
}
Expand All @@ -59,7 +62,7 @@ internal class DFPProviderImpl(

private lateinit var continuation: CancellableContinuation<String>

private lateinit var webview: WebView
private var webview: WebView? = null

override suspend fun getTelemetryId(): String =
suspendCancellableCoroutine { cont ->
Expand Down
1 change: 1 addition & 0 deletions workbench-apps/b2b-workbench/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ dependencies {
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
debugImplementation(libs.leakCanary)

// Compose
implementation(platform(libs.compose.bom))
Expand Down
2 changes: 2 additions & 0 deletions workbench-apps/consumer-workbench/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ dependencies {
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)

debugImplementation(libs.leakCanary)

// Compose
implementation(platform(libs.compose.bom))
implementation(libs.ui)
Expand Down

0 comments on commit 83ec8e3

Please sign in to comment.