Execute SEService initialization on the handler thread

This (hopefully) eliminates a race condition where the connected listenr
is called before the service variable is assigned.
This commit is contained in:
Peter Cai 2022-05-12 17:09:58 -04:00
parent d6a3cc820c
commit c3f4770108
1 changed files with 5 additions and 3 deletions

View File

@ -34,9 +34,11 @@ class EuiccChannelManager(private val context: Context) {
private val handler = Handler(HandlerThread("EuiccChannelManager").also { it.start() }.looper)
private suspend fun connectSEService(): SEService = suspendCoroutine { cont ->
var service: SEService? = null
service = SEService(context, { handler.post(it) }) {
cont.resume(service!!)
handler.post {
var service: SEService? = null
service = SEService(context, { handler.post(it) }) {
cont.resume(service!!)
}
}
}