Using SAM
This commit is contained in:
@@ -39,10 +39,11 @@
|
||||
|
||||
package com.github.shadowsocks.utils
|
||||
|
||||
import eu.chainfire.libsuperuser.Shell
|
||||
import eu.chainfire.libsuperuser.Shell.{OnCommandResultListener, SU, Builder}
|
||||
import java.util
|
||||
|
||||
import eu.chainfire.libsuperuser.Shell
|
||||
import eu.chainfire.libsuperuser.Shell.{Builder, SU}
|
||||
|
||||
object Console {
|
||||
|
||||
private def openShell(): Shell.Interactive = {
|
||||
@@ -68,14 +69,8 @@ object Console {
|
||||
|
||||
def runCommand(commands: Array[String]) {
|
||||
val shell = openShell()
|
||||
shell.addCommand(commands, 0, new OnCommandResultListener {
|
||||
override def onCommandResult(commandCode: Int, exitCode: Int,
|
||||
output: util.List[String]) {
|
||||
if (exitCode < 0) {
|
||||
shell.close()
|
||||
}
|
||||
}
|
||||
})
|
||||
shell.addCommand(commands, 0, ((commandCode: Int, exitCode: Int, output: util.List[String]) =>
|
||||
if (exitCode < 0) shell.close()): Shell.OnCommandResultListener)
|
||||
shell.waitForIdle()
|
||||
shell.close()
|
||||
}
|
||||
@@ -90,17 +85,14 @@ object Console {
|
||||
}
|
||||
val shell = openRootShell(context)
|
||||
val sb = new StringBuilder
|
||||
shell.addCommand(commands, 0, new OnCommandResultListener {
|
||||
override def onCommandResult(commandCode: Int, exitCode: Int,
|
||||
output: util.List[String]) {
|
||||
if (exitCode < 0) {
|
||||
shell.close()
|
||||
} else {
|
||||
import scala.collection.JavaConversions._
|
||||
output.foreach(line => sb.append(line).append('\n'))
|
||||
}
|
||||
shell.addCommand(commands, 0, ((commandCode: Int, exitCode: Int, output: util.List[String]) => {
|
||||
if (exitCode < 0) {
|
||||
shell.close()
|
||||
} else {
|
||||
import scala.collection.JavaConversions._
|
||||
output.foreach(line => sb.append(line).append('\n'))
|
||||
}
|
||||
})
|
||||
}): Shell.OnCommandResultListener)
|
||||
if (shell.waitForIdle()) {
|
||||
shell.close()
|
||||
sb.toString()
|
||||
|
||||
Reference in New Issue
Block a user