From 82850f100f5fe48374793b903b23b2af0c87b811 Mon Sep 17 00:00:00 2001 From: F43nd1r Date: Tue, 30 Aug 2016 14:59:22 +0200 Subject: [PATCH] simplify logcatcollector --- .../org/acra/collector/LogCatCollector.java | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/acra/collector/LogCatCollector.java b/src/main/java/org/acra/collector/LogCatCollector.java index 646a9fcdc2..3fd246db92 100644 --- a/src/main/java/org/acra/collector/LogCatCollector.java +++ b/src/main/java/org/acra/collector/LogCatCollector.java @@ -24,12 +24,10 @@ import org.acra.ACRA; import org.acra.annotation.ReportsCrashes; import org.acra.config.ACRAConfiguration; -import org.acra.collections.BoundedLinkedList; import org.acra.util.IOUtils; import java.io.IOException; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; import static org.acra.ACRA.LOG_TAG; @@ -63,10 +61,7 @@ class LogCatCollector { */ public String collectLogCat(@NonNull ACRAConfiguration config, @Nullable String bufferName) { final int myPid = android.os.Process.myPid(); - String myPidStr = null; - if (config.logcatFilterByPid() && myPid > 0) { - myPidStr = Integer.toString(myPid) +"):"; - } + final String myPidStr = config.logcatFilterByPid() && myPid > 0 ? Integer.toString(myPid) + "):" : null; final List commandLine = new ArrayList(); commandLine.add("logcat"); @@ -92,8 +87,7 @@ public String collectLogCat(@NonNull ACRAConfiguration config, @Nullable String tailCount = -1; } - final LinkedList logcatBuf = new BoundedLinkedList(tailCount > 0 ? tailCount - : DEFAULT_TAIL_COUNT); + String logcat = "N/A"; commandLine.addAll(logcatArgumentsList); try { @@ -112,18 +106,17 @@ public void run() { } }).start(); - final String finalMyPidStr = myPidStr; - logcatBuf.add(IOUtils.streamToString(process.getInputStream(), new Predicate() { + logcat = IOUtils.streamToString(process.getInputStream(), new Predicate() { @Override public boolean apply(String s) { - return finalMyPidStr == null || s.contains(finalMyPidStr); + return myPidStr == null || s.contains(myPidStr); } - })); + }, tailCount > 0 ? tailCount : DEFAULT_TAIL_COUNT); } catch (IOException e) { ACRA.log.e(LOG_TAG, "LogCatCollector.collectLogCat could not retrieve data.", e); } - return logcatBuf.toString(); + return logcat; } }