Stop VPN service before installing update

This commit is contained in:
世界
2026-01-13 21:26:19 +08:00
parent 5ec245f957
commit 355cfc8b89

View File

@@ -2,9 +2,11 @@ package io.nekohasekai.sfa.vendor
import android.content.Context
import io.nekohasekai.sfa.Application
import io.nekohasekai.sfa.bg.BoxService
import io.nekohasekai.sfa.database.Settings
import io.nekohasekai.sfa.utils.HookStatusClient
import io.nekohasekai.sfa.xposed.XposedActivation
import kotlinx.coroutines.delay
import java.io.File
enum class InstallMethod {
@@ -15,6 +17,20 @@ enum class InstallMethod {
object ApkInstaller {
private suspend fun stopServiceIfRunning() {
val commandSocket = File(Application.application.filesDir, "command.sock")
if (!commandSocket.exists()) {
return
}
BoxService.stop()
repeat(20) {
delay(100)
if (!commandSocket.exists()) {
return
}
}
}
fun getConfiguredMethod(): InstallMethod {
if (HookStatusClient.status.value?.active == true ||
XposedActivation.isActivated(Application.application)
@@ -29,6 +45,7 @@ object ApkInstaller {
}
suspend fun install(context: Context, apkFile: File, method: InstallMethod = getConfiguredMethod()) {
stopServiceIfRunning()
when (method) {
InstallMethod.SHIZUKU -> ShizukuInstaller.install(apkFile)
InstallMethod.ROOT -> RootInstaller.install(apkFile)