当前位置: 代码迷 >> 综合 >> 2021-12-22 AndroidR 电池信息 简单分析记录
  详细解决方案

2021-12-22 AndroidR 电池信息 简单分析记录

热度:24   发布时间:2023-11-27 11:14:50.0

一、应用接口层 frameworks\base\core\java\android\os\BatteryManager.java

 二、服务层 frameworks\bfase\services\core\java\com\android\server\BatteryService.java ,onStart将电池监听注册到底层。

 三、frameworks\bfase\services\core\java\com\android\server\BatteryService.java

通过 HIDL服务调用HAL。

 四、hidl服务在 \hardware\interfaces\health\2.1\default\service.cpp

 五、到这里从log上看就打开一个android.hardware.health@2.1-service服务了。

     1、查看log看服务。

    2、绑定模式的服务代码流程

hardware\interfaces\health\2.1\default\service.cppStartLoop()hardware\interfaces\health\utils\libhealthloop\HealthLoop.cppStartLoop()  >InitInternal()  >   Init(&healthd_config_)hardware\interfaces\health\utils\libhealth2impl\BinderHealth.cppInit(struct healthd_config* config)

 六、涉及的代码比较多,这里就简单分析一下后面的过程,从log上一直会打印下面的跟电池有关的信息,我这里就分析这些信息是怎么来,简单跟踪一下过程。

     1、电池检测的log。 

     2、跟踪得到上面的大概流程如下,最后的打印在BatteryMonitor.cpp 里面的logValues。

hardware\interfaces\health\2.1\default\service.cpp
binder->StartLoop();hardware\interfaces\health\utils\libhealthloop\HealthLoop.cpp
StartLoop()->MainLoop->  PeriodicChores    ->  ScheduleBatteryUpdate();  ->hardware\interfaces\health\utils\libhealth2impl\HalHealthLoop.cpp
ScheduleBatteryUpdate() _>update();\hardware\interfaces\health\utils\libhealth2impl\Health.cpp
update() >logValues()\system\core\healthd\BatteryMonitor.cpp
logValues

     3、在system\core\healthd\BatteryMonitor.cpp里面通过/sys/class/power_supply/battery/ 读底层的电池信息。

 

七、参考文章

Android Battery 架构_shichaog的专栏-CSDN博客_android battery