[Android] Rework the new permission workflow and wording

Nicolas Pomepuy git at videolan.org
Wed Nov 24 09:28:34 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Nov 24 08:37:06 2021 +0100| [3a37abc9b1212762218c2ff93816b4a62cfd1c49] | committer: Nicolas Pomepuy

Rework the new permission workflow and wording

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

 .../resources/src/main/res/values/strings.xml      |  5 +++--
 .../vlc-android/res/layout/dialog_all_access.xml   |  2 +-
 .../vlc/gui/dialogs/AllAccessPermissionDialog.kt   |  3 ++-
 .../gui/helpers/hf/StoragePermissionsDelegate.kt   | 25 ++++++++++++++--------
 .../src/org/videolan/vlc/util/Permissions.kt       |  2 +-
 5 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 8cdcfeb57..1c437d1fb 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -510,9 +510,10 @@
     <string name="allow_storage_access_title">Allow VLC to access video and audio files</string>
     <string name="allow_storage_access_description">VLC needs you to grant this permission to access the media files on this device.</string>
     <string name="allow_storage_manager_title">Allow VLC all file access</string>
-    <string name="allow_storage_manager_description">VLC needs you to grant this permission to access all your files on this device.\nGrant permission?</string>
+    <string name="allow_storage_manager_description">%s\n\nGrant permission?</string>
+    <string name="allow_storage_manager_explanation">To get all the capabilities of VLC and the support of all types of media files, we strongly suggest you to grant this permission.</string>
     <string name="partial_content">VLC cannot access all of your files</string>
-    <string name="partial_content_description">Starting with Android 11, applications cannot access all of the device\'s files without a special permission.\n\nIn order to allow VLC for Android to access all your files, including files that are not considered as media by the system, please grant this new permission to VLC.</string>
+    <string name="partial_content_description">Starting with Android 11, applications need a special permission to access all device\'s files.\n\n%s</string>
     <string name="never_ask_again">Never ask again</string>
     <string name="allow_settings_access_ringtone_title">Allow VLC to set the ringtone</string>
     <string name="allow_settings_access_ringtone_description">VLC needs you to grant this permission to set up this song as your ringtone.</string>
diff --git a/application/vlc-android/res/layout/dialog_all_access.xml b/application/vlc-android/res/layout/dialog_all_access.xml
index 9aa158628..748485a80 100644
--- a/application/vlc-android/res/layout/dialog_all_access.xml
+++ b/application/vlc-android/res/layout/dialog_all_access.xml
@@ -48,8 +48,8 @@
             android:layout_marginStart="16dp"
             android:layout_marginTop="8dp"
             android:layout_marginEnd="16dp"
-            android:text="@string/partial_content_description"
             android:textColor="?attr/font_default"
+            android:lineSpacingMultiplier="1.3"
             android:textSize="16sp"
             app:layout_constraintEnd_toEndOf="parent"
             app:layout_constraintStart_toStartOf="parent"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/AllAccessPermissionDialog.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/AllAccessPermissionDialog.kt
index 1dbbefd1d..5d98848fa 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/AllAccessPermissionDialog.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/AllAccessPermissionDialog.kt
@@ -60,10 +60,11 @@ class AllAccessPermissionDialog : VLCBottomSheetDialogFragment() {
     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
         val view = inflater.inflate(R.layout.dialog_all_access, container)
         titleView = view.findViewById(R.id.title)
+        view.findViewById<TextView>(R.id.description).text = getString(R.string.partial_content_description, getString(R.string.allow_storage_manager_explanation))
         grantAllAccessButton = view.findViewById(R.id.grant_all_access_button)
         neverAskAgain = view.findViewById(R.id.never_ask_again)
         grantAllAccessButton.setOnClickListener {
-            lifecycleScope.launch { requireActivity().getStoragePermission() }
+            lifecycleScope.launch { requireActivity().getStoragePermission(withDialog = false) }
             dismiss()
         }
         neverAskAgain.setOnCheckedChangeListener { _, isChecked ->
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 e7cc3ca35..053a809a4 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
@@ -58,6 +58,7 @@ import org.videolan.vlc.util.Permissions.canReadStorage
 import videolan.org.commontools.LiveEvent
 
 private const val WRITE_ACCESS = "write"
+private const val WITH_DIALOG = "with_dialog"
 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
 class StoragePermissionsDelegate : BaseHeadlessFragment() {
 
@@ -66,6 +67,7 @@ class StoragePermissionsDelegate : BaseHeadlessFragment() {
     private var firstRun: Boolean = false
     private var upgrade: Boolean = false
     private var write: Boolean = false
+    private var withDialog: Boolean = true
 
     interface CustomActionController {
         fun onStorageAccessGranted()
@@ -79,6 +81,7 @@ class StoragePermissionsDelegate : BaseHeadlessFragment() {
             firstRun = intent.getBooleanExtra(EXTRA_FIRST_RUN, false)
         }
         write = arguments?.getBoolean(WRITE_ACCESS) ?: false
+        withDialog = arguments?.getBoolean(WITH_DIALOG) ?: true
         if (AndroidUtil.isMarshMallowOrLater && (!canReadStorage(requireContext()) ||  !Permissions.hasAllAccess(requireContext()))) {
             if (shouldShowRequestPermissionRationale(Manifest.permission.READ_EXTERNAL_STORAGE) && !model.permissionRationaleShown) {
                 Permissions.showStoragePermissionDialog(requireActivity(), false)
@@ -132,15 +135,11 @@ class StoragePermissionsDelegate : BaseHeadlessFragment() {
             val uri = Uri.parse("package:${BuildConfig.APP_ID}")
             val intent = Intent(android.provider.Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, uri)
             if (intent.isCallable(requireActivity())) {
-                Permissions.showExternalPermissionDialog(requireActivity()) { asked ->
+               if (withDialog) Permissions.showExternalPermissionDialog(requireActivity()) { asked ->
                     if (asked) {
-                        val code = android.provider.Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
-                        askedPermission = Permissions.MANAGE_EXTERNAL_STORAGE
-                        timeAsked = System.currentTimeMillis()
-                        activityResultLauncher.launch(code)
-                        startActivity(intent)
+                        askAllAccessPermission(intent)
                     }
-                }
+                } else askAllAccessPermission(intent)
                 return
             }
         }
@@ -150,6 +149,14 @@ class StoragePermissionsDelegate : BaseHeadlessFragment() {
         activityResultLauncher.launch(code)
     }
 
+    private fun askAllAccessPermission(intent: Intent) {
+        val code = android.provider.Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION
+        askedPermission = Permissions.MANAGE_EXTERNAL_STORAGE
+        timeAsked = System.currentTimeMillis()
+        activityResultLauncher.launch(code)
+        startActivity(intent)
+    }
+
     companion object {
 
         const val TAG = "VLC/StorageHF"
@@ -169,7 +176,7 @@ class StoragePermissionsDelegate : BaseHeadlessFragment() {
             }
         }
 
-        suspend fun FragmentActivity.getStoragePermission(write: Boolean = false) : Boolean {
+        suspend fun FragmentActivity.getStoragePermission(write: Boolean = false, withDialog:Boolean = true) : Boolean {
             if (isFinishing) return false
             Settings.getInstance(this).putSingle(INITIAL_PERMISSION_ASKED, true)
             val model : PermissionViewmodel by viewModels()
@@ -180,7 +187,7 @@ class StoragePermissionsDelegate : BaseHeadlessFragment() {
             } else {
                 model.setupDeferred()
                 val fragment = StoragePermissionsDelegate().apply {
-                    arguments = bundleOf(WRITE_ACCESS to write)
+                    arguments = bundleOf(WRITE_ACCESS to write, WITH_DIALOG to withDialog)
                 }
                 supportFragmentManager.beginTransaction().add(fragment, TAG).commitAllowingStateLoss()
             }
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 d2555828b..66f4d1524 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/Permissions.kt
@@ -186,7 +186,7 @@ object Permissions {
     private fun createExternalManagerDialog(activity: FragmentActivity, listener: (boolean: Boolean) -> Unit): Dialog {
         val dialogBuilder = android.app.AlertDialog.Builder(activity)
                 .setTitle(activity.getString(R.string.allow_storage_manager_title))
-                .setMessage(activity.getString(R.string.allow_storage_manager_description))
+                .setMessage(activity.getString(R.string.allow_storage_manager_description, activity.getString(R.string.allow_storage_manager_explanation)))
                 .setIcon(R.drawable.ic_warning)
                 .setPositiveButton(activity.getString(R.string.ok)) { _, _ ->
                     listener.invoke(true)



More information about the Android mailing list