diff options
author | steckbrief <steckbrief@chefmail.de> | 2015-12-02 23:02:10 +0100 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2015-12-02 23:02:10 +0100 |
commit | a0dcdf5c762ff28edeea34c2cfe654c31889abc7 (patch) | |
tree | 9e92fc9f9f0bc44c2593c00e29290ad8f392747e /src/main/java/de/thedevstack/android/logcat/tasks | |
parent | 6bc277152a8e1bcf5347d3e1d60c93dfc904ca23 (diff) | |
parent | 9efc13983516c4c37540eb9544f8fa411ded81c7 (diff) |
Merge remote-tracking branch 'remotes/origin/trz/rename' into trz/rebase
Diffstat (limited to 'src/main/java/de/thedevstack/android/logcat/tasks')
-rw-r--r-- | src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java b/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java new file mode 100644 index 00000000..b9fa450b --- /dev/null +++ b/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java @@ -0,0 +1,67 @@ +package de.thedevstack.android.logcat.tasks; + +import android.os.AsyncTask; +import de.thedevstack.conversationsplus.utils.Logging; +import android.widget.ArrayAdapter; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; + +import de.thedevstack.conversationsplus.utils.StreamUtil; + +/** + * Created by tzur on 20.11.2015. + */ +public class ReadLogCatAsyncTask extends AsyncTask<Void, Void, String[]> { + private final ArrayAdapter<String> arrayAdapter; + 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" }; + + public ReadLogCatAsyncTask(ArrayAdapter<String> arrayAdapter) { + this.arrayAdapter = arrayAdapter; + } + @Override + protected String[] doInBackground(Void... params) { + ArrayList<String> logCatOutput = new ArrayList<>(); + BufferedReader bufferedReader = null; + try { + Process process = Runtime.getRuntime().exec(ReadLogCatAsyncTask.LOG_CAT_CMD); + bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line = ""; + 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); + } + logCatOutput.trimToSize(); + return logCatOutput.toArray(new String[0]); + } + + @Override + protected void onPostExecute(String[] items) { + this.arrayAdapter.clear(); + if (null != items && items.length > 0) { + for (String item : items) { + if (!filter(item)) { + this.arrayAdapter.add(item); + } + } + } + } + + protected boolean filter(String item) { + for (String whiteListed : ReadLogCatAsyncTask.WHITE_LIST) { + if (item.contains(whiteListed)) { + return false; + } + } + return true; + } +} |