From 3d09de693953063ea18fed31facf22806f4754ac Mon Sep 17 00:00:00 2001 From: fatih ergin Date: Sat, 5 Aug 2023 21:00:06 +0300 Subject: [PATCH] handle new READ_MEDIA_VISUAL_USER_SELECTED permission. now the app no longer forces media permission to run --- app/src/main/AndroidManifest.xml | 1 + .../camera/activities/MainActivity.kt | 58 ++++++++++--------- gradle/libs.versions.toml | 2 +- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2f9242cf..2a192fc4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -21,6 +21,7 @@ + diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt index e48601cf..4a8b6478 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/activities/MainActivity.kt @@ -225,30 +225,25 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera private fun tryInitCamera() { handlePermission(PERMISSION_CAMERA) { grantedCameraPermission -> if (grantedCameraPermission) { - handleStoragePermission { grantedStoragePermission -> - if (grantedStoragePermission) { - val isInPhotoMode = isInPhotoMode() - if (isInPhotoMode) { - initializeCamera(true) - } else { - handlePermission(PERMISSION_RECORD_AUDIO) { grantedRecordAudioPermission -> - if (grantedRecordAudioPermission) { - initializeCamera(false) + handleStoragePermission { + val isInPhotoMode = isInPhotoMode() + if (isInPhotoMode) { + initializeCamera(true) + } else { + handlePermission(PERMISSION_RECORD_AUDIO) { grantedRecordAudioPermission -> + if (grantedRecordAudioPermission) { + initializeCamera(false) + } else { + toast(com.simplemobiletools.commons.R.string.no_audio_permissions) + if (isThirdPartyIntent()) { + finish() } else { - toast(com.simplemobiletools.commons.R.string.no_audio_permissions) - if (isThirdPartyIntent()) { - finish() - } else { - // re-initialize in photo mode - config.initPhotoMode = true - tryInitCamera() - } + // re-initialize in photo mode + config.initPhotoMode = true + tryInitCamera() } } } - } else { - toast(com.simplemobiletools.commons.R.string.no_storage_permissions) - finish() } } } else { @@ -270,13 +265,12 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera private fun handleStoragePermission(callback: (granted: Boolean) -> Unit) { if (isTiramisuPlus()) { - handlePermission(PERMISSION_READ_MEDIA_IMAGES) { grantedReadImages -> - if (grantedReadImages) { - handlePermission(PERMISSION_READ_MEDIA_VIDEO, callback) - } else { - callback.invoke(false) - } + val mediaPermissionIds = mutableListOf(PERMISSION_READ_MEDIA_IMAGES, PERMISSION_READ_MEDIA_VIDEO) + if (isUpsideDownCakePlus()) { + mediaPermissionIds.add(PERMISSION_READ_MEDIA_VISUAL_USER_SELECTED) } + + handlePartialMediaPermissions(permissionIds = mediaPermissionIds, callback = callback) } else { handlePermission(PERMISSION_WRITE_STORAGE, callback) } @@ -574,7 +568,11 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera private fun hasPhotoModePermissions(): Boolean { return if (isTiramisuPlus()) { - hasPermission(PERMISSION_READ_MEDIA_IMAGES) && hasPermission(PERMISSION_READ_MEDIA_VIDEO) && hasPermission(PERMISSION_CAMERA) + var hasMediaPermission = hasPermission(PERMISSION_READ_MEDIA_IMAGES) || hasPermission(PERMISSION_READ_MEDIA_VIDEO) + if (isUpsideDownCakePlus()) { + hasMediaPermission = hasMediaPermission || hasPermission(PERMISSION_READ_MEDIA_VISUAL_USER_SELECTED) + } + hasMediaPermission && hasPermission(PERMISSION_CAMERA) } else { hasPermission(PERMISSION_WRITE_STORAGE) && hasPermission(PERMISSION_CAMERA) } @@ -582,7 +580,11 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera private fun hasVideoModePermissions(): Boolean { return if (isTiramisuPlus()) { - hasPermission(PERMISSION_READ_MEDIA_VIDEO) && hasPermission(PERMISSION_CAMERA) && hasPermission(PERMISSION_RECORD_AUDIO) + var hasMediaPermission = hasPermission(PERMISSION_READ_MEDIA_VIDEO) + if (isUpsideDownCakePlus()) { + hasMediaPermission = hasMediaPermission || hasPermission(PERMISSION_READ_MEDIA_VISUAL_USER_SELECTED) + } + hasMediaPermission && hasPermission(PERMISSION_CAMERA) && hasPermission(PERMISSION_RECORD_AUDIO) } else { hasPermission(PERMISSION_WRITE_STORAGE) && hasPermission(PERMISSION_CAMERA) && hasPermission(PERMISSION_RECORD_AUDIO) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d0939124..31eb8a15 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,7 +9,7 @@ androidx-window = "1.2.0-beta01" androidx-camera = "1.3.0-beta02" androidx-ktx = "2.6.1" #Simple tools -simple-commons = "53ad279f5e" +simple-commons = "d1629c7f1a" #Gradle gradlePlugins-agp = "8.1.0" #build