fix: мелкие исправления
This commit is contained in:
1 parent
e14f8f26e5
commit
5a03eeb3ea
6 files changed
+12
-61
No files matched your search
@@ -1,36 +0,0 @@
|
||||
{
|
||||
"permissions": {
|
||||
"allow": [
|
||||
"Bash(./gradlew assembleDebug)",
|
||||
"Bash(JAVA_HOME=\"/c/Program Files/Android/Android Studio/jbr\" ./gradlew assembleDebug)",
|
||||
"Bash(xargs sed:*)",
|
||||
"Bash(JAVA_HOME=\"C:/Program Files/Android/Android Studio/jbr\" ./gradlew assembleDebug)",
|
||||
"WebFetch(domain:composables.com)",
|
||||
"WebFetch(domain:cs.android.com)",
|
||||
"WebSearch",
|
||||
"WebFetch(domain:maven.google.com)",
|
||||
"Bash(find /c/Users/hxmelander/.gradle/caches -name material3-android-1.4.0*)",
|
||||
"Bash(wc:*)",
|
||||
"Bash(curl -s -L https://m3.material.io/components/bottom-sheets/guidelines)",
|
||||
"Bash(curl -s -L https://m3.material.io/components/bottom-sheets/specs)",
|
||||
"Bash(curl -s -L https://m3.material.io/components/lists/guidelines)",
|
||||
"Bash(curl -s -L https://m3.material.io/components/lists/specs)",
|
||||
"WebFetch(domain:m3.material.io)",
|
||||
"WebFetch(domain:m2.material.io)",
|
||||
"WebFetch(domain:medium.com)",
|
||||
"WebFetch(domain:www.boltuix.com)",
|
||||
"WebFetch(domain:github.com)",
|
||||
"WebFetch(domain:androidx.tech)",
|
||||
"WebFetch(domain:supercharge.design)",
|
||||
"Bash(for f:*)",
|
||||
"Bash(do echo:*)",
|
||||
"Read(//c/Users/hxmelander/StudioProjects/vk-turn-proxy-android/**)",
|
||||
"Bash(done)",
|
||||
"Bash(curl -s \"https://dl.google.com/dl/android/maven2/androidx/compose/material3/material3-expressive/maven-metadata.xml\")",
|
||||
"Bash(curl -s \"https://dl.google.com/dl/android/maven2/androidx/compose/material3/material3/maven-metadata.xml\")",
|
||||
"Bash(curl -s \"https://dl.google.com/dl/android/maven2/androidx/compose/compose-bom/2026.03.01/compose-bom-2026.03.01.pom\")",
|
||||
"Bash(git add:*)",
|
||||
"Bash(git commit:*)"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,8 @@ android {
|
||||
applicationId = "com.freeturn.app"
|
||||
minSdk = 26
|
||||
targetSdk = 36
|
||||
versionCode = 6
|
||||
versionName = "1.2.1"
|
||||
versionCode = 7
|
||||
versionName = "1.2.2"
|
||||
}
|
||||
|
||||
packaging {
|
||||
@@ -35,7 +35,6 @@ android {
|
||||
}
|
||||
|
||||
lint {
|
||||
checkReleaseBuilds = false
|
||||
disable += "ExpiredTargetSdkVersion"
|
||||
}
|
||||
|
||||
|
||||
@@ -64,13 +64,8 @@ class ProxyService : Service() {
|
||||
private var wakeLock: PowerManager.WakeLock? = null
|
||||
private var openAppIntent: PendingIntent? = null
|
||||
|
||||
// P1-1: AtomicReference вместо @Volatile — проверка null + вызов destroy() атомарны
|
||||
private val process = AtomicReference<Process?>(null)
|
||||
|
||||
// P1-1: AtomicBoolean — флаг читается и пишется из разных потоков
|
||||
private val userStopped = AtomicBoolean(false)
|
||||
|
||||
// P1-1: AtomicBoolean — compareAndSet предотвращает двойной postDelayed при параллельных quota-ошибках
|
||||
private val sessionKillScheduled = AtomicBoolean(false)
|
||||
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
@@ -78,7 +73,6 @@ class ProxyService : Service() {
|
||||
@Volatile private var networkInitialized = false
|
||||
private var restartCount = 0
|
||||
|
||||
// P1-2: CoroutineScope для запуска startBinaryProcess без runBlocking
|
||||
private lateinit var serviceScope: CoroutineScope
|
||||
|
||||
override fun onBind(intent: Intent?): IBinder? = null
|
||||
@@ -116,17 +110,14 @@ class ProxyService : Service() {
|
||||
registerNetworkCallback()
|
||||
|
||||
addLog("=== ЗАПУСК ПРОКСИ ===")
|
||||
// P1-2: запуск через корутину на Dispatchers.IO — никакого runBlocking
|
||||
serviceScope.launch { startBinaryProcess() }
|
||||
|
||||
return START_STICKY
|
||||
}
|
||||
|
||||
// P1-2: suspend fun — читает DataStore напрямую без runBlocking
|
||||
private suspend fun startBinaryProcess() {
|
||||
if (userStopped.get()) return
|
||||
|
||||
// P2-3: applicationContext вместо this@ProxyService
|
||||
val cfg = AppPreferences(applicationContext).clientConfigFlow.first()
|
||||
|
||||
val customBin = File(filesDir, "custom_vkturn")
|
||||
@@ -176,7 +167,6 @@ class ProxyService : Service() {
|
||||
val l = line ?: continue
|
||||
addLog(l)
|
||||
|
||||
// P2-1: сигнализируем результат запуска по первой строке stdout
|
||||
if (!startupEmitted) {
|
||||
val lower = l.lowercase()
|
||||
if (lower.contains("panic") || lower.contains("fatal") ||
|
||||
@@ -191,17 +181,14 @@ class ProxyService : Service() {
|
||||
startupEmitted = true
|
||||
}
|
||||
|
||||
// Session Killer: compareAndSet гарантирует что postDelayed вызывается только раз
|
||||
// даже если две quota-ошибки придут одновременно из одного потока чтения
|
||||
// compareAndSet гарантирует единственный postDelayed даже при параллельных quota-ошибках
|
||||
if (isQuotaError(l) && sessionKillScheduled.compareAndSet(false, true)) {
|
||||
addLog(">>> QUOTA ERROR — сброс сессии через 2с")
|
||||
handler.postDelayed({
|
||||
sessionKillScheduled.set(false)
|
||||
if (!userStopped.get()) {
|
||||
restartCount = 0
|
||||
// P2-5: destroyForcibly() — SIGKILL, нативный процесс не игнорирует
|
||||
val p = process.get()
|
||||
p?.destroyForcibly()
|
||||
process.get()?.destroyForcibly()
|
||||
}
|
||||
}, 2_000)
|
||||
}
|
||||
@@ -265,7 +252,6 @@ class ProxyService : Service() {
|
||||
addLog("=== WATCHDOG: перезапуск через ${delay}мс (попытка $restartCount/$MAX_RESTARTS) ===")
|
||||
updateNotification("VK TURN Proxy", "Переподключение ($restartCount/$MAX_RESTARTS)...")
|
||||
handler.postDelayed({
|
||||
// Проверка userStopped + запуск через serviceScope вместо thread {}
|
||||
if (!userStopped.get()) serviceScope.launch { startBinaryProcess() }
|
||||
}, delay)
|
||||
}
|
||||
@@ -339,7 +325,6 @@ class ProxyService : Service() {
|
||||
handler.removeCallbacksAndMessages(null)
|
||||
unregisterNetworkCallback()
|
||||
addLog("=== ОСТАНОВКА ИЗ ИНТЕРФЕЙСА ===")
|
||||
// P2-5: destroyForcibly() вместо destroy()
|
||||
process.get()?.destroyForcibly()
|
||||
serviceScope.cancel()
|
||||
if (wakeLock?.isHeld == true) wakeLock?.release()
|
||||
|
||||
@@ -44,7 +44,10 @@ class LocalProxyManager(private val context: Context) {
|
||||
|
||||
suspend fun observeProxyServiceStatus() {
|
||||
ProxyService.isRunning.collect { running ->
|
||||
if (!running && _proxyState.value == ProxyState.Running) {
|
||||
if (running && _proxyState.value !is ProxyState.Running && _proxyState.value !is ProxyState.Starting) {
|
||||
// Сервис запущен внешним источником (например, ProxyReceiver)
|
||||
_proxyState.value = ProxyState.Running
|
||||
} else if (!running && _proxyState.value is ProxyState.Running) {
|
||||
_proxyState.value = ProxyState.Idle
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,11 +177,11 @@ fun HomeScreen(
|
||||
when (proxyState) {
|
||||
is ProxyState.Idle, is ProxyState.Error -> {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.TOGGLE_ON)
|
||||
viewModel.startProxy(context)
|
||||
viewModel.startProxy()
|
||||
}
|
||||
is ProxyState.Running -> {
|
||||
HapticUtil.perform(context, HapticUtil.Pattern.TOGGLE_OFF)
|
||||
viewModel.stopProxy(context)
|
||||
viewModel.stopProxy()
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
|
||||
@@ -141,13 +141,13 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
||||
}
|
||||
|
||||
// ── Local proxy ────────────────────────────────────────────────────────
|
||||
fun startProxy(context: Context) {
|
||||
fun startProxy() {
|
||||
viewModelScope.launch {
|
||||
proxyManager.startProxy(clientConfig.value)
|
||||
}
|
||||
}
|
||||
|
||||
fun stopProxy(context: Context) {
|
||||
fun stopProxy() {
|
||||
proxyManager.stopProxy()
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user