mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-20 02:58:45 +00:00
Fix race condition where not all logs would be added to the viewer.
This commit is contained in:
@@ -27,7 +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.core.util.ThreadUtil;
|
||||||
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;
|
||||||
@@ -44,9 +44,9 @@ import org.thoughtcrime.securesms.util.views.CircularProgressMaterialButton;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
|
||||||
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
import io.reactivex.rxjava3.disposables.CompositeDisposable;
|
||||||
import io.reactivex.rxjava3.disposables.Disposable;
|
import io.reactivex.rxjava3.disposables.Disposable;
|
||||||
|
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||||
|
|
||||||
public class SubmitDebugLogActivity extends BaseActivity {
|
public class SubmitDebugLogActivity extends BaseActivity {
|
||||||
|
|
||||||
@@ -346,27 +346,29 @@ public class SubmitDebugLogActivity extends BaseActivity {
|
|||||||
|
|
||||||
private void subscribeToLogLines() {
|
private void subscribeToLogLines() {
|
||||||
Disposable disposable = viewModel.getLogLinesObservable()
|
Disposable disposable = viewModel.getLogLinesObservable()
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(Schedulers.io())
|
||||||
.subscribe(this::presentLines, throwable -> {
|
.subscribe(this::appendLines, throwable -> {
|
||||||
// Handle error
|
// Handle error
|
||||||
this.progressCard.setVisibility(View.GONE);
|
ThreadUtil.runOnMain(() -> {
|
||||||
|
this.progressCard.setVisibility(View.GONE);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
disposables.add(disposable);
|
disposables.add(disposable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void presentLines(@NonNull List<String> lines) {
|
private void appendLines(@NonNull List<String> lines) {
|
||||||
warningBanner.setVisibility(View.VISIBLE);
|
ThreadUtil.runOnMain(() -> {
|
||||||
submitButton.setVisibility(View.VISIBLE);
|
warningBanner.setVisibility(View.VISIBLE);
|
||||||
|
submitButton.setVisibility(View.VISIBLE);
|
||||||
SignalExecutors.BOUNDED.execute(() -> {
|
|
||||||
StringBuilder lineBuilder = new StringBuilder();
|
|
||||||
|
|
||||||
for (String line : lines) {
|
|
||||||
lineBuilder.append(line).append("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
DebugLogsViewer.appendLines(logWebView, lineBuilder.toString());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
StringBuilder lineBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
for (String line : lines) {
|
||||||
|
lineBuilder.append(line).append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
DebugLogsViewer.appendLines(logWebView, lineBuilder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void presentMode(@NonNull SubmitDebugLogViewModel.Mode mode) {
|
private void presentMode(@NonNull SubmitDebugLogViewModel.Mode mode) {
|
||||||
|
|||||||
@@ -220,6 +220,11 @@ function applyFilter() {
|
|||||||
editor.setValue(filtered, -1);
|
editor.setValue(filtered, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function appendLines(lines) {
|
||||||
|
editor.session.insert({ row: editor.session.getLength(), column: 0}, lines);
|
||||||
|
logLines += lines;
|
||||||
|
}
|
||||||
|
|
||||||
function readLines(offset, limit) {
|
function readLines(offset, limit) {
|
||||||
const lines = logLines.split("\n")
|
const lines = logLines.split("\n")
|
||||||
if (offset >= lines.length) {
|
if (offset >= lines.length) {
|
||||||
|
|||||||
@@ -46,7 +46,11 @@ object DebugLogsViewer {
|
|||||||
fun appendLines(webview: WebView, lines: String) {
|
fun appendLines(webview: WebView, lines: String) {
|
||||||
// Set the debug log lines
|
// Set the debug log lines
|
||||||
val escaped = JSONObject.quote(lines)
|
val escaped = JSONObject.quote(lines)
|
||||||
ThreadUtil.runOnMain { webview.evaluateJavascript("editor.insert($escaped); logLines+=$escaped;", null) }
|
val latch = CountDownLatch(1)
|
||||||
|
ThreadUtil.runOnMain {
|
||||||
|
webview.evaluateJavascript("appendLines($escaped)") { latch.countDown() }
|
||||||
|
}
|
||||||
|
latch.await()
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
|||||||
Reference in New Issue
Block a user