recheck at app launch if root permission hasnt been revoked

This commit is contained in:
tibbi 2017-09-04 18:58:15 +02:00
parent fa35107abe
commit 5cb9b6cc4f
3 changed files with 15 additions and 6 deletions

View file

@ -25,6 +25,7 @@ import com.simplemobiletools.filemanager.SCROLL_STATE
import com.simplemobiletools.filemanager.dialogs.ChangeSortingDialog
import com.simplemobiletools.filemanager.extensions.config
import com.simplemobiletools.filemanager.fragments.ItemsFragment
import com.simplemobiletools.filemanager.helpers.RootHelpers
import com.stericson.RootTools.RootTools
import kotlinx.android.synthetic.main.activity_main.*
import java.util.*
@ -256,6 +257,11 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
private fun checkIfRootAvailable() {
Thread({
config.isRootAvailable = RootTools.isRootAvailable()
if (config.isRootAvailable && config.enableRootAccess) {
RootHelpers().askRootIFNeeded(this) {
config.enableRootAccess = it
}
}
}).start()
}

View file

@ -189,7 +189,7 @@ class ItemsFragment : Fragment(), ItemsAdapter.ItemOperationsListener {
}
private fun getRootItemsOf(path: String, callback: (items: ArrayList<FileDirItem>) -> Unit) {
RootHelpers().getFiles(context, path.trimEnd('/'), callback)
RootHelpers().getFiles(activity as SimpleActivity, path.trimEnd('/'), callback)
}
private fun getChildren(file: File): Int {

View file

@ -1,6 +1,5 @@
package com.simplemobiletools.filemanager.helpers
import android.content.Context
import android.text.TextUtils
import com.simplemobiletools.commons.extensions.showErrorToast
import com.simplemobiletools.commons.models.FileDirItem
@ -37,9 +36,9 @@ class RootHelpers {
}
}
fun getFiles(context: Context, path: String, callback: (fileDirItems: ArrayList<FileDirItem>) -> Unit) {
fun getFiles(activity: SimpleActivity, path: String, callback: (fileDirItems: ArrayList<FileDirItem>) -> Unit) {
val files = ArrayList<FileDirItem>()
val showHidden = context.config.shouldShowHidden
val showHidden = activity.config.shouldShowHidden
val cmd = "ls -la $path | awk '{ system(\"echo \"\$1\" \"\$4\" `find $path/\"\$NF\" -mindepth 1 -maxdepth 1 | wc -l` \"\$NF\" \")}'"
val command = object : Command(0, cmd) {
@ -76,8 +75,12 @@ class RootHelpers {
super.commandCompleted(id, exitcode)
}
}
RootTools.getShell(true).add(command)
try {
RootTools.getShell(true).add(command)
} catch (e: Exception) {
activity.showErrorToast(e)
}
}
private fun areDigitsOnly(value: String) = value.matches(Regex("[0-9 ]+"))
private fun areDigitsOnly(value: String) = value.matches(Regex("[0-9]+"))
}