Skip to content

Commit

Permalink
Improve debuglog submission.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Feb 26, 2020
1 parent 1faf196 commit 0c254c9
Show file tree
Hide file tree
Showing 38 changed files with 1,575 additions and 1,004 deletions.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -337,12 +337,12 @@
android:label="@string/AndroidManifest__linked_devices"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>

<activity android:name=".LogSubmitActivity"
<activity android:name=".logsubmit.SubmitDebugLogActivity"
android:label="@string/AndroidManifest__log_submit"
android:windowSoftInputMode="stateHidden"
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"/>

<activity android:name=".MediaPreviewActivity"
<activity android:name=".MediaPreviewActivity"
android:label="@string/AndroidManifest__media_preview"
android:windowSoftInputMode="stateHidden"
android:launchMode="singleTask"
Expand Down

This file was deleted.

Expand Up @@ -55,6 +55,7 @@
import org.thoughtcrime.securesms.crypto.InvalidPassphraseException;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
import org.thoughtcrime.securesms.logsubmit.SubmitDebugLogActivity;
import org.thoughtcrime.securesms.util.DynamicIntroTheme;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
Expand Down Expand Up @@ -164,7 +165,7 @@ public void onActivityResult(int requestCode, int resultcode, Intent data) {
}

private void handleLogSubmit() {
Intent intent = new Intent(this, LogSubmitActivity.class);
Intent intent = new Intent(this, SubmitDebugLogActivity.class);
startActivity(intent);
}

Expand Down
@@ -0,0 +1,40 @@
package org.thoughtcrime.securesms.components;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.HorizontalScrollView;

import androidx.annotation.Nullable;

/**
* Unfortunately {@link HorizontalScrollView#setOnScrollChangeListener(OnScrollChangeListener)}
* wasn't added until API 23, so now we have to do this ourselves.
*/
public class ListenableHorizontalScrollView extends HorizontalScrollView {

private OnScrollListener listener;

public ListenableHorizontalScrollView(Context context) {
super(context);
}

public ListenableHorizontalScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public void setOnScrollListener(@Nullable OnScrollListener listener) {
this.listener = listener;
}

@Override
protected void onScrollChanged(int newLeft, int newTop, int oldLeft, int oldTop) {
if (listener != null) {
listener.onScroll(newLeft, oldLeft);
}
super.onScrollChanged(newLeft, newTop, oldLeft, oldTop);
}

public interface OnScrollListener {
void onScroll(int newLeft, int oldLeft);
}
}
Expand Up @@ -100,8 +100,8 @@ public void blockUntilAllWritesFinished() {
}

@WorkerThread
public ListenableFuture<String> getLogs() {
final SettableFuture<String> future = new SettableFuture<>();
public ListenableFuture<CharSequence> getLogs() {
final SettableFuture<CharSequence> future = new SettableFuture<>();

executor.execute(() -> {
StringBuilder builder = new StringBuilder();
Expand All @@ -118,7 +118,7 @@ public ListenableFuture<String> getLogs() {
}
}

future.set(builder.toString());
future.set(builder);
} catch (NoExternalStorageException e) {
future.setException(e);
}
Expand Down
@@ -0,0 +1,32 @@
package org.thoughtcrime.securesms.logsubmit;

import androidx.annotation.NonNull;

/**
* A {@link LogLine} with proper IDs.
*/
public class CompleteLogLine implements LogLine {

private final long id;
private final LogLine line;

public CompleteLogLine(long id, @NonNull LogLine line) {
this.id = id;
this.line = line;
}

@Override
public long getId() {
return id;
}

@Override
public @NonNull String getText() {
return line.getText();
}

@Override
public @NonNull Style getStyle() {
return line.getStyle();
}
}
@@ -0,0 +1,26 @@
package org.thoughtcrime.securesms.logsubmit;

import androidx.annotation.NonNull;

import com.annimon.stream.Stream;

import java.util.List;
import java.util.regex.Pattern;

interface LogLine {

long getId();
@NonNull String getText();
@NonNull Style getStyle();

static List<LogLine> fromText(@NonNull CharSequence text) {
return Stream.of(Pattern.compile("\\n").split(text))
.map(s -> new SimpleLogLine(s, Style.NONE))
.map(line -> (LogLine) line)
.toList();
}

enum Style {
NONE, VERBOSE, DEBUG, INFO, WARNING, ERROR
}
}
@@ -0,0 +1,21 @@
package org.thoughtcrime.securesms.logsubmit;

import android.content.Context;

import androidx.annotation.NonNull;

import java.util.List;

interface LogSection {
/**
* The title to show at the top of the log section.
*/
@NonNull String getTitle();

/**
* The full content of your log section. We use a {@link CharSequence} instead of a
* {@link List<LogLine> } for performance reasons. Scrubbing large swaths of text is faster than
* one line at a time.
*/
@NonNull CharSequence getContent(@NonNull Context context);
}
@@ -0,0 +1,54 @@
package org.thoughtcrime.securesms.logsubmit;

import android.content.Context;

import androidx.annotation.NonNull;

import com.annimon.stream.Stream;

import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.Util;

import java.util.Map;

public class LogSectionFeatureFlags implements LogSection {

@Override
public @NonNull String getTitle() {
return "FEATURE FLAGS";
}

@Override
public @NonNull CharSequence getContent(@NonNull Context context) {
StringBuilder out = new StringBuilder();
Map<String, Boolean> memory = FeatureFlags.getMemoryValues();
Map<String, Boolean> disk = FeatureFlags.getDiskValues();
Map<String, Boolean> forced = FeatureFlags.getForcedValues();
int remoteLength = Stream.of(memory.keySet()).map(String::length).max(Integer::compareTo).orElse(0);
int diskLength = Stream.of(disk.keySet()).map(String::length).max(Integer::compareTo).orElse(0);
int forcedLength = Stream.of(forced.keySet()).map(String::length).max(Integer::compareTo).orElse(0);

out.append("-- Memory\n");
for (Map.Entry<String, Boolean> entry : memory.entrySet()) {
out.append(Util.rightPad(entry.getKey(), remoteLength)).append(": ").append(entry.getValue()).append("\n");
}
out.append("\n");

out.append("-- Disk\n");
for (Map.Entry<String, Boolean> entry : disk.entrySet()) {
out.append(Util.rightPad(entry.getKey(), diskLength)).append(": ").append(entry.getValue()).append("\n");
}
out.append("\n");

out.append("-- Forced\n");
if (forced.isEmpty()) {
out.append("None\n");
} else {
for (Map.Entry<String, Boolean> entry : forced.entrySet()) {
out.append(Util.rightPad(entry.getKey(), forcedLength)).append(": ").append(entry.getValue()).append("\n");
}
}

return out;
}
}
@@ -0,0 +1,22 @@
package org.thoughtcrime.securesms.logsubmit;

import android.content.Context;

import androidx.annotation.NonNull;

import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;

import java.util.List;

public class LogSectionJobs implements LogSection {

@Override
public @NonNull String getTitle() {
return "JOBS";
}

@Override
public @NonNull CharSequence getContent(@NonNull Context context) {
return ApplicationDependencies.getJobManager().getDebugInfo();
}
}
@@ -0,0 +1,38 @@
package org.thoughtcrime.securesms.logsubmit;

import android.content.Context;

import androidx.annotation.NonNull;

import org.thoughtcrime.securesms.logging.Log;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class LogSectionLogcat implements LogSection {

@Override
public @NonNull String getTitle() {
return "LOGCAT";
}

@Override
public @NonNull CharSequence getContent(@NonNull Context context) {
try {
final Process process = Runtime.getRuntime().exec("logcat -d");
final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
final StringBuilder log = new StringBuilder();
final String separator = System.getProperty("line.separator");

String line;
while ((line = bufferedReader.readLine()) != null) {
log.append(line);
log.append(separator);
}
return log.toString();
} catch (IOException ioe) {
return "Failed to retrieve.";
}
}
}
@@ -0,0 +1,26 @@
package org.thoughtcrime.securesms.logsubmit;

import android.content.Context;

import androidx.annotation.NonNull;

import org.thoughtcrime.securesms.ApplicationContext;

import java.util.concurrent.ExecutionException;

public class LogSectionLogger implements LogSection {

@Override
public @NonNull String getTitle() {
return "LOGGER";
}

@Override
public @NonNull CharSequence getContent(@NonNull Context context) {
try {
return ApplicationContext.getInstance(context).getPersistentLogger().getLogs().get();
} catch (ExecutionException | InterruptedException e) {
return "Failed to retrieve.";
}
}
}

0 comments on commit 0c254c9

Please sign in to comment.