Hacker News new | ask | show | jobs
by jadengeller 1763 days ago
There are APIs for this.

iOS: https://developer.apple.com/documentation/uikit/uidevice/162...

Android: https://developer.android.com/reference/android/os/BatteryMa...

1 comments

I struggle to see a legitimate reason for an app to be able to access battery level. It's pretty unlikely that app is going to change behaviour to preserve battery life – that's probably better handled by the OS slowing things down. Better to simply deny the app this information.
Apps can change behaviors to preserve battery life though. Things like disabling prefetching will likely reduce radio time and thus preserve battery.

Delaying maintenance can help too, and that also helps reduce occurances of power failed during complex data operation and the resulting difficulties of resuming from a partial operation when the state may not have been fully persisted at any point, because filesystems and abrupt power loss don't tend to go so well together.

Also things like disabling complex animations, canceling high-CPU background jobs, doing more work on the server side rather than client (trading off latency for battery life), using less complex but less accurate algorithms, etc.

There's a lot of reasons why an app might want to know the battery status, and most of them are for the user's benefit.

First things first: you could develop a custom interface within your app, think of games for example, to show the battery level, or simply an icon when it's low, in a specific way instead of the system's style.

Then, depending on what your app does, you can act on a few things to reduce, or not, battery usage when it gets below some thresholds: reduce GPS precision, remove some animations, limit framerate, make less networking requests, ... It could be limited by the system, but it would probably not be as wise regarding to what is important in the context of one app vs another.

We have numerous cases where we adapt to the battery level so the user can get the best of our apps and not empty their battery while they still need it.

On the one hand, I generally favor allowing users/their apps to get more granular information out of their phone rather than somewhat arbitrarily deciding what they need to know (e.g. there's more GPS detail that iOS could provide but doesn't).

However, in this case, the phone has a battery meter and provides its own low battery warnings. I imagine you could have more sophisticated battery use tracking apps than Apple provides but, in general, not sure why you would legitimately need this info.

Oh, I fully agree: https://twitter.com/jadengeller/status/1427672235028795396?s...

(Seems like many others do too!)

Stop with all those permissions already: users are tired of those popups, they don't know or understand what they are asked about, and even when a pro user gets one, it's not possible to really know what will happen/break when it is allowed or denied, so this "solution" is not one, it's a bandaid and it's broken.
My phone disables the camera flash under 15%. I don't see that as anything particularly nefarious. That said I fully support the principle of least privilege.
Whatsapp uses this API to alert call participants that one of them is about to run out of battery, this is a very useful feature IMO.
So Whatsapp tells other participants in a call what your battery life is? By itself, I suppose that's pretty harmless. But it's really none of your business what the status of my phone is in general.
Yes, it says "ghaff's phone battery level is low. Call may end soon."

I think this results in a much better experience for everyone on the call.

I guess I don't really want an app doing that given it could probably tell participants other things that I don't want them to know, especially if I enabled something like location services.
This feels like a weird slippery slope fallacy.
That's what Permissions controls are for.
Even worse, some browsers expose this too: https://developer.mozilla.org/en-US/docs/Web/API/Battery_Sta...
This is the only app I'd trust with access to my battery level https://diewithme.online/
If the OS slows down the app, how will you stop the app from detecting that?