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
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
@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.
Some fixes were brought by 411f09a512d5847fc9c6270439308d1e3093f211, 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.
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)
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.
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).

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.
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.

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.
@alex-evelyn
https://github.com/godotengine/godot/issues/27143#issuecomment-473599216
Power management on Android was disabled by @reduz in b5a06ce, and nobody tried to reenable it since then.
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.
Most helpful comment
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.