2018-08-06Battery模块总结

1没写节点文件,常见属性
sys/class/power_supply
2没写注册过程

batteryproperties Binder 服务的特色:

  1. 能够在java和C++之间传递对象(BatteryProperties对象)
  2. 服务能够主动给客户端发送消息

一、电池电量从healthd传到Java层的通信过程

C++:

system/core/healthd/healthd.cpp,
system/core/healthd/BatteryMonitor.cpp,
framework/native/services/batteryservice/include/batteryservice/IBatteryPropertiesListener.h
framework/native/services/batteryservice/IBatteryPropertiesListener.cpp
framework/native/services/batteryservice/include/batteryservice/IBatteryPropertiesRegistrar.h
system/core/healthd/BatteryPropertiesRegistor.cpp,
framework/native/services/batteryservice/include/batteryservice/IBatteryPropertiesRegistrar.h
framework/native/services/batteryservice/IBatteryPropertiesRegistrar.cpp
framework/base/core/java/android/os/IBatteryPropertiesListener.aidl

Java:

BatteryService, BatteryListener, IBatteryPropertiesListener.aidl, IBatteryPropertiesRegistrar.aidl,
BatteryState,BatteryStatesService(这两个跟AMS相关,记录更新应用耗电信息,暂未分析)

healthd进程除了读取电池数据上报外,还有关机充电时绘制图标的功能

先来张图对Battery模块有个整体认知


2018-08-06Battery模块总结_第1张图片
图片.png

2018-08-06Battery模块总结_第2张图片
图片.png
2018-08-06Battery模块总结_第3张图片
图片.png

2018-08-06Battery模块总结_第4张图片
图片.png

流程图:


2018-08-06Battery模块总结_第5张图片
图片.png

Battery框架的AIDL,java层和c层的交互

batteryproperties Binder服务

定义:
/frameworks/native/include/batteryservice/IBatteryPropertiesRegistrar.h
接口:
IBatteryPropertiesRegistrar

33class IBatteryPropertiesRegistrar : public IInterface {
34public:
35    DECLARE_META_INTERFACE(BatteryPropertiesRegistrar)
36
37    virtual void registerListener(const sp& listener) = 0;
38    virtual void unregisterListener(const sp& listener) = 0;
39    virtual status_t getProperty(int id, struct BatteryProperty *val) = 0;
40    virtual void scheduleUpdate() = 0;
41};

实现:
BnBatteryPropertiesRegistrar
/system/core/healthd/BatteryPropertiesRegistrar.cpp

sub 接口2:
IBatteryPoroertiesListener
C++语言定义的接口
/frameworks/native/include/batteryservice/IBatteryPropertiesListener.h

34class IBatteryPropertiesListener : public IInterface {
35public:
36    DECLARE_META_INTERFACE(BatteryPropertiesListener)
37
38    virtual void batteryPropertiesChanged(struct BatteryProperties props) = 0;
39};

java定义的接口(利用了AIDL)
/frameworks/base/core/java/android/os/IBatteryPropertiesListener.aidl

package android.os;
import android.os.BatteryProperties;

oneway interface IBatteryPropertiesListener {
    void batteryPropertiesChanged(in BatteryProperties props);
}

others :BatteryProperties类是如何在java和C++传输的

/frameworks/base/core/java/android/os/BatteryProperties.java 和 BatteryProperties.aidl
/frameworks/native/services/batteryservice/BatteryProperties.cpp
两个保持一致,并且可序列化

参考资料:

(原创)android6.0系统Healthd深入分析
https://blog.csdn.net/u011311586/article/details/51082685
android 4.4 电池电量管理底层分析(C\C++层)
https://blog.csdn.net/daweibalang717/article/details/41446993

android 4.4 电池电量显示分析(低电量提醒与电池图标)Java 层
https://blog.csdn.net/daweibalang717/article/details/40615453
其他方面:
Android7.0BatteryStatsService[https://blog.csdn.net/gaugamela/article/details/52931949 ]
Android7.0BatteryService[https://blog.csdn.net/Gaugamela/article/details/52920222 ]
Android battery historian功耗分析之环境搭建[ https://www.jianshu.com/p/5abd53abcc1e ]

你可能感兴趣的:(2018-08-06Battery模块总结)