WEB开发网
开发学院手机开发Android 开发 Android之 BatteryService 阅读

Android之 BatteryService

 2010-05-31 14:22:00 来源:WEB开发网   
核心提示:电池的信息,电压,Android之 BatteryService,温度,充电状态等等,还有变量, 如下://##在BatteryService.java中声明的变量private boolean mAcOnline;private boolean mUsbOnline;private int mBatteryStatu

电池的信息,电压,温度,充电状态等等,都是由BatteryService来提供的。BatteryService是跑在system_process当中,在系统初始化的时候启动,如下

在BatteryService.java中:

Log.i(TAG, "Starting Battery Service.");

BatteryService battery = new BatteryService(context);

ServiceManager.addService("battery", battery);

========================================================================================

1. 数据来源

BatteryService通过JNI(com_android_server_BatteryService.cpp)读取数据。BatteryService通过JNI注册的不仅有函数,还有变量。 如下:

//##############在BatteryService.java中声明的变量################

private boolean mAcOnline;

private boolean mUsbOnline;

private int mBatteryStatus;

private int mBatteryHealth;

private boolean mBatteryPresent;

private int mBatteryLevel;

private int mBatteryVoltage;

private int mBatteryTemperature;

private String mBatteryTechnology;

//在BatteryService.java中声明的变量,在com_android_server_BatteryService.cpp中共用,即在com_android_server_BatteryService.cpp中其实操作的也是BatteryService.java中声明的变量

gFieldIds.mAcOnline = env->GetFieldID(clazz, "mAcOnline", "Z");

gFieldIds.mUsbOnline = env->GetFieldID(clazz, "mUsbOnline", "Z");

gFieldIds.mBatteryStatus = env->GetFieldID(clazz, "mBatteryStatus", "I");

gFieldIds.mBatteryHealth = env->GetFieldID(clazz, "mBatteryHealth", "I");

gFieldIds.mBatteryPresent = env->GetFieldID(clazz, "mBatteryPresent", "Z");

gFieldIds.mBatteryLevel = env->GetFieldID(clazz, "mBatteryLevel", "I");

gFieldIds.mBatteryTechnology = env->GetFieldID(clazz, "mBatteryTechnology", "Ljava/lang/String;");

gFieldIds.mBatteryVoltage = env->GetFieldID(clazz, "mBatteryVoltage", "I");

1 2 3 4  下一页

Tags:Android BatteryService

编辑录入:coldstar [复制链接] [打 印]
赞助商链接