A rootless Android app that boots Alpine Linux: run containers (Podman/Docker/LXC) and GUI desktop apps.
refactor(service): drop dead code and cancellation noise
ExTva7d9fd702107
diff --git a/app/src/main/java/com/excp/podroid/engine/hostbridge/HostRequestServer.kt b/app/src/main/java/com/excp/podroid/engine/hostbridge/HostRequestServer.ktindex 279053b..6b2335b 100644--- a/app/src/main/java/com/excp/podroid/engine/hostbridge/HostRequestServer.kt+++ b/app/src/main/java/com/excp/podroid/engine/hostbridge/HostRequestServer.kt@@ -10,13 +10,13 @@package com.excp.podroid.engine.hostbridgeimport android.util.Log+import kotlinx.coroutines.CancellationExceptionimport kotlinx.coroutines.CoroutineScopeimport kotlinx.coroutines.Dispatchersimport kotlinx.coroutines.Jobimport kotlinx.coroutines.delayimport kotlinx.coroutines.isActiveimport kotlinx.coroutines.launch-import kotlinx.coroutines.withContextclass HostRequestServer(private val openTransport: () -> HostTransport?,@@ -50,10 +50,12 @@ class HostRequestServer(Log.d(TAG, "host bridge connected")try {while (scope.isActive) {- val req = withContext(Dispatchers.IO) { transport.readRequest() } ?: break+ val req = transport.readRequest() ?: breakval resp = dispatcher.handle(req)- withContext(Dispatchers.IO) { transport.writeResponse(resp) }+ transport.writeResponse(resp)}+ } catch (c: CancellationException) {+ throw c // don't log a stop/swap's cancellation as a loop error} catch (e: Exception) {Log.w(TAG, "host bridge loop error: ${e.message}")} finally {diff --git a/app/src/main/java/com/excp/podroid/service/PodroidService.kt b/app/src/main/java/com/excp/podroid/service/PodroidService.ktindex 9517c5a..bb6a68c 100644--- a/app/src/main/java/com/excp/podroid/service/PodroidService.kt+++ b/app/src/main/java/com/excp/podroid/service/PodroidService.kt@@ -87,8 +87,6 @@ class PodroidService : Service() {private var wakeLock: PowerManager.WakeLock? = nullprivate var notificationBuilder: NotificationCompat.Builder? = null- private var stopPendingIntent: PendingIntent? = null- private var openPendingIntent: PendingIntent? = nulloverride fun onBind(intent: Intent?): IBinder? = null@@ -394,6 +392,8 @@ class PodroidService : Service() {serviceScope.launch { observeStateForUsb() }}engine.start(rules, config)+ } catch (c: CancellationException) {+ throw c // a stop/teardown cancelled this launch; not a start failure} catch (e: Exception) {Log.e(TAG, "QEMU failed to start", e)// A Service-side throw here (failed asset extraction, a@@ -445,9 +445,6 @@ class PodroidService : Service() {Intent(this, PodroidService::class.java).apply { action = ACTION_STOP },PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,)- openPendingIntent = openIntent- stopPendingIntent = stopIntent-val builder = NotificationCompat.Builder(this, CHANNEL_ID).setContentTitle("Podroid").setSmallIcon(R.drawable.ic_vm_notification)@@ -484,17 +481,23 @@ class PodroidService : Service() {}}+ // HostRequestDispatcher.handleHeadless already rejects any action other+ // than on/off/status before calling this, so the else branch here can+ // never run.private fun handleHeadlessRequest(action: String): String = when (action) {"on" -> { headlessModeManager.setActive(true); com.excp.podroid.engine.hostbridge.HostProtocol.ok() }"off" -> { headlessModeManager.setActive(false); com.excp.podroid.engine.hostbridge.HostProtocol.ok() }"status" -> com.excp.podroid.engine.hostbridge.HostProtocol.ok(if (headlessModeManager.active.value) "on" else "off")- else -> com.excp.podroid.engine.hostbridge.HostProtocol.err("usage: on|off|status")+ else -> error("unreachable: action=$action")}// Reply returned now; the stop/restart is posted to the main looper so the// bridge flushes the response before the VM (and this service) tear down. The// Handler callbacks capture the app-scoped engine + applicationContext (NOT// `this`), so they survive this service's death.+ // HostRequestDispatcher.handlePower already rejects any action other than+ // stop/restart/status before calling this, so the else branch here can+ // never run.private fun handlePowerRequest(action: String): String {val proto = com.excp.podroid.engine.hostbridge.HostProtocolreturn when (action) {@@ -514,7 +517,7 @@ class PodroidService : Service() {proto.ok()}"restart" -> { scheduleRestart(); proto.ok() }- else -> proto.err("usage: stop|restart|status")+ else -> error("unreachable: action=$action")}}