编译
AOSP 旧的版本winscope就是一个静态的html页面(winscope.html),新版本同步完后是一个web项目(development/tools/winscope)
安装依赖
$ npm install
$ npm run build:prod
...
> winscope@0.0.0 build:protos
> node protos/build.js
node:internal/process/promises:392
new UnhandledPromiseRejection(reason);
^
UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "Failed to execute command
command: npx pbjs --force-long --target json-module --wrap es6 --out /media/ken/mhd/lineage21/development/tools/winscope/protos/../deps_build/protos/ime/latest/json.js --root ime_latest --path /media/ken/mhd/lineage21/development/tools/winscope/protos/../../../../../main/external/perfetto --path /media/ken/mhd/lineage21/development/tools/winscope/protos/.. --path /media/ken/mhd/lineage21/development/tools/winscope/protos/../../../../../main /media/ken/mhd/lineage21/development/tools/winscope/protos/../../../../frameworks/base/core/proto/android/view/inputmethod/inputmethodeditortrace.proto
stdout:
stderr: /media/ken/mhd/lineage21/development/tools/winscope/node_modules/protobufjs-cli/pbjs.js:254
throw err;
^
Error: no such Type or Enum 'InputMethodManagerProto' in Type .android.view.inputmethod.InputMethodClientsTraceProto.ClientSideProto
at Type.lookupTypeOrEnum (/media/ken/mhd/lineage21/development/tools/winscope/node_modules/protobufjs/src/namespace.js:410:15)
at Field.resolve (/media/ken/mhd/lineage21/development/tools/winscope/node_modules/protobufjs/src/field.js:268:94)
at Type.set (/media/ken/mhd/lineage21/development/tools/winscope/node_modules/protobufjs/src/type.js:177:38)
at Type.get (/media/ken/mhd/lineage21/development/tools/winscope/node_modules/protobufjs/src/type.js:155:45)
at Field.resolve (/media/ken/mhd/lineage21/development/tools/winscope/node_modules/protobufjs/src/field.js:320:21)
at Type.resolveAll (/media/ken/mhd/lineage21/development/tools/winscope/node_modules/protobufjs/src/type.js:304:21)
at Type.resolveAll (/media/ken/mhd/lineage21/development/tools/winscope/node_modules/protobufjs/src/namespace.js:307:25)
at Type.resolveAll (/media/ken/mhd/lineage21/development/tools/winscope/node_modules/protobufjs/src/type.js:308:43)
at Namespace.resolveAll (/media/ken/mhd/lineage21/development/tools/winscope/node_modules/protobufjs/src/namespace.js:307:25)
at Namespace.resolveAll (/media/ken/mhd/lineage21/development/tools/winscope/node_modules/protobufjs/src/namespace.js:307:25)
Node.js v23.6.0
".
at throwUnhandledRejectionsMode (node:internal/process/promises:392:7)
at processPromiseRejections (node:internal/process/promises:475:17)
at process.processTicksAndRejections (node:internal/process/task_queues:106:32) {
code: 'ERR_UNHANDLED_REJECTION'
}
分析上面的错误,发现npx 命令中的路径是错误的:/media/ken/mhd/lineage21/development/tools/winscope/protos/…/…/…/…/…/main。
找到protos/build.js,将路径改正确
// const ANDROID_BUILD_TOP = __dirname + '/../../../../../main';
const ANDROID_BUILD_TOP = __dirname + '/../../../..';
再次编译成功了。
日志抓取
启动服务,运行winscope_proxy脚本,连接手机,日志抓取遇到的问题:
$ python3 src/adb/winscope_proxy.py
2025-03-02 11:39:24,533 - ADBProxy - ERROR - Internal error: Error executing adb command: adb shell su root id -u
/system/bin/sh: su: inaccessible or not found
2025-03-02 11:39:24,593 - ADBProxy - ERROR - Internal error: Error executing adb command: adb shell su root id -u
/system/bin/sh: su: inaccessible or not found
2025-03-02 11:40:54,454 - ADBProxy - ERROR - Internal error: Error executing adb command: adb shell su root id -u
看来是su命令没找到,在手机安装MagiskSU,依然出错
2025-03-02 11:40:54,517 - ADBProxy - ERROR - Internal error: Error executing adb command: adb shell su root id -u
MagiskSU
Usage: su [options] [-] [user [argument...]]
Options:
-c, --command COMMAND Pass COMMAND to the invoked shell
-g, --group GROUP Specify the primary group
-G, --supp-group GROUP Specify a supplementary group.
The first specified supplementary group is also used
as a primary group if the option -g is not specified.
-Z, --context CONTEXT Change SELinux context
-t, --target PID PID to take mount namespace from
-h, --help Display this help message and exit
-, -l, --login Pretend the shell to be a login shell
-m, -p,
--preserve-environment Preserve the entire environment
-s, --shell SHELL Use SHELL instead of the default /system/bin/sh
-v, --version Display version number and exit
-V Display version code and exit
-mm, -M,
--mount-master Force run in the global mount namespace
看来MagiskSU对 “su root id -u”这种格式的写法不支持。
干脆直接修改winscope_proxy.py脚本,将所有的"su root "删除. 然后直接通过“adb root“开启root权限。再次重新运行winscope_proxy.py即可。