Skip to content

Commit 6bd6422

Browse files
committed
Use the right scope
1 parent f3d1cc0 commit 6bd6422

File tree

5 files changed

+24
-380
lines changed

5 files changed

+24
-380
lines changed

lib/src/main/java/at/bitfire/cert4android/CustomCertManager.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package at.bitfire.cert4android
66

77
import android.annotation.SuppressLint
88
import android.content.Context
9-
import kotlinx.coroutines.flow.StateFlow
9+
import kotlinx.coroutines.CoroutineScope
1010
import java.security.cert.CertificateException
1111
import java.security.cert.X509Certificate
1212
import javax.net.ssl.SSLSession
@@ -24,11 +24,12 @@ import javax.net.ssl.X509TrustManager
2424
@SuppressLint("CustomX509TrustManager")
2525
class CustomCertManager @JvmOverloads constructor(
2626
context: Context,
27+
scope: CoroutineScope,
2728
val trustSystemCerts: Boolean = true,
2829
private val getUserDecision: suspend (X509Certificate) -> Boolean
2930
): X509TrustManager {
3031

31-
val certStore = CustomCertStore.getInstance(context)
32+
val certStore = CustomCertStore.getInstance(context, scope)
3233

3334

3435
@Throws(CertificateException::class)

lib/src/main/java/at/bitfire/cert4android/CustomCertStore.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package at.bitfire.cert4android
77
import android.annotation.SuppressLint
88
import android.content.Context
99
import androidx.annotation.VisibleForTesting
10+
import kotlinx.coroutines.CoroutineScope
1011
import kotlinx.coroutines.TimeoutCancellationException
1112
import kotlinx.coroutines.runBlocking
1213
import kotlinx.coroutines.withTimeout
@@ -21,6 +22,7 @@ import java.util.logging.Level
2122

2223
class CustomCertStore internal constructor(
2324
private val context: Context,
25+
private val scope: CoroutineScope,
2426
private val userTimeout: Long = 60000L
2527
) {
2628

@@ -33,12 +35,12 @@ class CustomCertStore internal constructor(
3335
private var instance: CustomCertStore? = null
3436

3537
@Synchronized
36-
fun getInstance(context: Context): CustomCertStore {
38+
fun getInstance(context: Context, scope: CoroutineScope): CustomCertStore {
3739
instance?.let {
3840
return it
3941
}
4042

41-
val newInstance = CustomCertStore(context.applicationContext)
43+
val newInstance = CustomCertStore(context.applicationContext, scope)
4244
instance = newInstance
4345
return newInstance
4446
}
@@ -108,7 +110,7 @@ class CustomCertStore internal constructor(
108110
}
109111

110112
return runBlocking {
111-
val ui = UserDecisionRegistry.getInstance(context)
113+
val ui = UserDecisionRegistry.getInstance(context, scope)
112114

113115
try {
114116
withTimeout(userTimeout) {

0 commit comments

Comments
 (0)