diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c927755..7ac7075 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,6 +5,8 @@ + + + android:exported="true" + android:permission="com.freeturn.app.permission.CONTROL_PROXY"> diff --git a/app/src/main/java/com/freeturn/app/ProxyService.kt b/app/src/main/java/com/freeturn/app/ProxyService.kt index 1f92661..caab676 100644 --- a/app/src/main/java/com/freeturn/app/ProxyService.kt +++ b/app/src/main/java/com/freeturn/app/ProxyService.kt @@ -109,7 +109,7 @@ class ProxyService : Service() { val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "VkTurn::BgLock") - wakeLock?.acquire(TimeUnit.HOURS.toMillis(8)) + wakeLock?.acquire(TimeUnit.HOURS.toMillis(24)) registerNetworkCallback() @@ -195,7 +195,8 @@ class ProxyService : Service() { if (!userStopped.get()) { restartCount = 0 // P2-5: destroyForcibly() — SIGKILL, нативный процесс не игнорирует - process.get()?.destroyForcibly() + val p = process.get() + p?.destroyForcibly() } }, 2_000) } @@ -279,7 +280,8 @@ class ProxyService : Service() { addLog("=== СМЕНА СЕТИ — ПЕРЕЗАПУСК ===") updateNotification("VK TURN Proxy", "Смена сети, переподключение...") restartCount = 0 - process.get()?.destroyForcibly() + val p = process.get() + p?.destroyForcibly() } } } diff --git a/app/src/main/java/com/freeturn/app/domain/LocalProxyManager.kt b/app/src/main/java/com/freeturn/app/domain/LocalProxyManager.kt index 0c5c40a..ac1ec1c 100644 --- a/app/src/main/java/com/freeturn/app/domain/LocalProxyManager.kt +++ b/app/src/main/java/com/freeturn/app/domain/LocalProxyManager.kt @@ -16,6 +16,9 @@ import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.first import kotlinx.coroutines.withContext import kotlinx.coroutines.withTimeoutOrNull +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.launch import java.io.File class LocalProxyManager(private val context: Context) { @@ -26,6 +29,9 @@ class LocalProxyManager(private val context: Context) { private val _customKernelExists = MutableStateFlow(false) val customKernelExists: StateFlow = _customKernelExists.asStateFlow() + private val scope = CoroutineScope(Dispatchers.Main + SupervisorJob()) + private var resetJob: kotlinx.coroutines.Job? = null + init { _customKernelExists.value = File(context.filesDir, "custom_vkturn").exists() } @@ -88,10 +94,13 @@ class LocalProxyManager(private val context: Context) { _proxyState.value = ProxyState.Idle } - suspend fun setErrorWithAutoReset(message: String) { + fun setErrorWithAutoReset(message: String) { + resetJob?.cancel() _proxyState.value = ProxyState.Error(message) - delay(3500) - if (_proxyState.value is ProxyState.Error) _proxyState.value = ProxyState.Idle + resetJob = scope.launch { + delay(3500) + if (_proxyState.value is ProxyState.Error) _proxyState.value = ProxyState.Idle + } } suspend fun setCustomKernel(uri: Uri) = withContext(Dispatchers.IO) { diff --git a/app/src/main/java/com/freeturn/app/domain/ServerScripts.kt b/app/src/main/java/com/freeturn/app/domain/ServerScripts.kt index e4ebade..8032f1e 100644 --- a/app/src/main/java/com/freeturn/app/domain/ServerScripts.kt +++ b/app/src/main/java/com/freeturn/app/domain/ServerScripts.kt @@ -58,7 +58,7 @@ object ServerScripts { cd /opt/vk-turn && ARCH=${'$'}(uname -m); if [ "${'$'}ARCH" = "x86_64" ]; then BIN="server-linux-amd64"; else BIN="server-linux-arm64"; fi; - nohup ./${'$'}BIN -listen $listen -connect $connect > server.log 2>&1 & + nohup ./${'$'}BIN -listen '${listen}' -connect '${connect}' > server.log 2>&1 & echo ${'$'}! > proxy.pid && echo "STARTED" """.trimIndent() diff --git a/app/src/main/java/com/freeturn/app/ui/HapticUtil.kt b/app/src/main/java/com/freeturn/app/ui/HapticUtil.kt index 33ad19e..090a781 100644 --- a/app/src/main/java/com/freeturn/app/ui/HapticUtil.kt +++ b/app/src/main/java/com/freeturn/app/ui/HapticUtil.kt @@ -4,9 +4,6 @@ import android.content.Context import android.os.VibrationEffect import android.os.Vibrator import kotlinx.coroutines.DelicateCoroutinesApi -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.launch /** * Apple-like haptic patterns for a tactile, musical feel. @@ -32,7 +29,6 @@ object HapticUtil { LAUNCH, } - @OptIn(DelicateCoroutinesApi::class) fun perform(context: Context, pattern: Pattern) { val vibrator = context.getSystemService(Vibrator::class.java) ?: return val effect = when (pattern) { @@ -87,8 +83,6 @@ object HapticUtil { -1 ) } - GlobalScope.launch(Dispatchers.Default) { - try { vibrator.vibrate(effect) } catch(_: Exception) {} - } + try { vibrator.vibrate(effect) } catch(_: Exception) {} } } diff --git a/app/src/main/java/com/freeturn/app/ui/screens/SshSetupScreen.kt b/app/src/main/java/com/freeturn/app/ui/screens/SshSetupScreen.kt index 3bd186d..d1f006b 100644 --- a/app/src/main/java/com/freeturn/app/ui/screens/SshSetupScreen.kt +++ b/app/src/main/java/com/freeturn/app/ui/screens/SshSetupScreen.kt @@ -70,7 +70,7 @@ fun SshSetupScreen( var ip by rememberSaveable(savedConfig.ip) { mutableStateOf(savedConfig.ip) } var port by rememberSaveable(savedConfig.port) { mutableStateOf(savedConfig.port.toString()) } var username by rememberSaveable(savedConfig.username) { mutableStateOf(savedConfig.username) } - var password by rememberSaveable { mutableStateOf(savedConfig.password) } + var password by remember { mutableStateOf(savedConfig.password) } var authType by rememberSaveable(savedConfig.authType) { mutableStateOf(savedConfig.authType) } var sshKey by rememberSaveable(savedConfig.sshKey) { mutableStateOf(savedConfig.sshKey) } var showPassword by remember { mutableStateOf(false) }