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

Power/Battery management #8770

Closed
9 tasks
StraToN opened this issue May 15, 2017 · 12 comments · Fixed by #36212
Closed
9 tasks

Power/Battery management #8770

StraToN opened this issue May 15, 2017 · 12 comments · Fixed by #36212

Comments

@StraToN
Copy link
Member

StraToN commented May 15, 2017

This issue keeps track of current implementation of battery/power management in Godot.
For reference, #314

The code is ready to welcome implementations for all missing platforms (classes and methods ready but return a warning - not implemented on this platform)

Platforms:

edit: adding a test project that may be used on every platform.
godot-power-test.zip

@Marqin
Copy link
Contributor

Marqin commented Jul 21, 2017

I'd not call X11 OK tested if code contains explicit NULL pointer dereference. Seems you didn't tested it fully or ignored crashes.

see https://github.com/godotengine/godot/blob/master/platform/x11/power_x11.cpp#L178

@StraToN
Copy link
Member Author

StraToN commented Jul 23, 2017

@Marqin Indeed, there's a big miss here. It's pretty old now, when I attempted to translate SDL code to Godot. I may have started this part and never finished it. But as you pointed it out, testing was obviously insufficient because I was lucky during my tests.

@StraToN
Copy link
Member Author

StraToN commented Jul 27, 2017

Some fixes were brought by 411f09a, my tests on X11 pass. I tried to take care of NULL pointer dereferences but I may have missed some. Also it is complicated to test all features as my laptop doesn't support a 'number of seconds remaining on battery' computation, thus it returns -1. However, un/plugging power cable does change the battery status and %.

I am currently unable to test this on Android though, as the scene being ran in the export is all grey, I can't explain why.

Other platforms need attention too.

@Marqin
Copy link
Contributor

Marqin commented Jul 28, 2017

I found it via Static Analyzer :D (I made our Scons generate clang's buils commands .json file and then run clang-tidy on that)

@williamd1k0
Copy link
Contributor

williamd1k0 commented Aug 30, 2018

I tried it on Manjaro and worked fine but it isn't working on Android.
Edit: I tried only the following methods: OS.get_power_state() and OS.get_power_percent_left().

I'm using master (9eb4d4a) and I added the android.permission.BATTERY_STATS on export.

@ghost
Copy link

ghost commented Nov 7, 2019

Can confirm, battery level detection does not work on Android.

Apparently my Screenshot Feature Is Low Quality When Used on My Game (and my game doesn't have permission to save the viewport screenshot to the sdcard).
photo5053350408013064292

Basically it says,

Battery: -1%
Seconds Left: -1
Battery State: Unknown

The battery and seconds left are raw values from Godot (OS.get_power_percent_left() and OS.get_power_seconds_left() respectively). The unknown is set from OS.POWERSTATE_UNKNOWN

Edit: I did not know there was a permission called android.permission.BATTERY_STATS. I'll have to retest it once I figure out how to add permissions for Android to my game.

Edit 2: I had to rebuild my export template (because screenshot is for older version of the engine used to compile the game) and for some reason, this template won't allow me to autoload singletons. I cannot get my game to go past the main menu right now. So, I cannot check if setting the permission allows me to get the battery level.

@ghost
Copy link

ghost commented Nov 7, 2019

OSX on Mojave works fine. My only complaint is the seconds left is not updated in real time and I cannot attest to the accuracy of seconds left. The percentage and battery state are correct.

Screen Shot 2019-11-07 at 3 58 44 AM

@Calinou
Copy link
Member

Calinou commented Nov 7, 2019

Edit: I did not know there was a permission called android.permission.BATTERY_STATS. I'll have to retest it once I figure out how to add permissions for Android to my game.

Would it be possible to print an error message if trying to access battery status without the permission? That said, it'll only be visible if you use remote debugging or adb logcat.

@williamd1k0
Copy link
Contributor

@alex-evelyn

#27143 (comment)
Power management on Android was disabled by @reduz in b5a06ce, and nobody tried to reenable it since then.

@GeorgeS2019
Copy link

Can someone either close this OR assign this to milestone 4.0 just like this and this?

@akien-mga akien-mga added this to the 4.0 milestone Jan 15, 2020
@akien-mga
Copy link
Member

Since this was never finished (despite @StraToN's best intentions :)) and is current either not implemented or not thorough tested on all platforms, I suggest to drop this API in 4.0.

We can then consider reimplementing it either for 4.0 or for a later release, taking the time to ensure that most platforms have good support before merging.

@akien-mga akien-mga self-assigned this Feb 14, 2020
akien-mga added a commit to akien-mga/godot that referenced this issue Feb 14, 2020
It was initially implemented in godotengine#5871 for Godot 3.0, but never really
completed or thoroughly tested for most platforms. It then stayed in
limbo and nobody seems really keen to finish it, so it's better to
remove it in 4.0, and re-add eventually (possibly with a different API)
if there's demand and an implementation confirmed working on all
platforms.

Closes godotengine#8770.
@jamie-pate
Copy link
Contributor

OS.get_power_state() This was useful on platforms where it worked 😭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants