Fix logcat flush blocking call on the wrong dispatcher (#3491)
* Fix logcat flush blocking call on the wrong dispatcher Moved the blocking `process.waitFor()` call to `Dispatchers.IO` to avoid potential thread starvation on `Dispatchers.Default`. This change ensures that the I/O-bound operation does not interfere with CPU-bound tasks, improving overall performance and responsiveness. * Fix logcat flush blocking call on the wrong dispatcher Moved the blocking `process.waitFor()` call to `Dispatchers.IO` to avoid potential thread starvation on `Dispatchers.Default`. This change ensures that the I/O-bound operation does not interfere with CPU-bound tasks, improving overall performance and responsiveness.
This commit is contained in:
1 parent
b37d8c2369
commit
8b806fe0be
1 file changed
+9
-7
@@ -1,8 +1,8 @@
|
|||||||
package com.v2ray.ang.ui
|
package com.v2ray.ang.ui
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.os.Bundle
|
|
||||||
import android.text.method.ScrollingMovementMethod
|
import android.text.method.ScrollingMovementMethod
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
@@ -14,11 +14,9 @@ import com.v2ray.ang.databinding.ActivityLogcatBinding
|
|||||||
import com.v2ray.ang.extension.toast
|
import com.v2ray.ang.extension.toast
|
||||||
import com.v2ray.ang.util.Utils
|
import com.v2ray.ang.util.Utils
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.LinkedHashSet
|
|
||||||
|
|
||||||
class LogcatActivity : BaseActivity() {
|
class LogcatActivity : BaseActivity() {
|
||||||
private val binding by lazy {
|
private val binding by lazy {
|
||||||
@@ -44,8 +42,10 @@ class LogcatActivity : BaseActivity() {
|
|||||||
val lst = LinkedHashSet<String>()
|
val lst = LinkedHashSet<String>()
|
||||||
lst.add("logcat")
|
lst.add("logcat")
|
||||||
lst.add("-c")
|
lst.add("-c")
|
||||||
val process = Runtime.getRuntime().exec(lst.toTypedArray())
|
withContext(Dispatchers.IO) {
|
||||||
process.waitFor()
|
val process = Runtime.getRuntime().exec(lst.toTypedArray())
|
||||||
|
process.waitFor()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val lst = LinkedHashSet<String>()
|
val lst = LinkedHashSet<String>()
|
||||||
lst.add("logcat")
|
lst.add("logcat")
|
||||||
@@ -54,7 +54,9 @@ class LogcatActivity : BaseActivity() {
|
|||||||
lst.add("time")
|
lst.add("time")
|
||||||
lst.add("-s")
|
lst.add("-s")
|
||||||
lst.add("GoLog,tun2socks,${ANG_PACKAGE},AndroidRuntime,System.err")
|
lst.add("GoLog,tun2socks,${ANG_PACKAGE},AndroidRuntime,System.err")
|
||||||
val process = Runtime.getRuntime().exec(lst.toTypedArray())
|
val process = withContext(Dispatchers.IO) {
|
||||||
|
Runtime.getRuntime().exec(lst.toTypedArray())
|
||||||
|
}
|
||||||
// val bufferedReader = BufferedReader(
|
// val bufferedReader = BufferedReader(
|
||||||
// InputStreamReader(process.inputStream))
|
// InputStreamReader(process.inputStream))
|
||||||
// val allText = bufferedReader.use(BufferedReader::readText)
|
// val allText = bufferedReader.use(BufferedReader::readText)
|
||||||
|
|||||||
Reference in new issue
Block a user