[Android] Fix fine permission for Android < 33

Nicolas Pomepuy git at videolan.org
Mon Nov 25 11:07:02 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Nov 21 07:22:22 2024 +0100| [24d19ea0f995d262b544bb9bd1dc6a2540fdbce0] | committer: Duncan McNamara

Fix fine permission for Android < 33

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

 .../vlc/gui/dialogs/PermissionListDialog.kt        | 27 ++++++++++++++++------
 .../vlc/gui/onboarding/OnboardingActivity.kt       |  6 ++---
 .../src/org/videolan/vlc/util/Permissions.kt       |  2 +-
 3 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/PermissionListDialog.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/PermissionListDialog.kt
index 7404cd8faf..4cdb0d586f 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/PermissionListDialog.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/PermissionListDialog.kt
@@ -46,6 +46,7 @@ import org.videolan.tools.setInvisible
 import org.videolan.tools.setVisible
 import org.videolan.vlc.R
 import org.videolan.vlc.databinding.DialogPermissionsBinding
+import org.videolan.vlc.gui.helpers.hf.StoragePermissionsDelegate.Companion.getStoragePermission
 import org.videolan.vlc.util.Permissions
 
 
@@ -128,7 +129,7 @@ class PermissionListDialog : VLCBottomSheetDialogFragment() {
 
         when {
             Permissions.hasAllAccess(requireActivity()) -> binding.manageAllPermsCheck.isChecked = true
-            Permissions.hasAnyFileFineAccess(requireActivity()) -> binding.manageMediaPermsCheck.isChecked = true
+            Permissions.canReadStorage(requireActivity()) -> binding.manageMediaPermsCheck.isChecked = true
             else -> binding.noAccessCheck.isChecked = true
         }
 
@@ -223,17 +224,24 @@ class PermissionListDialog : VLCBottomSheetDialogFragment() {
             if (Permissions.hasAnyFileFineAccess(requireActivity())) {
                 Permissions.showAppSettingsPage(requireActivity())
                 (it as RadioButton).isChecked = false
+            } else if (Permissions.canReadStorage(requireActivity())) {
+                Permissions.showAppSettingsPage(requireActivity())
+                (it as RadioButton).isChecked = false
             } else if (Permissions.hasAllAccess(requireActivity())) {
                 (it as RadioButton).isChecked = false
                 binding.manageAllPermsCheck.background  = ContextCompat.getDrawable(requireActivity(), R.drawable.rounded_corners_permissions_warning)
                 showWarning()
             } else
-                ActivityCompat.requestPermissions(
-                    requireActivity(), arrayOf(
-                        Manifest.permission.READ_MEDIA_VIDEO,
-                        Manifest.permission.READ_MEDIA_AUDIO
-                    ), Permissions.FINE_STORAGE_PERMISSION_REQUEST_CODE
-                )
+                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
+                    ActivityCompat.requestPermissions(
+                        requireActivity(), arrayOf(
+                            Manifest.permission.READ_MEDIA_VIDEO,
+                            Manifest.permission.READ_MEDIA_AUDIO
+                        ), Permissions.FINE_STORAGE_PERMISSION_REQUEST_CODE
+                    )
+                else lifecycleScope.launch {
+                    requireActivity().getStoragePermission(withDialog = false, onlyMedia = true)
+                }
         }
 
         binding.manageMediaAudio.setOnClickListener {
@@ -264,6 +272,11 @@ class PermissionListDialog : VLCBottomSheetDialogFragment() {
 
         }
 
+        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
+            binding.manageMediaAudio.setGone()
+            binding.manageMediaVideo.setGone()
+        }
+
         if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
             binding.notificationPermissionContainer.setGone()
             binding.notificationPermissionTitle.setGone()
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt
index 155e22eecc..676578eeb7 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/onboarding/OnboardingActivity.kt
@@ -112,13 +112,11 @@ class OnboardingActivity : AppCompatActivity(), OnboardingFragmentListener {
         }
     }
 
-    @RequiresApi(Build.VERSION_CODES.TIRAMISU)
     private fun askPermission() {
-
         lifecycleScope.launch {
             val onlyMedia = viewModel.permissionType == PermissionType.MEDIA
             viewModel.permissionAlreadyAsked = true
-            if (onlyMedia) {
+            if (onlyMedia && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                 ActivityCompat.requestPermissions(
                     this at OnboardingActivity, arrayOf<String>(
                         Manifest.permission.READ_MEDIA_AUDIO,
@@ -127,7 +125,7 @@ class OnboardingActivity : AppCompatActivity(), OnboardingFragmentListener {
                     ), Permissions.FINE_STORAGE_PERMISSION_REQUEST_CODE
                 )
                 return at launch
-            } else getStoragePermission(withDialog = false, onlyMedia = false)
+            } else getStoragePermission(withDialog = false, onlyMedia = onlyMedia)
             onNext()
         }
     }
diff --git a/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt b/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt
index e02e62f095..6d43518bdc 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt
@@ -140,7 +140,7 @@ object Permissions {
             ) == PackageManager.PERMISSION_GRANTED
             )
 
-    fun hasAnyFileFineAccess(context: Context) = (
+    fun hasAnyFileFineAccess(context: Context) = canReadStorage(context) || (
             ContextCompat.checkSelfPermission(
                 context,
                 Manifest.permission.READ_MEDIA_AUDIO



More information about the Android mailing list