-
Notifications
You must be signed in to change notification settings - Fork 19
AuthTab Support Feature #124
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
Changes from 1 commit
ee1cce3
cc39a8a
6ddac0d
4673301
2a792f7
5a137c7
7ddb477
742b29c
387e96c
befcdd1
11248d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,27 +73,6 @@ public BrowserSwitchClient(@NonNull ActivityResultCaller caller) { | |
| initializeAuthTabLauncher(caller); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Constructor to initialize BrowserSwitchClient with a pending request to handle process kill scenarios. | ||
| * <p> | ||
| * When an app is killed during a browser switch, the pending request is lost. To properly handle this: | ||
| * <ol> | ||
| * <li>Store the pendingRequest string from {@link BrowserSwitchStartResult.Started} in persistent storage</li> | ||
| * <li>In {@code onCreate()}, check if there's a stored pending request</li> | ||
| * <li>If present, initialize {@code BrowserSwitchClient} with this constructor</li> | ||
| * </ol> | ||
| * </p> | ||
| * | ||
| * @param caller The ActivityResultCaller used to initialize the Auth Tab launcher | ||
| * @param pendingRequest The base64 encoded JSON string of the pending browser switch request retrieved from persistent storage | ||
| * @throws BrowserSwitchException if the pendingRequest cannot be parsed | ||
| */ | ||
| public BrowserSwitchClient(@NonNull ActivityResultCaller caller, @NonNull String pendingRequest) throws BrowserSwitchException { | ||
| this(new BrowserSwitchInspector(), new AuthTabInternalClient()); | ||
| initializeAuthTabLauncher(caller); | ||
| this.pendingAuthTabRequest = BrowserSwitchRequest.fromBase64EncodedJSON(pendingRequest); | ||
| } | ||
| @VisibleForTesting | ||
| BrowserSwitchClient(BrowserSwitchInspector browserSwitchInspector, | ||
saperi22 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| AuthTabInternalClient authTabInternalClient) { | ||
|
|
@@ -141,6 +120,25 @@ private void initializeAuthTabLauncher(@NonNull ActivityResultCaller caller) { | |
| ); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Restores a pending request after process kill or app restart. | ||
| * | ||
| * <p>Use this method to restore the browser switch state when the app process is killed while the | ||
| * browser is open. This should be called in the Activity's {@code onCreate()} method and before calling | ||
| * {@link #completeRequest(Intent, String)} to ensure the pending request is properly restored. | ||
| * | ||
| * <p>The {@code pendingRequest} parameter is the string returned by | ||
| * {@link BrowserSwitchStartResult.Started#getPendingRequest()} that was stored in persistent storage | ||
| * before the process was killed. | ||
| * | ||
| * @param pendingRequest The Base64-encoded JSON string representing the pending request to restore | ||
| * @throws BrowserSwitchException if the pending request cannot be parsed | ||
| */ | ||
| public void restorePendingRequest(@NonNull String pendingRequest) throws BrowserSwitchException { | ||
| this.pendingAuthTabRequest = BrowserSwitchRequest.fromBase64EncodedJSON(pendingRequest); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did we want to validate that the pendingRequest sent is non-null?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hey, that's a great suggestion, I added it to befcdd1 |
||
| } | ||
|
|
||
| /** | ||
| * Open a browser or Auth Tab with a given set of {@link BrowserSwitchOptions} from an Android activity. | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,20 +33,17 @@ public class DemoActivitySingleTop extends AppCompatActivity { | |
| @Override | ||
| protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
| super.onCreate(savedInstanceState); | ||
|
|
||
| browserSwitchClient = new BrowserSwitchClient(this); | ||
| // Check if there is a preserved pending request after the process kill | ||
|
||
| String pendingRequest = PendingRequestStore.get(this); | ||
|
|
||
| if (pendingRequest != null) { | ||
| // Restore state after process kill | ||
| // Restore pending request after process kill | ||
| try { | ||
| browserSwitchClient = new BrowserSwitchClient(this, pendingRequest); | ||
| browserSwitchClient.restorePendingRequest(pendingRequest); | ||
| } catch (BrowserSwitchException e) { | ||
| PendingRequestStore.clear(this); | ||
| browserSwitchClient = new BrowserSwitchClient(this); | ||
| } | ||
| } else { | ||
| // Normal initialization | ||
| browserSwitchClient = new BrowserSwitchClient(this); | ||
| } | ||
|
|
||
| FragmentManager fm = getSupportFragmentManager(); | ||
|
|
||
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.
Tiny tiny nit: not sure if the
(without AuthTab support)is necessary and it make the entry a bit long