aosp安卓15新特性dump的wms窗口层级树优化的更加美观
背景:
近来在体验调试aosp15时候,使用了dumpsys activity containers时候,发现wms层级结构树有一个巨大的变化。
很多学员朋友对这个优化改进都给出巨大的点赞,有的学员朋友还想老版本自己实现一下这种树绘制:
对比安卓14老版本情况
明显可以看出以前的wms层级结构树看着不像一颗树,靠的序号和空格在区分,但是层级一多,而且相差不多时候,如果只相差一层空格就不明显了,经常可能需要对半天才对的清楚。
aosp15和老版本的源码分析对比:
aosp15代码
/**
* Dumps the names of this container children in the input print writer indenting each
* level with the input prefix.
*/
public void dumpChildrenNames(PrintWriter pw, String prefix, boolean isLastChild) {
int curWinMode = getWindowingMode();
String winMode = windowingModeToString(curWinMode);
if (curWinMode != WINDOWING_MODE_UNDEFINED &&
curWinMode != WINDOWING_MODE_FULLSCREEN) {
winMode = winMode.toUpperCase();
}
int requestedWinMode = getRequestedOverrideWindowingMode();
String overrideWinMode = windowingModeToString(requestedWinMode);
if (requestedWinMode != WINDOWING_MODE_UNDEFINED &&
requestedWinMode != WINDOWING_MODE_FULLSCREEN) {
overrideWinMode = overrideWinMode.toUpperCase();
}
String actType = activityTypeToString(getActivityType());
if (getActivityType() != ACTIVITY_TYPE_UNDEFINED
&& getActivityType() != ACTIVITY_TYPE_STANDARD) {
actType = actType.toUpperCase();
}
pw.print(prefix + (isLastChild ? "└─ " : "├─ "));//isLastChild属于新参数,绘制树枝的看看是不是最后一个child
pw.println(getName()
+ " type=" + actType
+ " mode=" + winMode
+ " override-mode=" + overrideWinMode
+ " requested-bounds=" + getRequestedOverrideBounds().toShortString()
+ " bounds=" + getBounds().toShortString());
String childPrefix = prefix + (isLastChild ? " " : "│ ");//注意这个是给子节点的标签,要么是空格要么是竖线
for (int i = getChildCount() - 1; i >= 0; --i) {
final E cc = getChildAt(i);
cc.dumpChildrenNames(pw, childPrefix, i == 0 /* isLastChild */);
}
}
aosp14代码
/**
* Dumps the names of this container children in the input print writer indenting each
* level with the input prefix.
*/
public void dumpChildrenNames(PrintWriter pw, String prefix) {
final String childPrefix = prefix + " ";//这里有给每一层增加空格
pw.println(getName()
+ " type=" + activityTypeToString(getActivityType())
+ " mode=" + windowingModeToString(getWindowingMode())
+ " override-mode=" + windowingModeToString(getRequestedOverrideWindowingMode())
+ " requested-bounds=" + getRequestedOverrideBounds().toShortString()
+ " bounds=" + getBounds().toShortString());
for (int i = getChildCount() - 1; i >= 0; --i) {
final E cc = getChildAt(i);
pw.print(childPrefix + "#" + i + " ");//这里主要表示child的索引
cc.dumpChildrenNames(pw, childPrefix);
}
}
更多framework实战干货内容资料,请关注下面“千里马学框架”