-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Bug: after OS update, Honor Magic4 pro can't be mirrored with screen turned off using ScrCpy (closes right away), but can be via Android Studio #4943
Comments
It should not work, because Android Studio declared that turn off device display while mirroring is not supported on Android 14. |
@eiyooooo They fixed it (maybe using some workaround) but didn't change the text for some reason. |
I tested on my Android 14 phone, and it did not work. And shows that it does not seem to support "turn off device display" on Android 14. |
@eiyooooo Seems it's as such for me for Android 14 : How odd... |
All the Honor phones with the recent updates are affected by this bug. This is very important to have a fix. Thanks! |
@eiyooooo @zoukyle For now, for the Honor device, I use the stable version of Android Studio. They also claim that it will be fixed on the next version of Android itself, not sure about the IDE itself: |
The reason why stable version of Android Studio can work is because Honor devices still can use sdk ≤ 33 way to turn off screen.
Because check Android version now. |
@eiyooooo So that's too bad. |
You could bypass Android 14 method for Honor devices by this and compile a scrcpy server for Honor devices |
@eiyooooo I'm not the developer of ScrCpy. I only reported about this issue. |
scrcpy-server.zip |
I hope for a new official version, then |
@naughtz I've closed this issue as now it works fine. |
Similar idea to avoid invoke |
scrcpy/server/src/main/java/com/genymobile/scrcpy/device/Device.java Lines 345 to 348 in ed40669
@rom1v I think here should have a fallback to turn only one display off instead of doing nothing. |
Do you have In theory, in this branch (on Android 14), AFAIK, the problem here is that the Honor Magic 4 with Android 14 is still really an Android 13 in this piece of code, and loading the native library with IIUC, Android Studio does not support turning screen off for devices with Android 14 (except the Honor which behaves like an Android 13), but only for Android <= 13 or Android >= 15. However, maybe we should use the multiple display ids even on the honor. Here is an alternative fix: Please someone with an Honor device test turning the screen off with this binary (built from
|
@rom1v About "Android Studio does not support turning screen off for devices with Android 14", they fixed it. About the "scrcpy-win64-honoroff.5.zip" file, it mirrors the device, but doesn't turn off the display, by using this:
|
No, but it's better to have a fallback in case physicalDisplayIds is null.
Android Studio now support turning screen off for devices with Android 14
The |
Oh cool.
In the code from Android studio, they check if the ids list is empty because they return an empty vector is the method is not found. We could add a fallback if I'm trying to understand how this code (ignoring the part for API >= 35 for now) works for all devices on Android 14, in particular, both a Pixel device (as expected), but also an Honor, without special cases (and I don't have any Honor device to test). In this bug report (#4943), it seems that the Honor device fails (and crashes) as soon as we load the native library (i.e. as soon as we call According to the
Here, they load the native libraries using exactly the same mechanism as scrcpy, but only if BOTH And in If I'm correct (I may be wrong), I think I prefer an explicit check for the Honor device (i.e. keeping the current code on It remains to implement I have no device with Android 15 for now, and the code is not released in AOSP, but we can implement it based on the code from Android Studio: https://android.googlesource.com/platform/tools/adt/idea/+/170a4f9317a8833f72661e2b6d51f64c685ce358/streaming/screen-sharing-agent/app/src/main/cpp/accessors/display_manager.cc#46 diff --git a/server/src/main/java/com/genymobile/scrcpy/device/Device.java b/server/src/main/java/com/genymobile/scrcpy/device/Device.java
index 5a1083fde..49bbe4796 100644
--- a/server/src/main/java/com/genymobile/scrcpy/device/Device.java
+++ b/server/src/main/java/com/genymobile/scrcpy/device/Device.java
@@ -323,6 +323,11 @@ public final class Device {
* @param mode one of the {@code POWER_MODE_*} constants
*/
public static boolean setScreenPowerMode(int mode) {
+ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
+ // TODO Turn off secondary physical displays
+ return ServiceManager.getDisplayManager().requestDisplayPower(0, mode);
+ }
+
boolean applyToMultiPhysicalDisplays = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
if (applyToMultiPhysicalDisplays
diff --git a/server/src/main/java/com/genymobile/scrcpy/wrappers/DisplayManager.java b/server/src/main/java/com/genymobile/scrcpy/wrappers/DisplayManager.java
index dd92330cf..fd2c58d24 100644
--- a/server/src/main/java/com/genymobile/scrcpy/wrappers/DisplayManager.java
+++ b/server/src/main/java/com/genymobile/scrcpy/wrappers/DisplayManager.java
@@ -19,6 +19,7 @@ import java.util.regex.Pattern;
public final class DisplayManager {
private final Object manager; // instance of hidden class android.hardware.display.DisplayManagerGlobal
private Method createVirtualDisplayMethod;
+ private Method requestDisplayPowerMethod;
static DisplayManager create() {
try {
@@ -124,4 +125,20 @@ public final class DisplayManager {
Method method = getCreateVirtualDisplayMethod();
return (VirtualDisplay) method.invoke(null, name, width, height, displayIdToMirror, surface);
}
+
+ private Method getRequestDisplayPowerMethod() throws NoSuchMethodException {
+ if (requestDisplayPowerMethod == null) {
+ requestDisplayPowerMethod = manager.getClass().getMethod("requestDisplayPower", int.class, int.class);
+ }
+ return requestDisplayPowerMethod;
+ }
+
+ public boolean requestDisplayPower(int displayId, int state) {
+ try {
+ Method method = getRequestDisplayPowerMethod();
+ return (boolean) method.invoke(manager, displayId, state);
+ } catch (ReflectiveOperationException e) {
+ throw new AssertionError(e);
+ }
+ }
} Could someone with an Android 15 test this patch? |
|
For Android 15, you can try the emulator, but it's probably a bad test.... |
Environment
Windows
2.4
Extracted the ZIP file.
[HONOR] HONOR LGE-NX9
Android 14
Describe the bug
When launching without any parameters and without any key combination, it works fine.
However, when I tell it to also turn off the display (either in parameter or using ALT+O combination), it closes the window of ScrCpy right away.
This is what I got from the console, after I used ALT+O:
And this is what I got on logcat, filtered by errors:
logcat.zip
This issue doesn't occur when using Android Studio to mirror the device and turning off the display.
ScrCpy used to work fine with this device.
The issue started only yesterday, as I've updated the OS.
The text was updated successfully, but these errors were encountered: