Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
103.68k stars 10.09k forks source link

Have phone screen off while mirroring on computer #175

Closed WrathX closed 5 years ago

WrathX commented 5 years ago

It would be nice to have the screen mirroring on like it does but have the phone screen off, only showing on the computer. Would need to be able have the screen awake all the time while plugged in as well. Great job on this so far, just got it recently and it's very responsive. I use it at work all day. Thanks.

alambike commented 5 years ago

πŸ‘ Disable phone screen will be a nice feature .

rom1v commented 5 years ago

Yes, that would be great. But I have no technical solution. See reddit comment.

WrathX commented 5 years ago

Ok thanks for the response. Anyway of having the screen switch to stay awake when using this? Currently every time I use this I have to go into developer options and switch on stay awake while charging. I don't really want it staying awake if I am charging my phone overnight while not using this so I have to go back in every time after using scrcpy and switch stay awake off. If possible it would be a nice convenience. Thanks for this, I've been using this for a few days now at work. Since Oreo came out Sidesync hasn't been working so this was a great find. thumbs up

rom1v commented 5 years ago

Anyway of having the screen switch to stay awake when using this?

Currently, no. It's probably possible to wrap scrcpy with a script that enable/disable "keep screen on".

(Just for info, a right click switches the screen on.)

WrathX commented 5 years ago

Ok thanks again for the response. Ya I was using the right click to turn on but I have to unlock the phone everytime so it would be better to have the screen awake all the time in my case. I use my phone a lot during the day to contact my drivers (I'm in dispatch) so unlocking the phone everytime gets clunky. Thanks for whatever you can do.

bonrry commented 5 years ago

Just an idea... If the server has enough privileges as shell, and has a chance to detect disconnection and do something before dying, it could set the global setting key "stay_on_while_plugged_in" to value 7 upon starting, and reset it just before dying? Same for brightness setting (if a global one exists?). That would "automate" the described behavior...

Le lun. 18 juin 2018 Γ  17:56, WrathX notifications@github.com a Γ©crit :

Ok thanks again for the response. Ya I was using the right click to turn on but I have to unlock the phone everytime so it would be better to have the screen awake all the time in my case. I use my phone a lot during the day to contact my drivers (I'm in dispatch) so unlocking the phone everytime gets clunky. Thanks for whatever you can do.

β€” You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Genymobile/scrcpy/issues/175#issuecomment-398104121, or mute the thread https://github.com/notifications/unsubscribe-auth/AB2kb9TKazS5UQ_km4k3zW145_DxbidYks5t982-gaJpZM4Up18Q .

Keneil-Thompson commented 5 years ago

bypassing the lock screen, that would be quite the exploit in the android os (unless u purposely put it there). if there is no lock screen on, maybe remove the unlock animation, turn screen brightness down to about 200 nits...very low , keep screen on while charging, have double tap to wake mappable to any key eg. double shift. have a copy of your android device in a virtual machine. dont know if this is even possible just throwing some ideas out there

cleberOliva commented 5 years ago

What's the version of downloaded scrcpy? If it's below the current then download the actual version and run on terminal the command scrcpy -h, there's a session of shortcuts in the end. To turn on/off screen of phone, type Ctrl + P.

yrrah commented 5 years ago

Anyway of having the screen switch to stay awake when using this?

Currently, no. It's probably possible to wrap scrcpy with a script that enable/disable "keep screen on".

(Just for info, a right click switches the screen on.)

I was able to do this with a script combined with Tasker and AutoRemote installed on the phone. Tasker sets the display timeout. I also have it set screen brightness to minimum.

I would like to turn off the screen on the phone but can't do it without blanking scrcpy as well.

Shinkiro1 commented 5 years ago

I was able to do this with a script combined with Tasker and AutoRemote installed on the phone. Tasker sets the display timeout. I also have it set screen brightness to minimum.

What did you use for the trigger? I'm looking to do something similar.

rom1v commented 5 years ago

Oh, I investigated a bit tonight, in fact it's quite easy:

IBinder display = SurfaceControlgetBuiltInDisplay(0); SurfaceControl.setDisplayPowerMode(display, POWER_MODE_OFF);

I have a working PoC.

The power button reenables the screen (which is good for the physical button, but is also an issue with the simulated power button on scrcpy starting and on right-click/Ctrl+P, e.g. when the screen goes black after timeout, a right-click also reenable the device screen).

I will probably work on this soon if I find some time.

rom1v commented 5 years ago

If you are interested, here is my quick test: screenoff.

cotfas commented 5 years ago

I am also interested when the screen goes off, in Vysor there was implemented when this happened and I click on any key it will turn on the screen. Will be nice to have this feature.

rom1v commented 5 years ago

I click on any key it will turn on the screen. Will be nice to have this feature.

If the screen is off, a right-click turns it on.

cotfas commented 5 years ago

It works, thanks!

xeon927 commented 5 years ago

+1 - have tried the test and it works just about perfectly (Galaxy Note 9) - only thing I've found is as stated above - if screen turns off, when it comes back on, phone display also does too.

Would also love to see if it's possible to include a --no-screen flag to choose at launch if you want screen off or not.

rom1v commented 5 years ago

Implemented on dev by 12a3bb25d39037931f577dc0165b3e517aad92df.

Press Ctrl+o to turn the device screen off while mirroring, and Ctrl+Shift+o to turn it back on.

Would also love to see if it's possible to include a --no-screen flag to choose at launch if you want screen off or not.

I decided not to add such an option, because as soon as the display is off (timeout or explicit power off), we need to "power on", causing both the device screen and the mirror to be turned on. Thus, the command line option would not be "persistent", and this would be confusing.

npes87184 commented 5 years ago

I have tested this feature.

There is a problem I find, after switch off and on sometimes, the device screen cannot be turned on.

I am using HTC One M8 with android 6 and OnePlus 6 with android 9 for testing.

rom1v commented 5 years ago

@npes87184 Anything in adb logcat?

Does it switch on with the power button?

(if both the device screen and the mirror are black, you need to POWER ON)

rom1v commented 5 years ago

Maybe Ctrl+Shift+o should power on instead when screen is off?

npes87184 commented 5 years ago

@rom1v

The problem is device screen is black and the scrcpy works. In this time I cannot turn on screen by Ctrl + Shift + o

There are some logs here:

It seems the first time failed, it will show:

06-01 23:41:34.604   429   429 D SurfaceFlinger: Set power mode=2, type=0 flinger=0xb8beadf0
06-01 23:41:34.604   429   429 D qdhwcomposer: hwc_blank: Unblanking display: 0
06-01 23:41:34.822   429   497 I qdhwcomposer: handle_blank_event: dpy:0 panel power state: 1
06-01 23:41:34.858   429   429 E qdexternal: writeHPDOption: file write failed '/sys/devices/virtual/graphics/fb1/hp
d'
06-01 23:41:34.858   429   429 D qdhwcomposer: hwc_blank: Done unblanking display: 0
06-01 23:41:34.883  4772  4946 D SurfaceControl: Excessive delay in setPowerMode(): 278ms
06-01 23:41:34.883  4772  4946 I scrcpy  : Device screen turned on

After it, when I try to turn it off:

06-01 23:42:15.209   429   429 D SurfaceFlinger: Set power mode=0, type=0 flinger=0xb8beadf0                        06-01 23:42:15.209   429   429 D qdhwcomposer: hwc_blank: Blanking display: 0                                       
06-01 23:42:15.418   429   497 I qdhwcomposer: handle_blank_event: dpy:0 panel power state: 0                       
06-01 23:42:15.434   429   429 E qdoverlay: Failed to call ioctl MSMFB_DISPLAY_COMMIT err=Bad file descriptor       
06-01 23:42:15.434   429   429 E qdoverlay: static bool overlay::Overlay::displayCommit(const int&, const overlay::utils::Dim&): commit failed                                                                                          
06-01 23:42:15.434   429   429 E qdhwcomposer: hwc_blank: display commit fail for virtual!                
06-01 23:42:15.434   429   429 D qdhwcomposer: hwc_blank: Done blanking display: 0                                  06-01 23:42:15.489  4772  4946 D SurfaceControl: Excessive delay in setPowerMode(): 287ms                           
06-01 23:42:15.493  4772  4946 I scrcpy  : Device screen turned off     

And try turn on again:

06-01 23:43:01.543  1747  1796 W SensorService: D/Accel(x, y, z, t) = (  1.8,  -0.1,   9.8, 241666ms), sys_time = 241666ms                                                                                                              
06-01 23:43:02.191  1747  1774 D XAN-DPS : setBB(2,255)                                                             
06-01 23:43:03.104   429   429 D SurfaceFlinger: Set power mode=2, type=0 flinger=0xb8beadf0                        
06-01 23:43:03.104   429   429 D qdhwcomposer: hwc_blank: Unblanking display: 0                                     
06-01 23:43:03.322   429   497 I qdhwcomposer: handle_blank_event: dpy:0 panel power state: 1                       
06-01 23:43:03.356   429   429 E qdexternal: writeHPDOption: file write failed '/sys/devices/virtual/graphics/fb1/hpd'                                                                                                                  
06-01 23:43:03.356   429   429 D qdhwcomposer: hwc_blank: Done unblanking display: 0                                06-01 23:43:03.380  4772  4946 D SurfaceControl: Excessive delay in setPowerMode(): 283ms                           
06-01 23:43:03.380  4772  4946 I scrcpy  : Device screen turned on                                              

The log is flowing, I try my best to get related log...

If the log does not meet the requirement, please contact me, I will reproduce it again and get more detail.

Thanks.

WrathX commented 5 years ago

Is there a release to test this out?

rom1v commented 5 years ago

@npes87184 I have no idea about the cause, and I cannot reproduce :(

rom1v commented 5 years ago

@WrathX

Here are scrcpy.exe and scrcpy-server.jar for the current dev branch for win64: https://tmp.rom1v.com/scrcpy/scrcpy-win64-e572d81.zip SHA-256: 859b545dd0290adbd2b21517286e53c775e802d356d23eeb9afee67f04906957.

Don't hesitate to build from sources if you can ;)

npes87184 commented 5 years ago

Maybe Ctrl+Shift+o should power on instead when screen is off?

I will do more test and try this workaround.

rom1v commented 5 years ago

I decided not to add such an option

Finally, I tried to add an option --turn-screen-off (like --fullscreen, it configures the initial state). But there is a race condition preventing it to work correctly.

When we start scrcpy, we inject KEYCODE_POWER if screen is off. The effects of this action are asynchronous. In particular, it sets the screen POWER_MODE_NORMAL (to turn screen on) asynchronously. If we set POWER_MODE_OFF to turn screen off after we pressed KEYCODE_POWER, it is in fact executed before POWER_MODE_NORMAL, so it does not work. Adding SystemClock.sleep(1000); avoids the problem, but it's ugly.

To avoid the problem, I attempted to replace KEYCODE_POWER by a WakeLock, but com.android.shell does not have enough permissions (android.permission.WAKE_LOCK only since 7.1.2, and for some reason android.permission.UPDATE_DEVICE_STATS is also necessary).

So for now, I don't add it :cry:

rom1v commented 5 years ago

There is a problem I find, after switch off and on sometimes, the device screen cannot be turned on.

Oh, I reproduced. This is very annoying, indeed.

06-03 10:11:27.421   409   409 D SurfaceFlinger: Set power mode=2, type=0 flinger=0x78ed047000
06-03 10:11:27.421   409   409 D qdhwcomposer: hwc_setPowerMode: Setting mode 2 on display: 0
06-03 10:11:27.654   409   542 I qdhwcomposer: handle_blank_event: dpy:0 panel power state: 1

That's stupid, Android does not do what we request (we set value 2, it actually applies value 1)

rom1v commented 5 years ago

So I removed "turn device screen on", we can still use POWER instead: 8c8649cfcd710859ce18eab557ed2af8cedb9a42

rom1v commented 4 years ago

So for now, I don't add it :cry:

In addition to the shortcut, I finally added -S/--turn-screen-off to turn the device screen off on start. To "avoid" the race condition, I just wait 500ms before handling control messages if we just powered on the device.

https://github.com/Genymobile/scrcpy/commit/8e66b33000994f3b95de5128e0f78fdf62f51a5a

apxp commented 4 years ago

Hello, can you please build this version - so i can download it? Thank you for the good work!

sjuxax commented 4 years ago

Going to build and debug with this on, see if we can suss out a cause. Have a toddler who likes to run off and play games on the phone and watching via scrcpy, can back him out if he gets out of the game. Disabling the screen is awesome because it makes it easy to stop him from button-mashing for a minute, but then it sucks that the screen doesn't come back on for him without a full Power On+Off, because then have to unlock it. Hard to get the unlock screen to work via scrcpy anyway (the fling up requires a very fast mouse movement), but with the button-mashing competition, it's impossible to actually unlock.

Ability to flip the display on and off like this would be a big help, but agreed that it's unacceptable to get the phone into a broken state in a release. Will test. Big thanks to @rom1v for everything. This is a great release!

char101 commented 4 years ago

And while keeping the screen turned off, we can use this batch file to prevent the OS from sleeping

@echo off
setlocal
set APP=scrcpy-noconsole.exe
set APP_DIR=C:\scrcpy

:scrcpy
pushd %APP_DIR%
start %APP% -b 16M -S
popd

rem generate mouse event while scrcpy is running
:loop
adb shell input keyevent mouse
timeout /t 5 /nobreak > NUL
tasklist /FI "IMAGENAME eq %APP%" 2>NUL | find /I /N "%APP%" > NUL
if "%ERRORLEVEL%"=="0" goto loop

:end
endlocal
rom1v commented 4 years ago

I just reactivated the shortcut (Ctrl+Shift+o), in practice it works: dcde578a50ffb9d2594c4764a067e9dd328bf55c

@npes87184 can you still reproduce the issue?

npes87184 commented 4 years ago

I would test it after 6/3.

iamthekings5 commented 4 years ago

My screen seems to get permanently dimmed if I use Ctrl + Shift + O (turning it off and on will make it remain dimmed, only can fix with restart).

npes87184 commented 3 years ago

I tested it on my samsung galaxy note10+. It worked!

sandeepkumardev-zz commented 3 years ago

when i press 'ctrl + o' then this error through πŸ‘‡ [server] ERROR: Exception on thread Thread[Thread-1,5,main] java.lang.AssertionError: java.lang.NoSuchMethodException: android.view.SurfaceControl.getBuiltInDisplay [int] at com.genymobile.scrcpy.wrappers.SurfaceControl.getBuiltInDisplay(SurfaceControl.java:82) at com.genymobile.scrcpy.Device.setScreenPowerMode(Device.java:164) at com.genymobile.scrcpy.Controller.handleEvent(Controller.java:113) at com.genymobile.scrcpy.Controller.control(Controller.java:73) at com.genymobile.scrcpy.Server$1.run(Server.java:45) at java.lang.Thread.run(Thread.java:919) Caused by: java.lang.NoSuchMethodException: android.view.SurfaceControl.getBuiltInDisplay [int] at java.lang.Class.getMethod(Class.java:2072) at java.lang.Class.getMethod(Class.java:1693) at com.genymobile.scrcpy.wrappers.SurfaceControl.getBuiltInDisplay(SurfaceControl.java:80) ... 5 more

rom1v commented 3 years ago

Which scrcpy version? Which Android version?

sandeepkumardev-zz commented 3 years ago

Which scrcpy version? Which Android version?

Scrcpy v1.9 and Android 10. plz help πŸ™

rom1v commented 3 years ago

Scrcpy v1.9

That's very old. Just use the latest version.

sandeepkumardev-zz commented 3 years ago

Scrcpy v1.9

That's very old. Just use the latest version.

which one ??

sandeepkumardev-zz commented 3 years ago

Scrcpy v1.9

That's very old. Just use the latest version.

'ctrl + o' does not work in scrcpy (v1.16)

rom1v commented 3 years ago

Since v1.15, the shortcuts are bound to Alt by default, so it's Alt+o.

sandeepkumardev-zz commented 3 years ago

Since v1.15, the shortcuts are bound to Alt by default, so it's Alt+o.

Thankyou 😊😊 'alt + o' work in v1.16. but how i can screen turned on.

rom1v commented 3 years ago

Please read the doc: https://github.com/Genymobile/scrcpy#shortcuts

sandeepkumardev-zz commented 3 years ago

Please read the doc: https://github.com/Genymobile/scrcpy#shortcuts

Thank you so much 😊😊

sandeepkumardev-zz commented 3 years ago

Please read the doc: https://github.com/Genymobile/scrcpy#shortcuts

sir where can i find it 32bit version.

npes87184 commented 3 years ago

Please read the doc: https://github.com/Genymobile/scrcpy#shortcuts

sir where can i find it 32bit version.

You can find 32bit version in release page.

sandeepkumardev-zz commented 3 years ago

Please read the doc: https://github.com/Genymobile/scrcpy#shortcuts

sir where can i find it 32bit version.

You can find 32bit version in release page.

I'm sorry, but maybe it's not safe. Here is the Virustotal report.

rom1v commented 3 years ago

@repositories-hub #1102