Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cczhr committed Apr 27, 2021
1 parent 461e860 commit b69df4c
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ class IMobileDeviceTools {
var successResult: BufferedReader? = null
var errorResult: BufferedReader? = null
var os: DataOutputStream? = null
@Volatile
var isKilling=false

fun killUsbmuxd(deviceNode: String = "") {
val killSystemMtp = if (deviceNode.isNotEmpty()) "kill `lsof -t $deviceNode`\n" else deviceNode
val killPort="kill -9 `netstat -tunlp | grep 27015|awk '{print $7} '|awk -F '/' '{print $1}'`"
runCommand("$killSystemMtp.$saveFilePath/usbmuxd -X\n$killPort")
SystemClock.sleep(1500)//保证进程杀死 休眠一下
if(!isKilling){
isKilling=true
SystemClock.sleep(1500)
val killSystemMtp = if (deviceNode.isNotEmpty()) "kill `lsof -t $deviceNode`\n" else deviceNode
val killPort="kill `netstat -tunlp | grep 27015|awk '{print $7} '|awk -F '/' '{print $1}'`"
runCommand("$killSystemMtp.$saveFilePath/usbmuxd -X -v -f\n$killPort")
SystemClock.sleep(2000)//保证进程杀死 休眠一下
isKilling=false
}

}

fun String.addLogStr() {
Expand All @@ -45,6 +53,7 @@ class IMobileDeviceTools {
fun release() {
try {
stopUsbmuxd {
killUsbmuxd()
fixedThreadPool.shutdownNow()
}
} catch (e: Exception) {
Expand All @@ -55,7 +64,7 @@ class IMobileDeviceTools {
fun stopUsbmuxd(disconnect: () -> Unit) {
fixedThreadPool.execute {
try {
killUsbmuxd()
//killUsbmuxd()
successResult?.close()
errorResult?.close()
os?.close()
Expand Down Expand Up @@ -84,6 +93,8 @@ class IMobileDeviceTools {
) {
fixedThreadPool.execute {
try {
if(isKilling)
return@execute
killUsbmuxd(deviceNode)
process = Runtime.getRuntime().exec("su", arrayOf("LD_LIBRARY_PATH=$saveFilePath"))
successResult = BufferedReader(InputStreamReader(process!!.inputStream))
Expand Down Expand Up @@ -142,7 +153,7 @@ class IMobileDeviceTools {
}

}
process!!.waitFor();
process!!.waitFor()
} catch (e: Exception) {
e.printStackTrace()
}
Expand Down

0 comments on commit b69df4c

Please sign in to comment.