Skip to content

Activity launches when Android desktop mode is active (Android 16 QPR1+ / Android 17)#6722

Draft
lmichaelwar wants to merge 7 commits intoGenymobile:masterfrom
lmichaelwar:master
Draft

Activity launches when Android desktop mode is active (Android 16 QPR1+ / Android 17)#6722
lmichaelwar wants to merge 7 commits intoGenymobile:masterfrom
lmichaelwar:master

Conversation

@lmichaelwar
Copy link

Summary of Changes
Problem
Virtual displays created by scrcpy don't correctly route activity launches when Android desktop mode is active (Android 16 QPR1+ / Android 17). Apps launched from the virtual display's desktop launcher open on the phone's main screen instead of the virtual display.

Root Cause
VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS was only set conditionally (via user option), not guaranteed on API 34+
The virtual display area was never assigned WINDOWING_MODE_FREEFORM via WindowContainerTransaction, which is required for freeform windowing in desktop mode
Changes Made
NewDisplayCapture.java (2 changes):

Added VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS to the unconditional API 34+ flag block — ensures the display is always treated as a full windowing environment on modern Android
Added call to setDisplayWindowingMode() after virtual display creation to set freeform windowing mode
WindowManager.java (1 new method + 2 constants):

Added WINDOWING_MODE_FREEFORM constant (= 5, from android.app.WindowConfiguration)
Added FEATURE_DEFAULT_TASK_CONTAINER constant (= 1, from android.window.DisplayAreaOrganizer)
Added setDisplayWindowingMode(int displayId, int windowingMode) method that:
Gets the IWindowOrganizerController service via reflection
Temporarily registers a no-op DisplayAreaOrganizer to obtain the display area's WindowContainerToken
Creates and applies a WindowContainerTransaction to set the windowing mode
Properly unregisters the organizer in a finally block
Gracefully handles failures with warning logs

Copilot AI and others added 7 commits March 13, 2026 20:41
…ay desktop mode

- Add VIRTUAL_DISPLAY_FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS unconditionally
  for API 34+ alongside OWN_FOCUS to ensure desktop mode compatibility
- Add WindowContainerTransaction-based setDisplayWindowingMode() to
  WindowManager using reflection to set WINDOWING_MODE_FREEFORM on the
  virtual display's default task area after creation
- Call setDisplayWindowingMode after virtual display creation on API 34+

Co-authored-by: lmichaelwar <20604470+lmichaelwar@users.noreply.github.com>
Co-authored-by: lmichaelwar <20604470+lmichaelwar@users.noreply.github.com>
…play-launches

Fix virtual display activity routing for Android desktop mode
… Binder descriptor, respect vdSystemDecorations flag

1. WindowManager.java: Replace manual reflection for window_organizer service
   with ServiceManager.getService() to avoid duplicating reflection logic.
2. WindowManager.java: Attach correct AIDL interface descriptor to the
   organizer Binder and override onTransact to safely handle callbacks.
3. NewDisplayCapture.java: Remove unconditional SHOULD_SHOW_SYSTEM_DECORATIONS
   from API 34+ block so --no-vd-system-decorations remains effective.

Co-authored-by: lmichaelwar <20604470+lmichaelwar@users.noreply.github.com>
…eview-comments

Address code review feedback on virtual display desktop mode fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants