updated redirect hint and fix anr for redirect port

This commit is contained in:
2026-02-06 01:18:20 +05:00
parent 652612e156
commit 23122d32a9
2 changed files with 7 additions and 6 deletions

View File

@@ -20,8 +20,8 @@ import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import sh.sar.textpipe.MainActivity import sh.sar.textpipe.MainActivity
import sh.sar.textpipe.TextpipeApplication import sh.sar.textpipe.TextpipeApplication
import sh.sar.textpipe.data.repository.SmsRepository import sh.sar.textpipe.data.repository.SmsRepository
@@ -124,7 +124,7 @@ class TextpipeService : Service() {
val port = getConfiguredPort(this) val port = getConfiguredPort(this)
_serverPort.value = port _serverPort.value = port
serviceScope.launch { serviceScope.launch(Dispatchers.IO) {
// Setup port redirect if configured // Setup port redirect if configured
redirectPort = getRedirectPort(this@TextpipeService) redirectPort = getRedirectPort(this@TextpipeService)
if (redirectPort > 0 && redirectPort != port) { if (redirectPort > 0 && redirectPort != port) {
@@ -164,10 +164,11 @@ class TextpipeService : Service() {
override fun onDestroy() { override fun onDestroy() {
Log.i(TAG, "Service 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) { if (redirectPort > 0) {
runBlocking { val port = textpipeServer?.getPort() ?: 8080
RootManager.clearPortRedirect(redirectPort, textpipeServer?.getPort() ?: 8080) GlobalScope.launch(Dispatchers.IO) {
RootManager.clearPortRedirect(redirectPort, port)
} }
} }

View File

@@ -256,7 +256,7 @@ private fun PortConfigCard(
) )
Text( 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, style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant, color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(top = 4.dp) modifier = Modifier.padding(top = 4.dp)