在Linux3.0+Android4.0上面开发了电池驱动,启动Android后,在Settings里面的Battery选项上可以监测到电池充电放电及剩余电量等信息,但是界面上总是显示"无法获取电池使用数据"。我看了一下Battery相关的信息,Android实际上都是从/sys/class/power_supply/battery/下读取到的,可以看到如下信息:
capacity
current_now
device
health
power
present
status
subsystem
technology
temp
type
uevent
voltage_now在Android上层的Java中PowerUsageSummary.java中判断并打印了"无法获取电池使用数据",如下:
if (mPowerProfile.getAveragePower(PowerProfile.POWER_SCREEN_FULL) < 10) {
            addNotAvailableMessage();
            return;
        }跟踪代码到PowerProfile.java中,找到了关于PowerProfile的定义如下:
public static final String POWER_SCREEN_FULL = "screen.full";但是不太清楚这个到底是什么意思?请问是否是Linux Battery底层驱动中还需要支持什么信息的读取?还是上层什么地方需要配置?请帮忙指点一下,谢谢!

解决方案 »

  1.   

    getAveragePower的实现:public double getAveragePower(String type) {
            if (sPowerMap.containsKey(type)) {
                Object data = sPowerMap.get(type);
                if (data instanceof Double[]) {
                    return ((Double[])data)[0];
                } else {
                    return (Double) sPowerMap.get(type);
                }
            } else {
                return 0;
            }
        }
    也许是读的这个key:POWER_SCREEN_FULL 没有value。那sPowerMap打印出来看看都有什么key 
      

  2.   

    public double getAveragePower(String type) {
            if (sPowerMap.containsKey(type)) {
                Object data = sPowerMap.get(type);
                if (data instanceof Double[]) {
                    return ((Double[])data)[0];
                } else {
                    return (Double) sPowerMap.get(type);
                }
            } else {
                return 0;
            }
        }
      

  3.   

    也碰到这个问题,在PowerProfile.java中明显可以看到是读的xml文件噻。
    在frameworks/base/core/res/res/xml/power_profile.xml
    中有<item name="screen.full">0.1</item>
    所以,在mPowerProfile.getAveragePower(PowerProfile.POWER_SCREEN_FULL)返回的应该是0.1,<10直接返回了,就显示了“无法获取电池使用数据”的情况了。不过,配置中的值,具体是什么涵义,应该如何修改,还不清楚。楼主搞懂了,也回复结贴呀。
      

  4.   

    请问,frameworks/base/core/res/res/xml/power_profile.xml中的配置,有没有了解? 有的话,麻烦帮忙解惑呀,谢谢!
      

  5.   

    4.1做如下修改可以恢复正常
          /*  if (mPowerProfile.getAveragePower(PowerProfile.POWER_SCREEN_FULL) < 10) {
                addNotAvailableMessage();
                return;
            }*/       // if (!com.android.settings.Utils.isWifiOnly(getActivity())) {
                addRadioUsage(uSecNow);
           // }
      

  6.   

    在设置应用中,Battery 中PowerUsageSummary.java通过power_profile.xml来获取screen.full键值,里面默认设置值为0.1,但在PowerUsageSummary.java中判断以大于10为判断标准,导致此现象。与之前的4.0.4代码比较分析后,确定是谷歌官方代码错误,将判断条件10改为0解决。
      

  7.   

    这个回复有误,哈!应该是下面这样:
    设置应用的:PowerUsageSummary.java文件,会判断:if (mPowerProfile.getAveragePower(PowerProfile.POWER_SCREEN_FULL) < 10)即亮屏时的功耗。这边主要通过:power_profile.xml 进行配置,默认配置是一个很小的值,如0.1mA(这个值当然不对),而实际配置正常后,如屏亮度为:300mA,此功能即可正常。更详细的内容,请查看:power_profile.xml 的注释说明。