Commit a7833cb4 authored by liuyang's avatar liuyang

log增加

parent 2edfb106
...@@ -38,6 +38,8 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback { ...@@ -38,6 +38,8 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback {
private lateinit var appInfoAdapter: AppConfigAdapter private lateinit var appInfoAdapter: AppConfigAdapter
private lateinit var refreshTimer: Timer private lateinit var refreshTimer: Timer
private lateinit var appInfoData: AppInfoData private lateinit var appInfoData: AppInfoData
private var startSet = false
private var isStart = false
private var apkPackageInfo: List<ApkPackageInfo>? = null private var apkPackageInfo: List<ApkPackageInfo>? = null
...@@ -65,7 +67,14 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback { ...@@ -65,7 +67,14 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback {
startRobotService() startRobotService()
startBtn.setOnClickListener{ startBtn.setOnClickListener{
toggle() if (isStart) {
stop()
}
else {
start()
}
isStart = !isStart
} }
startBtn.requestFocus() startBtn.requestFocus()
...@@ -79,8 +88,24 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback { ...@@ -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) { if (TaskManager.instance.isRunning) {
stopRobot() stopRobot()
startBtn.isEnabled = false startBtn.isEnabled = false
...@@ -90,15 +115,12 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback { ...@@ -90,15 +115,12 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback {
refreshBtn.isEnabled = true refreshBtn.isEnabled = true
}, 3000) }, 3000)
} }
else { }
startRobot()
startBtn.isEnabled = false private fun resetStartBtn() {
startBtn.postDelayed({ startBtn.isEnabled = true
startBtn.isEnabled = true startBtn.text = "开始"
startBtn.text = "停止" refreshBtn.isEnabled = true
refreshBtn.isEnabled = false
}, 2000)
}
} }
private fun requestAppList() { private fun requestAppList() {
...@@ -151,10 +173,18 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback { ...@@ -151,10 +173,18 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback {
override fun onProtocolFailed(protocol: IProtocol?) { override fun onProtocolFailed(protocol: IProtocol?) {
Toast.makeText(this, "获取应用列表信息出错", Toast.LENGTH_SHORT).show() Toast.makeText(this, "获取应用列表信息出错", Toast.LENGTH_SHORT).show()
if (startSet) {
resetStartBtn()
startSet = false
}
} }
override fun onHttpFailed(protocol: IProtocol?) { override fun onHttpFailed(protocol: IProtocol?) {
Toast.makeText(this, "网络错误", Toast.LENGTH_SHORT).show() Toast.makeText(this, "网络错误", Toast.LENGTH_SHORT).show()
if (startSet) {
resetStartBtn()
startSet = false
}
} }
override fun onProtocolSucceed(protocol: IProtocol?) { override fun onProtocolSucceed(protocol: IProtocol?) {
...@@ -172,6 +202,19 @@ class MainActivity : AppCompatActivity(), IAppBaseCallback { ...@@ -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 { ...@@ -19,9 +19,11 @@ object AdbUtil {
// 通过id判断是否有root权限,部分盒子是没有su的 // 通过id判断是否有root权限,部分盒子是没有su的
fun checkRootPermission(): Boolean { fun checkRootPermission(): Boolean {
var proc = getShellProc(ROOT_SHELL) ?: return false 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") 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)) { if (isRoot(result)) {
return true return true
} }
...@@ -58,6 +60,10 @@ object AdbUtil { ...@@ -58,6 +60,10 @@ object AdbUtil {
e.printStackTrace() e.printStackTrace()
} }
if (proc == null) {
Log.i(TAG, "get root proc failed")
}
return proc 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