aboutsummaryrefslogtreecommitdiffstats
path: root/libs/thedevstacklogcat
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2015-12-17 21:09:18 +0100
committersteckbrief <steckbrief@chefmail.de>2015-12-17 21:09:18 +0100
commit2fb31bcc3f9e4920891765ab8e0cf2e33227ea3e (patch)
treee3f4790a2c53bbe824636a94d881de9bcabff6c5 /libs/thedevstacklogcat
parentc26335f3e366110366eb89025a42875bcb7840a9 (diff)
Log error in case logcat command could not be executed; Show toast in case nothing is copied
Diffstat (limited to 'libs/thedevstacklogcat')
-rw-r--r--libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java31
-rw-r--r--libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java14
2 files changed, 39 insertions, 6 deletions
diff --git a/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java
index 1136faf8..e16009ee 100644
--- a/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java
+++ b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java
@@ -9,6 +9,7 @@ import java.io.InputStreamReader;
import java.util.ArrayList;
import de.thedevstack.android.logcat.Logging;
+import de.thedevstack.android.logcat.adapters.LogCatArrayAdapter;
/**
* Task to read the logcat of the App.
@@ -25,7 +26,7 @@ public class ReadLogCatAsyncTask extends AsyncTask<Void, Void, String[]> {
/**
* The array adapter to publish the log messages to.
*/
- private final ArrayAdapter<String> arrayAdapter;
+ private final LogCatArrayAdapter arrayAdapter;
/**
* The command to execute logcat.
*/
@@ -39,7 +40,7 @@ public class ReadLogCatAsyncTask extends AsyncTask<Void, Void, String[]> {
* Initializes the Task with the array adapter to publish the log messages to.
* @param arrayAdapter the array adapter
*/
- public ReadLogCatAsyncTask(ArrayAdapter<String> arrayAdapter) {
+ public ReadLogCatAsyncTask(LogCatArrayAdapter arrayAdapter) {
this.arrayAdapter = arrayAdapter;
}
@@ -52,15 +53,35 @@ public class ReadLogCatAsyncTask extends AsyncTask<Void, Void, String[]> {
protected String[] doInBackground(Void... params) {
ArrayList<String> logCatOutput = new ArrayList<>();
BufferedReader bufferedReader = null;
+ BufferedReader errorReader = null;
try {
Process process = Runtime.getRuntime().exec(ReadLogCatAsyncTask.LOG_CAT_CMD);
bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+ errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String line = "";
while ((line = bufferedReader.readLine()) != null) {
logCatOutput.add(line);
}
+
+ String errorLine = "";
+ StringBuilder sb = new StringBuilder();
+ while ((errorLine = errorReader.readLine()) != null) {
+ sb.append(errorLine);
+ sb.append('\n');
+ }
+ int exitValue = process.waitFor();
+
+ Logging.d("ReadLogCat", "Logcat command returned with exitValue '" + exitValue + "'.");
+
+ String errorMessage = sb.toString();
+ if (0 != exitValue && !errorMessage.isEmpty()) {
+ Logging.e("ReadLogCat", errorMessage);
+ logCatOutput.add(errorMessage);
+ }
} catch (IOException e) {
Logging.e("ReadLogCat", "error while retrieving information from logcat: " + e.getMessage(), e);
+ } catch (InterruptedException e) {
+ Logging.e("ReadLogCat", "error while retrieving information from logcat: " + e.getMessage(), e);
} finally {
if (null != bufferedReader) {
try {
@@ -68,6 +89,12 @@ public class ReadLogCatAsyncTask extends AsyncTask<Void, Void, String[]> {
} catch (IOException e) {
}
}
+ if (null != errorReader) {
+ try {
+ errorReader.close();
+ } catch (IOException e) {
+ }
+ }
}
logCatOutput.trimToSize();
return logCatOutput.toArray(new String[0]);
diff --git a/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java
index 6568a2c5..1be04c9c 100644
--- a/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java
+++ b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java
@@ -8,6 +8,7 @@ import android.widget.Toast;
import java.util.ArrayList;
+import de.thedevstack.android.logcat.Logging;
import de.thedevstack.android.logcat.adapters.LogCatArrayAdapter;
/**
@@ -16,16 +17,19 @@ import de.thedevstack.android.logcat.adapters.LogCatArrayAdapter;
public class LogCatOutputCopyOnClickListener implements View.OnClickListener {
private final LogCatArrayAdapter logCatOutputAdapter;
private final Context context;
- private final int resIdForToast;
+ private final int resIdLogcatCopied;
+ private final int resIdLogcatNotCopied;
- public LogCatOutputCopyOnClickListener(Context context, LogCatArrayAdapter logCatOutputAdapter, int resIdForToast) {
+ public LogCatOutputCopyOnClickListener(Context context, LogCatArrayAdapter logCatOutputAdapter, int resIdLogcatCopied, int resIdLogcatNotCopied) {
this.logCatOutputAdapter = logCatOutputAdapter;
this.context = context;
- this.resIdForToast = resIdForToast;
+ this.resIdLogcatCopied = resIdLogcatCopied;
+ this.resIdLogcatNotCopied = resIdLogcatNotCopied;
}
@Override
public void onClick(View v) {
+ Logging.d("copylogcat", "Start Copying log cat");
ArrayList<String> items = this.logCatOutputAdapter.getItems();
if (null != items && !items.isEmpty()) {
StringBuilder sb = new StringBuilder();
@@ -36,7 +40,9 @@ public class LogCatOutputCopyOnClickListener implements View.OnClickListener {
ClipboardManager clipboard = (ClipboardManager) this.context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("c+logcat", sb.toString());
clipboard.setPrimaryClip(clip);
- Toast.makeText(this.context, this.context.getText(this.resIdForToast), Toast.LENGTH_LONG).show();
+ Toast.makeText(this.context, this.context.getText(this.resIdLogcatCopied), Toast.LENGTH_LONG).show();
+ } else {
+ Toast.makeText(this.context, this.context.getText(this.resIdLogcatNotCopied), Toast.LENGTH_LONG).show();
}
}
}