Browse Source

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.
Peter Cai 3 years ago
parent
commit
c3f4770108
1 changed files with 5 additions and 3 deletions
  1. 5 3
      app/src/main/java/im/angry/openeuicc/core/EuiccChannelManager.kt

+ 5 - 3
app/src/main/java/im/angry/openeuicc/core/EuiccChannelManager.kt

@@ -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!!)
+            }
         }
     }