Skip to content

Commit

Permalink
Update: Add warning for KernelSU user
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanGIG committed Jan 9, 2024
1 parent 78722ee commit 064a426
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<queries>
<package android:name="me.weishu.kernelsu" />
</queries>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
69 changes: 63 additions & 6 deletions app/src/main/java/com/dumper/android/core/SplashActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.core.content.edit
import com.dumper.android.BuildConfig
import com.dumper.android.ui.config.IGNORE_KSU
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.topjohnwu.superuser.Shell
import kotlin.system.exitProcess

@SuppressLint("CustomSplashScreen")
class SplashActivity : Activity() {
Expand All @@ -23,16 +27,69 @@ class SplashActivity : Activity() {
}
}

private val sharedPreferences by lazy {
getSharedPreferences("settings", MODE_PRIVATE)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Shell.getShell {
val methodStr = if (it.isRoot) "root" else "non-root"
Toast.makeText(this@SplashActivity, "Using $methodStr method", Toast.LENGTH_SHORT).show()

val intent = Intent(this@SplashActivity, MainActivity::class.java)
intent.putExtra("IS_ROOT", it.isRoot)
kotlin.runCatching {
val launcher = packageManager.getLaunchIntentForPackage("me.weishu.kernelsu")
if (launcher != null) {
requestKSUPermission(launcher)
return
}
}

initShell()
}

private fun requestKSUPermission(launcher: Intent) {
sharedPreferences.getBoolean(IGNORE_KSU, false).also {
if (it) {
initShell()
return
}
}

MaterialAlertDialogBuilder(this)
.setTitle("Warning")
.setMessage(
"KernelSU is detected, please grant root permission manually!\n\n" +
"If you want to use Non Root method, ignore this 'warning and continue."
)
.setPositiveButton("Launch") { _, _ ->
startActivity(launcher)
exitProcess(0)
}
.setNegativeButton("Ignore") { _, _ ->
sharedPreferences.edit(commit = true) {
putBoolean(IGNORE_KSU, true)
}
initShell()
}
.setOnCancelListener {
sharedPreferences.edit(commit = true) {
putBoolean(IGNORE_KSU, true)
}
initShell()
}
.show()
}

private fun initShell() {
Shell.getShell { shell ->
val methodStr = if (shell.isRoot) "root" else "non-root"
Toast.makeText(applicationContext, "Using $methodStr method", Toast.LENGTH_SHORT)
.show()
launchActivity()
}
}

startActivity(intent)
private fun launchActivity() {
Intent(applicationContext, MainActivity::class.java).also {
startActivity(it)
finish()
}
}
Expand Down

0 comments on commit 064a426

Please sign in to comment.