From 71e5da32b409169b8783eda4397137a72144a099 Mon Sep 17 00:00:00 2001 From: Aayush Gupta Date: Thu, 1 Jun 2023 22:55:34 +0800 Subject: [PATCH] AppDetailsActivity: Only request storage manager perms when required Saving files in filesDir or externalFilesDir doesn't requires any perms as this is app's own storage. We only need perm if user is either installing an app with obb/patch files or has enabled external storage downloads Signed-off-by: Aayush Gupta --- .../java/com/aurora/store/util/PathUtil.kt | 4 +++ .../view/ui/details/AppDetailsActivity.kt | 30 +++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/aurora/store/util/PathUtil.kt b/app/src/main/java/com/aurora/store/util/PathUtil.kt index fae3779d4..a0db2e39b 100644 --- a/app/src/main/java/com/aurora/store/util/PathUtil.kt +++ b/app/src/main/java/com/aurora/store/util/PathUtil.kt @@ -82,6 +82,10 @@ object PathUtil { val obbDir = getObbDownloadPath(app) return "$obbDir/${file.name}" } + + fun needsStorageManagerPerm(fileList: List): Boolean { + return fileList.any { it.type == File.FileType.OBB || it.type == File.FileType.PATCH } + } } fun Context.isExternalStorageEnable(): Boolean { diff --git a/app/src/main/java/com/aurora/store/view/ui/details/AppDetailsActivity.kt b/app/src/main/java/com/aurora/store/view/ui/details/AppDetailsActivity.kt index 39b5f59ac..c070b3511 100644 --- a/app/src/main/java/com/aurora/store/view/ui/details/AppDetailsActivity.kt +++ b/app/src/main/java/com/aurora/store/view/ui/details/AppDetailsActivity.kt @@ -491,22 +491,26 @@ class AppDetailsActivity : BaseDetailsActivity() { bottomSheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED updateActionState(State.PROGRESS) - if (isRAndAbove()) { - if (!Environment.isExternalStorageManager()) { - startActivity(Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)) + if (PathUtil.needsStorageManagerPerm(app.fileList) || this.isExternalStorageEnable()) { + if (isRAndAbove()) { + if (!Environment.isExternalStorageManager()) { + startActivity(Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)) + } else { + updateApp(app) + } } else { - updateApp(app) + if (ContextCompat.checkSelfPermission( + this, + Manifest.permission.WRITE_EXTERNAL_STORAGE + ) == PackageManager.PERMISSION_GRANTED + ) { + updateApp(app) + } else { + startForPermissions.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE) + } } } else { - if (ContextCompat.checkSelfPermission( - this, - Manifest.permission.WRITE_EXTERNAL_STORAGE - ) == PackageManager.PERMISSION_GRANTED - ) { - updateApp(app) - } else { - startForPermissions.launch(Manifest.permission.WRITE_EXTERNAL_STORAGE) - } + updateApp(app) } }