[Android] Inject android version and device name in crash reports
Sébastien Toque
git at videolan.org
Sat May 18 14:14:34 CEST 2013
vlc-ports/android | branch: master | Sébastien Toque <xilasz at gmail.com> | Sat May 18 09:52:44 2013 +0200| [bf142390a8abb0db79826419389a98538e857007] | committer: Sébastien Toque
Inject android version and device name in crash reports
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=bf142390a8abb0db79826419389a98538e857007
---
vlc-android/src/org/videolan/vlc/AudioService.java | 2 --
vlc-android/src/org/videolan/vlc/Util.java | 2 ++
.../src/org/videolan/vlc/VlcCrashHandler.java | 23 ++++++++++++++------
3 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index fb90a62..556520e 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -134,8 +134,6 @@ public class AudioService extends Service {
e.printStackTrace();
}
- Thread.setDefaultUncaughtExceptionHandler(new VlcCrashHandler());
-
mCallback = new HashMap<IAudioServiceCallback, Integer>();
mMediaList = new ArrayList<Media>();
mPrevious = new Stack<Media>();
diff --git a/vlc-android/src/org/videolan/vlc/Util.java b/vlc-android/src/org/videolan/vlc/Util.java
index a572dd3..59592ff 100644
--- a/vlc-android/src/org/videolan/vlc/Util.java
+++ b/vlc-android/src/org/videolan/vlc/Util.java
@@ -69,6 +69,8 @@ public class Util {
public static LibVLC getLibVlcInstance() throws LibVlcException {
LibVLC instance = LibVLC.getExistingInstance();
if (instance == null) {
+ Thread.setDefaultUncaughtExceptionHandler(new VlcCrashHandler());
+
instance = LibVLC.getInstance();
Context context = VLCApplication.getAppContext();
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
diff --git a/vlc-android/src/org/videolan/vlc/VlcCrashHandler.java b/vlc-android/src/org/videolan/vlc/VlcCrashHandler.java
index 5c39759..1974ef1 100644
--- a/vlc-android/src/org/videolan/vlc/VlcCrashHandler.java
+++ b/vlc-android/src/org/videolan/vlc/VlcCrashHandler.java
@@ -50,18 +50,27 @@ public class VlcCrashHandler implements UncaughtExceptionHandler {
final Writer result = new StringWriter();
final PrintWriter printWriter = new PrintWriter(result);
+
+ // Inject some info about android version and the device, since google can't provide them in the developer console
+ StackTraceElement[] trace = ex.getStackTrace();
+ StackTraceElement[] trace2 = new StackTraceElement[trace.length+3];
+ System.arraycopy(trace, 0, trace2, 0, trace.length);
+ trace2[trace.length+0] = new StackTraceElement("Android", "MODEL", android.os.Build.MODEL, -1);
+ trace2[trace.length+1] = new StackTraceElement("Android", "VERSION", android.os.Build.VERSION.RELEASE, -1);
+ trace2[trace.length+2] = new StackTraceElement("Android", "FINGERPRINT", android.os.Build.FINGERPRINT, -1);
+ ex.setStackTrace(trace2);
+
ex.printStackTrace(printWriter);
String stacktrace = result.toString();
printWriter.close();
-
Log.e(TAG, stacktrace);
- if(!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
- defaultUEH.uncaughtException(thread, ex);
- return; // We can't save the log if SD card is unavailable
+
+ // Save the log on SD card if available
+ if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
+ String sdcardPath = Environment.getExternalStorageDirectory().getPath();
+ writeLog(stacktrace, sdcardPath + "/vlc_crash");
+ writeLogcat(sdcardPath + "/vlc_logcat");
}
- String sdcardPath = Environment.getExternalStorageDirectory().getPath();
- writeLog(stacktrace, sdcardPath + "/vlc_crash");
- writeLogcat(sdcardPath + "/vlc_logcat");
defaultUEH.uncaughtException(thread, ex);
}
More information about the Android
mailing list