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 flag doesn't work when device isn't charging #1445

Closed
2 tasks done
Matthbo opened this issue May 28, 2020 · 6 comments
Closed
2 tasks done

stay-awake flag doesn't work when device isn't charging #1445

Matthbo opened this issue May 28, 2020 · 6 comments

Comments

@Matthbo
Copy link

Matthbo commented May 28, 2020

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

Environment

  • OS: Windows 10
  • scrcpy version: 1.14
  • installation method: Windows x64 zip
  • device model: Xiaomi Mi A1
  • Android version: 9

Describe the bug
The screen won't stay awake as the flag suggests, unless the device is charging

Using commands:

./scrcpy -Sw
# or
./scrcpy -w
# or
./scrcpy --stay-awake

Expected behaviour:
The screen will stay awake, even if the device isn't charging

rom1v added a commit that referenced this issue May 28, 2020
The "stay awake" feature only works when the device is plugged in.

Refs #1445 <#1445>
@rom1v
Copy link
Collaborator

rom1v commented May 28, 2020

That is correct. Btw, the Android option is called stay_on_while_plugged_in.

I just added this limitation to the documentation: 0e4a6f4

AFAIK, there is no way to "stay awake" while the device is unplugged with an Android setting (without a separate app taking a wake lock, with its own limitations).

@Matthbo
Copy link
Author

Matthbo commented May 28, 2020

Ah okay, that makes sense

@jsuelwald
Copy link

I'd like to re-open this ticket and would like to have "stay awake even while not charging" as a feature.

Reason: If other apps can do this, why can't scrcpy do this as well?

@rom1v
Copy link
Collaborator

rom1v commented Nov 20, 2020

Reason: If other apps can do this, why can't scrcpy do this as well?

Because (at least for now) the device side of scrcpy is not an Android app. But even if it was, I'm not sure you can hold a wakelock if you are not the app with an activity in the background.

@Pawloland
Copy link

Pawloland commented Oct 23, 2021

@rom1v
Obligatory sorry for ping.
I was searching for a way to make --staye-awake work when connecting through wifi and found one.
As you said there isn't any way to make stay_on_while_plugged_in respected when device isn't connected.
However there is a way to mock the state of the device being plugged in. How to do it via adb:

  • mocking device being plugged in and charging (in my tests it was better to also mock charging because the first one alone sometimes isn't sufficient on specific devices) EDIT: the second one seems to be redundant after all, sorry for misinformation. Also keep in mind that while this workaround works it has one drawback - systemui stops displaying correct battery percentage (it freezes on the value displayed at the time of executing the command), so it's hard to guess what percentage is left. As a workaround for this issue we could write a script that periodically quickly resets changes with the last command and then instantly sets them again. This would limit the stuck percentage value bug to a small extent. Given how often it would trigger, the lesser "stuck percentages" would happen.

    adb shell dumpsys battery set ac 1                 # mocks being connected to power source
    adb shell dumpsys battery set status 2             # mocks device charging
    
  • starting scrcpy with our flag

    scrcpy  --staye-awake
    
  • after disconnecting resetting our mocked state to reflect a real situation

     adb shell dumpsys battery reset
    

With this method the device won't go to sleep. It could be implemented directly inside scrcpy. Whenever we would connect through wifi with --staye-awake flag set, scrcpy would automatically mock battery state. After disconnecting it would automatically revert those changes, so device wouldn't be stuck in this strange state where it says it is charging while actually discharging.
I lack the skills to make a PR myself so I leave it here, hoping someday it will be implemented. By that time anyone can use it manually like in the example above. Just remember to manually reset changes after ending using scrcpy.
More about it can be found here.

@ahmed98Osama
Copy link

#1445 (comment)

a Very good trick from @Pawloland
i love it and it is working 😍

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