[Android] Add a watermark to forced logged exceptions

Nicolas Pomepuy git at videolan.org
Tue Oct 26 06:45:23 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Oct 20 08:35:27 2021 +0200| [350bab5649c0ab3fa91f3bc3995edcd1079cef59] | committer: Nicolas Pomepuy

Add a watermark to forced logged exceptions

That way it will be easier to find them in the crash reporter email

> https://code.videolan.org/videolan/vlc-android/commit/350bab5649c0ab3fa91f3bc3995edcd1079cef59
---

 .../src/main/java/org/videolan/resources/util/VLCCrashHandler.kt     | 5 +++--
 application/vlc-android/src/org/videolan/vlc/PlaybackService.kt      | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/application/resources/src/main/java/org/videolan/resources/util/VLCCrashHandler.kt b/application/resources/src/main/java/org/videolan/resources/util/VLCCrashHandler.kt
index 22a3b5ad6..b4b6a8fae 100644
--- a/application/resources/src/main/java/org/videolan/resources/util/VLCCrashHandler.kt
+++ b/application/resources/src/main/java/org/videolan/resources/util/VLCCrashHandler.kt
@@ -52,17 +52,18 @@ class VLCCrashHandler : UncaughtExceptionHandler {
          * @param ex: the [Throwable] to log
          * @return the [Throwable] with versions appended
          */
-        fun saveLog(ex: Throwable):Throwable {
+        fun saveLog(ex: Throwable, watermark:String = ""):Throwable {
             val result = StringWriter()
             val printWriter = PrintWriter(result)
 
             // Inject some info about android version and the device, since google can't provide them in the developer console
             val trace = ex.stackTrace
-            val trace2 = arrayOfNulls<StackTraceElement>(trace.size + 3)
+            val trace2 = arrayOfNulls<StackTraceElement>(trace.size + if (watermark.isNotEmpty()) 4  else 3)
             System.arraycopy(trace, 0, trace2, 0, trace.size)
             trace2[trace.size + 0] = StackTraceElement("Android", "MODEL", android.os.Build.MODEL, -1)
             trace2[trace.size + 1] = StackTraceElement("Android", "VERSION", android.os.Build.VERSION.RELEASE, -1)
             trace2[trace.size + 2] = StackTraceElement("Android", "FINGERPRINT", android.os.Build.FINGERPRINT, -1)
+           if (watermark.isNotEmpty()) trace2[trace.size + 3] = StackTraceElement("VLC", "Watermark", watermark, -1)
             ex.stackTrace = trace2
 
             ex.printStackTrace(printWriter)
diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index d86598f83..687d56335 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -1223,7 +1223,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
                     }
                 } catch (e: java.lang.NullPointerException) {
                     Log.e("PlaybackService", "Caught NullPointerException", e)
-                    VLCCrashHandler.saveLog(e)
+                    VLCCrashHandler.saveLog(e, "NullPointerException in PlaybackService updateMediaQueue")
                 }
             }
             artworkToUriCache.clear()
@@ -1290,7 +1290,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
                         it.add(MediaSessionCompat.QueueItem(mediaDesc, (fromIndex + position).toLong()))
                     } catch (e: NullPointerException) {
                         Log.e("PlaybackService", e.message, e)
-                        VLCCrashHandler.saveLog(e)
+                        VLCCrashHandler.saveLog(e, "NullPointerException in PlaybackService buildQueue")
                     }
                 }
             }



More information about the Android mailing list