aboutsummaryrefslogtreecommitdiffstats
path: root/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java (renamed from src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java)52
1 files changed, 45 insertions, 7 deletions
diff --git a/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java
index b9fa450b..1136faf8 100644
--- a/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java
+++ b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java
@@ -1,7 +1,6 @@
package de.thedevstack.android.logcat.tasks;
import android.os.AsyncTask;
-import de.thedevstack.conversationsplus.utils.Logging;
import android.widget.ArrayAdapter;
import java.io.BufferedReader;
@@ -9,20 +8,46 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
-import de.thedevstack.conversationsplus.utils.StreamUtil;
+import de.thedevstack.android.logcat.Logging;
/**
- * Created by tzur on 20.11.2015.
+ * Task to read the logcat of the App.
+ * The command <code>logcat -d -v time</code> is used to load the logs.
+ * This reader uses a white list to restrict the messages to display, otherwise it might be flooded with useless log messages.
+ * The white list checks if a log messages contains one of the following strings:
+ * <ul>
+ * <li>{@value Logging#LOG_TAG_PREFIX}</li>
+ * <li><code>E/</code> - for every error message</li>
+ * <li><code>W/</code> - for every warning message</li>
+ * </ul>
*/
public class ReadLogCatAsyncTask extends AsyncTask<Void, Void, String[]> {
+ /**
+ * The array adapter to publish the log messages to.
+ */
private final ArrayAdapter<String> arrayAdapter;
+ /**
+ * The command to execute logcat.
+ */
private static final String[] LOG_CAT_CMD = { "logcat", "-d", "-v", "time"};
- private static final String[] WHITE_LIST = { "thedevstack.", "E/", "W/" };
- private static final String[] BLACK_LIST = { "D/TextLayoutCache" };
+ /**
+ * The white list to filter log messages.
+ */
+ private static final String[] WHITE_LIST = { Logging.getLogTagPrefix(), "E/", "W/" };
+ /**
+ * Initializes the Task with the array adapter to publish the log messages to.
+ * @param arrayAdapter the array adapter
+ */
public ReadLogCatAsyncTask(ArrayAdapter<String> arrayAdapter) {
this.arrayAdapter = arrayAdapter;
}
+
+ /**
+ * Executes the logcat command, reads the output of the command and returns all log messages.
+ * @param params no params will be passed. (interface compliance)
+ * @return the array of log messages
+ */
@Override
protected String[] doInBackground(Void... params) {
ArrayList<String> logCatOutput = new ArrayList<>();
@@ -34,16 +59,24 @@ public class ReadLogCatAsyncTask extends AsyncTask<Void, Void, String[]> {
while ((line = bufferedReader.readLine()) != null) {
logCatOutput.add(line);
}
- bufferedReader.close();
} catch (IOException e) {
Logging.e("ReadLogCat", "error while retrieving information from logcat: " + e.getMessage(), e);
} finally {
- StreamUtil.close(bufferedReader);
+ if (null != bufferedReader) {
+ try {
+ bufferedReader.close();
+ } catch (IOException e) {
+ }
+ }
}
logCatOutput.trimToSize();
return logCatOutput.toArray(new String[0]);
}
+ /**
+ * Clears the array adapter and adds the filtered log messages.
+ * @param items all log messages
+ */
@Override
protected void onPostExecute(String[] items) {
this.arrayAdapter.clear();
@@ -56,6 +89,11 @@ public class ReadLogCatAsyncTask extends AsyncTask<Void, Void, String[]> {
}
}
+ /**
+ * Checks whether a log message contains a white listed string or not.
+ * @param item the item to filter
+ * @return <code>true</code> if the string should be filtered (removed from the list) <code>false</code> otherwise.
+ */
protected boolean filter(String item) {
for (String whiteListed : ReadLogCatAsyncTask.WHITE_LIST) {
if (item.contains(whiteListed)) {