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.
This commit is contained in:
parent
a717ebaf9c
commit
7d4fd105bf
5 changed files with 38 additions and 12 deletions
19
app/src/debug/AndroidManifest.xml
Normal file
19
app/src/debug/AndroidManifest.xml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
<application>
|
||||||
|
<!-- Remove permission requirements only for debug versions to make development easier -->
|
||||||
|
<activity
|
||||||
|
android:name="com.stevesoltys.seedvault.settings.SettingsActivity"
|
||||||
|
android:exported="true"
|
||||||
|
android:permission=""
|
||||||
|
tools:replace="android:permission" />
|
||||||
|
<activity
|
||||||
|
android:name="com.stevesoltys.seedvault.restore.RestoreActivity"
|
||||||
|
android:exported="true"
|
||||||
|
android:permission=""
|
||||||
|
tools:replace="android:permission" />
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
|
@ -13,8 +13,7 @@ private const val RESTORE_SECRET_CODE = "7378673"
|
||||||
class SecretCodeReceiver : BroadcastReceiver() {
|
class SecretCodeReceiver : BroadcastReceiver() {
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
val host = intent.data.host
|
if (intent.data?.host != RESTORE_SECRET_CODE) return
|
||||||
if (RESTORE_SECRET_CODE != host) return
|
|
||||||
Log.d(TAG, "Restore secret code received.")
|
Log.d(TAG, "Restore secret code received.")
|
||||||
val i = Intent(context, RestoreActivity::class.java).apply {
|
val i = Intent(context, RestoreActivity::class.java).apply {
|
||||||
flags = FLAG_ACTIVITY_NEW_TASK
|
flags = FLAG_ACTIVITY_NEW_TASK
|
||||||
|
|
|
@ -41,8 +41,11 @@ class RestoreActivity : RequireProvisioningActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
override fun onStart() {
|
override fun onResume() {
|
||||||
super.onStart()
|
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
|
if (isFinishing) return
|
||||||
|
|
||||||
// check that backup is provisioned
|
// check that backup is provisioned
|
||||||
|
|
|
@ -39,8 +39,11 @@ class SettingsActivity : RequireProvisioningActivity(), OnPreferenceStartFragmen
|
||||||
}
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
override fun onStart() {
|
override fun onResume() {
|
||||||
super.onStart()
|
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
|
if (isFinishing) return
|
||||||
|
|
||||||
// check that backup is provisioned
|
// check that backup is provisioned
|
||||||
|
|
|
@ -55,16 +55,18 @@ abstract class RequireProvisioningActivity : BackupActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun showStorageActivity() {
|
protected fun showStorageActivity() {
|
||||||
val intent = Intent(this, StorageActivity::class.java)
|
val intent = Intent(this, StorageActivity::class.java).apply {
|
||||||
intent.putExtra(INTENT_EXTRA_IS_RESTORE, getViewModel().isRestoreOperation)
|
putExtra(INTENT_EXTRA_IS_RESTORE, getViewModel().isRestoreOperation)
|
||||||
intent.putExtra(INTENT_EXTRA_IS_SETUP_WIZARD, isSetupWizard)
|
putExtra(INTENT_EXTRA_IS_SETUP_WIZARD, isSetupWizard)
|
||||||
|
}
|
||||||
requestLocation.launch(intent)
|
requestLocation.launch(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun showRecoveryCodeActivity() {
|
protected fun showRecoveryCodeActivity() {
|
||||||
val intent = Intent(this, RecoveryCodeActivity::class.java)
|
val intent = Intent(this, RecoveryCodeActivity::class.java).apply {
|
||||||
intent.putExtra(INTENT_EXTRA_IS_RESTORE, getViewModel().isRestoreOperation)
|
putExtra(INTENT_EXTRA_IS_RESTORE, getViewModel().isRestoreOperation)
|
||||||
intent.putExtra(INTENT_EXTRA_IS_SETUP_WIZARD, isSetupWizard)
|
putExtra(INTENT_EXTRA_IS_SETUP_WIZARD, isSetupWizard)
|
||||||
|
}
|
||||||
recoveryCodeRequest.launch(intent)
|
recoveryCodeRequest.launch(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue