查看所有應用:adb shell dumpsys
當前運行的服務:adb shell dumpsys -l
常見電量問題
1、喚醒鎖:關閉屏幕后,讓CPU在后台運行;app長期獲取喚醒鎖,不釋放;阻止設備進入低電量模式
查看喚醒鎖信息:adb shell dumpsys power
2、開啟應用過多;
3、充電過程中運行app
一、耗電量數據收集
模擬器收集的數據可能不准,盡量用真機
1、清理耗電量數據
adb shell dumpsys batterystats --reset
adb shell dumpsys batterystats --enable full-wake-history
2、運行測試用例或者手工操作一段時間
3、收集數據
Android 7.0及以上:adb bugreport bugreport.zip
Android 6.0及以下:adb bugreport >bugreport.txt
二、耗電量數據可視化展示分析
這里使用谷歌開源工具battery-historian進行分析,開源地址:https://github.com/google/battery-historian
提供了兩種方式進行安裝:
1、手動編譯方式:配置環境很復雜,搞了很久沒搞好,可能是有些依賴下載不了
2、docker方式安裝:
按照官網提供的鏡像安裝不了:docker -- run -p <port>:9999 gcr.io/android-battery-historian/stable:3.0 --port 9999
然后用其他博客里面寫的這個鏡像bhaavan/battery-historian可以安裝並啟動,也可以訪問,但是前端有很多報錯,點擊上傳文件后無響應。
探索很久后,突然靈光一現,為啥不換個鏡像試試呢,於是查看了鏡像:
使用紅框中的鏡像運行后,訪問正常,也可以正常上傳耗電量報告:
docker run -d -p 8010:9999 runcare/battery-historian
由於是在模擬器中導出的報告,可能沒有數據,后面用真機再做嘗試