Skip to content

fix: restore Android sign-in by routing OAuth callback through a trampoline activity#3091

Merged
veloce merged 2 commits intomainfrom
fix_android_signin
May 2, 2026
Merged

fix: restore Android sign-in by routing OAuth callback through a trampoline activity#3091
veloce merged 2 commits intomainfrom
fix_android_signin

Conversation

@veloce
Copy link
Copy Markdown
Contributor

@veloce veloce commented May 2, 2026

Problem

android:launchMode="singleTop" was restored in #3080. With singleTop, when Chrome Custom Tab
redirects to org.lichess.mobile://login-callback, Android creates a new MainActivity
instance
(because the existing one is not at the top of the task stack — the Custom Tab is).
That new instance gets a new Flutter engine and a separate Dart isolate, so the OAuth callback URI
never reaches the callbackCompleter waiting in the original signIn() call. The app lifecycle's
onResume fires, the 300 ms cancellation guard trips, and sign-in silently fails.

Fix

Introduce OAuthCallbackActivity, a minimal trampoline with no UI (Theme.NoDisplay) that owns
the org.lichess.mobile://login-callback intent filter instead of MainActivity. When the
redirect fires it immediately forwards the URI to the existing MainActivity via:

FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP

  • NEW_TASK crosses the task boundary if Chrome launched the trampoline in its own task
  • CLEAR_TOP finds the existing MainActivity in the app's task
  • SINGLE_TOP calls onNewIntent on it rather than recreating it

onNewIntent is delivered before onResume, so app_links routes the URI through uriLinkStream
and the callbackCompleter completes successfully before the cancellation timer can fire.
MainActivity stays singleTop, preserving correct back-navigation when opening the app from
external intents (e.g. file manager).

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to fix Android OAuth sign-in by routing the org.lichess.mobile://login-callback deep link through a dedicated trampoline activity instead of letting MainActivity receive the redirect directly. In the codebase, this change is intended to make the app-links/OAuth callback flow more reliable while preserving the existing Flutter MainActivity instance.

Changes:

  • Added a new OAuthCallbackActivity to receive the OAuth redirect URI and forward it to MainActivity.
  • Removed the OAuth callback intent filter from MainActivity.
  • Declared the new callback activity in the Android manifest as the sole handler for org.lichess.mobile://login-callback.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
android/app/src/main/kotlin/org/lichess/mobileV2/OAuthCallbackActivity.kt Adds the Android trampoline activity that forwards the login callback to MainActivity.
android/app/src/main/AndroidManifest.xml Rewires deep-link registration so the OAuth callback is handled by the new activity instead of MainActivity.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread android/app/src/main/AndroidManifest.xml
Chrome Custom Tabs fires the redirect intent from its own process/task, and the default taskAffinity rules mean OAuthCallbackActivity ends up in Chrome's task. When it then tries FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP, Android only searches the current task — MainActivity isn't there, so a new instance is created instead of onNewIntent being called.
The fix is to add FLAG_ACTIVITY_NEW_TASK to the forwarding intent. This tells Android to find the existing task whose affinity matches MainActivity (the app's task), bring it to the foreground, then apply CLEAR_TOP | SINGLE_TOP within that task to call onNewIntent on the existing MainActivity.
@veloce veloce changed the title Fix sign in on android fix: restore Android sign-in by routing OAuth callback through a trampoline activity May 2, 2026
@veloce veloce requested a review from Copilot May 2, 2026 11:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@veloce veloce merged commit 71dd48b into main May 2, 2026
4 checks passed
@veloce veloce deleted the fix_android_signin branch May 2, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants