diff --git a/app/src/github/java/io/nekohasekai/sfa/vendor/RootInstaller.kt b/app/src/github/java/io/nekohasekai/sfa/vendor/RootInstaller.kt index 051a876..64cf0a0 100644 --- a/app/src/github/java/io/nekohasekai/sfa/vendor/RootInstaller.kt +++ b/app/src/github/java/io/nekohasekai/sfa/vendor/RootInstaller.kt @@ -18,16 +18,6 @@ import kotlin.coroutines.resumeWithException object RootInstaller { - suspend fun checkAccess(): Boolean = withContext(Dispatchers.IO) { - try { - val process = Runtime.getRuntime().exec("su -c echo test") - val exitCode = process.waitFor() - exitCode == 0 - } catch (e: Exception) { - false - } - } - suspend fun install(apkFile: File) { withContext(Dispatchers.IO) { bindRootService().use { handle -> diff --git a/app/src/main/java/io/nekohasekai/sfa/compose/screen/settings/ProfileOverrideScreen.kt b/app/src/main/java/io/nekohasekai/sfa/compose/screen/settings/ProfileOverrideScreen.kt index 314e26b..59d7740 100644 --- a/app/src/main/java/io/nekohasekai/sfa/compose/screen/settings/ProfileOverrideScreen.kt +++ b/app/src/main/java/io/nekohasekai/sfa/compose/screen/settings/ProfileOverrideScreen.kt @@ -58,6 +58,7 @@ import androidx.navigation.NavController import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleEventObserver import io.nekohasekai.sfa.R +import io.nekohasekai.sfa.bg.RootClient import io.nekohasekai.sfa.compose.topbar.OverrideTopBar import io.nekohasekai.sfa.database.Settings import io.nekohasekai.sfa.compose.screen.profileoverride.PerAppProxyScanner @@ -206,18 +207,7 @@ fun ProfileOverrideScreen(navController: NavController) { onCheckedChange = { checked -> if (checked && !autoRedirect) { scope.launch { - val hasRoot = - withContext(Dispatchers.IO) { - try { - val process = Runtime.getRuntime().exec("su -c id") - process.inputStream.close() - process.outputStream.close() - process.errorStream.close() - process.waitFor() == 0 - } catch (e: Exception) { - false - } - } + val hasRoot = RootClient.checkRootAvailable() if (hasRoot) { autoRedirect = true withContext(Dispatchers.IO) { 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 a167edf..a67ac69 100644 --- a/app/src/other/java/io/nekohasekai/sfa/vendor/ApkInstaller.kt +++ b/app/src/other/java/io/nekohasekai/sfa/vendor/ApkInstaller.kt @@ -3,6 +3,7 @@ package io.nekohasekai.sfa.vendor import android.content.Context import io.nekohasekai.sfa.Application import io.nekohasekai.sfa.bg.BoxService +import io.nekohasekai.sfa.bg.RootClient import io.nekohasekai.sfa.database.Settings import io.nekohasekai.sfa.utils.HookStatusClient import io.nekohasekai.sfa.xposed.XposedActivation @@ -62,7 +63,7 @@ object ApkInstaller { return when (method) { InstallMethod.PACKAGE_INSTALLER -> canSystemSilentInstall() InstallMethod.SHIZUKU -> ShizukuInstaller.isAvailable() && ShizukuInstaller.checkPermission() - InstallMethod.ROOT -> RootInstaller.checkAccess() + InstallMethod.ROOT -> RootClient.checkRootAvailable() } } } diff --git a/app/src/other/java/io/nekohasekai/sfa/vendor/Vendor.kt b/app/src/other/java/io/nekohasekai/sfa/vendor/Vendor.kt index 3408751..23a8887 100644 --- a/app/src/other/java/io/nekohasekai/sfa/vendor/Vendor.kt +++ b/app/src/other/java/io/nekohasekai/sfa/vendor/Vendor.kt @@ -8,6 +8,7 @@ import androidx.camera.core.ImageAnalysis import com.google.android.material.dialog.MaterialAlertDialogBuilder import io.nekohasekai.sfa.Application import io.nekohasekai.sfa.R +import io.nekohasekai.sfa.bg.RootClient import io.nekohasekai.sfa.database.Settings import io.nekohasekai.sfa.compose.screen.qrscan.QRCodeCropArea import io.nekohasekai.sfa.update.UpdateCheckException @@ -135,7 +136,7 @@ object Vendor : VendorInterface { } true } - "ROOT" -> RootInstaller.checkAccess() + "ROOT" -> RootClient.checkRootAvailable() else -> false } } diff --git a/app/src/otherLegacy/java/io/nekohasekai/sfa/vendor/ApkInstaller.kt b/app/src/otherLegacy/java/io/nekohasekai/sfa/vendor/ApkInstaller.kt index 39bb4b5..d52f905 100644 --- a/app/src/otherLegacy/java/io/nekohasekai/sfa/vendor/ApkInstaller.kt +++ b/app/src/otherLegacy/java/io/nekohasekai/sfa/vendor/ApkInstaller.kt @@ -2,6 +2,7 @@ package io.nekohasekai.sfa.vendor import android.content.Context import io.nekohasekai.sfa.Application +import io.nekohasekai.sfa.bg.RootClient import io.nekohasekai.sfa.database.Settings import io.nekohasekai.sfa.utils.HookStatusClient import io.nekohasekai.sfa.xposed.XposedActivation @@ -43,7 +44,7 @@ object ApkInstaller { val method = getConfiguredMethod() return when (method) { InstallMethod.PACKAGE_INSTALLER -> canSystemSilentInstall() - InstallMethod.ROOT -> RootInstaller.checkAccess() + InstallMethod.ROOT -> RootClient.checkRootAvailable() } } } diff --git a/app/src/otherLegacy/java/io/nekohasekai/sfa/vendor/Vendor.kt b/app/src/otherLegacy/java/io/nekohasekai/sfa/vendor/Vendor.kt index 5969174..5b29009 100644 --- a/app/src/otherLegacy/java/io/nekohasekai/sfa/vendor/Vendor.kt +++ b/app/src/otherLegacy/java/io/nekohasekai/sfa/vendor/Vendor.kt @@ -8,6 +8,7 @@ import androidx.camera.core.ImageAnalysis import com.google.android.material.dialog.MaterialAlertDialogBuilder import io.nekohasekai.sfa.Application import io.nekohasekai.sfa.R +import io.nekohasekai.sfa.bg.RootClient import io.nekohasekai.sfa.database.Settings import io.nekohasekai.sfa.compose.screen.qrscan.QRCodeCropArea import io.nekohasekai.sfa.update.UpdateCheckException @@ -125,7 +126,7 @@ object Vendor : VendorInterface { "PACKAGE_INSTALLER" -> { ApkInstaller.canSystemSilentInstall() } - "ROOT" -> RootInstaller.checkAccess() + "ROOT" -> RootClient.checkRootAvailable() else -> false } }