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