add a helper function for fetching root items

This commit is contained in:
tibbi 2017-09-03 18:18:03 +02:00
parent 4ad01751af
commit 80d834e7eb
3 changed files with 35 additions and 0 deletions

View File

@ -40,6 +40,8 @@ dependencies {
compile 'com.simplemobiletools:commons:2.27.7'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile files('../libs/RootTools.jar')
}
buildscript {

View File

@ -0,0 +1,33 @@
package com.simplemobiletools.filemanager.helpers
import com.simplemobiletools.commons.models.FileDirItem
import com.stericson.RootShell.execution.Command
import com.stericson.RootTools.RootTools
class RootHelpers {
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) {
super.commandOutput(id, line)
val parts = line.split(" ")
val files = ArrayList<FileDirItem>()
val filename = parts[1]
val filePath = "${path.trimEnd('/')}/$filename"
val isDirectory = parts[0].startsWith("d")
val fileDirItem = FileDirItem(filePath, filename, isDirectory, 0, 0)
files.add(fileDirItem)
callback(files)
}
override fun commandTerminated(id: Int, reason: String?) {
super.commandTerminated(id, reason)
}
override fun commandCompleted(id: Int, exitcode: Int) {
super.commandCompleted(id, exitcode)
}
}
RootTools.getShell(true).add(command)
}
}

BIN
libs/RootTools.jar Normal file

Binary file not shown.