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

scrcpy[v3.0] seems locked when -S argument or meta-o pressed #5530

Closed
chopin1998 opened this issue Nov 25, 2024 · 34 comments
Closed

scrcpy[v3.0] seems locked when -S argument or meta-o pressed #5530

chopin1998 opened this issue Nov 25, 2024 · 34 comments

Comments

@chopin1998
Copy link

chopin1998 commented Nov 25, 2024

Environment

  • OS: [ Linux ubuntu 24.04]
  • Scrcpy version: [ 3.0/ master/ dev]
  • Installation method: [./install_release.sh]
  • vivo iqooo13
  • Android version: [15]

Describe the bug

scrcpy seems locked (out of control via mouse) when -S argument or meta-o pressed, but after meta-shift-o pressed, when phone screen light, it unlocked..

no error on terminal

❯ scrcpy
scrcpy 3.0 <https://github.com/Genymobile/scrcpy>
INFO: ADB device found:
INFO:     -->   (usb)  10AEB53ADU001JP                 device  V2408A
/usr/local/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 278.4 MB/s (90224 bytes in 0.000s)
[server] INFO: Device: [vivo] vivo V2408A (Android 15)
INFO: Renderer: opengl
INFO: OpenGL version: 4.6 (Compatibility Profile) Mesa 24.0.9-0ubuntu0.2
INFO: Trilinear filtering enabled
INFO: Texture: 1440x3168
[server] INFO: Device display turned off
[server] INFO: Device display turned on
@chopin1998
Copy link
Author

v2.7 is fine..

@chopin1998 chopin1998 changed the title scrcpy seems locked when -K argument or meta-o pressed scrcpy[v3.0] seems locked when -K argument or meta-o pressed Nov 25, 2024
@chopin1998 chopin1998 changed the title scrcpy[v3.0] seems locked when -K argument or meta-o pressed scrcpy[v3.0] seems locked when -S argument or meta-o pressed Nov 25, 2024
@rom1v
Copy link
Collaborator

rom1v commented Nov 25, 2024

If you can build manually, could you please find the specific commit which introduce this behavior on your device using git rebase?

@chopin1998
Copy link
Author

If you can build manually, could you please find the specific commit which introduce this behavior on your device using git rebase?

git checkout 3d478d7, fine.

git checkout 5e05f2a, cannot launch after ./install_release.sh. seems v2.7/v3.0 mismatch

git checkout 74aecc0(master now), can lauch, but locked when -S or MOD_O

@rom1v
Copy link
Collaborator

rom1v commented Nov 25, 2024

Thanks, but you must biild the server too, not use ./install_release.sh which will always download the same server release (either 2.7 or 3), but without the changes in between.

@chopin1998
Copy link
Author

Thanks, but you must biild the server too, not use ./install_release.sh which will always download the same server release (either 2.7 or 3), but without the changes in between.

build scrcpy-server need android sdk that needtoo much dependency...

@razielaka
Copy link

razielaka commented Nov 25, 2024

I have the same problem on Windows with version 3.0. I'm guessing this problem is related to issue #5529.

@rom1v
Copy link
Collaborator

rom1v commented Nov 25, 2024

I suspect this change: d193967

@icantremember
Copy link

icantremember commented Nov 25, 2024

Also not able to "turn screen off" with the command line option or meta-o. Pixel 9 Fold, running beta 15 qpr 2.

screen-off-timeout is nice, though.... I had been using Tasker for that :)

here's my command line when hitting meta-o:

PS C:\android\scrcpy> .\scrcpy.exe
scrcpy 3.0 <https://github.com/Genymobile/scrcpy>
INFO: ADB device found:
INFO:     -->   (usb)  47291FDKD001EB                  device  Pixel_9_Pro_Fold
C:\android\scrcpy\scrcpy-server: 1 file pushed, 0 skipped. 55.6 MB/s (90224 bytes in 0.002s)
[server] INFO: Device: [Google] google Pixel 9 Pro Fold (Android 15)
INFO: Renderer: direct3d
INFO: Texture: 2080x2152
[server] ERROR: Could not invoke method
java.lang.NoSuchMethodException: android.hardware.display.DisplayManagerGlobal.requestDisplayPower [int, boolean]
        at java.lang.Class.getMethod(Class.java:2950)
        at java.lang.Class.getMethod(Class.java:2450)
        at com.genymobile.scrcpy.wrappers.DisplayManager.getRequestDisplayPowerMethod(DisplayManager.java:169)
        at com.genymobile.scrcpy.wrappers.DisplayManager.requestDisplayPower(DisplayManager.java:177)
        at com.genymobile.scrcpy.device.Device.setDisplayPower(Device.java:131)
        at com.genymobile.scrcpy.control.Controller.setDisplayPower(Controller.java:694)
        at com.genymobile.scrcpy.control.Controller.handleEvent(Controller.java:285)
        at com.genymobile.scrcpy.control.Controller.control(Controller.java:194)
        at com.genymobile.scrcpy.control.Controller.lambda$start$0$com-genymobile-scrcpy-control-Controller(Controller.java:202)
        at com.genymobile.scrcpy.control.Controller$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
        at java.lang.Thread.run(Thread.java:1012)

@rom1v
Copy link
Collaborator

rom1v commented Nov 25, 2024

Please post your framework.jar:

adb pull /system/framework/framework.jar

@icantremember
Copy link

icantremember commented Nov 25, 2024

here it is:
framework_jar.zip

also, just tried new-display and got an error (sorry, code block not working for some reason):

PS C:\android\scrcpy> ./scrcpy --new-display=1920x1080
scrcpy 3.0 <https://github.com/Genymobile/scrcpy>
INFO: ADB device found:
INFO:     -->   (usb)  47291FDKD001EB                  device  Pixel_9_Pro_Fold
C:\android\scrcpy\scrcpy-server: 1 file pushed, 0 skipped. 56.2 MB/s (90224 bytes in 0.002s)
[server] INFO: Device: [Google] google Pixel 9 Pro Fold (Android 15)
[server] ERROR: Could not create display
java.lang.SecurityException: Requires ADD_TRUSTED_DISPLAY permission to create a trusted virtual display.
        at android.os.Parcel.createExceptionOrNull(Parcel.java:3231)
        at android.os.Parcel.createException(Parcel.java:3215)
        at android.os.Parcel.readException(Parcel.java:3198)
        at android.os.Parcel.readException(Parcel.java:3140)
        at android.hardware.display.IDisplayManager$Stub$Proxy.createVirtualDisplay(IDisplayManager.java:1570)
        at android.hardware.display.DisplayManagerGlobal.createVirtualDisplay(DisplayManagerGlobal.java:757)
        at android.hardware.display.DisplayManager.createVirtualDisplay(DisplayManager.java:1186)
        at android.hardware.display.DisplayManager.createVirtualDisplay(DisplayManager.java:1146)
        at android.hardware.display.DisplayManager.createVirtualDisplay(DisplayManager.java:1094)
        at android.hardware.display.DisplayManager.createVirtualDisplay(DisplayManager.java:1033)
        at com.genymobile.scrcpy.wrappers.DisplayManager.createNewVirtualDisplay(DisplayManager.java:164)
        at com.genymobile.scrcpy.video.NewDisplayCapture.startNew(NewDisplayCapture.java:186)
        at com.genymobile.scrcpy.video.NewDisplayCapture.start(NewDisplayCapture.java:207)
        at com.genymobile.scrcpy.video.SurfaceEncoder.streamCapture(SurfaceEncoder.java:95)
        at com.genymobile.scrcpy.video.SurfaceEncoder.lambda$start$0$com-genymobile-scrcpy-video-SurfaceEncoder(SurfaceEncoder.java:292)
        at com.genymobile.scrcpy.video.SurfaceEncoder$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
        at java.lang.Thread.run(Thread.java:1012)
Caused by: android.os.RemoteException: Remote stack trace:
        at com.android.server.display.DisplayManagerService.createVirtualDisplayInternal(DisplayManagerService.java:1836)
        at com.android.server.display.DisplayManagerService.-$$Nest$mcreateVirtualDisplayInternal(DisplayManagerService.java:0)
        at com.android.server.display.DisplayManagerService$BinderService.createVirtualDisplay(DisplayManagerService.java:4593)
        at android.hardware.display.IDisplayManager$Stub.onTransact(IDisplayManager.java:802)
        at android.os.Binder.execTransactInternal(Binder.java:1406)

[server] ERROR: Exception on thread Thread[video,5,main]
java.lang.AssertionError: Could not create display
        at com.genymobile.scrcpy.video.NewDisplayCapture.startNew(NewDisplayCapture.java:193)
        at com.genymobile.scrcpy.video.NewDisplayCapture.start(NewDisplayCapture.java:207)
        at com.genymobile.scrcpy.video.SurfaceEncoder.streamCapture(SurfaceEncoder.java:95)
        at com.genymobile.scrcpy.video.SurfaceEncoder.lambda$start$0$com-genymobile-scrcpy-video-SurfaceEncoder(SurfaceEncoder.java:292)
        at com.genymobile.scrcpy.video.SurfaceEncoder$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
        at java.lang.Thread.run(Thread.java:1012)
INFO: Renderer: direct3d
WARN: Device disconnected
ERROR: Demuxer 'audio': stream disabled due to connection error

@rom1v
Copy link
Collaborator

rom1v commented Nov 25, 2024

sorry, code block not working for some reason

You need ``` as delimiter.

also, just tried new-display and got an error

#5523

here it is: framework_jar.zip

Thank you.

On your system, the method is:

public boolean requestDisplayPower(int displayId, int state)

instead of

public boolean requestDisplayPower(int displayId, boolean on)

https://android.googlesource.com/platform/frameworks/base/+/6cf18f06f2ae89d807fbec1d36a8530f14d20fd2/core/java/android/hardware/display/DisplayManagerGlobal.java#556

(which has never been the case in the Android sources)

I don't know if it an old interval version, or if the new method signature will now be with an int.

I will upgrade my Pixel 8 to Android 15 to check all these problems.

@icantremember
Copy link

sorry, code block not working for some reason

You need ``` as delimiter.

gotcha :)

I will upgrade my Pixel 8 to Android 15 to check all these problems.

Thank you! Let me know if I can provide anything else. I don't have a dev environment set up, but I excel at copy/pasting.

@rom1v
Copy link
Collaborator

rom1v commented Nov 25, 2024

Everything works fine on Android 15 stable.

I will wait a bit before fixing issues on Beta versions (maybe they will be automatically fixed, or the final fix will be different).

@drothenberger
Copy link

Everything works fine on Android 15 stable.

It's not working correctly for me on Android 15 stable (Pixel 9 Pro). When the screen is turned off with meta-o, the scrcpy display stops updating. For example, if I use the scroll wheel on my mouse to scroll a page, the scrcpy display does not update. However, if I turn on the phone display with meta-shift-o, the scrcpy display updates.

@rom1v
Copy link
Collaborator

rom1v commented Nov 26, 2024

@drothenberger Sorry, I was talking about the exceptions in the previous comments.

Indeed, I can reproduce the problem when the screen is turned off. I'm afraid the problem will have to be reported to Android, regarding the new method to turn the screen off: 58ba00f

@defix
Copy link

defix commented Nov 26, 2024

@drothenberger Sorry, I was talking about the exceptions in the previous comments.

Indeed, I can reproduce the problem when the screen is turned off. I'm afraid the problem will have to be reported to Android, regarding the new method to turn the screen off: 58ba00f

@rom1v Now I'm using version 2.7, and the control is normal after the screen of my Android 15 phone is turned off. So, is it possible to use the method to control the screen off before Android 15, or add an option switch?

@icantremember
Copy link

Everything works fine on Android 15 stable.

I will wait a bit before fixing issues on Beta versions (maybe they will be automatically fixed, or the final fix will be different).

Understood. But, like @defix, I just rolled back to scrcpy 2.7 and meta-(shift)-o works fine on the beta android version.

@rom1v
Copy link
Collaborator

rom1v commented Nov 26, 2024

Yes, because it doesn't use the new method introduced in Android 15. If there is no solution, I will change to use the old method.

@rom1v
Copy link
Collaborator

rom1v commented Nov 26, 2024

Please test:

diff --git server/src/main/java/com/genymobile/scrcpy/device/Device.java server/src/main/java/com/genymobile/scrcpy/device/Device.java
index cd7134993..0aaba9d14 100644
--- server/src/main/java/com/genymobile/scrcpy/device/Device.java
+++ server/src/main/java/com/genymobile/scrcpy/device/Device.java
@@ -127,10 +127,6 @@ public final class Device {
     public static boolean setDisplayPower(int displayId, boolean on) {
         assert displayId != Device.DISPLAY_ID_NONE;
 
-        if (Build.VERSION.SDK_INT >= AndroidVersions.API_35_ANDROID_15) {
-            return ServiceManager.getDisplayManager().requestDisplayPower(displayId, on);
-        }
-
         boolean applyToMultiPhysicalDisplays = Build.VERSION.SDK_INT >= AndroidVersions.API_29_ANDROID_10;
 
         if (applyToMultiPhysicalDisplays

Replace this file in scrcpy 3.0:

  • scrcpy-server SHA-256: d34d4c657ce3ccecc79b01293ca0ace459ce757115bf3e071dc2fad10c463bc

@defix
Copy link

defix commented Nov 26, 2024

Please test:

diff --git server/src/main/java/com/genymobile/scrcpy/device/Device.java server/src/main/java/com/genymobile/scrcpy/device/Device.java
index cd7134993..0aaba9d14 100644
--- server/src/main/java/com/genymobile/scrcpy/device/Device.java
+++ server/src/main/java/com/genymobile/scrcpy/device/Device.java
@@ -127,10 +127,6 @@ public final class Device {
     public static boolean setDisplayPower(int displayId, boolean on) {
         assert displayId != Device.DISPLAY_ID_NONE;
 
-        if (Build.VERSION.SDK_INT >= AndroidVersions.API_35_ANDROID_15) {
-            return ServiceManager.getDisplayManager().requestDisplayPower(displayId, on);
-        }
-
         boolean applyToMultiPhysicalDisplays = Build.VERSION.SDK_INT >= AndroidVersions.API_29_ANDROID_10;
 
         if (applyToMultiPhysicalDisplays
  • scrcpy-server SHA-256: d34d4c657ce3ccecc79b01293ca0ace459ce757115bf3e071dc2fad10c463bc
  1. In mirror mode, the screen can be normally turned off by commands and shortcut keys. After the screen is turned off, the control functions normally, and the audio also works fine.
  2. In virtual display mode:
    1. Neither "alt + o" nor "alt + shift + o" works properly, while "alt + p" functions.
    2. After turning off the screen with "alt + p", the virtual display does not respond to the mouse and keyboard, but the frame rate output in the console is normal.
    3. When using the virtual display, the input method keyboard does not follow onto the virtual screen.

@rom1v
Copy link
Collaborator

rom1v commented Nov 26, 2024

Thank you for your test.

In virtual display mode:
Neither "alt + o" nor "alt + shift + o" works properly, while "alt + p" functions.

#5522

With both fixes:

  • scrcpy-server SHA-256: e8276d42cd44014fc3b8e5adce825bbfe989cf30cc302acd1365514cd06306c

@defix
Copy link

defix commented Nov 26, 2024

In virtual display mode:
Neither "alt + o" nor "alt + shift + o" works properly, while "alt + p" functions.

#5522

With both fixes:

  • scrcpy-server SHA-256: e8276d42cd44014fc3b8e5adce825bbfe989cf30cc302acd1365514cd06306c

You're amazing!

  1. Both "alt + o" and "alt + shift + o" work as expected.
  2. When "alt + p" is expected to lock, the physical screen turns off while the virtual screen is still displaying normally but not responding. Pressing "alt + p" again, when it is expected to unlock, the physical screen can be lit up normally and the virtual screen resumes responding.
  3. (New issue) After turning off the screen with "alt + o" and then locking it with "alt + p", one has to press both "alt + p" and "alt + shift + o" to light up the screen. Could it be optimized so that after turning off the screen and locking it with shortcut keys, pressing "alt + p" once can unlock it and make it display?

@chopin1998
Copy link
Author

c00l!
in my device, vivo iqoo 13, the new patch worked with -S or MOD-o!

but cannot MOD-Shift-O to turn device display on again... in terminal show "[server] INFO: Device display turned on", but in face no..

@defix
Copy link

defix commented Nov 26, 2024

c00l! in my device, vivo iqoo 13, the new patch worked with -S or MOD-o!

but cannot MOD-Shift-O to turn device display on again... in terminal show "[server] INFO: Device display turned on", but in face no..

After turning off the screen with "alt + o" and then locking it with "alt + p", one has to press both "alt + p" and "alt + shift + o" to light up the screen.
It may still require further optimization.

@rom1v
Copy link
Collaborator

rom1v commented Nov 26, 2024

After turning off the screen with "alt + o" and then locking it with "alt + p", one has to press both "alt + p" and "alt + shift + o" to light up the screen.

Please test with this additional change:

diff --git server/src/main/java/com/genymobile/scrcpy/control/Controller.java server/src/main/java/com/genymobile/scrcpy/control/Controller.java
index fb9eba105..5b4b4e327 100644
--- server/src/main/java/com/genymobile/scrcpy/control/Controller.java
+++ server/src/main/java/com/genymobile/scrcpy/control/Controller.java
@@ -695,7 +695,8 @@ public class Controller implements AsyncProcessor, VirtualDisplayListener {
         int targetDisplayId = displayId != Device.DISPLAY_ID_NONE ? displayId : 0;
         boolean setDisplayPowerOk = Device.setDisplayPower(targetDisplayId, on);
         if (setDisplayPowerOk) {
-            keepDisplayPowerOff = !on;
+            // Do not keep display power off for virtual displays: MOD+p must wake up the physical device
+            keepDisplayPowerOff = displayId != Device.DISPLAY_ID_NONE && !on;
             Ln.i("Device display turned " + (on ? "on" : "off"));
             if (cleanUp != null) {
                 boolean mustRestoreOnExit = !on;
  • scrcpy-server SHA-256: ddf4683b173823307e16cda72a01e2b78645b9fd0712e62ec7086c12d0f29c2

@defix
Copy link

defix commented Nov 26, 2024

@rom1v

  1. When the physical screen mirroring and the virtual screen coexist, it works as expected.
  2. When only using physical screen mirroring, after pressing Alt + O and Alt + P, it is still necessary to press these two shortcut keys to restore the physical screen display. However, this is completely acceptable.

Thank you again for your excellent work!

@rom1v
Copy link
Collaborator

rom1v commented Nov 26, 2024

When only using physical screen mirroring, after pressing Alt + O and Alt + P, it is still necessary to press these two shortcut keys to restore the physical screen display. However, this is completely acceptable.

In fact, this is on purpose: cf9d449

When mirroring the physical screen, after the "screen off timeout", you might need to press POWER to turn it on in the scrcpy window, but without turning it on the physical display.

@defix
Copy link

defix commented Nov 26, 2024

I've tried it and that's indeed the case. What a clever design!👍

@rom1v
Copy link
Collaborator

rom1v commented Nov 26, 2024

What a clever design!

It's a bit hacky and becomes inconsistent with the behavior for virtual displays. But not to the point we need to add yet a new option, I think these default behaviors (even if different for physical and virtual display mirroring) are good enough. 👍

@icantremember
Copy link

With both fixes:

Can confirm "turn screen off" command line and key combo both working on pixel android 15 beta qpr2b1.
Thank you!

rom1v added a commit that referenced this issue Nov 26, 2024
Change the display power of the main display when mirroring a virtual
display, to make it possible to turn off the screen.

Fixes #5522 <#5522>
Refs #5530 <#5530>
@rom1v
Copy link
Collaborator

rom1v commented Nov 26, 2024

Thank you for your tests.

Merged into dev.

@viktormauch
Copy link

Is there a release date for this improvement?

@rom1v
Copy link
Collaborator

rom1v commented Nov 28, 2024

Not yet, it will be included in 3.0.1 with other fixes.

Meanwhile, you can use: #5530 (comment)

@rom1v
Copy link
Collaborator

rom1v commented Dec 4, 2024

Released in 3.0.1.

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

No branches or pull requests

7 participants