3

Sometimes I run a server app on my Android device (OnePlus 6 rooted with Android 10) but it appears that most apps only run when the screen is on which is a much worse battery drainer than background services. I know that scrcpy which is an adb powered app which allows the control the device from a computer over USB or Wifi and the 'virtual screen' (i.e. display in the scrcpy app on the computer) is on but the physical screen is off. And this app does not use root, so it should be possible. How do they do that ?

3 Answers 3

5
scrcpy --stay-awake --turn-screen-off >& /dev/null & exit
1
  • 1
    Please read How do I write a good answer?. While this code block may answer the OP's question, this answer would be much more useful if you explain how this code is different from the code in the question, what you've changed, why you've changed it and why that solves the problem without introducing others. Commented Jul 27, 2022 at 10:53
2

scrcpy author explained it here:

Question about how can scrcpy tool can control a phone even its screen is turned off · Issue #2888 · Genymobile/scrcpy · GitHub

To turn the screen off, scrcpy calls the private API setDisplayPowerMode() by introspection here.

To execute such Java code from shell:

AFAIK there is command to turn the screen off via adb only.

0

To wake up my Galaxy I start scrcpy from my mac with this command:

scrcpy --tcpip="[DEVICE IP]" --stay-awake

DEVICE IP is the IP of the Android device.

Whenever it goes black I type in the Android PIN (numbers and then ENTER on my laptop) to unlock the device.

Not the answer you're looking for? Browse other questions tagged or ask your own question.