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"
|
applicationId = "com.freeturn.app"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 6
|
versionCode = 7
|
||||||
versionName = "1.2.1"
|
versionName = "1.2.2"
|
||||||
}
|
}
|
||||||
|
|
||||||
packaging {
|
packaging {
|
||||||
@@ -35,7 +35,6 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lint {
|
lint {
|
||||||
checkReleaseBuilds = false
|
|
||||||
disable += "ExpiredTargetSdkVersion"
|
disable += "ExpiredTargetSdkVersion"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,13 +64,8 @@ class ProxyService : Service() {
|
|||||||
private var wakeLock: PowerManager.WakeLock? = null
|
private var wakeLock: PowerManager.WakeLock? = null
|
||||||
private var openAppIntent: PendingIntent? = null
|
private var openAppIntent: PendingIntent? = null
|
||||||
|
|
||||||
// P1-1: AtomicReference вместо @Volatile — проверка null + вызов destroy() атомарны
|
|
||||||
private val process = AtomicReference<Process?>(null)
|
private val process = AtomicReference<Process?>(null)
|
||||||
|
|
||||||
// P1-1: AtomicBoolean — флаг читается и пишется из разных потоков
|
|
||||||
private val userStopped = AtomicBoolean(false)
|
private val userStopped = AtomicBoolean(false)
|
||||||
|
|
||||||
// P1-1: AtomicBoolean — compareAndSet предотвращает двойной postDelayed при параллельных quota-ошибках
|
|
||||||
private val sessionKillScheduled = AtomicBoolean(false)
|
private val sessionKillScheduled = AtomicBoolean(false)
|
||||||
|
|
||||||
private val handler = Handler(Looper.getMainLooper())
|
private val handler = Handler(Looper.getMainLooper())
|
||||||
@@ -78,7 +73,6 @@ class ProxyService : Service() {
|
|||||||
@Volatile private var networkInitialized = false
|
@Volatile private var networkInitialized = false
|
||||||
private var restartCount = 0
|
private var restartCount = 0
|
||||||
|
|
||||||
// P1-2: CoroutineScope для запуска startBinaryProcess без runBlocking
|
|
||||||
private lateinit var serviceScope: CoroutineScope
|
private lateinit var serviceScope: CoroutineScope
|
||||||
|
|
||||||
override fun onBind(intent: Intent?): IBinder? = null
|
override fun onBind(intent: Intent?): IBinder? = null
|
||||||
@@ -116,17 +110,14 @@ class ProxyService : Service() {
|
|||||||
registerNetworkCallback()
|
registerNetworkCallback()
|
||||||
|
|
||||||
addLog("=== ЗАПУСК ПРОКСИ ===")
|
addLog("=== ЗАПУСК ПРОКСИ ===")
|
||||||
// P1-2: запуск через корутину на Dispatchers.IO — никакого runBlocking
|
|
||||||
serviceScope.launch { startBinaryProcess() }
|
serviceScope.launch { startBinaryProcess() }
|
||||||
|
|
||||||
return START_STICKY
|
return START_STICKY
|
||||||
}
|
}
|
||||||
|
|
||||||
// P1-2: suspend fun — читает DataStore напрямую без runBlocking
|
|
||||||
private suspend fun startBinaryProcess() {
|
private suspend fun startBinaryProcess() {
|
||||||
if (userStopped.get()) return
|
if (userStopped.get()) return
|
||||||
|
|
||||||
// P2-3: applicationContext вместо this@ProxyService
|
|
||||||
val cfg = AppPreferences(applicationContext).clientConfigFlow.first()
|
val cfg = AppPreferences(applicationContext).clientConfigFlow.first()
|
||||||
|
|
||||||
val customBin = File(filesDir, "custom_vkturn")
|
val customBin = File(filesDir, "custom_vkturn")
|
||||||
@@ -176,7 +167,6 @@ class ProxyService : Service() {
|
|||||||
val l = line ?: continue
|
val l = line ?: continue
|
||||||
addLog(l)
|
addLog(l)
|
||||||
|
|
||||||
// P2-1: сигнализируем результат запуска по первой строке stdout
|
|
||||||
if (!startupEmitted) {
|
if (!startupEmitted) {
|
||||||
val lower = l.lowercase()
|
val lower = l.lowercase()
|
||||||
if (lower.contains("panic") || lower.contains("fatal") ||
|
if (lower.contains("panic") || lower.contains("fatal") ||
|
||||||
@@ -191,17 +181,14 @@ class ProxyService : Service() {
|
|||||||
startupEmitted = true
|
startupEmitted = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Session Killer: compareAndSet гарантирует что postDelayed вызывается только раз
|
// compareAndSet гарантирует единственный postDelayed даже при параллельных quota-ошибках
|
||||||
// даже если две quota-ошибки придут одновременно из одного потока чтения
|
|
||||||
if (isQuotaError(l) && sessionKillScheduled.compareAndSet(false, true)) {
|
if (isQuotaError(l) && sessionKillScheduled.compareAndSet(false, true)) {
|
||||||
addLog(">>> QUOTA ERROR — сброс сессии через 2с")
|
addLog(">>> QUOTA ERROR — сброс сессии через 2с")
|
||||||
handler.postDelayed({
|
handler.postDelayed({
|
||||||
sessionKillScheduled.set(false)
|
sessionKillScheduled.set(false)
|
||||||
if (!userStopped.get()) {
|
if (!userStopped.get()) {
|
||||||
restartCount = 0
|
restartCount = 0
|
||||||
// P2-5: destroyForcibly() — SIGKILL, нативный процесс не игнорирует
|
process.get()?.destroyForcibly()
|
||||||
val p = process.get()
|
|
||||||
p?.destroyForcibly()
|
|
||||||
}
|
}
|
||||||
}, 2_000)
|
}, 2_000)
|
||||||
}
|
}
|
||||||
@@ -265,7 +252,6 @@ class ProxyService : Service() {
|
|||||||
addLog("=== WATCHDOG: перезапуск через ${delay}мс (попытка $restartCount/$MAX_RESTARTS) ===")
|
addLog("=== WATCHDOG: перезапуск через ${delay}мс (попытка $restartCount/$MAX_RESTARTS) ===")
|
||||||
updateNotification("VK TURN Proxy", "Переподключение ($restartCount/$MAX_RESTARTS)...")
|
updateNotification("VK TURN Proxy", "Переподключение ($restartCount/$MAX_RESTARTS)...")
|
||||||
handler.postDelayed({
|
handler.postDelayed({
|
||||||
// Проверка userStopped + запуск через serviceScope вместо thread {}
|
|
||||||
if (!userStopped.get()) serviceScope.launch { startBinaryProcess() }
|
if (!userStopped.get()) serviceScope.launch { startBinaryProcess() }
|
||||||
}, delay)
|
}, delay)
|
||||||
}
|
}
|
||||||
@@ -339,7 +325,6 @@ class ProxyService : Service() {
|
|||||||
handler.removeCallbacksAndMessages(null)
|
handler.removeCallbacksAndMessages(null)
|
||||||
unregisterNetworkCallback()
|
unregisterNetworkCallback()
|
||||||
addLog("=== ОСТАНОВКА ИЗ ИНТЕРФЕЙСА ===")
|
addLog("=== ОСТАНОВКА ИЗ ИНТЕРФЕЙСА ===")
|
||||||
// P2-5: destroyForcibly() вместо destroy()
|
|
||||||
process.get()?.destroyForcibly()
|
process.get()?.destroyForcibly()
|
||||||
serviceScope.cancel()
|
serviceScope.cancel()
|
||||||
if (wakeLock?.isHeld == true) wakeLock?.release()
|
if (wakeLock?.isHeld == true) wakeLock?.release()
|
||||||
|
|||||||
@@ -44,7 +44,10 @@ class LocalProxyManager(private val context: Context) {
|
|||||||
|
|
||||||
suspend fun observeProxyServiceStatus() {
|
suspend fun observeProxyServiceStatus() {
|
||||||
ProxyService.isRunning.collect { running ->
|
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
|
_proxyState.value = ProxyState.Idle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,11 +177,11 @@ fun HomeScreen(
|
|||||||
when (proxyState) {
|
when (proxyState) {
|
||||||
is ProxyState.Idle, is ProxyState.Error -> {
|
is ProxyState.Idle, is ProxyState.Error -> {
|
||||||
HapticUtil.perform(context, HapticUtil.Pattern.TOGGLE_ON)
|
HapticUtil.perform(context, HapticUtil.Pattern.TOGGLE_ON)
|
||||||
viewModel.startProxy(context)
|
viewModel.startProxy()
|
||||||
}
|
}
|
||||||
is ProxyState.Running -> {
|
is ProxyState.Running -> {
|
||||||
HapticUtil.perform(context, HapticUtil.Pattern.TOGGLE_OFF)
|
HapticUtil.perform(context, HapticUtil.Pattern.TOGGLE_OFF)
|
||||||
viewModel.stopProxy(context)
|
viewModel.stopProxy()
|
||||||
}
|
}
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,13 +141,13 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ── Local proxy ────────────────────────────────────────────────────────
|
// ── Local proxy ────────────────────────────────────────────────────────
|
||||||
fun startProxy(context: Context) {
|
fun startProxy() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
proxyManager.startProxy(clientConfig.value)
|
proxyManager.startProxy(clientConfig.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stopProxy(context: Context) {
|
fun stopProxy() {
|
||||||
proxyManager.stopProxy()
|
proxyManager.stopProxy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user