mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-20 02:58:45 +00:00
Fix potential ANR in debug log viewer.
This commit is contained in:
committed by
Greyson Parrelli
parent
308f4c817f
commit
5e8d72e19e
@@ -27,6 +27,7 @@ import androidx.lifecycle.ViewModelProvider;
|
|||||||
|
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||||
|
|
||||||
|
import org.signal.core.util.concurrent.SignalExecutors;
|
||||||
import org.signal.debuglogsviewer.DebugLogsViewer;
|
import org.signal.debuglogsviewer.DebugLogsViewer;
|
||||||
import org.thoughtcrime.securesms.BaseActivity;
|
import org.thoughtcrime.securesms.BaseActivity;
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
@@ -357,6 +358,7 @@ public class SubmitDebugLogActivity extends BaseActivity {
|
|||||||
hasPresentedLines = true;
|
hasPresentedLines = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SignalExecutors.BOUNDED.execute(() -> {
|
||||||
int chunkSize = 1000;
|
int chunkSize = 1000;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
@@ -378,6 +380,7 @@ public class SubmitDebugLogActivity extends BaseActivity {
|
|||||||
if (lineBuilder.length() > 0) {
|
if (lineBuilder.length() > 0) {
|
||||||
DebugLogsViewer.presentLines(logWebView, lineBuilder.toString());
|
DebugLogsViewer.presentLines(logWebView, lineBuilder.toString());
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void presentMode(@NonNull SubmitDebugLogViewModel.Mode mode) {
|
private void presentMode(@NonNull SubmitDebugLogViewModel.Mode mode) {
|
||||||
|
|||||||
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
package org.signal.debuglogsviewer
|
package org.signal.debuglogsviewer
|
||||||
|
|
||||||
import android.content.ClipData
|
|
||||||
import android.content.ClipboardManager
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.webkit.ValueCallback
|
import android.webkit.ValueCallback
|
||||||
@@ -14,10 +12,9 @@ import android.webkit.WebView
|
|||||||
import android.webkit.WebViewClient
|
import android.webkit.WebViewClient
|
||||||
import kotlinx.coroutines.Runnable
|
import kotlinx.coroutines.Runnable
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
import org.signal.core.util.ThreadUtil
|
||||||
import java.util.function.Consumer
|
import java.util.function.Consumer
|
||||||
|
|
||||||
var readOnly = true
|
|
||||||
|
|
||||||
object DebugLogsViewer {
|
object DebugLogsViewer {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun initWebView(webview: WebView, context: Context, onFinished: Runnable) {
|
fun initWebView(webview: WebView, context: Context, onFinished: Runnable) {
|
||||||
@@ -47,7 +44,7 @@ object DebugLogsViewer {
|
|||||||
fun presentLines(webview: WebView, lines: String) {
|
fun presentLines(webview: WebView, lines: String) {
|
||||||
// Set the debug log lines
|
// Set the debug log lines
|
||||||
val escaped = JSONObject.quote(lines)
|
val escaped = JSONObject.quote(lines)
|
||||||
webview.evaluateJavascript("editor.insert($escaped); logLines+=$escaped;", null)
|
ThreadUtil.runOnMain { webview.evaluateJavascript("editor.insert($escaped); logLines+=$escaped;", null) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@@ -110,26 +107,4 @@ object DebugLogsViewer {
|
|||||||
fun onSearchClose(webview: WebView) {
|
fun onSearchClose(webview: WebView) {
|
||||||
webview.evaluateJavascript("onSearchClose();", null)
|
webview.evaluateJavascript("onSearchClose();", null)
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun onEdit(webview: WebView) {
|
|
||||||
readOnly = !readOnly
|
|
||||||
webview.evaluateJavascript("editor.setReadOnly($readOnly);", null)
|
|
||||||
}
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun onCancelEdit(webview: WebView, lines: String) {
|
|
||||||
readOnly = !readOnly
|
|
||||||
webview.evaluateJavascript("editor.setReadOnly($readOnly);", null)
|
|
||||||
webview.evaluateJavascript("editor.setValue($lines, -1);", null)
|
|
||||||
}
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun onCopy(webview: WebView, context: Context, appName: String) {
|
|
||||||
webview.evaluateJavascript("editor.getValue();") { value ->
|
|
||||||
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
|
||||||
val clip = ClipData.newPlainText(appName, value)
|
|
||||||
clipboard.setPrimaryClip(clip)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user