-
Notifications
You must be signed in to change notification settings - Fork 659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FC] Handle process kills after returning from browsers in AuthSessions #6853
[FC] Handle process kills after returning from browsers in AuthSessions #6853
Conversation
sealed class WebAuthFlowState : Parcelable { | ||
@Parcelize | ||
object Uninitialized : WebAuthFlowState() | ||
|
||
@Parcelize | ||
object InProgress : WebAuthFlowState() | ||
|
||
@Parcelize | ||
data class Success( | ||
val url: String | ||
) : WebAuthFlowState() | ||
|
||
@Parcelize | ||
object Canceled : WebAuthFlowState() | ||
|
||
@Parcelize | ||
data class Failed( | ||
val message: String, | ||
val reason: String? | ||
) : WebAuthFlowState() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created a Parcelable state that can be saved and restored on process kills via @PersistState and replaced the Async object by this. It should also be simpler (there's no need for an Async object here, a plain sealed class is enough).
That way we can recover the web state pre-process kill and act accordingly.
Before this, we were losing the Web AuthFlow state on process kills.
override fun onResume() { | ||
super.onResume() | ||
// prevent playground configuration from leaking to example apps. | ||
connectionsDebugSharedPrefs.edit { clear() } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small change on the Playground in the example app to make it work across process kills -> we override a deeplink based on a shared preference for local testing. We were clearing them on Activity's onDestroy to prevent it from leaking to the official examples just in case.
Process kills kill the activity triggering the preference clear. Moved the clear to the launcher activity instead.
withState { | ||
if (it.firstInit) { | ||
setState { copy(firstInit = false) } | ||
launchBrowserIfNonOauth() | ||
createAuthSession() | ||
} else { | ||
restoreAuthSession() | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to create a new session if coming from a process kill. We'll restore the session from the manifest instead.
import com.airbnb.mvrx.Success | ||
import com.airbnb.mvrx.Uninitialized | ||
import com.stripe.android.financialconnections.model.DataAccessNotice | ||
import com.stripe.android.financialconnections.model.FinancialConnectionsAuthorizationSession | ||
import com.stripe.android.financialconnections.model.FinancialConnectionsInstitution | ||
|
||
internal data class PartnerAuthState( | ||
@PersistState | ||
val firstInit: Boolean = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of persisting firstInit
, would it make sense to persist a nullable session ID?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that better actually! Even if we can't "fetch the auth session by id" I find it more readable as well - c9b74e9
…7116/fc-handle-process-kills-after-returning-from-brows # Conflicts: # financial-connections/src/main/java/com/stripe/android/financialconnections/presentation/FinancialConnectionsSheetNativeViewModel.kt
Problem
We're not handling process kills while authenticating in the browser:
FinancialConnectionsNativeActivity
is in the foreground and it launches the browser.Solution
@PersistState
(that uses onSaveInstanceState and onRestoreInstanceState internally)Testing
don't keep activities
and test the same cases. Settings -> Developer options -> Don't keep activitiesMotivation
📔 [Android] Handle process kills after returning from browsers in AuthSessions
🌐 BANKCON-7116