From 0fd801accbb84517e73d3e6f0b003e9bf29765a7 Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Wed, 11 Sep 2024 10:56:38 +1000 Subject: [PATCH] SES-2702 - making sure we hook the permission results everywhere --- .../java/org/thoughtcrime/securesms/home/HomeActivity.kt | 5 +++++ .../securesms/onboarding/loadaccount/LoadAccountActivity.kt | 6 ++++++ .../java/org/thoughtcrime/securesms/ui/components/QR.kt | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt index 05c2fe658b..aeaa7338f2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/home/HomeActivity.kt @@ -388,6 +388,11 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), super.onDestroy() EventBus.getDefault().unregister(this) } + + override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults) + Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults) + } // endregion // region Updating diff --git a/app/src/main/java/org/thoughtcrime/securesms/onboarding/loadaccount/LoadAccountActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/onboarding/loadaccount/LoadAccountActivity.kt index 85fbeba78f..39b119e5b6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/onboarding/loadaccount/LoadAccountActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/onboarding/loadaccount/LoadAccountActivity.kt @@ -13,6 +13,7 @@ import org.session.libsession.utilities.TextSecurePreferences import org.thoughtcrime.securesms.BaseActionBarActivity import org.thoughtcrime.securesms.onboarding.manager.LoadAccountManager import org.thoughtcrime.securesms.onboarding.messagenotifications.MessageNotificationsActivity +import org.thoughtcrime.securesms.permissions.Permissions import org.thoughtcrime.securesms.ui.setComposeContent import org.thoughtcrime.securesms.util.start @@ -45,4 +46,9 @@ class LoadAccountActivity : BaseActionBarActivity() { LoadAccountScreen(state, viewModel.qrErrors, viewModel::onChange, viewModel::onContinue, viewModel::onScanQrCode) } } + + override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults) + Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults) + } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/ui/components/QR.kt b/app/src/main/java/org/thoughtcrime/securesms/ui/components/QR.kt index 3258257112..ea996b59ce 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/ui/components/QR.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/ui/components/QR.kt @@ -120,6 +120,12 @@ fun QRScannerScreen( stringResource(R.string.cameraGrantAccess), modifier = Modifier.fillMaxWidth(), onClick = { + // NOTE: We used to use the Accompanist's way to handle permissions in compose + // but it doesn't seem to offer a solution when a user manually changes a permission + // to 'Ask every time' form the app's settings. + // So we are using our custom implementation. ONE IMPORTANT THING with this approach + // is that we need to make sure every activity where this composable is used NEED to + // implement `onRequestPermissionsResult` (see LoadAccountActivity.kt for an example) Permissions.with(context.findActivity()) .request(permission) .withPermanentDenialDialog(