[Android] Display right permissions for Android 30- in the permissions dialog

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 14 14:32:45 2024 +0100| [c2768e69ba1afdd0dd61dda8f3e3c9f19e305552] | committer: Duncan McNamara

Display right permissions for Android 30- in the permissions dialog

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

 .../vlc-android/res/layout/dialog_permissions.xml  |  4 +--
 .../vlc/gui/dialogs/PermissionListDialog.kt        | 42 +++++++++++++++++-----
 .../src/org/videolan/vlc/util/Permissions.kt       |  4 +--
 3 files changed, 38 insertions(+), 12 deletions(-)

diff --git a/application/vlc-android/res/layout/dialog_permissions.xml b/application/vlc-android/res/layout/dialog_permissions.xml
index 738e5925b2..0e2ca1d9b4 100644
--- a/application/vlc-android/res/layout/dialog_permissions.xml
+++ b/application/vlc-android/res/layout/dialog_permissions.xml
@@ -49,7 +49,7 @@
                     app:layout_constraintTop_toTopOf="parent" />
 
             <TextView
-                    android:id="@+id/textView38"
+                    android:id="@+id/notification_permission_title"
                     style="@style/Theme.VLC.BottomSheetTitle"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
@@ -73,7 +73,7 @@
                     android:orientation="horizontal"
                     app:layout_constraintEnd_toEndOf="parent"
                     app:layout_constraintStart_toStartOf="parent"
-                    app:layout_constraintTop_toBottomOf="@+id/textView38">
+                    app:layout_constraintTop_toBottomOf="@+id/notification_permission_title">
 
                 <ImageView
                         android:id="@+id/notification_permission_check"
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 2b5805bdd6..cbe41861b1 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
@@ -26,6 +26,7 @@ package org.videolan.vlc.gui.dialogs
 import android.Manifest
 import android.content.Intent
 import android.net.Uri
+import android.os.Build
 import android.os.Bundle
 import android.util.TypedValue
 import android.view.LayoutInflater
@@ -195,14 +196,26 @@ class PermissionListDialog : VLCBottomSheetDialogFragment() {
                 binding.manageMediaPermsCheck.background  = ContextCompat.getDrawable(requireActivity(), R.drawable.rounded_corners_permissions_warning)
                 showWarning()
             } else
-                requireActivity().lifecycleScope.launch {
-                    val uri = Uri.fromParts(SCHEME_PACKAGE, requireContext().packageName, null)
-                    val intent = Intent(
-                        android.provider.Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION,
-                        uri
-                    )
-                    startActivity(intent)
-                }
+                if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.R) {
+                    if (!Permissions.hasAllAccess(requireActivity())) {
+                        Permissions.checkReadStoragePermission(
+                            requireActivity(),
+                            false,
+                            forceAsking = true
+                        )
+                        binding.manageAllPermsCheck.isChecked = false
+                    }
+                    else
+                        Permissions.showAppSettingsPage(requireActivity())
+                } else
+                    requireActivity().lifecycleScope.launch {
+                        val uri = Uri.fromParts(SCHEME_PACKAGE, requireContext().packageName, null)
+                        val intent = Intent(
+                            android.provider.Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION,
+                            uri
+                        )
+                        startActivity(intent)
+                    }
         }
 
         binding.manageMediaPermsCheck.setOnClickListener {
@@ -242,6 +255,19 @@ class PermissionListDialog : VLCBottomSheetDialogFragment() {
             }
         }
 
+        //Manage view visibility for older versions
+        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.R) {
+            binding.manageMediaPermsCheck.setGone()
+            binding.manageMediaVideo.setGone()
+            binding.manageMediaAudio.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/util/Permissions.kt b/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt
index d213c3e7dc..e02e62f095 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt
@@ -198,9 +198,9 @@ object Permissions {
                 Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
     }
 
-    fun checkReadStoragePermission(activity: FragmentActivity, exit: Boolean = false): Boolean {
+    fun checkReadStoragePermission(activity: FragmentActivity, exit: Boolean = false, forceAsking: Boolean = false): Boolean {
         if (AndroidUtil.isMarshMallowOrLater && !canReadStorage(activity)) {
-            if (ActivityCompat.shouldShowRequestPermissionRationale(activity,
+            if (!forceAsking && ActivityCompat.shouldShowRequestPermissionRationale(activity,
                             Manifest.permission.READ_EXTERNAL_STORAGE)) {
                 showStoragePermissionDialog(activity, exit)
             } else



More information about the Android mailing list