Merge pull request #10924 from nextcloud/fix/storage-permission-background

PermissionUtil: ensure fragment result is listened to on activity thread
This commit is contained in:
Álvaro Brey 2022-10-26 11:08:08 +02:00 committed by GitHub
commit aab8fcfe2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -31,6 +31,7 @@ import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.provider.Settings
import androidx.annotation.RequiresApi
@ -213,10 +214,7 @@ object PermissionUtil {
if (shouldRequestPermission &&
activity.supportFragmentManager.findFragmentByTag(PERMISSION_CHOICE_DIALOG_TAG) == null
) {
activity.supportFragmentManager.setFragmentResultListener(
StoragePermissionDialogFragment.REQUEST_KEY,
activity
) { _, resultBundle ->
val listener: (requestKey: String, result: Bundle) -> Unit = { _, resultBundle ->
val result: StoragePermissionDialogFragment.Result? =
resultBundle.getParcelable(StoragePermissionDialogFragment.RESULT_KEY)
if (result != null) {
@ -238,6 +236,14 @@ object PermissionUtil {
}
}
activity.runOnUiThread {
activity.supportFragmentManager.setFragmentResultListener(
StoragePermissionDialogFragment.REQUEST_KEY,
activity,
listener
)
}
val dialogFragment = StoragePermissionDialogFragment.newInstance(permissionRequired)
dialogFragment.show(activity.supportFragmentManager, PERMISSION_CHOICE_DIALOG_TAG)
}