Android电池电量使用详情查看

来源:互联网 发布:广数g92车英制螺纹编程 编辑:程序博客网 时间:2024/06/11 03:30

Android电池电量使用详情查看

关于Android电量的基础知识

  1. 关于电能的相关物理公式

    1. 电功率公式P=UI,P为电功率单位为w(瓦),U为电压单位V(伏特),I为电流单位安(A)
    2. 电能公式W=Pt=UIt,W为电能单位j(焦耳),t时间单位s(秒)
  2. 手机电池容量相关说明

    手机上的电池容量一般是以mAh为单位的,这是因为手机的电压是保持稳定的,一般手机的电池容量在1500mAh到5000mAh之间,比如3000mAh表示的意思是手机能够保持电流大小为3000毫安的情况下对外输出电流一小时

Android手机各部件运行时能耗详情

  1. 在Android手机中,对于手机中的每个部件(cpu、led、gps、3g等等)运行时对应的能耗值都放在power_profile.xml文件中,而且系统的 设置–>电池–>使用情况中,统计的能耗的使用情况也是以power_profile.xml的value作为基础参数的。

    google官网介绍:http://source.android.com/devices/tech/power.html

    1. 我的手机获取的prower_profile.xml内容:华为 SCL-CL00

    screen.full:320.0 手机屏幕全亮状态电流
    radio.active:140.0 无线网路最高功率工作电流
    wifi.scan:130.0 扫描wifi电流
    cpu.speeds: cpu的工作速度 [200000.0,345600.0,400000.0,422400.0,499200.0,533333.0,652800.0,729600.0,800000.0,806400.0,883200.0,960000.0,1036800.0,1113600.0,1190400.0,1267200.0,1344000.0,1420800.0,1497600.0,1593600.0,]
    dsp.video:300.0
    wifi.on:3.0
    cpu.idle:3.0
    wifi.active:130.0
    bluetooth.on:1.0
    none:0.0
    wifi.batchedscan:[2.0E-4,0.002,0.02,0.2,2.0,]
    screen.on:120.0
    cpu.active:[75.0,85.0,100.0,107.0,115.0,120.0,130.0,140.0,160.0,200.0,210.0,220.0,230.0,240.0,250.0,270.0,320.0,370.0,420.0,480.0,]
    radio.scanning:10.0
    radio.on:[10.0,5.0,]
    dsp.audio:50.0
    battery.capacity:3000.0
    gps.on:40.0
    bluetooth.active:70.0

Google官网参数说明:http://source.android.com/devices/tech/power/values.html

 2. 如何获取power_profile

通过源码搜索power_profile,发现在代码PowerProfile这个类中有加载这个配置文件,通过反射PowerProfile来获取power_profile.xml信息,反射代码如下:

try {            Class powerProfile = Class.forName("com.android.internal.os.PowerProfile");            Constructor constructor = powerProfile.getConstructor(new Class[]{Context.class});            Object o = constructor.newInstance(this);            Field field = powerProfile.getDeclaredField("sPowerMap");            field.setAccessible(true);            Object values = field.get(o);            HashMap<String, Object> powerMap = (HashMap<String, Object>) values;            Iterator<Map.Entry<String, Object>> entryit = powerMap.entrySet().iterator();            while (entryit.hasNext()) {                Map.Entry<String, Object> entry = entryit.next();                String key = entry.getKey();                Object value = entry.getValue();                if (value instanceof Double[]) {                    Double[] vs = (Double[]) value;                    StringBuilder sb = new StringBuilder();                    sb.append("[");                    for (double v : vs) {                        sb.append(v + ",");                    }                    sb.append("]");                    Log.i("power", key + ":" + sb.toString());                } else {                    Log.i("power", key + ":" + value.toString());                }            }        } catch (Exception e) {            e.printStackTrace();        }

Android源码查询:http://androidxref.com/source/xref/frameworks/base/core/java/com/android/internal/os/PowerProfile.java

Android获取电池电量使用详情

对于android5.0以上的版本可以用开源项目Battery Historian来查看详情,GitHub上的地址为:https://github.com/google/battery-historian.

  1. 下载battery-historian
  2. 找到historian.py(在scripty文件夹里面)位置
  3. adb链接手机,并且cd到historian.py目录下
  4. adb shell dumpsys batterystats –reset重置,
  5. 手机端断开和电脑的连接,并且运行你的程序一段时间
  6. 连接电脑
  7. adb shell dumpsys batterystats > batterystats.txt
  8. python historian.py batterystats.txt > batterystats.html(确保你下载了python,并且使用版本为2.7)
  9. 打开batterystats.html查看详情

google官网地址:https://developer.android.com/studio/profile/battery-historian.html

我的手机获取的信息如下:
battery useage

参数说明:
battery_level:手机电量
screen:屏幕
top:当前运行的app
running:cpu运行
mobile-radio:无线网路运行
date_conn:数据连接

Google官网参数说明:https://developer.android.com/studio/profile/battery-historian-charts.html

0 0
原创粉丝点击