Skip to content

Commit

Permalink
Fix logcat flush blocking call on the wrong dispatcher (#3491)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
CodeWithTamim committed Aug 16, 2024
1 parent b37d8c2 commit 8b806fe
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/LogcatActivity.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.v2ray.ang.ui

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.Bundle
import android.text.method.ScrollingMovementMethod
import android.view.Menu
import android.view.MenuItem
Expand All @@ -14,11 +14,9 @@ import com.v2ray.ang.databinding.ActivityLogcatBinding
import com.v2ray.ang.extension.toast
import com.v2ray.ang.util.Utils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

import kotlinx.coroutines.withContext
import java.io.IOException
import java.util.LinkedHashSet

class LogcatActivity : BaseActivity() {
private val binding by lazy {
Expand All @@ -44,8 +42,10 @@ class LogcatActivity : BaseActivity() {
val lst = LinkedHashSet<String>()
lst.add("logcat")
lst.add("-c")
val process = Runtime.getRuntime().exec(lst.toTypedArray())
process.waitFor()
withContext(Dispatchers.IO) {
val process = Runtime.getRuntime().exec(lst.toTypedArray())
process.waitFor()
}
}
val lst = LinkedHashSet<String>()
lst.add("logcat")
Expand All @@ -54,7 +54,9 @@ class LogcatActivity : BaseActivity() {
lst.add("time")
lst.add("-s")
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(
// InputStreamReader(process.inputStream))
// val allText = bufferedReader.use(BufferedReader::readText)
Expand Down

0 comments on commit 8b806fe

Please sign in to comment.