Skip to content

Commit ea23a80

Browse files
committed
Record log in a separated thread
Prevent triggering strict mode violation and improve performance.
1 parent d03edf7 commit ea23a80

File tree

1 file changed

+8
-3
lines changed
  • xposed/src/main/java/icu/nullptr/hidemyapplist/xposed

1 file changed

+8
-3
lines changed

xposed/src/main/java/icu/nullptr/hidemyapplist/xposed/Logcat.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import android.util.Log
44
import de.robv.android.xposed.XposedBridge
55
import java.text.SimpleDateFormat
66
import java.util.*
7+
import java.util.concurrent.Executors
8+
9+
private val logExecutor = Executors.newSingleThreadExecutor()
710

811
private fun parseLog(level: Int, tag: String, msg: String, cause: Throwable? = null) = buildString {
912
val levelStr = when (level) {
@@ -22,9 +25,11 @@ private fun parseLog(level: Int, tag: String, msg: String, cause: Throwable? = n
2225

2326
private fun log(level: Int, tag: String, msg: String, cause: Throwable? = null) {
2427
if (level <= Log.DEBUG && HMAService.instance?.config?.detailLog == false) return
25-
val parsedLog = parseLog(level, tag, msg, cause)
26-
HMAService.instance?.addLog(parsedLog)
27-
XposedBridge.log(parsedLog)
28+
logExecutor.execute {
29+
val parsedLog = parseLog(level, tag, msg, cause)
30+
HMAService.instance?.addLog(parsedLog)
31+
XposedBridge.log(parsedLog)
32+
}
2833
}
2934

3035
fun logD(tag: String, msg: String, cause: Throwable? = null) = log(Log.DEBUG, tag, msg, cause)

0 commit comments

Comments
 (0)