diff --git a/app/src/other/java/io/nekohasekai/sfa/vendor/ApkInstaller.kt b/app/src/other/java/io/nekohasekai/sfa/vendor/ApkInstaller.kt index a07226b..a167edf 100644 --- a/app/src/other/java/io/nekohasekai/sfa/vendor/ApkInstaller.kt +++ b/app/src/other/java/io/nekohasekai/sfa/vendor/ApkInstaller.kt @@ -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)