[Android] Fix NPE on TV Channel creation

Nicolas Pomepuy git at videolan.org
Tue Mar 17 08:40:39 CET 2020


vlc-android | branch: 3.2.x | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Mar 17 07:05:40 2020 +0100| [f3ede43517251bbb5fc7d69049c760a984eb72b1] | committer: Nicolas Pomepuy

Fix NPE on TV Channel creation

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

 tools/src/main/java/videolan/org/commontools/TvChannelUtils.kt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/src/main/java/videolan/org/commontools/TvChannelUtils.kt b/tools/src/main/java/videolan/org/commontools/TvChannelUtils.kt
index a51b0e0b7..330773c74 100644
--- a/tools/src/main/java/videolan/org/commontools/TvChannelUtils.kt
+++ b/tools/src/main/java/videolan/org/commontools/TvChannelUtils.kt
@@ -27,10 +27,10 @@ import android.content.SharedPreferences
 import android.database.Cursor
 import android.net.Uri
 import android.os.Build
+import android.util.Log
 import androidx.annotation.RequiresApi
 import androidx.annotation.WorkerThread
 import androidx.tvprovider.media.tv.*
-import android.util.Log
 
 typealias ProgramsList = MutableList<TvPreviewProgram>
 
@@ -58,6 +58,7 @@ fun createOrUpdateChannel(prefs: SharedPreferences, context: Context, name: Stri
             .setAppLinkIntentUri(createUri(appId))
     if (channelId == -1L) {
         val channelUri = context.contentResolver.insert(TvContractCompat.Channels.CONTENT_URI, builder.build().toContentValues())
+                ?: return -1L
         channelId = ContentUris.parseId(channelUri)
         prefs.edit().putLong(KEY_TV_CHANNEL_ID, channelId).apply()
         TvContractCompat.requestChannelBrowsable(context, channelId)



More information about the Android mailing list