-
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
Fix issue with PaymentLauncher configuration change #4776
Fix issue with PaymentLauncher configuration change #4776
Conversation
Diffuse output: |
e1538a7
to
a02c12f
Compare
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.
LGTM. Before approving though, did you check to see if this works with dont keep activity on? Just want to make sure the payment doesn't try to do through twice and that it restores and redirects back correctly after being killed.
Assigning Chen explicitly so he can take a look too.
/** | ||
* Set when activity calls [register]. Used to redirect back to calling activity. | ||
*/ | ||
private var authActivityStarterHost: AuthActivityStarterHost? = null |
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.
This keeps a reference to the activity internally. A viewModel cannot hold a reference to an Activity / any other view.
The Activity / Fragment gets destroyed and recreated on every configuration change, and a new instance gets the same instance of the ViewModel. Keeping a reference to the activity would prevent it from getting GCed here.
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.
Update on this - Looks like we were already leaking by keeping an activity reference on the viewModel, so this seems out of the scope of this bugfix. Unblocking.
Blocked originally due to an existing memory leak.
a02c12f
to
ab1b8d4
Compare
Checked DKA, works as expected. Thanks! |
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.
Unlocking this bugfix, but proposing a follow-up to avoid potential OOMs due to screen rotations.
authActivityStarterHost?.let { | ||
authenticatorRegistry.getAuthenticator(intent).authenticate( | ||
it, | ||
intent, | ||
apiRequestOptionsProvider.get() | ||
) | ||
} | ||
}, |
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.
looks like we're keeping a reference to authActivityStarterHost
just to be able to run this logic right?
We're unlocking rotations with this PR, meaning every time the user rotates we're stacking an activity in memory that cannot be GCed, eventually running into an OOM / crash.
An important follow-up of this would be:
- Move
authActivityStarterHost
to activity - Move this logic to the activity Communicate from viewModel to activity via a
SharedFlow
or LiveData<Event>
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.
+1 to this. I'm not too thrilled about holding on to this AuthActivityStarterHost
in the view model. I think flow is the way to go. We've been using those over LiveData.
aae1069
aae1069
to
1c0432a
Compare
1c0432a
to
9c940ea
Compare
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.
LGTM, not holding an activity reference 👏
Summary
References #4739
Fixes an issue where configuration change of
PaymentLauncherConfirmationActivity
would cause a crash. This was becausePaymentLauncherConfirmationActivity
was launching a coroutine in theonCreate
and would get called whenever there is a configuration change (e.g. screen rotation) and would emit aJobCancellationException
. This exception was trying to be serialized asPaymentResult.Failed
, but the exception contains aJob
which cannot be serialized, causing a crash.To fix this issue, we make sure that
PaymentLauncherViewModel
starts the coroutine so that it can survive configuration changes. However, additional changes needed to be made. The activity would also lose the ability to listen to theActivityResultCallback
after configuration change. This was fixed by adding aregister
method on the ViewModel.Motivation
This issue will break all landscape mode
PaymentLauncher
confirmations.Testing
Screenshots
Before
crash.mov
After
landscapepaymentlauncher.mov
Changelog