Commit a7833cb4 authored by liuyang's avatar liuyang

log增加

parent 2edfb106
......@@ -38,6 +38,8 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback {
private lateinit var appInfoAdapter: AppConfigAdapter
private lateinit var refreshTimer: Timer
private lateinit var appInfoData: AppInfoData
private var startSet = false
private var isStart = false
private var apkPackageInfo: List<ApkPackageInfo>? = null
......@@ -65,7 +67,14 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback {
startRobotService()
startBtn.setOnClickListener{
toggle()
if (isStart) {
stop()
}
else {
start()
}
isStart = !isStart
}
startBtn.requestFocus()
......@@ -79,8 +88,24 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback {
}
private fun toggle() {
// 暂时测试用
private fun start() {
startBtn.isEnabled = false
if (TaskManager.instance.tasks.size > 0) {
startRobot()
startBtn.postDelayed({
startBtn.isEnabled = true
startBtn.text = "停止"
refreshBtn.isEnabled = false
}, 2000)
}
else {
startSet = true
requestAppList()
}
}
private fun stop() {
if (TaskManager.instance.isRunning) {
stopRobot()
startBtn.isEnabled = false
......@@ -90,15 +115,12 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback {
refreshBtn.isEnabled = true
}, 3000)
}
else {
startRobot()
startBtn.isEnabled = false
startBtn.postDelayed({
startBtn.isEnabled = true
startBtn.text = "停止"
refreshBtn.isEnabled = false
}, 2000)
}
}
private fun resetStartBtn() {
startBtn.isEnabled = true
startBtn.text = "开始"
refreshBtn.isEnabled = true
}
private fun requestAppList() {
......@@ -151,10 +173,18 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback {
override fun onProtocolFailed(protocol: IProtocol?) {
Toast.makeText(this, "获取应用列表信息出错", Toast.LENGTH_SHORT).show()
if (startSet) {
resetStartBtn()
startSet = false
}
}
override fun onHttpFailed(protocol: IProtocol?) {
Toast.makeText(this, "网络错误", Toast.LENGTH_SHORT).show()
if (startSet) {
resetStartBtn()
startSet = false
}
}
override fun onProtocolSucceed(protocol: IProtocol?) {
......@@ -172,6 +202,19 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback {
}
}
}
if (startSet) {
startBtn.isEnabled = true
if (TaskManager.instance.tasks.size > 0) {
startRobot()
startSet = false
startBtn.text = "停止"
refreshBtn.isEnabled = false
}
else {
Toast.makeText(this, "没有任务可以执行", Toast.LENGTH_SHORT).show()
}
}
}
}
......
......@@ -19,9 +19,11 @@ object AdbUtil {
// 通过id判断是否有root权限,部分盒子是没有su的
fun checkRootPermission(): Boolean {
var proc = getShellProc(ROOT_SHELL) ?: return false
var commands = ArrayList<String>()
Log.i(TAG, "get root proc success!")
val commands = ArrayList<String>()
commands.add("id -u")
var result = this.sendCommands(commands, proc)
val result = this.sendCommands(commands, proc)
Log.i(TAG, "check permission error ${result.errorLines} and message ${result.successLines}")
if (isRoot(result)) {
return true
}
......@@ -58,6 +60,10 @@ object AdbUtil {
e.printStackTrace()
}
if (proc == null) {
Log.i(TAG, "get root proc failed")
}
return proc
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment