|
|
|
@ -19,6 +19,10 @@ import com.yinuo.safetywatcher.xls.SimpleCellValue
|
|
|
|
|
import com.yinuo.safetywatcher.xls.utils.ExcelUtils
|
|
|
|
|
import kotlinx.coroutines.GlobalScope
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
import java.io.BufferedReader
|
|
|
|
|
import java.io.DataOutputStream
|
|
|
|
|
import java.io.IOException
|
|
|
|
|
import java.io.InputStreamReader
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
object TestUtils {
|
|
|
|
@ -111,8 +115,71 @@ object TestUtils {
|
|
|
|
|
row.add(SimpleCellValue(it.unit))
|
|
|
|
|
allData.add(row)
|
|
|
|
|
}
|
|
|
|
|
ExcelUtils.writeStringListToExcel(allData, context);
|
|
|
|
|
val excelPath = ExcelUtils.writeStringListToExcel(allData, context)
|
|
|
|
|
// val dataPath = LztekUtil.getLztek()?.usbStoragePath + "/"
|
|
|
|
|
// // 直接copy到机身
|
|
|
|
|
// val command = arrayOf("remount","cp -r $excelPath $dataPath")
|
|
|
|
|
// execCommand(command, true, true)
|
|
|
|
|
commonDialog?.dismiss()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
commonDialog?.dialogBinding?.root?.postDelayed({ commonDialog.dismiss() }, 1000)
|
|
|
|
|
// ShellUtils execCommand()方法
|
|
|
|
|
fun execCommand(
|
|
|
|
|
commands: Array<String>,
|
|
|
|
|
isRoot: Boolean,
|
|
|
|
|
isNeedResultMsg: Boolean
|
|
|
|
|
) {
|
|
|
|
|
var result = -1
|
|
|
|
|
if (commands.isEmpty()) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
var process: Process? = null
|
|
|
|
|
var successResult: BufferedReader? = null
|
|
|
|
|
var errorResult: BufferedReader? = null
|
|
|
|
|
var successMsg: StringBuilder? = null
|
|
|
|
|
var errorMsg: StringBuilder? = null
|
|
|
|
|
var os: DataOutputStream? = null
|
|
|
|
|
try {
|
|
|
|
|
process = Runtime.getRuntime().exec(if (isRoot) "su" else "sh")
|
|
|
|
|
os = DataOutputStream(process!!.outputStream)
|
|
|
|
|
for (command in commands) {
|
|
|
|
|
if (command == null) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// do not use os.writeBytes(command), avoid chinese charset error
|
|
|
|
|
os.write(command.toByteArray())
|
|
|
|
|
os.writeBytes("\n")
|
|
|
|
|
os.flush()
|
|
|
|
|
}
|
|
|
|
|
os.writeBytes("exit\n")
|
|
|
|
|
os.flush()
|
|
|
|
|
result = process.waitFor()
|
|
|
|
|
// get command result
|
|
|
|
|
if (isNeedResultMsg) {
|
|
|
|
|
successMsg = StringBuilder()
|
|
|
|
|
errorMsg = StringBuilder()
|
|
|
|
|
successResult = BufferedReader(InputStreamReader(process.inputStream))
|
|
|
|
|
errorResult = BufferedReader(InputStreamReader(process.errorStream))
|
|
|
|
|
var s: String?
|
|
|
|
|
while (successResult.readLine().also { s = it } != null) {
|
|
|
|
|
successMsg.append(s)
|
|
|
|
|
}
|
|
|
|
|
while (errorResult.readLine().also { s = it } != null) {
|
|
|
|
|
errorMsg.append(s)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (e: Exception) {
|
|
|
|
|
e.printStackTrace()
|
|
|
|
|
} finally {
|
|
|
|
|
try {
|
|
|
|
|
os?.close()
|
|
|
|
|
successResult?.close()
|
|
|
|
|
errorResult?.close()
|
|
|
|
|
} catch (e: IOException) {
|
|
|
|
|
e.printStackTrace()
|
|
|
|
|
}
|
|
|
|
|
process?.destroy()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|