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 <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2023-06-01 22:55:34 +08:00
parent 3733c8437d
commit 71e5da32b4
2 changed files with 21 additions and 13 deletions

View File

@@ -82,6 +82,10 @@ object PathUtil {
val obbDir = getObbDownloadPath(app)
return "$obbDir/${file.name}"
}
fun needsStorageManagerPerm(fileList: List<File>): Boolean {
return fileList.any { it.type == File.FileType.OBB || it.type == File.FileType.PATCH }
}
}
fun Context.isExternalStorageEnable(): Boolean {

View File

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