-
Notifications
You must be signed in to change notification settings - Fork 167
fix: Handle configuration changes during WebAuth flow to prevent memory leak #941
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
Open
utkrishtsahu
wants to merge
11
commits into
v4_development
Choose a base branch
from
SDK-6233-The-SDK-doesn-t-handle-configuration-changes-correctly-on-device-rotation-and-causes-a-memory-leak
base: v4_development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b6cacb3
fix: handle configuration changes during WebAuth flow to prevent memo…
utkrishtsahu 8058fe8
fix: handle configuration changes during WebAuth flow to prevent memo…
utkrishtsahu 8795d30
Merge branch 'v4_development' into SDK-6233-The-SDK-doesn-t-handle-co…
utkrishtsahu c0831d1
updated Migration doc
utkrishtsahu 61e92fe
fix: handle config changes in WebAuth flow with unified attach() API
utkrishtsahu 6ed2d1f
updated example.md file
utkrishtsahu 6b7675c
refactor: rename attach() to registerCallbacks(), deliver pending res…
utkrishtsahu ad0df64
make pendingLoginResult and pendingLogoutResult private, use reflecti…
utkrishtsahu ec02d07
fix: cache result in onRestoreInstanceState for process death recover…
utkrishtsahu 0886953
fix: prevent rotation from canceling auth, clear stale pending result…
utkrishtsahu c84ed7a
Fixing UT case
utkrishtsahu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
auth0/src/main/java/com/auth0/android/provider/LifecycleAwareCallback.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package com.auth0.android.provider | ||
|
|
||
| import androidx.lifecycle.DefaultLifecycleObserver | ||
| import androidx.lifecycle.LifecycleOwner | ||
| import com.auth0.android.authentication.AuthenticationException | ||
| import com.auth0.android.callback.Callback | ||
|
|
||
| /** | ||
| * Wraps a user-provided callback and observes the Activity/Fragment lifecycle. | ||
| * When the host is destroyed (e.g. config change), [delegateCallback] is set to null so | ||
| * the destroyed Activity is no longer referenced by the SDK. | ||
| * | ||
| * If a result arrives after [delegateCallback] has been cleared, the [onDetached] lambda | ||
| * is invoked to cache the result for later recovery via resumePending*Result(). | ||
| * | ||
| * @param S the success type (Credentials for login, Void? for logout) | ||
| * @param delegateCallback the user's original callback | ||
| * @param lifecycleOwner the Activity or Fragment whose lifecycle to observe | ||
| * @param onDetached called when a result arrives but the callback is already detached | ||
| */ | ||
| internal class LifecycleAwareCallback<S>( | ||
| @Volatile private var delegateCallback: Callback<S, AuthenticationException>?, | ||
| lifecycleOwner: LifecycleOwner, | ||
| private val onDetached: (success: S?, error: AuthenticationException?) -> Unit, | ||
| ) : Callback<S, AuthenticationException>, DefaultLifecycleObserver { | ||
|
|
||
| init { | ||
| lifecycleOwner.lifecycle.addObserver(this) | ||
| } | ||
|
|
||
| override fun onSuccess(result: S) { | ||
| val cb = delegateCallback | ||
| if (cb != null) { | ||
| cb.onSuccess(result) | ||
| } else { | ||
| onDetached(result, null) | ||
| } | ||
| } | ||
|
|
||
| override fun onFailure(error: AuthenticationException) { | ||
| val cb = delegateCallback | ||
| if (cb != null) { | ||
| cb.onFailure(error) | ||
| } else { | ||
| onDetached(null, error) | ||
| } | ||
| } | ||
|
|
||
| override fun onDestroy(owner: LifecycleOwner) { | ||
| delegateCallback = null | ||
| owner.lifecycle.removeObserver(this) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
How will this change behave when user back presses the browser ? With this change, the AuthenticationActivity stays in an invisible state doing nothing and user might get stuck