Fix fine permission for Android < 33

This commit is contained in:
Nicolas Pomepuy 2024-11-21 07:22:22 +01:00 committed by Duncan McNamara
parent 08dce8d9c6
commit 24d19ea0f9
3 changed files with 23 additions and 12 deletions

View File

@ -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()

View File

@ -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@OnboardingActivity, arrayOf<String>(
Manifest.permission.READ_MEDIA_AUDIO,
@ -127,7 +125,7 @@ class OnboardingActivity : AppCompatActivity(), OnboardingFragmentListener {
), Permissions.FINE_STORAGE_PERMISSION_REQUEST_CODE
)
return@launch
} else getStoragePermission(withDialog = false, onlyMedia = false)
} else getStoragePermission(withDialog = false, onlyMedia = onlyMedia)
onNext()
}
}

View File

@ -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