-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Get raw battery max and current capacity on macOS #7721
Conversation
Apple's x86 laptops report battery status in mAh but its ARM laptops use percent. This commit uses an undocumented raw capacity field which reports mAh on both x86 and ARM laptops
|
You mention undocumented. Do you think it's going to stick around? |
Can confirm I get the exact same results before/after change on 2020 Intel MBP running 12.5. Can confirm the change provides numbers that appear to be mAh on M1 running 13 beta 3. |
I'm not sure what basis we would have to make such a determination... Osquery does use tons of undocumented and private APIs to get at the data we provide, so it seems reasonable enough to me to do so here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'm game
I guess the other question is whether we should expose both. |
I'd say leave it as-is? The percentage can be calculated from these values in both cases. |
I've tested this PR using
|
Apple's x86 laptops report battery status in mAh but its ARM laptops use percent.
This commit uses an undocumented raw capacity field which reports mAh on both x86 and ARM laptops. I've tested on a 2022 M2 MacBook Pro and a 2012 i5 MacBook Pro, both running macOS 12. However, this needs more testing on more systems.
This will partially fix #6800 but will not fix the incorrect health column. I've spent a while trying to figure out how the Battery.prefPane and coconutBattery get correct results but so far I've only found that Battery.prefPane uses
IOPSCopyPowerSourcesByType(1)
then gets theBattery Service State
field from the first battery, which does not exist for me