From 44176a840b23c919093fa798701bca34ed7bb9eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Thu, 26 Dec 2024 11:12:07 +0800 Subject: [PATCH] Enable fix stack for Android 7 and 9 --- .../main/java/io/nekohasekai/sfa/bg/BoxService.kt | 9 ++++++++- .../io/nekohasekai/sfa/bg/DefaultNetworkMonitor.kt | 8 +++----- .../main/java/io/nekohasekai/sfa/constant/Bugs.kt | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/io/nekohasekai/sfa/constant/Bugs.kt diff --git a/app/src/main/java/io/nekohasekai/sfa/bg/BoxService.kt b/app/src/main/java/io/nekohasekai/sfa/bg/BoxService.kt index c8361b8..36264e8 100644 --- a/app/src/main/java/io/nekohasekai/sfa/bg/BoxService.kt +++ b/app/src/main/java/io/nekohasekai/sfa/bg/BoxService.kt @@ -24,11 +24,13 @@ import io.nekohasekai.libbox.CommandServerHandler import io.nekohasekai.libbox.Libbox import io.nekohasekai.libbox.Notification import io.nekohasekai.libbox.PlatformInterface +import io.nekohasekai.libbox.SetupOptions import io.nekohasekai.libbox.SystemProxyStatus import io.nekohasekai.sfa.Application import io.nekohasekai.sfa.R import io.nekohasekai.sfa.constant.Action import io.nekohasekai.sfa.constant.Alert +import io.nekohasekai.sfa.constant.Bugs import io.nekohasekai.sfa.constant.Status import io.nekohasekai.sfa.database.ProfileManager import io.nekohasekai.sfa.database.Settings @@ -57,7 +59,12 @@ class BoxService( workingDir.mkdirs() val tempDir = Application.application.cacheDir tempDir.mkdirs() - Libbox.setup(baseDir.path, workingDir.path, tempDir.path, false) + Libbox.setup(SetupOptions().also { + it.basePath = baseDir.path + it.workingPath = workingDir.path + it.tempPath = tempDir.path + it.fixAndroidStack = Bugs.fixAndroidStack + }) Libbox.redirectStderr(File(workingDir, "stderr.log").path) initializeOnce = true return diff --git a/app/src/main/java/io/nekohasekai/sfa/bg/DefaultNetworkMonitor.kt b/app/src/main/java/io/nekohasekai/sfa/bg/DefaultNetworkMonitor.kt index 7ca51e4..d6b30cb 100644 --- a/app/src/main/java/io/nekohasekai/sfa/bg/DefaultNetworkMonitor.kt +++ b/app/src/main/java/io/nekohasekai/sfa/bg/DefaultNetworkMonitor.kt @@ -4,7 +4,7 @@ import android.net.Network import android.os.Build import io.nekohasekai.libbox.InterfaceUpdateListener import io.nekohasekai.sfa.Application -import io.nekohasekai.sfa.BuildConfig +import io.nekohasekai.sfa.constant.Bugs import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch @@ -59,9 +59,7 @@ object DefaultNetworkMonitor { Thread.sleep(100) continue } - // TODO: remove launch after fixed - // https://github.com/golang/go/issues/68760 - if (BuildConfig.DEBUG) { + if (Bugs.fixAndroidStack) { GlobalScope.launch(Dispatchers.IO) { listener.updateDefaultInterface(interfaceName, interfaceIndex) } @@ -70,7 +68,7 @@ object DefaultNetworkMonitor { } } } else { - if (BuildConfig.DEBUG) { + if (Bugs.fixAndroidStack) { GlobalScope.launch(Dispatchers.IO) { listener.updateDefaultInterface("", -1) } diff --git a/app/src/main/java/io/nekohasekai/sfa/constant/Bugs.kt b/app/src/main/java/io/nekohasekai/sfa/constant/Bugs.kt new file mode 100644 index 0000000..1dfc0c1 --- /dev/null +++ b/app/src/main/java/io/nekohasekai/sfa/constant/Bugs.kt @@ -0,0 +1,14 @@ +package io.nekohasekai.sfa.constant + +import android.os.Build +import io.nekohasekai.sfa.BuildConfig + +object Bugs { + + // TODO: remove launch after fixed + // https://github.com/golang/go/issues/68760 + val fixAndroidStack = BuildConfig.DEBUG || + Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1 || + Build.VERSION.SDK_INT >= Build.VERSION_CODES.P + +} \ No newline at end of file