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

--stay-awake isn't working on Pixel3a (Android 11) #2612

Open
2 tasks done
jpage4500 opened this issue Sep 4, 2021 · 11 comments
Open
2 tasks done

--stay-awake isn't working on Pixel3a (Android 11) #2612

jpage4500 opened this issue Sep 4, 2021 · 11 comments

Comments

@jpage4500
Copy link

  • I have read the FAQ.
  • I have searched in existing issues.

Environment

  • OS: macOS
  • scrcpy version: 1.17
  • installation method: brew
  • device model: Pixel 3a XL
  • Android version: 11

Describe the bug
--stay-awake doesn't appear to be working for me. After whatever display timeout period, the screen goes black and I can't get it to come back on again. I can however close the scrcpy window and re-open and the screen will display fine again.

I'm running a Pixel3aXL running Android 11

Here's the command I use to launch scrcpy

scrcpy -s $ADB_DEVICE $ADB_PORT --show-touches --stay-awake --encoder 'c2.android.avc.encoder'

using device: 04QAX0NRLM, port: -p 17947
2021-09-04 11:37:57.040 scrcpy[6943:58134413] INFO: scrcpy 1.17 <https://github.com/Genymobile/scrcpy>
/usr/local/Cellar/scrcpy/1.17/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 55.8 MB/s (34930 bytes in 0.001s)
[server] INFO: Device: Google AOSP on bonito (Android 11)
2021-09-04 11:37:57.467 scrcpy[6943:58134413] INFO: Renderer: metal
2021-09-04 11:37:57.470 scrcpy[6943:58134413] INFO: Initial texture: 1080x2160
@rom1v
Copy link
Collaborator

rom1v commented Sep 4, 2021

The option only works when the device is plugged in:
https://github.com/Genymobile/scrcpy#stay-awake

(this is a limitation of the Android option)

@jpage4500
Copy link
Author

Thanks for the quick feedback!

This device is plugged-in.. direct USB

If you're looking at that -s and PORT line in my command - I have a script that will list all of the connected devices via adb and let me select which one to mirror. It does work with connected and wireless devices - but this device is usb

scrcpy -s $ADB_DEVICE $ADB_PORT

@jpage4500
Copy link
Author

FWIW -- here's the full script I use in case it'll benefit anyone else too.. I often have several devices connected so it'll prompt me which one to mirror. Let me know if you see any issues with how I'm running scrcpy.. I'm unsure about the encoding param - don't remember what caused me to try that. I think due to some really laggy starts at one point.

screenMirror.sh

#################################################################################################
# mirror a device screen
#################################################################################################

// get the device ID (serial number) of connected device to use
// - sets the env variable ADB_DEVICE to the device selected
// - if multiple devices are present, also sets the env variable ADB_PORT to a random number
function selectDevice() {
    DEVICES=$(adb devices -l | grep -v "List" | grep -v "offline" | grep -v '^$' | sed 's/ device:.*//')

    NUM_DEVICES=`echo "${DEVICES}" | wc -l`

    if [ $NUM_DEVICES -eq 0 ]; then
        echo "no devices!"
        return 1
    elif [ $NUM_DEVICES -eq 1 ]; then
        echo "using device: $ADB_DEVICE"
        export ADB_DEVICE=$(echo $DEVICES | sed 's/ .*//')
        return 0
    fi

    IFS=$'\n'
    select device in $DEVICES
    do
        export ADB_DEVICE=$(echo "$device" | sed $'s/[ \t].*$//g')
        export ADB_PORT="-p $RANDOM"
        echo "using device: $ADB_DEVICE, port: $ADB_PORT"
        return 0
    done
}

#################################################################################################
# start
#################################################################################################
cd "$(dirname $0)"

selectDevice
if [ $? -eq 1 ]; then
    echo "no devices! press any key!"
    read n
    exit 1
fi

# options:
# --stay-awake
# --always-on-top 
# --encoder ['OMX.qcom.video.encoder.avc', 'c2.android.avc.encoder', 'OMX.google.h264.encoder']

scrcpy -s $ADB_DEVICE $ADB_PORT --show-touches --stay-awake --encoder 'c2.android.avc.encoder'

@rom1v
Copy link
Collaborator

rom1v commented Sep 4, 2021

The feature --stay-awake basically changes an Android setting. You can do it manually without scrcpy.

Read the value:

adb shell settings get global stay_on_while_plugged_in

Write the value:

adb shell settings put global stay_on_while_plugged_in 7  # enable
adb shell settings put global stay_on_while_plugged_in 0  # disable

@jpage4500
Copy link
Author

I see.. the developer 'stay awake while charging' setting. I guess I could just call those commands before and after running scrcpy.. I'll give that a try

thanks

@rom1v
Copy link
Collaborator

rom1v commented Sep 5, 2021

I guess I could just call those commands before and after running scrcpy

scrcpy calls them if you pass --stay-awake. Check the value while scrcpy is running.

@dbareis
Copy link

dbareis commented May 16, 2022

--stay-awake also fails on my Oneplus 8 Pro on Android 12, if I try the ADB command from above:

adb shell settings put global stay_on_while_plugged_in 7

Then I get:

Exception occurred while executing 'put':
java.lang.SecurityException: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS
        at com.android.providers.settings.SettingsProvider.enforceWritePermission(SettingsProvider.java:2663)
        at com.android.providers.settings.SettingsProvider.mutateGlobalSetting(SettingsProvider.java:1635)
        at com.android.providers.settings.SettingsProvider.insertGlobalSetting(SettingsProvider.java:1589)
        at com.android.providers.settings.SettingsProvider.call(SettingsProvider.java:591)
        at android.content.ContentProvider.call(ContentProvider.java:2473)
        at android.content.ContentProvider$Transport.call(ContentProvider.java:521)
        at com.android.providers.settings.SettingsService$MyShellCommand.putForUser(SettingsService.java:382)
        at com.android.providers.settings.SettingsService$MyShellCommand.onCommand(SettingsService.java:278)
        at com.android.modules.utils.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:97)
        at android.os.ShellCommand.exec(ShellCommand.java:38)
        at com.android.providers.settings.SettingsService.onShellCommand(SettingsService.java:50)
        at android.os.Binder.shellCommand(Binder.java:970)
        at android.os.Binder.onTransact(Binder.java:854)
        at android.os.Binder.execTransactInternal(Binder.java:1226)
        at android.os.Binder.execTransact(Binder.java:1163)

SCRCPY says:

[server] ERROR: Could not change "stay_on_while_plugged_in"
com.genymobile.scrcpy.SettingsException: Could not access settings: put global stay_on_while_plugged_in 7
        at com.genymobile.scrcpy.Settings.execSettingsPut(Settings.java:26)
        at com.genymobile.scrcpy.Settings.putValue(Settings.java:61)
        at com.genymobile.scrcpy.Settings.getAndPutValue(Settings.java:80)
        at com.genymobile.scrcpy.Server.initAndCleanUp(Server.java:37)
        at com.genymobile.scrcpy.Server.access$000(Server.java:12)
        at com.genymobile.scrcpy.Server$2.run(Server.java:121)
        at java.lang.Thread.run(Thread.java:920)
Caused by: java.io.IOException: Command [settings, put, global, stay_on_while_plugged_in, 7] returned with value 255
        at com.genymobile.scrcpy.Command.exec(Command.java:16)
        at com.genymobile.scrcpy.Settings.execSettingsPut(Settings.java:24)
        ... 6 more

@rom1v
Copy link
Collaborator

rom1v commented May 17, 2022

Exception occurred while executing 'put':
java.lang.SecurityException: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS

Genymobile/gnirehtet#302 (comment)
Genymobile/gnirehtet#5

@dbareis
Copy link

dbareis commented May 21, 2022

Setting "Disable Permission Monitoring" (developer option) works for me on OnePlus 8 PRO on Android 12.

Now the ADB shell commands no longer fail either.

@cool-delete
Copy link

Setting "Disable Permission Monitoring" (developer option) works for me on OnePlus 8 PRO on Android 12.

It is effective for my OnePlus 13. After using the USB connect OnePlus debug, then disconnect the USB Connect and use it to use WiFi Connect.

@Uj947nXmRqV2nRaWshKtHzTvckUUpD
Copy link

Disable Permission Monitoring

still getting error on android 12 even after disabling permission monitoring
I am connecting wirelessly, using ethernally wrapper on top of scrcpy

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

5 participants