add a simple echo message at checking root access

This commit is contained in:
tibbi 2017-09-03 18:53:11 +02:00
parent 2aafa3344b
commit c8d790b246
2 changed files with 41 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.helpers.SHOW_ALL_TABS
import com.simplemobiletools.filemanager.R
import com.simplemobiletools.filemanager.extensions.config
import com.simplemobiletools.filemanager.helpers.RootHelpers
import kotlinx.android.synthetic.main.activity_settings.*
class SettingsActivity : SimpleActivity() {
@ -74,8 +75,18 @@ class SettingsActivity : SimpleActivity() {
private fun setupEnableRootAccess() {
settings_enable_root_access.isChecked = config.enableRootAccess
settings_enable_root_access_holder.setOnClickListener {
settings_enable_root_access.toggle()
config.enableRootAccess = settings_enable_root_access.isChecked
if (!config.enableRootAccess) {
RootHelpers().askRootIFNeeded(this) {
toggleRootAccess(it)
}
} else {
toggleRootAccess(false)
}
}
}
private fun toggleRootAccess(enable: Boolean) {
settings_enable_root_access.isChecked = enable
config.enableRootAccess = enable
}
}

View File

@ -1,10 +1,38 @@
package com.simplemobiletools.filemanager.helpers
import com.simplemobiletools.commons.extensions.showErrorToast
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.filemanager.activities.SimpleActivity
import com.stericson.RootShell.execution.Command
import com.stericson.RootTools.RootTools
class RootHelpers {
fun askRootIFNeeded(activity: SimpleActivity, callback: (success: Boolean) -> Unit) {
val SIMPLE_MOBILE_TOOLS = "simple mobile tools"
val command = object : Command(0, "echo $SIMPLE_MOBILE_TOOLS") {
override fun commandOutput(id: Int, line: String) {
if (line == SIMPLE_MOBILE_TOOLS)
callback(true)
super.commandOutput(id, line)
}
override fun commandTerminated(id: Int, reason: String?) {
super.commandTerminated(id, reason)
}
override fun commandCompleted(id: Int, exitcode: Int) {
super.commandCompleted(id, exitcode)
}
}
try {
RootTools.getShell(true).add(command)
} catch (exception: Exception) {
activity.showErrorToast(exception)
callback(false)
}
}
fun getFiles(path: String, callback: (fileDirItems: ArrayList<FileDirItem>) -> Unit) {
val command = object : Command(0, "ls -la $path | awk '{print \$1,\$NF}'") {
override fun commandOutput(id: Int, line: String) {