How does Android keeps track of how much battery each specific apps used? How does Android keeps track of how much battery each specific apps used?

For example, if you go to battery usage on android phone, it will say something like:


Display 70%
Whatsapp 25%
Browser 3%


etc.

Is this done by battery manager?

And how accurate is this values computed, I am trying to come up with an app that can accurately measure how much battery each apps specifically consume.
There will be low level APIs that Android uses when computing battery stats.


  I am trying to come up with an app that can accurately measure how much battery each apps specifically comsume.


Although this sub isn't for development related questions, check out Batterystats on how to implement battery collection stats.