Commit e3e65358 authored by Edward Wang's avatar Edward Wang
Browse files

Move writeLogcat() to Util

parent 2439df36
......@@ -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;
......@@ -200,6 +203,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
......
......@@ -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");
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment