Skip to content

Commit

Permalink
Fix: Fix manage app all files access permission intent.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghai committed Mar 11, 2024
1 parent 33eda7b commit d8b951d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ import me.zhanghai.android.files.util.copyText
import me.zhanghai.android.files.util.create
import me.zhanghai.android.files.util.createInstallPackageIntent
import me.zhanghai.android.files.util.createIntent
import me.zhanghai.android.files.util.createManageAppAllFilesAccessPermissionIntent
import me.zhanghai.android.files.util.createSendStreamIntent
import me.zhanghai.android.files.util.createViewIntent
import me.zhanghai.android.files.util.extraPath
Expand Down Expand Up @@ -1517,10 +1518,7 @@ class FileListFragment : Fragment(), BreadcrumbLayout.Listener, FileListAdapter.
private class RequestAllFilesAccessContract : ActivityResultContract<Unit, Boolean>() {
@RequiresApi(Build.VERSION_CODES.R)
override fun createIntent(context: Context, input: Unit): Intent =
Intent(
android.provider.Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION,
Uri.fromParts("package", context.packageName, null)
)
Environment::class.createManageAppAllFilesAccessPermissionIntent(context.packageName)

@RequiresApi(Build.VERSION_CODES.R)
override fun parseResult(resultCode: Int, intent: Intent?): Boolean =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
package me.zhanghai.android.files.util

import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.provider.Settings
import androidx.annotation.ChecksSdkIntAtLeast
import androidx.annotation.RequiresApi
import me.zhanghai.android.files.app.application
import me.zhanghai.android.files.app.packageManager
import kotlin.reflect.KClass

Expand All @@ -25,11 +26,16 @@ fun KClass<Environment>.supportsExternalStorageManager(): Boolean =
else -> false
}

@RequiresApi(Build.VERSION_CODES.R)
fun KClass<Environment>.createManageAppAllFilesAccessPermissionIntent(packageName: String): Intent =
Intent(
Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION,
Uri.fromParts("package", packageName, null)
)

@delegate:RequiresApi(Build.VERSION_CODES.R)
private val isManageAppAllFilesAccessPermissionIntentResolved: Boolean
by lazy(LazyThreadSafetyMode.NONE) {
packageManager.resolveActivity(
Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION),
PackageManager.MATCH_DEFAULT_ONLY or PackageManager.MATCH_SYSTEM_ONLY
) != null
Environment::class.createManageAppAllFilesAccessPermissionIntent(application.packageName)
.resolveActivity(packageManager) != null
}

0 comments on commit d8b951d

Please sign in to comment.