欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android开发中Battery Historian遇到的问题

程序员文章站 2022-06-18 11:05:33
BatteryHistorian所遇到的坑1. JS 编译问题2. Android Q无法解析bugreport问题3. 搭建本地离线版Battery Historian浏览本文,你可以获取以下信息1. 解决执行 go run setup.go时,无法编译通过的问题;2. 上传bgr.zip/bgr.txt后,Android Q无法解析的问题;3. 搭建离线版Battery Historian1. JS 编译问题如下在执行go run setup.go时,会出现如下图片所示的报错,这个问题在最新...



浏览本文,你可以获取以下信息
1. 解决执行 go run setup.go时,无法编译通过的问题;
2. 上传bgr.zip/bgr.txt后,Android Q无法解析的问题;
3. 搭建离线版Battery Historian

1. JS 编译问题

如下在执行go run setup.go时,会出现如下图片所示的报错,这个问题在最新的(2020.08.20)代码还是并未解决,不知道是什么时候引入的问题,可参考Github BatteryHistorian 183问题的描述,主要解决办法就是回退版本。如果你是从Github上单独拉的closure-library,需要先在你拉下来的路径下回退版本,再拷贝到third_party,无法直接在third_party/closure-library下回退,会提示“ambiguous argument ‘v20170409’: unknown revision or path not in the working tree.”;如果执行完go get -d -u github.com/google/battery-historian/...后,在third_party路径下有closure-library文件夹,那你可以直接在这回退版本

// 直接有closure-library文件夹
go run setup.go (this fails)
cd third_party/closure-library/
git reset --hard v20170409
cd -
go run setup.go (this passes)

//单独拉closure-library
cd closure-library
git reset --hard v20170409
拷贝closure-library到$GOPATH/src/github.com/google/battery-historian/third_party下
go run setup.go 

Android开发中Battery Historian遇到的问题Android开发中Battery Historian遇到的问题
回退后,执行成功的界面
Android开发中Battery Historian遇到的问题

2. Android Q无法解析bugreport问题

如下图片,当你解决环境问题时,有Submit按钮,能上传log时,却发现打开的是这样的界面,提示" Could not parse aggregated battery stats."。这个问题原因应当是Android系统更新后,在代码中的有些参数变了导致解析失败,类似于0.0和0的问题,相关问题见GIthub BatteryHistorian 188的描述,解决方法见GitHub lilydjwg的提交。解决办法是修改本地工具代码,修改如下所示:

diff --git a/checkinparse/checkin_parse.go b/checkinparse/checkin_parse.go index d8d6fcb..4519281 100644 --- a/checkinparse/checkin_parse.go +++ b/checkinparse/checkin_parse.go @@ -1979,7 +1979,7 @@ func parseAppWifi(record []string, app *bspb.BatteryStats_App) (string, []error) // // format: <idle_time>, <rx_time>, <power_ma_ms>, tx_time... func parseControllerData(pc checkinutil.Counter, section string, record []string) (*bspb.BatteryStats_ControllerActivity, error) { - var idle, rx, pwr int64 + var idle, rx, pwr float64 rem, err := parseSlice(pc, section, record, &idle, &rx, &pwr) if err != nil { return nil, err
@@ -1988,12 +1988,12 @@ func parseControllerData(pc checkinutil.Counter, section string, record []string return nil, fmt.Errorf(`%s didn't contain any transmit level data: "%v"`, section, record) } c := &bspb.BatteryStats_ControllerActivity{ - IdleTimeMsec: proto.Int64(idle), - RxTimeMsec: proto.Int64(rx), - PowerMah: proto.Int64(pwr), + IdleTimeMsec: proto.Int64(int64(idle)), + RxTimeMsec: proto.Int64(int64(rx)), + PowerMah: proto.Int64(int64(pwr)), } for i, t := range rem { - tm, err := strconv.Atoi(t) + tm, err := strconv.ParseFloat(t, 64) if err != nil { return nil, fmt.Errorf("%s contained invalid transmit value: %v", section, err) } diff --git a/packageutils/packageutils.go b/packageutils/packageutils.go index 709274c..32ad7c2 100644 --- a/packageutils/packageutils.go +++ b/packageutils/packageutils.go @@ -51,7 +51,7 @@ const ( ) // abrUIDRE is a regular expression to match an abbreviated uid (ie u0a2). Based on the format printed in frameworks/base/core/java/android/os/UserHandle.java -var abrUIDRE = regexp.MustCompile("u(?P<userId>\\d+)(?P<aidType>[ias])(?P<appId>\\d+)") +var abrUIDRE = regexp.MustCompile("u(?P<userId>\\d+)(?P<aidType>[ias]+)(?P<appId>\\d+)") // This list is not comprehensive but it will cover the most common cases. The list was curated // from the output of running both 'adb shell dumpsys activity providers' and 

Android开发中Battery Historian遇到的问题

3. 搭建本地离线版Battery Historian

根据base.html的配置,当上传bugreport后,需要访问ajax.googleapis.com、cdnjs.cloudflare.com、https://www.google.com等资源,这些资源中,有部分资源由于墙的原因无法访问,创建离线版就是在本地提供这些资源,感谢GitHub用户gusha915提供的所需资源,具体操作如下:

  1. 执行完go get -d -u github.com/google/battery-historian/…后,将下载好的base.html 替换原码下的 battery-historian\templates\base.html;
  2. 下载好cdn目录 放入到battery-historian\third_party 目录;
  3. 进行 cd $GOPATH/src/github.com/google/battery-historian;
  4. 运行 go run setup.go 进行编译;
  5. 运行 go run cmd/battery-historian/battery-historian.go

Android开发中Battery Historian遇到的问题

本文地址:https://blog.csdn.net/qq_26100545/article/details/108163244