Skip to content

Commit

Permalink
[Refactor] Refactor storage permission check in LinuxPath.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghai committed Feb 7, 2022
1 parent 23c07b5 commit e583ea3
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ internal class LinuxPath : ByteStringListPath<LinuxPath>, RootablePath {
override val rootStrategy: RootStrategy
get() {
val strategy = super.rootStrategy
if (strategy == RootStrategy.PREFER_NO && !isStoragePermissionGranted) {
if (strategy == RootStrategy.PREFER_NO && isMissingStoragePermission) {
return RootStrategy.NEVER
}
return strategy
Expand Down Expand Up @@ -129,15 +129,15 @@ val Path.isLinuxPath: Boolean
// IPC for checking the storage permission is expensive if we do it on every file system access, so
// cache its result here.
@Volatile
private var wasStoragePermissionGranted: Boolean = false
private val isStoragePermissionGranted: Boolean
private var wasMissingStoragePermission = true
private val isMissingStoragePermission: Boolean
get() {
// Android kills an app if the user revokes any of its runtime permissions.
if (wasStoragePermissionGranted) {
return true
if (!wasMissingStoragePermission) {
return false
}
return (Build.VERSION.SDK_INT !in Build.VERSION_CODES.M until Build.VERSION_CODES.R
|| application.checkSelfPermissionCompat(Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED)
.also { wasStoragePermissionGranted = it }
return (Build.VERSION.SDK_INT in Build.VERSION_CODES.M until Build.VERSION_CODES.R
&& application.checkSelfPermissionCompat(Manifest.permission.WRITE_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED)
.also { wasMissingStoragePermission = it }
}

0 comments on commit e583ea3

Please sign in to comment.