[Android] Move writeLogcat() to Util

Edward Wang git at videolan.org
Thu Jan 30 15:26:50 CET 2014


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Thu Jan 30 09:05:45 2014 -0500| [e3e65358c9746458944e75471152ec95e358015d] | committer: Edward Wang

Move writeLogcat() to Util

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=e3e65358c9746458944e75471152ec95e358015d
---

 vlc-android/src/org/videolan/vlc/Util.java         |   32 ++++++++++++++++++++
 .../src/org/videolan/vlc/VlcCrashHandler.java      |   25 ++-------------
 2 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/Util.java b/vlc-android/src/org/videolan/vlc/Util.java
index 4a6206f..ef9f400 100644
--- a/vlc-android/src/org/videolan/vlc/Util.java
+++ b/vlc-android/src/org/videolan/vlc/Util.java
@@ -21,11 +21,14 @@
 package org.videolan.vlc;
 
 import java.io.BufferedReader;
+import java.io.BufferedWriter;
 import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
 import java.text.DecimalFormat;
 import java.text.NumberFormat;
 import java.util.ArrayList;
@@ -201,6 +204,35 @@ public class Util {
     }
 
     /**
+     * Writes the current app logcat to a file.
+     *
+     * @param filename The filename to save it as
+     * @throws IOException
+     */
+    public static void writeLogcat(String filename) throws IOException {
+        String[] args = { "logcat", "-v", "time", "-d" };
+
+        Process process = Runtime.getRuntime().exec(args);
+        InputStreamReader input = new InputStreamReader(
+                process.getInputStream());
+        OutputStreamWriter output = new OutputStreamWriter(
+                new FileOutputStream(filename));
+        BufferedReader br = new BufferedReader(input);
+        BufferedWriter bw = new BufferedWriter(output);
+        String line;
+
+        while ((line = br.readLine()) != null) {
+            bw.write(line);
+            bw.newLine();
+        }
+
+        bw.close();
+        output.close();
+        br.close();
+        input.close();
+    }
+
+    /**
      * Convert time to a string
      * @param millis e.g.time/length from file
      * @return formated string (hh:)mm:ss
diff --git a/vlc-android/src/org/videolan/vlc/VlcCrashHandler.java b/vlc-android/src/org/videolan/vlc/VlcCrashHandler.java
index 1974ef1..e4a2493 100644
--- a/vlc-android/src/org/videolan/vlc/VlcCrashHandler.java
+++ b/vlc-android/src/org/videolan/vlc/VlcCrashHandler.java
@@ -20,11 +20,9 @@
 
 package org.videolan.vlc;
 
-import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.StringWriter;
@@ -97,29 +95,10 @@ public class VlcCrashHandler implements UncaughtExceptionHandler {
     private void writeLogcat(String name) {
         CharSequence timestamp = DateFormat.format("yyyyMMdd_kkmmss", System.currentTimeMillis());
         String filename = name + "_" + timestamp + ".log";
-        String[] args = { "logcat", "-v", "time", "-d" };
-
         try {
-            Process process = Runtime.getRuntime().exec(args);
-            InputStreamReader input = new InputStreamReader(
-                    process.getInputStream());
-            OutputStreamWriter output = new OutputStreamWriter(
-                    new FileOutputStream(filename));
-            BufferedReader br = new BufferedReader(input);
-            BufferedWriter bw = new BufferedWriter(output);
-            String line;
-
-            while ((line = br.readLine()) != null) {
-                bw.write(line);
-                bw.newLine();
-            }
-
-            bw.close();
-            output.close();
-            br.close();
-            input.close();
+            Util.writeLogcat(filename);
         } catch (IOException e) {
-            e.printStackTrace();
+            Log.e(TAG, "Cannot write logcat to disk");
         }
     }
 }



More information about the Android mailing list