From 7d4fd105bffdfe2ed250fd87b313d46aca49dd84 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Tue, 4 Jan 2022 10:37:35 -0300 Subject: [PATCH] Fix finishing RequireProvisioningActivity when provisioning is aborted On Android 11 this worked fine, but on Android 12 onStart() happens before activity results get delivered. We finish the activity when receiving a cancelled result. However, when onStart() gets called before we know the result, we relaunch an activity required for provisioning again instead of finishing. --- app/src/debug/AndroidManifest.xml | 19 +++++++++++++++++++ .../seedvault/SecretCodeReceiver.kt | 3 +-- .../seedvault/restore/RestoreActivity.kt | 7 +++++-- .../seedvault/settings/SettingsActivity.kt | 7 +++++-- .../ui/RequireProvisioningActivity.kt | 14 ++++++++------ 5 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 app/src/debug/AndroidManifest.xml diff --git a/app/src/debug/AndroidManifest.xml b/app/src/debug/AndroidManifest.xml new file mode 100644 index 00000000..09836263 --- /dev/null +++ b/app/src/debug/AndroidManifest.xml @@ -0,0 +1,19 @@ + + + + + + + + + + diff --git a/app/src/main/java/com/stevesoltys/seedvault/SecretCodeReceiver.kt b/app/src/main/java/com/stevesoltys/seedvault/SecretCodeReceiver.kt index 0e9350fe..63563609 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/SecretCodeReceiver.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/SecretCodeReceiver.kt @@ -13,8 +13,7 @@ private const val RESTORE_SECRET_CODE = "7378673" class SecretCodeReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { - val host = intent.data.host - if (RESTORE_SECRET_CODE != host) return + if (intent.data?.host != RESTORE_SECRET_CODE) return Log.d(TAG, "Restore secret code received.") val i = Intent(context, RestoreActivity::class.java).apply { flags = FLAG_ACTIVITY_NEW_TASK diff --git a/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreActivity.kt b/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreActivity.kt index db4bdc08..a9548d43 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreActivity.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/restore/RestoreActivity.kt @@ -41,8 +41,11 @@ class RestoreActivity : RequireProvisioningActivity() { } @CallSuper - override fun onStart() { - super.onStart() + override fun onResume() { + super.onResume() + // Activity results from the parent will get delivered before and might tell us to finish. + // Don't start any new activities when that happens. + // Note: onStart() can get called *before* results get delivered, so we use onResume() here if (isFinishing) return // check that backup is provisioned diff --git a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsActivity.kt b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsActivity.kt index 2dbba5c7..68194e29 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsActivity.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/settings/SettingsActivity.kt @@ -39,8 +39,11 @@ class SettingsActivity : RequireProvisioningActivity(), OnPreferenceStartFragmen } @CallSuper - override fun onStart() { - super.onStart() + override fun onResume() { + super.onResume() + // Activity results from the parent will get delivered before and might tell us to finish. + // Don't start any new activities when that happens. + // Note: onStart() can get called *before* results get delivered, so we use onResume() here if (isFinishing) return // check that backup is provisioned diff --git a/app/src/main/java/com/stevesoltys/seedvault/ui/RequireProvisioningActivity.kt b/app/src/main/java/com/stevesoltys/seedvault/ui/RequireProvisioningActivity.kt index 8aceedcf..2e362ce6 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/ui/RequireProvisioningActivity.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/ui/RequireProvisioningActivity.kt @@ -55,16 +55,18 @@ abstract class RequireProvisioningActivity : BackupActivity() { } protected fun showStorageActivity() { - val intent = Intent(this, StorageActivity::class.java) - intent.putExtra(INTENT_EXTRA_IS_RESTORE, getViewModel().isRestoreOperation) - intent.putExtra(INTENT_EXTRA_IS_SETUP_WIZARD, isSetupWizard) + val intent = Intent(this, StorageActivity::class.java).apply { + putExtra(INTENT_EXTRA_IS_RESTORE, getViewModel().isRestoreOperation) + putExtra(INTENT_EXTRA_IS_SETUP_WIZARD, isSetupWizard) + } requestLocation.launch(intent) } protected fun showRecoveryCodeActivity() { - val intent = Intent(this, RecoveryCodeActivity::class.java) - intent.putExtra(INTENT_EXTRA_IS_RESTORE, getViewModel().isRestoreOperation) - intent.putExtra(INTENT_EXTRA_IS_SETUP_WIZARD, isSetupWizard) + val intent = Intent(this, RecoveryCodeActivity::class.java).apply { + putExtra(INTENT_EXTRA_IS_RESTORE, getViewModel().isRestoreOperation) + putExtra(INTENT_EXTRA_IS_SETUP_WIZARD, isSetupWizard) + } recoveryCodeRequest.launch(intent) }