mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-24 10:51:27 +01:00
Ensure uploaded logs match debug log viewer.
This commit is contained in:
@@ -13,6 +13,7 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation(project(":core-util"))
|
||||
implementation(project(":core-util-jvm"))
|
||||
|
||||
implementation(libs.kotlin.reflect)
|
||||
implementation(libs.jackson.module.kotlin)
|
||||
|
||||
@@ -220,4 +220,13 @@ function applyFilter() {
|
||||
editor.setValue(filtered, -1);
|
||||
}
|
||||
|
||||
function readLines(offset, limit) {
|
||||
const lines = logLines.split("\n")
|
||||
if (offset >= lines.length) {
|
||||
return "<<END OF INPUT>>";
|
||||
}
|
||||
|
||||
return lines.slice(offset, offset + limit).join("\n")
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -11,8 +11,10 @@ import android.webkit.ValueCallback
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import kotlinx.coroutines.Runnable
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import org.signal.core.util.ThreadUtil
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.function.Consumer
|
||||
|
||||
object DebugLogsViewer {
|
||||
@@ -47,6 +49,27 @@ object DebugLogsViewer {
|
||||
ThreadUtil.runOnMain { webview.evaluateJavascript("editor.insert($escaped); logLines+=$escaped;", null) }
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun readLogs(webview: WebView): LogReader {
|
||||
var position = 0
|
||||
return LogReader { size ->
|
||||
val latch = CountDownLatch(1)
|
||||
var result: String? = null
|
||||
ThreadUtil.runOnMain {
|
||||
webview.evaluateJavascript("readLines($position, $size)") { value ->
|
||||
// Annoying, string returns from javascript land are always encoded as JSON strings (wrapped in quotes, various strings escaped, etc)
|
||||
val parsed = JSONArray("[$value]").getString(0)
|
||||
result = parsed.takeUnless { it == "<<END OF INPUT>>" }
|
||||
position += size
|
||||
latch.countDown()
|
||||
}
|
||||
}
|
||||
|
||||
latch.await()
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun scrollToTop(webview: WebView) {
|
||||
webview.evaluateJavascript("editor.scrollToRow(0);", null)
|
||||
@@ -107,4 +130,9 @@ object DebugLogsViewer {
|
||||
fun onSearchClose(webview: WebView) {
|
||||
webview.evaluateJavascript("onSearchClose();", null)
|
||||
}
|
||||
|
||||
fun interface LogReader {
|
||||
/** Returns the next bit of log, containing at most [size] lines (but may be less), or null if there are no logs remaining. */
|
||||
fun nextChunk(size: Int): String?
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user