Skip to content
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

Start the virtualdisplay‘s desktop #5838

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

Mr-JingShi
Copy link

@Mr-JingShi Mr-JingShi commented Feb 11, 2025

Android API 33(+) start the secondary screen desktop when creating a virtualdisplay.
Android API 29 ~ 32 does not start the secondary screen desktop when creating a virtualdisplay, and the virtualdisplay is a black screen. so I try to start the secondary screen desktop.
as show (even though it's ugly 🙂):

imageimage

Some Huawei phones do not have SECONDARY_HOME activity,
com.huawei.android.launcher/com.huawei.android.launcher.unihome.UniHomeLauncher is returned during resolve CATEGORY_HOME,
But com.huawei.android.internal.app/com.huawei.android.internal.app.HwResolverActivity is returned instead of null during resolve CATEGORY_SECONDARY_HOME. So I compared packageName.

@Mr-JingShi Mr-JingShi force-pushed the virtualDisplayLauncher branch from 887a51e to 2eebaf3 Compare February 11, 2025 03:37
@rom1v
Copy link
Collaborator

rom1v commented Feb 14, 2025

Thank you for the PR.

I tested on a OnePlus 7 Pro on Android 11, which shows a black screen for new displays on scrcpy 3.1.
With this PR, it correctly shows a "secondary home" (only if the device is unlocked). However, clicking on an app icon launches the app on the main display, which defeats the purpose. It also happens with another launcher, but I don't know if this behavior occurs on all Android 11 devices.

Btw, this PR only launches a secondary home for Android < 13, but I observed that on some devices even with Android 14, virtual displays have no home.
For example, on a Xiaomi Redmi Note 13 with Android 14, scrcpy --new-display shows a black screen. I modified this PR to call displayLauncher() anyway, the resulting package name is com.miui.home, but this does not work (it does not launch anything). Worse, it "broke" the main display home (the wallpapers changed, and could not be changed back, until a reboot).

@Mr-JingShi
Copy link
Author

Mr-JingShi commented Feb 18, 2025

Thank you for the PR.

I tested on a OnePlus 7 Pro on Android 11, which shows a black screen for new displays on scrcpy 3.1. With this PR, it correctly shows a "secondary home" (only if the device is unlocked). However, clicking on an app icon launches the app on the main display, which defeats the purpose. It also happens with another launcher, but I don't know if this behavior occurs on all Android 11 devices.

Btw, this PR only launches a secondary home for Android < 13, but I observed that on some devices even with Android 14, virtual displays have no home. For example, on a Xiaomi Redmi Note 13 with Android 14, scrcpy --new-display shows a black screen. I modified this PR to call displayLauncher() anyway, the resulting package name is com.miui.home, but this does not work (it does not launch anything). Worse, it "broke" the main display home (the wallpapers changed, and could not be changed back, until a reboot).

Thank you for your replay.

Sorry, I only tested the icon click events on Android 12 and 12_v2. Android 10 and 11 are not tested.

The icon click events on Android 12 and 12_v2 are ok.
Report the following warning on Android 10 or 11:

02-17 19:45:25.209  1524  8881 W ActivityTaskManager: Failed to put Task{9d21c00 #1175 visible=true type=standard mode=fullscreen translucent=true A=10210:com.secondaryscreen.sample U=0 StackId=1175 sz=1} on display 27

Then the app re-route to the default display.

https://cs.android.com/android/platform/superproject/+/android-12.0.0_r1:frameworks/base/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java;l=1097

Android 12's ProtoLog log
02-21 16:46:29.497  1957 10843 D WindowManager: Launch on display check: displayId=11 callingPid=6136 callingUid=2000
02-21 16:46:29.497  1957 10843 D WindowManager: Launch on display check: allow launch any on display
...
02-21 16:46:33.866  1957  4189 D WindowManager: Launch on display check: displayId=11 callingPid=3606 callingUid=10085
02-21 16:46:33.867  1957  4189 D WindowManager: Launch on display check: allow launch any on display

Android 12 and 12_v2 are allowed to launch activities on specified display.

I have an Android 10 Huawei device but it doesn't have seconday home.
I have an Android 12 Huawei device that the secondaryhome is re-routesd from virtualdisplay to the defalut display when special codes are used. just like your Xiaomi Redmi Note 13 with Android 14.

When I use the following code, the secondaryhome is re-routesd from virtualdisplay to the defalut display.

Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
launcherIntent.addCategory(Intent.CATEGORY_SECONDARY_HOME);

or

Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
launcherIntent.addCategory(Intent.CATEGORY_SECONDARY_HOME);
launcherIntent.setClassName(secondaryHomeResolveInfo.activityInfo.packageName, secondaryHomeResolveInfo.activityInfo.name);

When I use the following code, It is ok.

Intent launcherIntent = new Intent(Intent.ACTION_MAIN);
launcherIntent.addCategory(Intent.CATEGORY_SECONDARY_HOME);
launcherIntent.addCategory(Intent.CATEGORY_DEFAULT);

or

Intent launcherIntent = new Intent();
launcherIntent.setClassName(secondaryHomeResolveInfo.activityInfo.packageName, secondaryHomeResolveInfo.activityInfo.name);

https://cs.android.com/android/platform/superproject/+/android-11.0.0_r14:packages/apps/Launcher3/AndroidManifest-common.xml;l=186

<activity
    android:name="com.android.launcher3.secondarydisplay.SecondaryDisplayLauncher"
    android:theme="@style/AppTheme"
    android:launchMode="singleTop"
    android:enabled="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.SECONDARY_HOME" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

CATEGORY_SECONDARY_HOME and CATEGORY_DEFAULT must be used together.

@Mr-JingShi
Copy link
Author

Mr-JingShi commented Feb 18, 2025

I open Developer options-Simulate secondary displays and Developer options-Force desktop mode.
The OVERLAY display shows as follows:
image

It has secondary home、navigationbar、background or wallpaper, so I want to start the virtualdisplay‘s desktop

I tried to fix the icon click problem, the app can be launched on the virtual display, but there is a toast texted "App does not support launch on secondary displays." on the default display.

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