Skip to content
Snippets Groups Projects
Commit 3a37abc9 authored by Nicolas Pomepuy's avatar Nicolas Pomepuy
Browse files

Rework the new permission workflow and wording

parent c2f4c7d0
No related branches found
No related tags found
No related merge requests found
......@@ -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>
......
......@@ -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"
......
......@@ -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 ->
......
......@@ -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()
}
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment