refactor: ProxyPrefs → DataStore, включён R8 для release

This commit is contained in:
samosvalishe committed 2026-03-29 01:17:34 +03:00
1 parent d276d2fa9e
commit cc00883fb4
4 files changed
+45 -48

No files matched your search

+1 -1
View File
@@ -28,7 +28,7 @@ android {
buildTypes {
release {
isMinifyEnabled = false
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
+29 -18
View File
@@ -1,21 +1,32 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# ── Stacktraces ───────────────────────────────────────────────────────────────
# Сохраняем имена файлов и номера строк для читаемых крэш-репортов
-keepattributes SourceFile,LineNumberTable
-renamesourcefileattribute SourceFile
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# ── JSch ──────────────────────────────────────────────────────────────────────
# JSch загружает криптографические алгоритмы через reflection по имени класса.
# Без этого правила R8 удалит/переименует нужные классы и SSH не будет работать.
-keep class com.jcraft.jsch.** { *; }
-dontwarn com.jcraft.jsch.**
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# ── Kotlin Coroutines ─────────────────────────────────────────────────────────
-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}
-keepclassmembernames class kotlinx.coroutines.** {
volatile <fields>;
}
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
# ── Android Security Crypto (EncryptedSharedPreferences) ──────────────────────
-keep class androidx.security.crypto.** { *; }
# ── DataStore ─────────────────────────────────────────────────────────────────
-keep class androidx.datastore.** { *; }
# ── Tink (транзитивная зависимость security-crypto) ───────────────────────────
# Аннотационные библиотеки не включены в runtime, предупреждения безопасно подавить
-dontwarn com.google.errorprone.annotations.CanIgnoreReturnValue
-dontwarn com.google.errorprone.annotations.CheckReturnValue
-dontwarn com.google.errorprone.annotations.Immutable
-dontwarn com.google.errorprone.annotations.RestrictedApi
-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.concurrent.GuardedBy
@@ -12,6 +12,7 @@ import android.os.IBinder
import android.os.Looper
import android.os.PowerManager
import androidx.core.app.NotificationCompat
import com.freeturn.app.data.AppPreferences
import java.io.BufferedReader
import java.io.File
import java.io.InputStreamReader
@@ -20,7 +21,9 @@ import kotlin.concurrent.thread
import kotlin.random.Random
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.runBlocking
class ProxyService : Service() {
@@ -80,8 +83,7 @@ class ProxyService : Service() {
}
private fun startBinaryProcess() {
val prefs = getSharedPreferences("ProxyPrefs", Context.MODE_PRIVATE)
val isRaw = prefs.getBoolean("isRaw", false)
val cfg = runBlocking { AppPreferences(this@ProxyService).clientConfigFlow.first() }
val customBin = File(filesDir, "custom_vkturn")
val executable = if (customBin.exists()) {
@@ -94,25 +96,19 @@ class ProxyService : Service() {
val cmdArgs = mutableListOf<String>()
if (isRaw) {
val rawCmd = prefs.getString("rawCmd", "") ?: ""
val parts = rawCmd.trim().split("\\s+".toRegex())
if (cfg.isRawMode) {
val parts = cfg.rawCommand.trim().split("\\s+".toRegex())
cmdArgs.add(executable)
if (parts.size > 1) cmdArgs.addAll(parts.subList(1, parts.size))
} else {
val peer = prefs.getString("peer", "") ?: ""
val link = prefs.getString("link", "") ?: ""
val n = prefs.getString("n", "") ?: ""
val listen = prefs.getString("listen", "127.0.0.1:9000") ?: ""
cmdArgs.add(executable)
cmdArgs.add("-peer"); cmdArgs.add(peer)
cmdArgs.add(if (link.contains("yandex")) "-yandex-link" else "-vk-link")
cmdArgs.add(link)
cmdArgs.add("-listen"); cmdArgs.add(listen)
if (n.isNotEmpty()) { cmdArgs.add("-n"); cmdArgs.add(n) }
if (prefs.getBoolean("udp", false)) cmdArgs.add("-udp")
if (prefs.getBoolean("noDtls", false)) cmdArgs.add("-no-dtls")
cmdArgs.add("-peer"); cmdArgs.add(cfg.serverAddress)
cmdArgs.add(if (cfg.vkLink.contains("yandex")) "-yandex-link" else "-vk-link")
cmdArgs.add(cfg.vkLink)
cmdArgs.add("-listen"); cmdArgs.add(cfg.localPort)
if (cfg.threads > 0) { cmdArgs.add("-n"); cmdArgs.add(cfg.threads.toString()) }
if (cfg.useUdp) cmdArgs.add("-udp")
if (cfg.noDtls) cmdArgs.add("-no-dtls")
}
var exitCode = -1
@@ -22,7 +22,6 @@ import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import androidx.core.content.edit
import java.io.File
// ── SSH connection states ──────────────────────────────────────────────────
@@ -291,17 +290,8 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
_proxyState.value = ProxyState.Starting
viewModelScope.launch {
// Write to legacy SharedPreferences so ProxyService can read them
context.getSharedPreferences("ProxyPrefs", Context.MODE_PRIVATE).edit {
putString("peer", cfg.serverAddress)
putString("link", cfg.vkLink)
putString("n", cfg.threads.toString())
putBoolean("udp", cfg.useUdp)
putBoolean("noDtls", cfg.noDtls)
putString("listen", cfg.localPort)
putBoolean("isRaw", cfg.isRawMode)
putString("rawCmd", cfg.rawCommand)
}
// Сохраняем актуальный конфиг в DataStore — ProxyService читает его напрямую
prefs.saveClientConfig(cfg)
ProxyService.logs.value = emptyList()
context.startForegroundService(Intent(context, ProxyService::class.java))