分支确定
在源代码标记和 build中可查得Pixel 3 XL 可以支持的最新Android Build为:SP1A.210812.016.A1 , 对应的分支: android-12.0.0_r3 .
在Driver Binaries for Nexus and Pixel Devices中可以找到对应的驱动为:Pixel 3 XL binaries for Android 12.0.0 (SP1A.210812.016.A1)
准备代码
$ mkdir -p ~/bin/
$ mkdir ~/work/aosp/
$ cd ~/work/aosp/
$ repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-12.0.0_r3
$ repo sync
下载驱动并解压
$ cd ~/Downloads
$ tar xvf qcom-crosshatch-*.tgz
$ tar xvf google_devices-crosshatch-*.tgz
$ cd ~/work/aosp/
$ ~/Downloads/extract-qcom-crosshatch.sh
$ ~/Downloads/extract-google_devices-crosshatch.sh
Lake
编译固件
$ source build/envsetup.sh
$ lunch aosp_crosshatch-userdebug
$ m
配置adb
$ sudo usermod -aG plugdev $LOGNAME
$ apt-get install android-sdk-platform-tools-common
重新插拔USB, 然后手机选择总是信任当前已经连接的计算机.
刷写固件
$ adb reboot bootloader
$ fastboot flashall -w
等待设备刷写完成.
调试cameraserver
$ adb root
$ gdbclient.py -n cameraserver
Redirecting gdbserver output to /tmp/gdbclient.log
GNU gdb (GDB) 8.3
Copyright (C) 2019 Free Software Foundation, Inc.
... ...
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
__ioctl () at out/soong/.intermediates/bionic/libc/syscalls-arm.S/gen/syscalls-arm.S:850
850 swi #0
打断电调试
(gdb) b CameraProviderManager::openSession
Breakpoint 1 at 0xed4c7f1a: CameraProviderManager::openSession. (3 locations)
(gdb) c
Continuing.
[New Thread 10170.11808]
[Switching to Thread 10170.10286]
打开相机APP验证断点
Thread 6 "Binder:10170_3" hit Breakpoint 1, android::CameraProviderManager::openSession (this=0xeab00590, id=..., callback=..., session=0xe9d7bb4c)
at frameworks/av/services/camera/libcameraservice/common/CameraProviderManager.cpp:379
379 std::lock_guard<std::mutex> lock(mInterfaceMutex);
查看堆栈
(gdb) bt
#0 android::CameraProviderManager::openSession (this=0xeab00590, id=..., callback=..., session=0xe9d7bb4c)
at frameworks/av/services/camera/libcameraservice/common/CameraProviderManager.cpp:379
#1 0xed51bd12 in android::Camera3Device::initialize (this=0xedc05c80, manager=..., monitorTags=...)
at frameworks/av/services/camera/libcameraservice/device3/Camera3Device.cpp:123
#2 0xed4c5786 in android::Camera2ClientBase<android::CameraDeviceClientBase>::initializeImpl<android::sp<android::CameraProviderManager> > (
this=0xeaa404d0, providerPtr=..., monitorTags=...) at frameworks/av/services/camera/libcameraservice/common/Camera2ClientBase.cpp:107
#3 0xed4c56f0 in android::Camera2ClientBase<android::CameraDeviceClientBase>::initialize (this=0xaa716, manager=..., monitorTags=...)
at frameworks/av/services/camera/libcameraservice/common/Camera2ClientBase.cpp:83
#4 ... ...
... ...
导出配置到vscode
执行:
$ gdbclient.py --setup-forwarding vscode -n cameraserver
Redirecting gdbserver output to /tmp/gdbclient.log
{
"miDebuggerPath": "/home/nickli/work/aosp/prebuilts/gdb/linux-x86/bin/gdb",
"program": "/home/nickli/work/aosp/out/target/product/crosshatch/symbols/system/bin/cameraserver",
"setupCommands": [
{
... ...
}
]
}
... ...
将导出的配置({} 中的部分)粘贴到~/work/aosp/.vscode/launch.json 的如下位置:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
<粘贴到此处>
}
]
}
使用vscode打开~/work/aosp 目录, 然后打开frameworks/av/services/camera/libcameraservice/common/CameraProviderManager.cpp 文件在:
status_t CameraProviderManager::openSession(const std::string &id,
const sp<device::V1_0::ICameraDeviceCallback>& callback,
/*out*/
sp<device::V1_0::ICameraDevice> *session)
内下断点, 然后点击"Run" -> “Start Debugging”
效果类似下图:
|