Repository navigation
Keep the Android auth tab out of the app's task - #3
Merged
Merged
Conversation
Browser::auth() opened its Custom Tab straight from MainActivity, so the tab joined the app's task. If the app's activities were removed while the tab was open (an update, a force-stop, or the process dying in the background), the launcher kept bringing that task back. The user saw the old sign-in page and the app never started. The tab now opens from a small translucent AuthTabActivity started as its own document task, which the launcher never resumes. An init function and the existing lifecycle events end the sign-in: any deep link into the app removes the tab's task, closing the tab returns to the app, and coming back to the app while the sign-in is open brings the tab back to the front. A new process removes tabs left over from an old one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
On Android,
Browser::auth()opened its Custom Tab straight from MainActivity, so the tab joined the app's task. That's fine while everything stays alive. But if the app's activities are removed while the tab is open (a Play Store update, a force-stop, or Android killing the process in the background), the tab is left in the app's task on top of nothing. The launcher keeps bringing that task back, so tapping the app icon shows the old sign-in page and the app never starts. We hit this with the dev/null app on a Moto g24.Approving was never the problem. Chrome and Firefox both send the redirect back with
CLEAR_TOP, which closes the tab. It only goes wrong when the tab is still open when the app goes away.What changed
Browser.OpenAuthnow startsAuthTabActivity, an invisible activity in a separate document task, and that activity opens the Custom Tab on top of itself. The launcher never resumes that task, so the app icon always opens the app.AuthTabthen ends the sign-in roughly the way iOS's ASWebAuthenticationSession does:auth()again replaces the old tabnativephp.json gets an
android.init_functionand anandroid.activitiesentry, with a test that both exist. The README explains the Android behaviour. iOS,inApp()andopen()are unchanged.What to watch for
NATIVEPHP_DEEPLINK_SCHEME, but on Android the redirect can be an https app link, and the plugin can't tell that apart from other links.init_functionneeds nativephp/mobile 3.2 or later. On older coresauth()subscribes the listeners itself, so only the cleanup at startup is missing.Reproduction
Android 15 emulator with Chrome 124, dev/null app, and a local stand-in for dev-null.sh whose Approve button answers with a 303 to
devnull://auth/callback, like the real page.adb install -rthe same APK (update),adb shell am force-stop <id>, oradb shell am kill <id>(background process death).Update, then icon. Before on the left, after on the right:
Recents while a sign-in is open, after this change:
The Moto g24 (Android 14, Chrome 153) failed the same way. A sign-in tab left open over an
adb installbecame the only activity in the app's task, and later launches showed it.On the Moto with this branch (profileable build, opened from the app drawer):
Background kill, force-stop and update with the tab open: the icon opens the app, and the old sign-in task is gone once it starts.
Closing the tab returns to the app and leaves nothing in Recents.
Coming back through the icon mid sign-in: the tab is moved back 33 ms after the app resumes, and showing 137 ms later.
A full sign-in against a local copy of dev-null.sh over a tunnel (production was in maintenance): the real "Approve devnull on moto g24?" page, Approve, the callback arrives with
NEW_TASK|CLEAR_TOP, the app signs in, and nothing is left in Recents.Not tried with a non-Chrome browser.
The plugin suite passes locally with CI's composer setup (59 tests), and Pint is clean.
🤖 Generated with Claude Code