forked from geode-sdk/android-launcher
add internal request all files perm
This commit is contained in:
1 file changed
+31
-10
@@ -371,32 +371,53 @@ object GeodeUtils {
|
|||||||
return "com.geode.launcher.user" == uri.authority
|
return "com.geode.launcher.user" == uri.authority
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const val INTERNAL_PERMISSION_PREFIX = "geode.permission_internal"
|
||||||
|
private const val MANAGE_ALL_FILES = "${INTERNAL_PERMISSION_PREFIX}.MANAGE_ALL_FILES"
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getPermissionStatus(permission: String): Boolean {
|
fun getPermissionStatus(permission: String): Boolean {
|
||||||
return ContextCompat.checkSelfPermission(
|
val context = activity.get() ?: return false
|
||||||
activity.get()?.applicationContext ?: return false,
|
|
||||||
permission
|
return when (permission) {
|
||||||
) == PackageManager.PERMISSION_GRANTED
|
MANAGE_ALL_FILES -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S_V2) {
|
||||||
|
Environment.isExternalStorageManager()
|
||||||
|
} else {
|
||||||
|
val permissions = listOf(
|
||||||
|
Manifest.permission.READ_EXTERNAL_STORAGE,
|
||||||
|
Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||||
|
)
|
||||||
|
|
||||||
|
return permissions.all {
|
||||||
|
ContextCompat.checkSelfPermission(context, it) == PackageManager.PERMISSION_GRANTED
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun requestPermission(permission: String) {
|
fun requestPermission(permission: String) {
|
||||||
|
if (permission == MANAGE_ALL_FILES) {
|
||||||
|
// this function handles already having perms for us
|
||||||
|
checkForFilePermissions(onSuccess = {
|
||||||
|
permissionCallback(true)
|
||||||
|
}, onFailure = {
|
||||||
|
permissionCallback(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (getPermissionStatus(permission)) {
|
if (getPermissionStatus(permission)) {
|
||||||
permissionCallback(true)
|
permissionCallback(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
activity.get()?.run {
|
|
||||||
try {
|
try {
|
||||||
requestPermissionLauncher.launch(permission)
|
requestPermissionLauncher.launch(permission)
|
||||||
} catch (e: ActivityNotFoundException) {
|
} catch (e: ActivityNotFoundException) {
|
||||||
permissionCallback(false)
|
permissionCallback(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
permissionCallback(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private external fun permissionCallback(granted: Boolean)
|
private external fun permissionCallback(granted: Boolean)
|
||||||
|
|||||||
Reference in new issue
Block a user