From d8b951db01dc88f33f3e68a8a0ca668247f066f4 Mon Sep 17 00:00:00 2001 From: Hai Zhang Date: Mon, 11 Mar 2024 14:51:46 -0700 Subject: [PATCH] Fix: Fix manage app all files access permission intent. --- .../android/files/filelist/FileListFragment.kt | 6 ++---- .../android/files/util/EnvironmentExtensions.kt | 16 +++++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/me/zhanghai/android/files/filelist/FileListFragment.kt b/app/src/main/java/me/zhanghai/android/files/filelist/FileListFragment.kt index ffe8d7d58..24825720a 100644 --- a/app/src/main/java/me/zhanghai/android/files/filelist/FileListFragment.kt +++ b/app/src/main/java/me/zhanghai/android/files/filelist/FileListFragment.kt @@ -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 @@ -1517,10 +1518,7 @@ class FileListFragment : Fragment(), BreadcrumbLayout.Listener, FileListAdapter. private class RequestAllFilesAccessContract : ActivityResultContract() { @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 = diff --git a/app/src/main/java/me/zhanghai/android/files/util/EnvironmentExtensions.kt b/app/src/main/java/me/zhanghai/android/files/util/EnvironmentExtensions.kt index 668f59b11..b740962e9 100644 --- a/app/src/main/java/me/zhanghai/android/files/util/EnvironmentExtensions.kt +++ b/app/src/main/java/me/zhanghai/android/files/util/EnvironmentExtensions.kt @@ -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 @@ -25,11 +26,16 @@ fun KClass.supportsExternalStorageManager(): Boolean = else -> false } +@RequiresApi(Build.VERSION_CODES.R) +fun KClass.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 }