fix: исправления для старых устройств

This commit is contained in:
samosvalishe committed 2026-04-19 00:48:44 +03:00
1 parent 77acff2752
commit 8340481631
7 files changed
+57 -22

No files matched your search

+4 -4
View File
@@ -52,10 +52,10 @@ kotlin {
}
dependencies {
implementation("androidx.core:core-splashscreen:1.2.0")
implementation("com.github.mwiede:jsch:2.28.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2")
implementation("androidx.security:security-crypto:1.1.0")
implementation(libs.androidx.core.splashscreen)
implementation(libs.jsch)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.androidx.security.crypto)
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
@@ -7,6 +7,8 @@ import android.app.Service
import android.content.Intent
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
import android.net.NetworkRequest
import android.os.Build
import android.os.Handler
import android.os.IBinder
@@ -65,8 +67,10 @@ class ProxyService : Service() {
override fun onCreate() {
super.onCreate()
serviceScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
val channel = NotificationChannel("ProxyChannel", "Proxy", NotificationManager.IMPORTANCE_LOW)
getSystemService(NotificationManager::class.java).createNotificationChannel(channel)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel("ProxyChannel", "Proxy", NotificationManager.IMPORTANCE_LOW)
getSystemService(NotificationManager::class.java).createNotificationChannel(channel)
}
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
@@ -212,11 +216,11 @@ class ProxyService : Service() {
if (lower.contains("panic") || lower.contains("fatal") ||
lower.contains("rate limit")) {
ProxyServiceState.setStartupResult(StartupResult.Failed(l))
updateNotification("VK TURN Proxy", "Ошибка подключения")
updateNotification("Ошибка подключения")
startupFailed = true
} else {
ProxyServiceState.setStartupResult(StartupResult.Success)
updateNotification("VK TURN Proxy", "Прокси активен")
updateNotification("Прокси активен")
}
startupEmitted = true
}
@@ -228,7 +232,7 @@ class ProxyService : Service() {
sessionKillScheduled.set(false)
if (!userStopped.get()) {
restartCount = 0
process.get()?.destroyForcibly()
process.get()?.destroyCompat()
}
}, 2_000)
}
@@ -236,7 +240,7 @@ class ProxyService : Service() {
}
exitCode = if (withContext(Dispatchers.IO) {
proc.waitFor(5, TimeUnit.MINUTES)
proc.waitForCompat(5, TimeUnit.MINUTES)
}) proc.exitValue() else -1
ProxyServiceState.addLog("=== ПРОЦЕСС ОСТАНОВЛЕН (Код: $exitCode) ===")
if (!startupEmitted) {
@@ -297,7 +301,7 @@ class ProxyService : Service() {
val jitter = Random.nextLong(0, 500)
val delay = baseDelay + jitter
ProxyServiceState.addLog("=== WATCHDOG: перезапуск через ${delay}мс (попытка $restartCount/$MAX_RESTARTS) ===")
updateNotification("VK TURN Proxy", "Переподключение ($restartCount/$MAX_RESTARTS)...")
updateNotification("Переподключение ($restartCount/$MAX_RESTARTS)...")
handler.postDelayed({
if (!userStopped.get()) serviceScope.launch { startBinaryProcess() }
}, delay)
@@ -323,16 +327,23 @@ class ProxyService : Service() {
kotlinx.coroutines.delay(2000)
if (!userStopped.get() && process.get() != null) {
ProxyServiceState.addLog("=== СМЕНА СЕТИ — ПЕРЕЗАПУСК ===")
updateNotification("VK TURN Proxy", "Смена сети, переподключение...")
updateNotification("Смена сети, переподключение...")
restartCount = 0
val p = process.get()
p?.destroyForcibly()
p?.destroyCompat()
}
}
}
}
networkCallback = cb
cm.registerDefaultNetworkCallback(cb)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
cm.registerDefaultNetworkCallback(cb)
} else {
val request = NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.build()
cm.registerNetworkCallback(request, cb)
}
}
private fun unregisterNetworkCallback() {
@@ -347,9 +358,9 @@ class ProxyService : Service() {
// Notification
private fun updateNotification(title: String, text: String) {
private fun updateNotification(text: String) {
val notification = NotificationCompat.Builder(this, "ProxyChannel")
.setContentTitle(title)
.setContentTitle("VK TURN Proxy")
.setContentText(text)
.setSmallIcon(android.R.drawable.ic_menu_preferences)
.setOngoing(true)
@@ -372,8 +383,21 @@ class ProxyService : Service() {
handler.removeCallbacksAndMessages(null)
unregisterNetworkCallback()
ProxyServiceState.addLog("=== ОСТАНОВКА ИЗ ИНТЕРФЕЙСА ===")
process.get()?.destroyForcibly()
process.get()?.destroyCompat()
serviceScope.cancel()
if (wakeLock?.isHeld == true) wakeLock?.release()
}
}
private fun Process.destroyCompat() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) destroyForcibly() else destroy()
}
private fun Process.waitForCompat(timeout: Long, unit: TimeUnit): Boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) return waitFor(timeout, unit)
val deadline = System.currentTimeMillis() + unit.toMillis(timeout)
while (System.currentTimeMillis() < deadline) {
try { exitValue(); return true } catch (_: IllegalThreadStateException) { Thread.sleep(100) }
}
return try { exitValue(); true } catch (_: IllegalThreadStateException) { false }
}
@@ -1,3 +1,5 @@
@file:Suppress("DEPRECATION")
package com.freeturn.app.data
import android.content.Context
@@ -52,8 +54,6 @@ object DnsMode {
val ALL = listOf(AUTO, UDP, DOH)
}
// P2-3 / P3-6: всегда используем applicationContext, чтобы lazy-init encryptedPrefs
// не мог сработать на уничтоженном контексте (например Service после onDestroy)
class AppPreferences(context: Context) {
private val context = context.applicationContext
@@ -309,6 +309,7 @@ fun HomeScreen(
// Диалоги обновления
@Suppress("AssignedValueIsNeverRead")
@Composable
private fun UpdateDialogs(viewModel: MainViewModel) {
val context = LocalContext.current
@@ -462,6 +463,7 @@ private fun ProxyToggleButton(state: ProxyState, onClick: () -> Unit) {
// Bottom sheet
@Suppress("AssignedValueIsNeverRead")
@Composable
private fun InfoBottomSheet(
viewModel: MainViewModel,
@@ -64,6 +64,7 @@ internal fun extendedColorSchemeFor(darkTheme: Boolean): ExtendedColorScheme =
internal val LocalExtendedColorScheme = staticCompositionLocalOf { extendedLight }
@Suppress("UnusedReceiverParameter")
val MaterialTheme.extendedColorScheme: ExtendedColorScheme
@Composable
@ReadOnlyComposable
@@ -11,7 +11,6 @@ import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.core.view.WindowCompat
+11 -2
View File
@@ -5,9 +5,14 @@ coreKtx = "1.18.0"
appcompat = "1.7.1"
activity = "1.13.0"
composeBom = "2026.03.01"
material3 = "1.5.0-alpha17"
navigationCompose = "2.9.7"
datastorePreferences = "1.2.1"
lifecycleViewmodelCompose = "2.10.0"
coreSplashscreen = "1.2.0"
jsch = "2.28.0"
coroutinesAndroid = "1.10.2"
securityCrypto = "1.1.0"
[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
@@ -18,12 +23,16 @@ androidx-compose-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-compose-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3", version = "1.5.0-alpha16" }
androidx-compose-material3-adaptive-nav-suite = { group = "androidx.compose.material3", name = "material3-adaptive-navigation-suite", version = "1.5.0-alpha16" }
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "material3" }
androidx-compose-material3-adaptive-nav-suite = { group = "androidx.compose.material3", name = "material3-adaptive-navigation-suite", version.ref = "material3" }
androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigationCompose" }
androidx-datastore-preferences = { group = "androidx.datastore", name = "datastore-preferences", version.ref = "datastorePreferences" }
androidx-lifecycle-viewmodel-compose = { group = "androidx.lifecycle", name = "lifecycle-viewmodel-compose", version.ref = "lifecycleViewmodelCompose" }
androidx-lifecycle-runtime-compose = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "lifecycleViewmodelCompose" }
androidx-core-splashscreen = { group = "androidx.core", name = "core-splashscreen", version.ref = "coreSplashscreen" }
androidx-security-crypto = { group = "androidx.security", name = "security-crypto", version.ref = "securityCrypto" }
jsch = { group = "com.github.mwiede", name = "jsch", version.ref = "jsch" }
kotlinx-coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref = "coroutinesAndroid" }
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }