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:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user