From 1c06d3c694e7daf43e1915048bd2a023ce7a976f Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 3 Sep 2022 15:39:44 +0200 Subject: [PATCH] require the proper permission on Android 13 --- app/src/main/AndroidManifest.xml | 2 ++ .../gallery/pro/activities/EditActivity.kt | 2 +- .../gallery/pro/activities/MainActivity.kt | 6 +++--- .../gallery/pro/activities/MediaActivity.kt | 2 +- .../gallery/pro/activities/PhotoVideoActivity.kt | 2 +- .../gallery/pro/activities/ViewPagerActivity.kt | 4 ++-- .../com/simplemobiletools/gallery/pro/helpers/Constants.kt | 6 +++++- .../gallery/pro/activities/NewPhotoEditActivity.kt | 6 +++--- .../gallery/pro/activities/NewVideoEditActivity.kt | 3 ++- 9 files changed, 20 insertions(+), 13 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cae2d3dd4..d54831ac9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,6 +13,8 @@ + + Unit) { - handlePermission(PERMISSION_WRITE_STORAGE) { granted -> + handlePermission(getPermissionToRequest()) { granted -> callback(granted) if (granted && isRPlus()) { handlePermission(PERMISSION_MEDIA_LOCATION) {} @@ -445,7 +445,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { private fun checkOTGPath() { ensureBackgroundThread { - if (!config.wasOTGHandled && hasPermission(PERMISSION_WRITE_STORAGE) && hasOTGConnected() && config.OTGPath.isEmpty()) { + if (!config.wasOTGHandled && hasPermission(getPermissionToRequest()) && hasOTGConnected() && config.OTGPath.isEmpty()) { getStorageDirectories().firstOrNull { it.trimEnd('/') != internalStoragePath && it.trimEnd('/') != sdCardPath }?.apply { config.wasOTGHandled = true val otgPath = trimEnd('/') @@ -474,7 +474,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { private fun tryLoadGallery() { // avoid calling anything right after granting the permission, it will be called from onResume() - val wasMissingPermission = config.appRunCount == 1 && !hasPermission(PERMISSION_WRITE_STORAGE) + val wasMissingPermission = config.appRunCount == 1 && !hasPermission(getPermissionToRequest()) handleMediaPermissions { if (wasMissingPermission) { return@handleMediaPermissions diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt index 2b15e5b2a..c2a21cda3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MediaActivity.kt @@ -393,7 +393,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { } private fun tryLoadGallery() { - handlePermission(PERMISSION_WRITE_STORAGE) { + handlePermission(getPermissionToRequest()) { if (it) { val dirName = when { mPath == FAVORITES -> getString(R.string.favorites) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PhotoVideoActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PhotoVideoActivity.kt index 7fc0595b1..9ec7f2065 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PhotoVideoActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/PhotoVideoActivity.kt @@ -47,7 +47,7 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList setupOptionsMenu() refreshMenuItems() - handlePermission(PERMISSION_WRITE_STORAGE) { + handlePermission(getPermissionToRequest()) { if (it) { checkIntent(savedInstanceState) } else { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt index a9d2000b9..a9d1df0fa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/ViewPagerActivity.kt @@ -101,7 +101,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View checkNotchSupport() (MediaActivity.mMedia.clone() as ArrayList).filterIsInstanceTo(mMediaFiles, Medium::class.java) - handlePermission(PERMISSION_WRITE_STORAGE) { + handlePermission(getPermissionToRequest()) { if (it) { initViewPager() } else { @@ -115,7 +115,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View override fun onResume() { super.onResume() - if (!hasPermission(PERMISSION_WRITE_STORAGE)) { + if (!hasPermission(getPermissionToRequest())) { finish() return } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt index 626de068b..1a37f469d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt @@ -1,7 +1,9 @@ package com.simplemobiletools.gallery.pro.helpers import com.simplemobiletools.commons.helpers.MONTH_SECONDS -import com.simplemobiletools.commons.helpers.isQPlus +import com.simplemobiletools.commons.helpers.PERMISSION_READ_MEDIA_IMAGES +import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE +import com.simplemobiletools.commons.helpers.isTiramisuPlus // shared preferences const val DIRECTORY_SORT_ORDER = "directory_sort_order" @@ -244,3 +246,5 @@ const val FOLDER_MEDIA_CNT_NONE = 3 const val FOLDER_STYLE_SQUARE = 1 const val FOLDER_STYLE_ROUNDED_CORNERS = 2 + +fun getPermissionToRequest() = if (isTiramisuPlus()) PERMISSION_READ_MEDIA_IMAGES else PERMISSION_WRITE_STORAGE diff --git a/app/src/proprietary/kotlin/com/simplemobiletools/gallery/pro/activities/NewPhotoEditActivity.kt b/app/src/proprietary/kotlin/com/simplemobiletools/gallery/pro/activities/NewPhotoEditActivity.kt index 959ddb124..3b1cfb2d5 100644 --- a/app/src/proprietary/kotlin/com/simplemobiletools/gallery/pro/activities/NewPhotoEditActivity.kt +++ b/app/src/proprietary/kotlin/com/simplemobiletools/gallery/pro/activities/NewPhotoEditActivity.kt @@ -3,13 +3,12 @@ package com.simplemobiletools.gallery.pro.activities import android.annotation.TargetApi import android.app.Activity import android.content.Intent -import androidx.exifinterface.media.ExifInterface import android.net.Uri import android.os.Build import android.os.Bundle import android.provider.MediaStore +import androidx.exifinterface.media.ExifInterface import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.commons.helpers.REAL_FILE_PATH import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.isNougatPlus @@ -20,6 +19,7 @@ import com.simplemobiletools.gallery.pro.dialogs.SaveAsDialog import com.simplemobiletools.gallery.pro.extensions.config import com.simplemobiletools.gallery.pro.extensions.fixDateTaken import com.simplemobiletools.gallery.pro.extensions.tryDeleteFileDirItem +import com.simplemobiletools.gallery.pro.helpers.getPermissionToRequest import ly.img.android.pesdk.PhotoEditorSettingsList import ly.img.android.pesdk.assets.filter.basic.FilterPackBasic import ly.img.android.pesdk.assets.font.basic.FontPackBasic @@ -62,7 +62,7 @@ class NewPhotoEditActivity : SimpleActivity() { return } - handlePermission(PERMISSION_WRITE_STORAGE) { + handlePermission(getPermissionToRequest()) { if (it) { initEditActivity() } else { diff --git a/app/src/proprietary/kotlin/com/simplemobiletools/gallery/pro/activities/NewVideoEditActivity.kt b/app/src/proprietary/kotlin/com/simplemobiletools/gallery/pro/activities/NewVideoEditActivity.kt index b73a54ae9..8650a786d 100644 --- a/app/src/proprietary/kotlin/com/simplemobiletools/gallery/pro/activities/NewVideoEditActivity.kt +++ b/app/src/proprietary/kotlin/com/simplemobiletools/gallery/pro/activities/NewVideoEditActivity.kt @@ -16,6 +16,7 @@ import com.simplemobiletools.gallery.pro.dialogs.SaveAsDialog import com.simplemobiletools.gallery.pro.extensions.config import com.simplemobiletools.gallery.pro.extensions.fixDateTaken import com.simplemobiletools.gallery.pro.extensions.tryDeleteFileDirItem +import com.simplemobiletools.gallery.pro.helpers.getPermissionToRequest import ly.img.android.pesdk.VideoEditorSettingsList import ly.img.android.pesdk.assets.filter.basic.FilterPackBasic import ly.img.android.pesdk.assets.font.basic.FontPackBasic @@ -56,7 +57,7 @@ class NewVideoEditActivity : SimpleActivity() { return } - handlePermission(PERMISSION_WRITE_STORAGE) { + handlePermission(getPermissionToRequest()) { if (it) { initEditActivity() } else {