mirror of
https://github.com/videolan/vlc-android
synced 2024-12-04 23:34:38 +08:00
Fix fine permission for Android < 33
This commit is contained in:
parent
08dce8d9c6
commit
24d19ea0f9
@ -46,6 +46,7 @@ import org.videolan.tools.setInvisible
|
|||||||
import org.videolan.tools.setVisible
|
import org.videolan.tools.setVisible
|
||||||
import org.videolan.vlc.R
|
import org.videolan.vlc.R
|
||||||
import org.videolan.vlc.databinding.DialogPermissionsBinding
|
import org.videolan.vlc.databinding.DialogPermissionsBinding
|
||||||
|
import org.videolan.vlc.gui.helpers.hf.StoragePermissionsDelegate.Companion.getStoragePermission
|
||||||
import org.videolan.vlc.util.Permissions
|
import org.videolan.vlc.util.Permissions
|
||||||
|
|
||||||
|
|
||||||
@ -128,7 +129,7 @@ class PermissionListDialog : VLCBottomSheetDialogFragment() {
|
|||||||
|
|
||||||
when {
|
when {
|
||||||
Permissions.hasAllAccess(requireActivity()) -> binding.manageAllPermsCheck.isChecked = true
|
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
|
else -> binding.noAccessCheck.isChecked = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,17 +224,24 @@ class PermissionListDialog : VLCBottomSheetDialogFragment() {
|
|||||||
if (Permissions.hasAnyFileFineAccess(requireActivity())) {
|
if (Permissions.hasAnyFileFineAccess(requireActivity())) {
|
||||||
Permissions.showAppSettingsPage(requireActivity())
|
Permissions.showAppSettingsPage(requireActivity())
|
||||||
(it as RadioButton).isChecked = false
|
(it as RadioButton).isChecked = false
|
||||||
|
} else if (Permissions.canReadStorage(requireActivity())) {
|
||||||
|
Permissions.showAppSettingsPage(requireActivity())
|
||||||
|
(it as RadioButton).isChecked = false
|
||||||
} else if (Permissions.hasAllAccess(requireActivity())) {
|
} else if (Permissions.hasAllAccess(requireActivity())) {
|
||||||
(it as RadioButton).isChecked = false
|
(it as RadioButton).isChecked = false
|
||||||
binding.manageAllPermsCheck.background = ContextCompat.getDrawable(requireActivity(), R.drawable.rounded_corners_permissions_warning)
|
binding.manageAllPermsCheck.background = ContextCompat.getDrawable(requireActivity(), R.drawable.rounded_corners_permissions_warning)
|
||||||
showWarning()
|
showWarning()
|
||||||
} else
|
} else
|
||||||
ActivityCompat.requestPermissions(
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
|
||||||
requireActivity(), arrayOf(
|
ActivityCompat.requestPermissions(
|
||||||
Manifest.permission.READ_MEDIA_VIDEO,
|
requireActivity(), arrayOf(
|
||||||
Manifest.permission.READ_MEDIA_AUDIO
|
Manifest.permission.READ_MEDIA_VIDEO,
|
||||||
), Permissions.FINE_STORAGE_PERMISSION_REQUEST_CODE
|
Manifest.permission.READ_MEDIA_AUDIO
|
||||||
)
|
), Permissions.FINE_STORAGE_PERMISSION_REQUEST_CODE
|
||||||
|
)
|
||||||
|
else lifecycleScope.launch {
|
||||||
|
requireActivity().getStoragePermission(withDialog = false, onlyMedia = true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.manageMediaAudio.setOnClickListener {
|
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) {
|
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
|
||||||
binding.notificationPermissionContainer.setGone()
|
binding.notificationPermissionContainer.setGone()
|
||||||
binding.notificationPermissionTitle.setGone()
|
binding.notificationPermissionTitle.setGone()
|
||||||
|
@ -112,13 +112,11 @@ class OnboardingActivity : AppCompatActivity(), OnboardingFragmentListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
|
|
||||||
private fun askPermission() {
|
private fun askPermission() {
|
||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val onlyMedia = viewModel.permissionType == PermissionType.MEDIA
|
val onlyMedia = viewModel.permissionType == PermissionType.MEDIA
|
||||||
viewModel.permissionAlreadyAsked = true
|
viewModel.permissionAlreadyAsked = true
|
||||||
if (onlyMedia) {
|
if (onlyMedia && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
ActivityCompat.requestPermissions(
|
ActivityCompat.requestPermissions(
|
||||||
this@OnboardingActivity, arrayOf<String>(
|
this@OnboardingActivity, arrayOf<String>(
|
||||||
Manifest.permission.READ_MEDIA_AUDIO,
|
Manifest.permission.READ_MEDIA_AUDIO,
|
||||||
@ -127,7 +125,7 @@ class OnboardingActivity : AppCompatActivity(), OnboardingFragmentListener {
|
|||||||
), Permissions.FINE_STORAGE_PERMISSION_REQUEST_CODE
|
), Permissions.FINE_STORAGE_PERMISSION_REQUEST_CODE
|
||||||
)
|
)
|
||||||
return@launch
|
return@launch
|
||||||
} else getStoragePermission(withDialog = false, onlyMedia = false)
|
} else getStoragePermission(withDialog = false, onlyMedia = onlyMedia)
|
||||||
onNext()
|
onNext()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ object Permissions {
|
|||||||
) == PackageManager.PERMISSION_GRANTED
|
) == PackageManager.PERMISSION_GRANTED
|
||||||
)
|
)
|
||||||
|
|
||||||
fun hasAnyFileFineAccess(context: Context) = (
|
fun hasAnyFileFineAccess(context: Context) = canReadStorage(context) || (
|
||||||
ContextCompat.checkSelfPermission(
|
ContextCompat.checkSelfPermission(
|
||||||
context,
|
context,
|
||||||
Manifest.permission.READ_MEDIA_AUDIO
|
Manifest.permission.READ_MEDIA_AUDIO
|
||||||
|
Loading…
Reference in New Issue
Block a user