2

When there is multiple Android-devices connected with Linux computer (using Linux Mint 20.2 Cinnamon, which is based on appropriate Ubuntu 20.04 LTS version) and scrcpy v1.12 then how to keep multiple devices awake? When one device connected, then I used:

adb shell svc power stayon true

... and it worked.

When multiple devices, then there will be an error message:

error: more than one device/emulator

Tried find a solution, but no luck so far. Tried to connect devices one at a time and then run, but it didn't work. Having one device using OxygenOS 9.0.6, which is based on Android appropriate version. Second device has LineageOS 18.1, which is based on Android 11.

Using following commands to connect with multiple devices:

scrcpy -s <ID1> -m 1024 -S&
scrcpy -s <ID2> -S&

The -S will turn of device screen, once it is connected. I would like to keep screen on at computer, while using scrcpy, but device screen should be turned off at the same time.

Tried also GUI but it didn't help either. One device with Android 9 has screen always on, but another device with Android 11 will time out and also scrcpy window will turn off. I know, that there is a shortcut key CTRL+O at scrcpy, which helps to turn off device screen or using -S will do it immediately after connecting.

Any idea, how to solve this?

3
  • adb -s <ID1> shell commands will work as usual, but afaik scrcpy has special cmd line parameters. try --stay-awake
    – alecxs
    Commented Aug 9, 2021 at 20:11
  • Isn't there an command-line option is scrcpy that keeps the device awake? I remember that I have used such an option some months ago.
    – Robert
    Commented Aug 9, 2021 at 20:15
  • The --stay-awake seems to be possible since v1.14 (github.com/Genymobile/scrcpy/releases/tag/v1.14), but having still v1.12 in latest LTS-version of Ubuntu. But "adb -s <ID> shell svc power stayon true" did the trick and seems, that this the only one alternative until scrcpy v1.14 and newer arrive to LTS-version of Ubuntu. Seems, that Ubuntu 20.10 has v1.14 already. So, next Ubuntu LTS should have it. Until that the mentioned adb command can be used.
    – zeroconf
    Commented Aug 9, 2021 at 20:58

1 Answer 1

1

The answer is

adb -s <ID> shell svc power stayon true

Device IDs can be retrieved, while Android devices are connected with computer via USB-cable (or WiFi):

adb devices
<ID1>  device
<ID2>  device

If device is not recognized, then please ensure, that USB-debugging is turned on while USB-cable is connected. For that in turn there is needed a developer mode beforehand. Also Default USB configuration is worth to check, e.g. charge only and no data transfer by default in order to avoid possible personal data revealing or malware infection at foreign computer. Even in own computer, it is not needed all the time mount device storage, if you just need to use screen mirroring. Whenever data retrieval from Android device is needed, USB mode can be changed (while Android device USB-cable is connected with computer) via notification menu, usually pulled down from upper edge on Android device.

E.g. in Linux there can be created dedicated shortcut icons (~/.local/share/applications/*.desktop) with appropriate PNG-images (~/.local/share/icons/*.png).

device 1:

Exec=sh -c 'adb -s <ID1> shell svc power stayon true && scrcpy -s <ID1> -S &'

device 2

Exec=sh -c 'adb -s <ID2> shell svc power stayon true && scrcpy -s <ID2> -S &'

The -S will turn off Android device screen immediately when connecting, but the first part of command until && will keep scrcpy mirrored image on computer screen always on and device will not be locked even on idle time. Additional explanation about svc power command can be found from source code. The command will set whether to keep your device awake (prevent sleeping) or not while it's being charged on specific platform: USB charging, AC power, wireless charging, or all of them:

  • true will set all flags (usb, ac, wireless)
  • false will clear all flags
  • usb/ac/wireless will set that specific flag while clear the other

The same setting usually can be accessed on "Developer options" named "Stay awake", though it's simpler with only toggle to turn on/off.

The overall desktop shortcut code (replace the <device name> and <ID> with appropriate values) for ~/.local/share/applications/*.desktop file(s), also possibly change category:

#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Encoding=UTF-8
Type=Application
Name=<device name>
GenericName=<device name>
Comment=Android screen copy
Icon=scrcpy-<device>
Exec=sh -c 'adb -s <ID> shell svc power stayon true && scrcpy -s <ID> -S &'
Terminal=false
StartupNotify=false
Categories=Utility;

Thank you commentators for hints!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .