From 23122d32a9ce941d66e50ab030ea5b5c17dc66eb Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Fri, 6 Feb 2026 01:18:20 +0500 Subject: [PATCH] updated redirect hint and fix anr for redirect port --- .../java/sh/sar/textpipe/service/TextpipeService.kt | 11 ++++++----- app/src/main/java/sh/sar/textpipe/ui/MainScreen.kt | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/sh/sar/textpipe/service/TextpipeService.kt b/app/src/main/java/sh/sar/textpipe/service/TextpipeService.kt index 4a2a438..62cf4c5 100644 --- a/app/src/main/java/sh/sar/textpipe/service/TextpipeService.kt +++ b/app/src/main/java/sh/sar/textpipe/service/TextpipeService.kt @@ -20,8 +20,8 @@ import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.cancel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking import sh.sar.textpipe.MainActivity import sh.sar.textpipe.TextpipeApplication import sh.sar.textpipe.data.repository.SmsRepository @@ -124,7 +124,7 @@ class TextpipeService : Service() { val port = getConfiguredPort(this) _serverPort.value = port - serviceScope.launch { + serviceScope.launch(Dispatchers.IO) { // Setup port redirect if configured redirectPort = getRedirectPort(this@TextpipeService) if (redirectPort > 0 && redirectPort != port) { @@ -164,10 +164,11 @@ class TextpipeService : Service() { override fun onDestroy() { Log.i(TAG, "Service onDestroy") - // Clear port redirect synchronously before stopping + // Clear port redirect asynchronously (fire and forget to avoid ANR) if (redirectPort > 0) { - runBlocking { - RootManager.clearPortRedirect(redirectPort, textpipeServer?.getPort() ?: 8080) + val port = textpipeServer?.getPort() ?: 8080 + GlobalScope.launch(Dispatchers.IO) { + RootManager.clearPortRedirect(redirectPort, port) } } diff --git a/app/src/main/java/sh/sar/textpipe/ui/MainScreen.kt b/app/src/main/java/sh/sar/textpipe/ui/MainScreen.kt index 20efa8d..1141054 100644 --- a/app/src/main/java/sh/sar/textpipe/ui/MainScreen.kt +++ b/app/src/main/java/sh/sar/textpipe/ui/MainScreen.kt @@ -256,7 +256,7 @@ private fun PortConfigCard( ) Text( - text = "Traffic on redirect port will be forwarded to server port via iptables", + text = "Ports below 1024 (like 80, 443) require root. Uses iptables to redirect traffic to server port.", style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(top = 4.dp)