[Android] SendCrashActivity: Prevent NPE

Geoffrey Métais git at videolan.org
Tue Oct 8 11:25:06 CEST 2019


vlc-android | branch: 3.2.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Oct  8 11:24:21 2019 +0200| [479f7614be0a72f0de9d4c8de416d574fc5d642a] | committer: Geoffrey Métais

SendCrashActivity: Prevent NPE

(cherry picked from commit 57db5b984905c5b5157c645f8da558c5de136159)

> https://code.videolan.org/videolan/vlc-android/commit/479f7614be0a72f0de9d4c8de416d574fc5d642a
---

 .../src/org/videolan/vlc/gui/SendCrashActivity.kt      | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/SendCrashActivity.kt b/vlc-android/src/org/videolan/vlc/gui/SendCrashActivity.kt
index d2e0c0164..f424b94dc 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SendCrashActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/SendCrashActivity.kt
@@ -83,6 +83,10 @@ class SendCrashActivity : AppCompatActivity(), DebugLogService.Client.Callback,
         launch(start = CoroutineStart.UNDISPATCHED) {
             val emailIntent = withContext(Dispatchers.IO) {
                 client.stop()
+                if (!::logcatZipPath.isInitialized) {
+                    val path = VLCApplication.appContext.getExternalFilesDir(null)?.absolutePath ?: return at withContext null
+                    logcatZipPath =  "$path/logcat.zip"
+                }
                 FileUtils.zip(arrayOf(path), logcatZipPath)
 
                 val emailIntent = Intent(Intent.ACTION_SEND_MULTIPLE)
@@ -91,6 +95,12 @@ class SendCrashActivity : AppCompatActivity(), DebugLogService.Client.Callback,
                 val attachments = ArrayList<Uri>()
                 if (binding.includeMedialibSwitch.isChecked) {
                     if (StoragePermissionsDelegate.getStoragePermission(this at SendCrashActivity, true)) {
+
+                        if (!::dbPath.isInitialized) {
+                            val path = VLCApplication.appContext.getExternalFilesDir(null)?.absolutePath ?: return at withContext null
+                            dbPath = "$path/${AbstractMedialibrary.VLC_MEDIA_DB_NAME}"
+                            dbZipPath = "$path/db.zip"
+                        }
                         val db = File(getDir("db", Context.MODE_PRIVATE).toString() + AbstractMedialibrary.VLC_MEDIA_DB_NAME)
                         val dbFile = File(dbPath)
                         FileUtils.copyFile(db, dbFile)
@@ -131,16 +141,16 @@ class SendCrashActivity : AppCompatActivity(), DebugLogService.Client.Callback,
                 emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                 emailIntent
             }
-            startActivity(emailIntent)
+            emailIntent?.let { startActivity(it) }
             finish()
         }
     }
 
     private lateinit var client: DebugLogService.Client
     private lateinit var binding: SendCrashActivityBinding
-    private val dbPath = VLCApplication.appContext.getExternalFilesDir(null)!!.absolutePath + "/" + AbstractMedialibrary.VLC_MEDIA_DB_NAME
-    private val dbZipPath = VLCApplication.appContext.getExternalFilesDir(null)!!.absolutePath + "/" + "db.zip"
-    private val logcatZipPath = VLCApplication.appContext.getExternalFilesDir(null)!!.absolutePath + "/" + "logcat.zip"
+    private lateinit var dbPath : String
+    private lateinit var dbZipPath : String
+    private lateinit var logcatZipPath : String
     private lateinit var errMsg : String
     private lateinit var errCtx : String
 



More information about the Android mailing list