add a simple echo message at checking root access
This commit is contained in:
parent
2aafa3344b
commit
c8d790b246
|
@ -8,6 +8,7 @@ import com.simplemobiletools.commons.extensions.updateTextColors
|
||||||
import com.simplemobiletools.commons.helpers.SHOW_ALL_TABS
|
import com.simplemobiletools.commons.helpers.SHOW_ALL_TABS
|
||||||
import com.simplemobiletools.filemanager.R
|
import com.simplemobiletools.filemanager.R
|
||||||
import com.simplemobiletools.filemanager.extensions.config
|
import com.simplemobiletools.filemanager.extensions.config
|
||||||
|
import com.simplemobiletools.filemanager.helpers.RootHelpers
|
||||||
import kotlinx.android.synthetic.main.activity_settings.*
|
import kotlinx.android.synthetic.main.activity_settings.*
|
||||||
|
|
||||||
class SettingsActivity : SimpleActivity() {
|
class SettingsActivity : SimpleActivity() {
|
||||||
|
@ -74,8 +75,18 @@ class SettingsActivity : SimpleActivity() {
|
||||||
private fun setupEnableRootAccess() {
|
private fun setupEnableRootAccess() {
|
||||||
settings_enable_root_access.isChecked = config.enableRootAccess
|
settings_enable_root_access.isChecked = config.enableRootAccess
|
||||||
settings_enable_root_access_holder.setOnClickListener {
|
settings_enable_root_access_holder.setOnClickListener {
|
||||||
settings_enable_root_access.toggle()
|
if (!config.enableRootAccess) {
|
||||||
config.enableRootAccess = settings_enable_root_access.isChecked
|
RootHelpers().askRootIFNeeded(this) {
|
||||||
|
toggleRootAccess(it)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
toggleRootAccess(false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun toggleRootAccess(enable: Boolean) {
|
||||||
|
settings_enable_root_access.isChecked = enable
|
||||||
|
config.enableRootAccess = enable
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,38 @@
|
||||||
package com.simplemobiletools.filemanager.helpers
|
package com.simplemobiletools.filemanager.helpers
|
||||||
|
|
||||||
|
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||||
import com.simplemobiletools.commons.models.FileDirItem
|
import com.simplemobiletools.commons.models.FileDirItem
|
||||||
|
import com.simplemobiletools.filemanager.activities.SimpleActivity
|
||||||
import com.stericson.RootShell.execution.Command
|
import com.stericson.RootShell.execution.Command
|
||||||
import com.stericson.RootTools.RootTools
|
import com.stericson.RootTools.RootTools
|
||||||
|
|
||||||
class RootHelpers {
|
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) {
|
fun getFiles(path: String, callback: (fileDirItems: ArrayList<FileDirItem>) -> Unit) {
|
||||||
val command = object : Command(0, "ls -la $path | awk '{print \$1,\$NF}'") {
|
val command = object : Command(0, "ls -la $path | awk '{print \$1,\$NF}'") {
|
||||||
override fun commandOutput(id: Int, line: String) {
|
override fun commandOutput(id: Int, line: String) {
|
||||||
|
|
Loading…
Reference in New Issue