整体想法: 替换sdk-28源码中每一个x.java文件为指向软连接LineageOS-16.0对应的x.java
调试前奏(准备)
android-studio-4.2并不像老版本android-studio那样容易替换api源文件路径
android-studio-4.2:
- 在Project Structure不能设置api(如28)的源码路径
- 在x.class的反编译窗口,并没有提供选择源码路径的界面
因此 以下记录 简单粗暴的替换android-studio-4.2的android-sdk-manger中api(android9, api28)的源码为LinageOS-16.0(android9,api28)的方法
1. android studio 4.2 下载api 28源码
android-studio-4.2 --> Tools --> sdk manager --> show package details --> android 9.0 (pie) --> sources for android 28
2. 寻找下载的源码目录路径
下载的源码目录为android-sdk-home/sources/android-28
bash
find ~/ -type f -name "*.xml" | while read k ; do ( grep -Hn "/sources/" $k ;) ; done
/home/z/.config/Google/AndroidStudioPreview4.2/options/jdk.table.xml:65: <root url="file:///app5/android-sdk-home/sources/android-35" type="simple" />
/home/z/.config/Google/AndroidStudioPreview4.2/options/jdk.table.xml:120: <root url="file:///app5/android-sdk-home/sources/android-28" type="simple" />
3. android9(pie)源码目录与LinageOS16.0源码frameworks/base/core
的*.java
差异
只做了一边差集(L中的每一个在A中有无情况),另一边TODO
bash
( cd /app5/OP3TLos16Build/frameworks/base/core/java && find . -type f -name "*.java" ;) | while read k ; do ( cd /app5/android-sdk-home/sources/android-28/ && [[ ! -f $k ]] && echo $k ;); done
./android/app/NotificationGroup.java
./android/database/sqlite/SQLiteTokenizer.java
./android/view/WindowManagerPolicyControl.java
./com/android/internal/os/DeviceKeyHandler.java
./com/google/android/collect/Lists.java
./com/google/android/collect/Maps.java
./com/google/android/collect/Sets.java
./com/google/android/util/AbstractMessageParser.java
./com/google/android/util/Procedure.java
./com/google/android/util/SmileyParser.java
./com/google/android/util/SmileyResources.java
./com/nvidia/NvAppProfiles.java
./com/nvidia/NvAppProfileService.java
./com/nvidia/NvConstants.java
./com/nvidia/NvCPLSvc/NvAppProfile.java
./com/nvidia/NvCPLSvc/NvSaverAppInfo.java
./com/nvidia/NvWhitelistService.java
./com/nvidia/profilemanager/NvAppProfileSettingId.java
./com/nvidia/profilemanager/ProfileTypeId.java
4. LinageOS16.0源码frameworks/base/core
每个*.java
文件 覆盖 android9(pie)源码目录的对应文件
bash
LosD=/app5/OP3TLos16Build/frameworks/base/core/java
AnD=/app5/android-sdk-home/sources/android-28/
( cd $LosD && find . -type f -name "*.java" ;) | while read k ; do ( rm $AnD/$k && ln -s $LosD/$k $AnD/$k ;); done
find $AnD -type l | wc -l
== 2537
find $LosD -type f -name "*.java" | wc -l
==2556
比如
file /app5/android-sdk-home/sources/android-28/android/view/ViewRootImpl.java
/app5/android-sdk-home/sources/android-28/android/view/ViewRootImpl.java: symbolic link to /app5/OP3TLos16Build/frameworks/base/core/java/./android/view/ViewRootImpl.java
还原方法: 重做1 卸载、安装 即可还原
5. 此时android-studio-4.2即可调试LinageOS16.0的frameworks/base/core
而不是 调试 AOSP的frameworks/base/core
android-studio-4.2打开 比如 /app5/android-sdk-home/sources/android-28/android/view/ViewRootImpl.java
在以下方法加断点,即可调试view的绘制流程
performMeasure
performLayout
performDraw
4B. LinageOS16.0源码frameworks/support/v7/appcompat/src/main/java/androidx
每个*.java
文件 覆盖 android9(pie)源码目录的对应文件
androidx下x.java文件个数 二者相差不多
AOSP api28(android9): find /app5/android-sdk-home/sources/android-28/androidx -type f -name "*.java" |wc -l
==2452
LineageOS16.0(android9)find /app5/OP3TLos16Build/frameworks/ -type f -path "*/androidx/*/*.java" | wc -l
==2593
但是
但是LineageOS16.0/frameworks/下的androidx是分散的, 则有可能有重复,理想做法是遍历 AOSP api28(android9) 这边(虽然也一样可能捞错) 但至少脚本更容易点
find /app5/OP3TLos16Build/frameworks/ -type d -name "androidx" | while read k ; do ( c=$(find $k -type f -name "*.java" | wc -l) && [[ $c -gt 20 ]] && echo "$k: $c" ;); done
/app5/OP3TLos16Build/frameworks/base/tests/Camera2Tests/SmartCamera/SimpleCamera/src/androidx: 80
/app5/OP3TLos16Build/frameworks/support/annotations/src/main/java/androidx: 53
/app5/OP3TLos16Build/frameworks/support/car/src/androidTest/java/androidx: 21
/app5/OP3TLos16Build/frameworks/support/car/src/main/java/androidx: 36
/app5/OP3TLos16Build/frameworks/support/compat/src/androidTest/java/androidx: 66
/app5/OP3TLos16Build/frameworks/support/compat/src/main/java/androidx: 177
/app5/OP3TLos16Build/frameworks/support/emoji/core/src/androidTest/java/androidx: 32
/app5/OP3TLos16Build/frameworks/support/emoji/core/src/main/java/androidx: 24
/app5/OP3TLos16Build/frameworks/support/fragment/src/androidTest/java/androidx: 44
/app5/OP3TLos16Build/frameworks/support/leanback/src/androidTest/java/androidx: 87
/app5/OP3TLos16Build/frameworks/support/leanback/src/main/java/androidx: 217
/app5/OP3TLos16Build/frameworks/support/media/src/main/java/androidx: 43
/app5/OP3TLos16Build/frameworks/support/mediarouter/src/main/java/androidx: 30
/app5/OP3TLos16Build/frameworks/support/preference/src/main/java/androidx: 36
/app5/OP3TLos16Build/frameworks/support/recyclerview-selection/src/androidTest/java/androidx: 36
/app5/OP3TLos16Build/frameworks/support/recyclerview-selection/src/main/java/androidx: 33
/app5/OP3TLos16Build/frameworks/support/room/common/src/main/java/androidx: 22
/app5/OP3TLos16Build/frameworks/support/room/integration-tests/testapp/src/androidTest/java/androidx: 78
/app5/OP3TLos16Build/frameworks/support/slices/view/src/main/java/androidx: 24
/app5/OP3TLos16Build/frameworks/support/transition/src/androidTest/java/androidx: 28
/app5/OP3TLos16Build/frameworks/support/transition/src/main/java/androidx: 58
/app5/OP3TLos16Build/frameworks/support/v7/appcompat/src/androidTest/java/androidx: 89
/app5/OP3TLos16Build/frameworks/support/v7/appcompat/src/main/java/androidx: 130
/app5/OP3TLos16Build/frameworks/support/v7/recyclerview/src/androidTest/java/androidx: 84
/app5/OP3TLos16Build/frameworks/support/v7/recyclerview/src/main/java/androidx: 38
/app5/OP3TLos16Build/frameworks/support/wear/src/androidTest/java/androidx: 31
/app5/OP3TLos16Build/frameworks/support/wear/src/main/java/androidx: 42
/app5/OP3TLos16Build/frameworks/support/webkit/src/main/java/androidx: 29
/app5/OP3TLos16Build/frameworks/support/work/workmanager/src/androidTest/java/androidx: 45
/app5/OP3TLos16Build/frameworks/support/work/workmanager/src/main/java/androidx: 103
经过检验Los16.0/frameworks/*/androidx/*.java
大部分无重复(有一个重复)
bash
LosD=/app5/OP3TLos16Build/frameworks/
AnD=/app5/android-sdk-home/sources/android-28/androidx
#直接书写版(太慢了)
( cd $AnD && find . -type f -name "*.java" ;) | while read k ; do ( k2="androidx/${k/.\//}" && cd $LosD && c=$(find . -path "*$k2"|wc -l) && [[ $c -ge 2 ]] && echo "$k2:$c" ;); done
#(等效加速版)
LosDJLsF=/tmp/LosD-java.txt
( cd $LosD && find . -type f -name "*.java" -path "*/androidx/*" | tee $LosDJLsF 1>/dev/null ;)
( cd $AnD && find . -type f -name "*.java" ;) | while read k ; do ( k2="androidx/${k/.\//}" && c=$(grep -E "*$k2" $LosDJLsF|wc -l) && echo -n ",$c" && [[ $c -ge 2 ]] && echo -e "\n,$k2:$c,\n" ;); done
有一个重复androidx/work/impl/utils/taskexecutor/InstantTaskExecutorRule.java:2
执行软链接: ASOP9(api28)/sources/androidx/.java --> LineageOS16.0(android9,api18)/frameworks//androidx/*.java
bash
LosD=/app5/OP3TLos16Build/frameworks/
AnD=/app5/android-sdk-home/sources/android-28/androidx
#直接书写版(太慢了)
( cd $AnD && find . -type f -name "*.java" ;) | while read k ; do ( k2="androidx/${k/.\//}" && cd $LosD && fL=$(find . -path "*$k2") && echo -e "${fL}\n" && fLF=$LosD/$fL && fAF=$AnD/$k && rm -v $fAF && ln -s $fLF $fAF && ls -lh $fAF ;); done
#(等效加速版)
LosDJLsF=/tmp/LosD-java.txt
( cd $LosD && find . -type f -name "*.java" -path "*/androidx/*" | tee $LosDJLsF 1>/dev/null ;)
( cd $AnD && find . -type f -name "*.java" ;) | while read k ; do ( k2="androidx/${k/.\//}" && fL=$(grep -E "*$k2" $LosDJLsF) && echo "$fL" && fLF=$LosD/$fL && fAF=$AnD/$k && rm -v $fAF && ln -s $fLF $fAF && ls -lh $fAF ;); done
检查成果、有无伤害
无伤害 find $LosD -type l -name "*.java" | wc -l
== 0
成果大约正常 find $AnD -type l -name "*.java" | wc -l
==2441
android9 view绘制流程理解笔记
被调试的布局树 截图0