Skip to content

Conversation

@p3dr0rv
Copy link
Contributor

@p3dr0rv p3dr0rv commented Aug 29, 2025

Problem

The current DUNA implementation launches BrokerAuthorizationActivity with
FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_CLEAR_TASK.

This causes:

  • Device registration failures
  • Other authentication flows failing

The issue arises because the activity stack is cleared, preventing proper continuation of dependent flows.


Solution

Introduce SwitchBrowserActivity to handle the browser switch during the DUNA authentication flow.

This approach:

  • Isolates the browser-based authentication
  • Preserves the existing activity stack for device registration and other auth processes
  • Leaves non-DUNA flows unchanged

Activity Stack Behavior

  1. Task 1: BrokerAuthorizationActivity launches SwitchBrowserActivity in Task 2
  2. Task 1: BrokerAuthorizationActivity | Task 2: SwitchBrowserActivity → Chrome Custom Tabs
  3. Task 1: BrokerAuthorizationActivity | Task 2: SwitchBrowserActivity → Chrome Custom Tabs | Task 3: BrokerBrowserRedirectActivity
  4. Task 1: BrokerAuthorizationActivity | Task 2: SwitchBrowserActivity → Chrome Custom Tabs | Task 3: BrokerBrowserRedirectActivity (finishes)

Flow Overview of SwitchBrowserActivity

  1. WebViewAuthorizationFragment receives a SwitchBrowser challenge
  2. SwitchBrowserActivity is launched with browser configuration parameters
  3. Launches external browser (Custom Tabs or standard browser)
  4. User completes authentication in the external browser
  5. Browser redirects to BrokerBrowserRedirectActivity in a new task
  6. BrokerBrowserRedirectActivity forwards redirect result back to SwitchBrowserActivity via onNewIntent()
  7. SwitchBrowserActivity passes the result to WebViewAuthorizationFragment
  8. SwitchBrowserActivity finishes and removes itself from the task stack

Security Note

  • SwitchBrowserActivity is not exported
  • Can only be launched from inside the app
  • Prevents external apps from triggering unwanted browser switches

@p3dr0rv p3dr0rv changed the title Pedroro/duna fix activity backstack [WIP] Aug 29, 2025
@github-actions
Copy link

❌ Work item link check failed. Description does not contain AB#{ID}.

Click here to Learn more.

p3dr0rv and others added 5 commits August 29, 2025 14:12
…ine intent handling and improve code clarity
…uce SwitchBrowserActivity for improved browser switching flow
…mproved logging and clarity; streamline intent creation in SwitchBrowserProtocolCoordinator
… remove unused parameters for improved clarity and simplicity
…dle user cancellations and improve activity lifecycle management
@p3dr0rv p3dr0rv marked this pull request as ready for review September 1, 2025 21:23
Copilot AI review requested due to automatic review settings September 1, 2025 21:23
@p3dr0rv p3dr0rv requested review from a team as code owners September 1, 2025 21:23
Copy link
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 implements a redesigned switch browser flow to fix back stack management issues. The changes replace direct browser launching from the challenge handler with a dedicated SwitchBrowserActivity that manages the browser lifecycle more cleanly.

Key Changes:

  • Introduced SwitchBrowserActivity to handle browser launch and redirect management
  • Updated SwitchBrowserRequestHandler to delegate to the new activity instead of launching browsers directly
  • Modified protocol coordinator to support the new activity-based flow

Reviewed Changes

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

Show a summary per file
File Description
SwitchBrowserActivity.kt New activity that manages browser launch and authentication redirects
SwitchBrowserRequestHandler.kt Simplified to launch SwitchBrowserActivity instead of managing browsers directly
SwitchBrowserProtocolCoordinator.kt Updated to work with new activity and renamed property
WebViewAuthorizationFragment.java Added static bundle management for switch browser resume data
BrokerAuthorizationActivity.java Removed switch browser specific onNewIntent handling
AuthorizationActivityFactory.kt Removed switch browser specific intent flags
Test files Updated to reflect API changes and removed unused dependencies

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

p3dr0rv and others added 2 commits September 1, 2025 14:24
…oviders/oauth2/SwitchBrowserActivity.kt

Co-authored-by: Copilot <[email protected]>
…oviders/oauth2/WebViewAuthorizationFragment.java

Co-authored-by: Copilot <[email protected]>
@p3dr0rv p3dr0rv changed the title [WIP] Fix Switch browser back stack erro Sep 2, 2025
@p3dr0rv p3dr0rv changed the title Fix Switch browser back stack erro Fix Switch browser back stack error Sep 2, 2025
@p3dr0rv p3dr0rv merged commit f3aac73 into dev Sep 2, 2025
24 of 25 checks passed
@p3dr0rv p3dr0rv deleted the pedroro/duna-fix-activity-backstack branch September 2, 2025 23:24
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.

4 participants