Android手机获取power_profile.xml

我们知道,从手机的“设置–>电池–>耗电情况”栏目中我们可以获得手机各部件、应用、服务的耗电情况。从原理上看,在Android设计中,手机LCM、Bluetooth、wifi、audio、通话等的耗电信息会被研发事先测试出来,然后记录在android/frameworks/base/core/res/res/xml/power_profile.xml文件里面,这些就是手机耗电统计的数据依据。power_profile.xml会被编译进framework-res.apk文件文件,存储在手机的/system/framework/framework-res.apk路径中。相反的操作,我们可以将framework-res.apk文件从手机中导出来,然后采用反编译手法获得power_profile.xml文件。

power_profile.xml可以在google网站查询到详细介绍:http://source.android.com/devices/tech/power.html

下面将介绍从手机获取power_profile.xml的方法。

1、安装JAVA环境。

以apktool1.5.2为例,需要安装JRE1.7。


2、下载apktool.jar及apktool工具包

以windows环境为例,我从http://apktool.shoujifans.com/2014/12/21.html分别下载了apktool1.5.2.tar.bz2和apktool-install-windows-r05-ibot.tar.bz2。分别解压后,将apktool.jar从apktool1.5.2文件夹拷贝到文件夹apktool-install-windows-r05-ibot里面。
dir一下,可以看到如下信息:
2015/01/06  13:57    <DIR>          .
2015/01/06  13:57    <DIR>          ..
2012/12/06  11:44           854,016 aapt.exe
2012/12/23  23:39                92 apktool.bat
2015/01/06  13:55         2,655,843 apktool.jar
点击开始菜单->运行->输入CMD->回车,用cd命令转到刚刚解压apktool-install-windows-r05-ibot所在的文件夹,输入apktool,出现下面类似信息则说明apktool可以正常工作了。
Apktool v1.5.2 - a tool for reengineering Android apk files
Copyright 2010 Ryszard Wi?niewski <brut.alll@gmail.com>
with smali v1.4.1, and baksmali v1.4.1
Updated by @iBotPeaches <connor.tumbleson@gmail.com>
Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)

Usage: apktool [-q|--quiet OR -v|--verbose] COMMAND [...]

COMMANDs are:

    d[ecode] [OPTS] <file.apk> [<dir>]
        Decode <file.apk> to <dir>.

        OPTS:

        -s, --no-src
            Do not decode sources.
        -r, --no-res
            Do not decode resources.
        -d, --debug
            Decode in debug mode. Check project page for more info.
        -b, --no-debug-info
            Baksmali -- don't write out debug info (.local, .param, .line, etc.)
        -f, --force
            Force delete destination directory.
        -t <tag>, --frame-tag <tag>
            Try to use framework files tagged by <tag>.
        --frame-path <dir>
            Use the specified directory for framework files
        --keep-broken-res
            Use if there was an error and some resources were dropped, e.g.:
            "Invalid config flags detected. Dropping resources", but you
            want to decode them anyway, even with errors. You will have to
            fix them manually before building.

    b[uild] [OPTS] [<app_path>] [<out_file>]
        Build an apk from already decoded application located in <app_path>.

        It will automatically detect, whether files was changed and perform
        needed steps only.

        If you omit <app_path> then current directory will be used.
        If you omit <out_file> then <app_path>/dist/<name_of_original.apk>
        will be used.

        OPTS:

        -f, --force-all
            Skip changes detection and build all files.
        -d, --debug
            Build in debug mode. Check project page for more info.
        -a, --aapt
            Loads aapt from specified location.

    if|install-framework <framework.apk> [<tag>] --frame-path [<location>]
        Install framework file to your system.

For additional info, see: http://code.google.com/p/android-apktool/
For smali/baksmali info, see: http://code.google.com/p/smali/

3、将framework-res.apk从手机中导出
使用下面命令:
adb root
adb pull /system/framework/framework-res.apk
framework-res.apk会出现在电脑的当前文件夹里面。

4、反编译framework-res.apk
输入命令:
apk tool d framework-res.apk aaa
之后出现如下信息:
I: Loading resource table...
I: Loaded.
I: Decoding AndroidManifest.xml with resources...
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Done.
I: Copying assets and libs...
framework-res.apk的反编译文件将生成在aaa文件夹里面。



没有更多推荐了,返回首页