[Android] Fix UninitializedPropertyAccessException when deferredGrant is not initialized

Nicolas Pomepuy git at videolan.org
Tue Nov 30 06:28:32 UTC 2021


vlc-android | branch: 3.4.x | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Nov 29 09:23:51 2021 +0100| [fe7ca3b658659a298290eed14c8272816823219d] | committer: Nicolas Pomepuy

Fix UninitializedPropertyAccessException when deferredGrant is not initialized

(cherry picked from commit bf18f6a24c7655645a631d7d5f93f652e603bec2)

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

 .../src/org/videolan/vlc/gui/helpers/hf/BaseHeadlessFragment.kt       | 4 ++++
 .../src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.kt | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/hf/BaseHeadlessFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/hf/BaseHeadlessFragment.kt
index dba9c2ddf..984192fd9 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/hf/BaseHeadlessFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/hf/BaseHeadlessFragment.kt
@@ -63,6 +63,10 @@ class PermissionViewmodel : ViewModel() {
     val isCompleted : Boolean
         get() = ::deferredGrant.isInitialized && deferredGrant.isCompleted
 
+    fun complete(value:Boolean) {
+        if (::deferredGrant.isInitialized) deferredGrant.complete(value)
+    }
+
     fun setupDeferred() {
         deferredGrant = CompletableDeferred<Boolean>().apply {
             invokeOnCompletion { permissionRationaleShown = false }
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.kt
index 053a809a4..c10321d5e 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/hf/StoragePermissionsDelegate.kt
@@ -115,7 +115,7 @@ class StoragePermissionsDelegate : BaseHeadlessFragment() {
                     if(activity == null) return at registerForActivityResult
                     if (isGranted || isExternalStorageManager()) {
                         storageAccessGranted.value = true
-                        model.deferredGrant.complete(true)
+                        model.complete(true)
                         exit()
                         return at registerForActivityResult
                     }



More information about the Android mailing list