mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 03:09:04 +01:00
Load the current and previous session's logs.
This commit is contained in:
@@ -95,16 +95,11 @@ public class BriarReportPrimer implements ReportPrimer {
|
||||
}
|
||||
customData.put("Log", sb.toString());
|
||||
|
||||
sb = new StringBuilder();
|
||||
try {
|
||||
File logDir = ctx.getDir("log", MODE_PRIVATE);
|
||||
for (String line : logManager.getPersistedLog(logDir)) {
|
||||
sb.append(line).append('\n');
|
||||
}
|
||||
} catch (IOException e) {
|
||||
sb.append("Could not recover persisted log: ").append(e);
|
||||
}
|
||||
customData.put("Persisted log", sb.toString());
|
||||
customData.put("Persisted log",
|
||||
getPersistedLog(ctx, logManager, false));
|
||||
|
||||
customData.put("Previous persisted log",
|
||||
getPersistedLog(ctx, logManager, true));
|
||||
|
||||
// System memory
|
||||
Object o = ctx.getSystemService(ACTIVITY_SERVICE);
|
||||
@@ -270,6 +265,20 @@ public class BriarReportPrimer implements ReportPrimer {
|
||||
|
||||
return unmodifiableMap(customData);
|
||||
}
|
||||
|
||||
private String getPersistedLog(Context ctx,
|
||||
PersistentLogManager logManager, boolean old) {
|
||||
File logDir = ctx.getDir("log", MODE_PRIVATE);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
try {
|
||||
for (String line : logManager.getPersistedLog(logDir, old)) {
|
||||
sb.append(line).append('\n');
|
||||
}
|
||||
} catch (IOException e) {
|
||||
sb.append("Could not recover persisted log: ").append(e);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private static class SingleShotAndroidExecutor extends Thread {
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.briarproject.bramble.api.settings.Settings;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.logging.Handler;
|
||||
|
||||
@NotNullByDefault
|
||||
@@ -32,6 +32,9 @@ public interface PersistentLogManager {
|
||||
/**
|
||||
* Loads and returns the persistent log entries stored in the given
|
||||
* directory, or an empty list if no log entries are found.
|
||||
*
|
||||
* @param old True if the previous session's log should be loaded, or false
|
||||
* if the current session's log should be loaded
|
||||
*/
|
||||
Collection<String> getPersistedLog(File dir) throws IOException;
|
||||
List<String> getPersistedLog(File dir, boolean old) throws IOException;
|
||||
}
|
||||
|
||||
@@ -22,9 +22,8 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
@@ -134,22 +133,31 @@ class PersistentLogManagerImpl implements PersistentLogManager,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getPersistedLog(File dir) throws IOException {
|
||||
SecretKey oldLogKey = this.oldLogKey;
|
||||
if (oldLogKey == null) {
|
||||
LOG.info("Old log key has not been loaded");
|
||||
return emptyList();
|
||||
public List<String> getPersistedLog(File dir, boolean old)
|
||||
throws IOException {
|
||||
if (old) {
|
||||
SecretKey oldLogKey = this.oldLogKey;
|
||||
if (oldLogKey == null) {
|
||||
LOG.info("Old log key has not been loaded");
|
||||
return emptyList();
|
||||
}
|
||||
return getPersistedLog(new File(dir, OLD_LOG_FILE), oldLogKey);
|
||||
} else {
|
||||
return getPersistedLog(new File(dir, LOG_FILE), logKey);
|
||||
}
|
||||
File oldLogFile = new File(dir, OLD_LOG_FILE);
|
||||
if (oldLogFile.exists()) {
|
||||
LOG.info("Reading old log file");
|
||||
Deque<String> lines = new LinkedList<>();
|
||||
}
|
||||
|
||||
private List<String> getPersistedLog(File logFile, SecretKey key)
|
||||
throws IOException {
|
||||
if (logFile.exists()) {
|
||||
LOG.info("Reading log file");
|
||||
LinkedList<String> lines = new LinkedList<>();
|
||||
int numLines = 0;
|
||||
InputStream in = new FileInputStream(oldLogFile);
|
||||
InputStream in = new FileInputStream(logFile);
|
||||
//noinspection TryFinallyCanBeTryWithResources
|
||||
try {
|
||||
InputStream reader = streamReaderFactory
|
||||
.createLogStreamReader(in, oldLogKey);
|
||||
.createLogStreamReader(in, key);
|
||||
Scanner s = new Scanner(reader);
|
||||
while (s.hasNextLine()) {
|
||||
lines.add(s.nextLine());
|
||||
@@ -162,7 +170,7 @@ class PersistentLogManagerImpl implements PersistentLogManager,
|
||||
in.close();
|
||||
}
|
||||
} else {
|
||||
LOG.info("Old log file does not exist");
|
||||
LOG.info("Log file does not exist");
|
||||
return emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user