当前位置: 首页 > ai >正文

aosp15实现SurfaceFlinger的dump输出带上Layer详细信息踩坑笔记

背景:

针对上一篇文章
aosp15上SurfaceFlinger的dump部分新特性-无Layer信息输出如何解决?
给大家布置了一个小作业,那就是需要实现dumpsys SurfaceFlinger相关输出中可以携带上所有的Layer的详细信息需求,今天来带大家详细实现一下这个需求。

实战踩坑过程

本来想参考以前版本方式,直接使用mDrawingState.traverse的相关方法来进行遍历每一个Layer然后输出相关的信息。

std::string compositionLayers;mDrawingState.traverseInReverseZOrder([&](Layer* layer) {//输出相关的layer信息auto* compositionState = layer->getCompositionState();android::base::StringAppendF(&compositionLayers, "* Layer %p (%s)\n", layer,layer->getDebugName() ? layer->getDebugName(): "<unknown>");compositionState->dump(compositionLayers);});

但是明显发现这个mDrawingState.traverse方法压根就不会进入对应的循环,一行代码都不会执行,所以自然没有任何输出。

其实从SurfaceFlinger.cpp的相关代码也可以看出相关的痕迹,要调用 mDrawingState.traverse相关方法一般都会有一个判断值mLayerLifecycleManagerEnabled:

if (!mLayerLifecycleManagerEnabled) {StringAppendF(&result, "Composition layers\n");mDrawingState.traverseInZOrder([&](Layer* layer) {auto* compositionState = layer->getCompositionState();if (!compositionState || !compositionState->isVisible) return;android::base::StringAppendF(&result, "* Layer %p (%s)\n", layer,layer->getDebugName() ? layer->getDebugName(): "<unknown>");compositionState->dump(result);});StringAppendF(&result, "Offscreen Layers\n");for (Layer* offscreenLayer : mOffscreenLayers) {offscreenLayer->traverse(LayerVector::StateSet::Drawing,[&](Layer* layer) { layer->dumpOffscreenDebugInfo(result); });}}

但是在aosp15版本上这个mLayerLifecycleManagerEnabled值一直都是true,所以根本不会进入执行这块的mDrawingState.traverse,也就是说在aosp15版本的SurfaceFlinger已经弃用了这个mDrawingState.traverse。

正确实战实现

代码实现:
实现要采用2种方式
方式1–采用dumpsys SurfaceFlinger --带上参数,主要是可以单独dump layer数据
代码实现如下:
在这里插入图片描述这个dumpsysAllLayer的实现代码如下:
在这里插入图片描述

方式2采用setprop方式然后控制prop可以整体进行dump
在总的dump方法最后,加入如下代码
在这里插入图片描述这样就可以实现通过prop值控制是否在正常dumpsys SurfaceFlinger输出中带上所有Layer的信息。

使用方式:
方式1

adb shell dumpsys SurfaceFlinger --all-layer

adb shell dumpsys SurfaceFlinger  --all-layer
+ Layer (Display 0 name="Built-in Screen"#43) uid=1000Region TransparentRegion (this=0 count=0)Region VisibleRegion (this=0 count=0)Region SurfaceDamageRegion (this=0 count=0)layerStack=   0, z=        0, pos=(0,0), size=(   0,   0), crop=[  0,   0,  -1,  -1], cornerRadius=0.000000, isProtected=0, isTrustedOverlay=0, isOpaque=0, invalidate=0, dataspace=BT709 sRGB Full range, defaultPixelFormat=, backgroundBlurRadius=0, color=(-1.000,-1.000,-1.000,1.000), flags=0x00000002, tr=[0.00, 0.00][0.00, 0.00]parent=nonezOrderRelativeOf=noneactiveBuffer=[   0x   0:   0,Unknown/None], tr=[0.00, 0.00][0.00, 0.00] queued-frames=0 metadata={9:4bytes}, cornerRadiusCrop=[0.00, 0.00, 0.00, 0.00],  shadowRadius=0.000, 
+ Layer (WindowedMagnification:0:31#3) uid=1000Region TransparentRegion (this=0 count=0)Region VisibleRegion (this=0 count=0)Region SurfaceDamageRegion (this=0 count=0)layerStack=   0, z=        0, pos=(0,0), size=(   0,   0), crop=[  0,   0,   0,   0], cornerRadius=0.000000, isProtected=0, isTrustedOverlay=0, isOpaque=0, invalidate=0, dataspace=BT709 sRGB Full range, defaultPixelFormat=, backgroundBlurRadius=0, color=(-1.000,-1.000,-1.000,1.000), flags=0x00000000, tr=[0.00, 0.00][0.00, 0.00]parent=Display 0 name="Built-in Screen"#43zOrderRelativeOf=noneactiveBuffer=[   0x   0:   0,Unknown/None], tr=[0.00, 0.00][0.00, 0.00] queued-frames=0 metadata={9:4bytes}, cornerRadiusCrop=[0.00, 0.00, 0.00, 0.00],  shadowRadius=0.000, 
+ Layer (HideDisplayCutout:0:14#4) uid=1000Region TransparentRegion (this=0 count=0)Region VisibleRegion (this=0 count=0)Region SurfaceDamageRegion (this=0 count=0)layerStack=   0, z=        0, pos=(0,0), size=(   0,   0), crop=[  0,   0,  -1,  -1], cornerRadius=0.000000, isProtected=0, isTrustedOverlay=0, isOpaque=0, invalidate=0, dataspace=BT709 sRGB Full range, defaultPixelFormat=, backgroundBlurRadius=0, color=(-1.000,-1.000,-1.000,1.000), flags=0x00000000, tr=[0.00, 0.00][0.00, 0.00]parent=WindowedMagnification:0:31#3zOrderRelativeOf=noneactiveBuffer=[   0x   0:   0,Unknown/None], tr=[0.00, 0.00][0.00, 0.00] queued-frames=0 metadata={9:4bytes}, cornerRadiusCrop=[0.00, 0.00, 0.00, 0.00],  shadowRadius=0.000, 
+ Layer (OneHanded:0:14#5) uid=1000Region TransparentRegion (this=0 count=0)Region VisibleRegion (this=0 count=0)Region SurfaceDamageRegion (this=0 count=0)layerStack=   0, z=        0, pos=(0,0), size=(   0,   0), crop=[  0,   0,  -1,  -1], cornerRadius=0.000000, isProtected=0, isTrustedOverlay=0, isOpaque=0, invalidate=0, dataspace=BT709 sRGB Full range, defaultPixelFormat=, backgroundBlurRadius=0, color=(-1.000,-1.000,-1.000,1.000), flags=0x00000000, tr=[0.00, 0.00][0.00, 0.00]parent=HideDisplayCutout:0:14#4zOrderRelativeOf=noneactiveBuffer=[   0x   0:   0,Unknown/None], tr=[0.00, 0.00][0.00, 0.00] queued-frames=0 metadata={9:4bytes}, cornerRadiusCrop=[0.00, 0.00, 0.00, 0.00],  shadowRadius=0.000, 
+ Layer (FullscreenMagnification:0:12#6) uid=1000Region TransparentRegion (this=0 count=0)Region VisibleRegion (this=0 count=0)Region SurfaceDamageRegion (this=0 count=0)layerStack=   0, z=        0, pos=(0,0), size=(   0,   0), crop=[  0,   0,  -1,  -1], cornerRadius=0.000000, isProtected=0, isTrustedOverlay=0, isOpaque=0, invalidate=0, dataspace=BT709 sRGB Full range, defaultPixelFormat=, backgroundBlurRadius=0, color=(-1.000,-1.000,-1.000,1.000), flags=0x00000000, tr=[0.00, 0.00][0.00, 0.00]parent=OneHanded:0:14#5zOrderRelativeOf=noneactiveBuffer=[   0x   0:   0,Unknown/None], tr=[0.00, 0.00][0.00, 0.00] queued-frames=0 metadata={9:4bytes}, cornerRadiusCrop=[0.00, 0.00, 0.00, 0.00],  shadowRadius=0.000, 
+ Layer (Leaf:0:1#7) uid=1000Region TransparentRegion (this=0 count=0)Region VisibleRegion (this=0 count=0)Region SurfaceDamageRegion (this=0 count=0)layerStack=   0, z=        0, pos=(0,0), size=(   0,   0), crop=[  0,   0,  -1,  -1], cornerRadius=0.000000, isProtected=0, isTrustedOverlay=0, isOpaque=0, invalidate=0, dataspace=BT709 sRGB Full range, defaultPixelFormat=, backgroundBlurRadius=0, color=(-1.000,-1.000,-1.000,1.000), flags=0x00000000, tr=[0.00, 0.00][0.00, 0.00]parent=FullscreenMagnification:0:12#6zOrderRelativeOf=noneactiveBuffer=[   0x   0:   0,Unknown/None], tr=[0.00, 0.00][0.00, 0.00] queued-frames=0 metadata={9:4bytes}, cornerRadiusCrop=[0.00, 0.00, 0.00, 0.00],  shadowRadius=0.000, 
+ Layer (WallpaperWindowToken{970337b token=android.os.Binder@2e0df0a}#62) uid=1000Region TransparentRegion (this=0 count=0)Region VisibleRegion (this=0 count=0)Region SurfaceDamageRegion (this=0 count=0)layerStack=   0, z=        0, pos=(0,0), size=(   0,   0), crop=[  0,   0,  -1,  -1], cornerRadius=0.000000, isProtected=0, isTrustedOverlay=0, isOpaque=0, invalidate=0, dataspace=BT709 sRGB Full range, defaultPixelFormat=, backgroundBlurRadius=0, color=(-1.000,-1.000,-1.000,1.000), flags=0x00000000, tr=[0.00, 0.00][0.00, 0.00]parent=Leaf:0:1#7zOrderRelativeOf=noneactiveBuffer=[   0x   0:   0,Unknown/None], tr=[0.00, 0.00][0.00, 0.00] queued-frames=0 metadata={9:4bytes}, cornerRadiusCrop=[0.00, 0.00, 0.00, 0.00],  shadowRadius=0.000, 

方式2
先进行prop的设置,开启dump所有的layers

adb shell setprop debug.sf.dump_all_layers true

然后再执行dumpsys SurfaceFlinger

Window Infos:max send vsync id: -1max send delay (ns): 0 nsunsent messages: 0  #正常情况下的结束地方+ Layer (Display 0 name="Built-in Screen"#43) uid=1000Region TransparentRegion (this=0 count=0)Region VisibleRegion (this=0 count=0)Region SurfaceDamageRegion (this=0 count=0)layerStack=   0, z=        0, pos=(0,0), size=(   0,   0), crop=[  0,   0,  -1,  -1], cornerRadius=0.000000, isProtected=0, isTrustedOverlay=0, isOpaque=0, invalidate=0, dataspace=BT709 sRGB Full range, defaultPixelFormat=, backgroundBlurRadius=0, color=(-1.000,-1.000,-1.000,1.000), flags=0x00000002, tr=[0.00, 0.00][0.00, 0.00]parent=nonezOrderRelativeOf=noneactiveBuffer=[   0x   0:   0,Unknown/None], tr=[0.00, 0.00][0.00, 0.00] queued-frames=0 metadata={9:4bytes}, cornerRadiusCrop=[0.00, 0.00, 0.00, 0.00],  shadowRadius=0.000, 
+ Layer (WindowedMagnification:0:31#3) uid=1000Region TransparentRegion (this=0 count=0)Region VisibleRegion (this=0 count=0)Region SurfaceDamageRegion (this=0 count=0)layerStack=   0, z=        0, pos=(0,0), size=(   0,   0), crop=[  0,   0,   0,   0], cornerRadius=0.000000, isProtected=0, isTrustedOverlay=0, isOpaque=0, invalidate=0, dataspace=BT709 sRGB Full range, defaultPixelFormat=, backgroundBlurRadius=0, color=(-1.000,-1.000,-1.000,1.000), flags=0x00000000, tr=[0.00, 0.00][0.00, 0.00]parent=Display 0 name="Built-in Screen"#43zOrderRelativeOf=noneactiveBuffer=[   0x   0:   0,Unknown/None], tr=[0.00, 0.00][0.00, 0.00] queued-frames=0 metadata={9:4bytes}, cornerRadiusCrop=[0.00, 0.00, 0.00, 0.00],  shadowRadius=0.000, 
+ Layer (HideDisplayCutout:0:14#4) uid=1000Region TransparentRegion (this=0 count=0)Region VisibleRegion (this=0 count=0)Region SurfaceDamageRegion (this=0 count=0)layerStack=   0, z=        0, pos=(0,0), size=(   0,   0), crop=[  0,   0,  -1,  -1], cornerRadius=0.000000, isProtected=0, isTrustedOverlay=0, isOpaque=0, invalidate=0, dataspace=BT709 sRGB Full range, defaultPixelFormat=, backgroundBlurRadius=0, color=(-1.000,-1.000,-1.000,1.000), flags=0x00000000, tr=[0.00, 0.00][0.00, 0.00]parent=WindowedMagnification:0:31#3zOrderRelativeOf=noneactiveBuffer=[   0x   0:   0,Unknown/None], tr=[0.00, 0.00][0.00, 0.00] queued-frames=0 metadata={9:4bytes}, cornerRadiusCrop=[0.00, 0.00, 0.00, 0.00],  shadowRadius=0.000, 
+ Layer (OneHanded:0:14#5) uid=1000Region TransparentRegion (this=0 count=0)Region VisibleRegion (this=0 count=0)Region SurfaceDamageRegion (this=0 count=0)layerStack=   0, z=        0, pos=(0,0), size=(   0,   0), crop=[  0,   0,  -1,  -1], cornerRadius=0.000000, isProtected=0, isTrustedOverlay=0, isOpaque=0, invalidate=0, dataspace=BT709 sRGB Full range, defaultPixelFormat=, backgroundBlurRadius=0, color=(-1.000,-1.000,-1.000,1.000), flags=0x00000000, tr=[0.00, 0.00][0.00, 0.00]parent=HideDisplayCutout:0:14#4zOrderRelativeOf=noneactiveBuffer=[   0x   0:   0,Unknown/None], tr=[0.00, 0.00][0.00, 0.00] queued-frames=0 metadata={9:4bytes}, cornerRadiusCrop=[0.00, 0.00, 0.00, 0.00],  shadowRadius=0.000, 
+ Layer (FullscreenMagnification:0:12#6) uid=1000Region TransparentRegion (this=0 count=0)Region VisibleRegion (this=0 count=0)Region SurfaceDamageRegion (this=0 count=0)layerStack=   0, z=        0, pos=(0,0), size=(   0,   0), crop=[  0,   0,  -1,  -1], cornerRadius=0.000000, isProtected=0, isTrustedOverlay=0, isOpaque=0, invalidate=0, dataspace=BT709 sRGB Full range, defaultPixelFormat=, backgroundBlurRadius=0, color=(-1.000,-1.000,-1.000,1.000), flags=0x00000000, tr=[0.00, 0.00][0.00, 0.00]parent=OneHanded:0:14#5zOrderRelativeOf=noneactiveBuffer=[   0x   0:   0,Unknown/None], tr=[0.00, 0.00][0.00, 0.00] queued-frames=0 metadata={9:4bytes}, cornerRadiusCrop=[0.00, 0.00, 0.00, 0.00],  shadowRadius=0.000, 
+ Layer (Leaf:0:1#7) uid=1000Region TransparentRegion (this=0 count=0)Region VisibleRegion (this=0 count=0)Region SurfaceDamageRegion (this=0 count=0)layerStack=   0, z=        0, pos=(0,0), size=(   0,   0), crop=[  0,   0,  -1,  -1], cornerRadius=0.000000, isProtected=0, isTrustedOverlay=0, isOpaque=0, invalidate=0, dataspace=BT709 sRGB Full range, defaultPixelFormat=, backgroundBlurRadius=0, color=(-1.000,-1.000,-1.000,1.000), flags=0x00000000, tr=[0.00, 0.00][0.00, 0.00]parent=FullscreenMagnification:0:12#6zOrderRelativeOf=noneactiveBuffer=[   0x   0:   0,Unknown/None], tr=[0.00, 0.00][0.00, 0.00] queued-frames=0 metadata={9:4bytes}, cornerRadiusCrop=[0.00, 0.00, 0.00, 0.00],  shadowRadius=0.000, 
+ Layer (WallpaperWindowToken{970337b token=android.os.Binder@2e0df0a}#62) uid=1000Region TransparentRegion (this=0 count=0)Region VisibleRegion (this=0 count=0)Region SurfaceDamageRegion (this=0 count=0)layerStack=   0, z=        0, pos=(0,0), size=(   0,   0), crop=[  0,   0,  -1,  -1], cornerRadius=0.000000, isProtected=0, isTrustedOverlay=0, isOpaque=0, invalidate=0, dataspace=BT709 sRGB Full range, defaultPixelFormat=, backgroundBlurRadius=0, color=(-1.000,-1.000,-1.000,1.000), flags=0x00000000, tr=[0.00, 0.00][0.00, 0.00]parent=Leaf:0:1#7zOrderRelativeOf=noneactiveBuffer=[   0x   0:   0,Unknown/None], tr=[0.00, 0.00][0.00, 0.00] queued-frames=0 metadata={9:4bytes}, cornerRadiusCrop=[0.00, 0.00, 0.00, 0.00],  shadowRadius=0.000, 

默认情况下debug.sf.dump_all_layers是false,所以不会dump
在这里插入图片描述
更多framework实战干货,请关注下面“千里马学框架”

http://www.xdnf.cn/news/15765.html

相关文章:

  • EP01:【Python 第一弹】基础入门知识
  • Vue rem回顾
  • 文档表格标题跑到表格下方,或标题跟表格空隔太大如何处理
  • Java无服务架构新范式:Spring Native与AWS Lambda冷启动深度优化
  • Flutter基础(前端教程①⑤-API请求转化为模型列成列表展示实战)
  • 财务数字化——解读财务指标及财务分析的基本步骤与方法【附全文阅读】
  • Error:HTTP Status 405 - HTTP method POST is not supported by this URL
  • 大数据之路:阿里巴巴大数据实践——日志采集与数据同步
  • 短视频矩阵的未来前景:机遇无限,挑战并存
  • [spring6: Advice Advisor Advised]-快速理解
  • stm32继电器使用方法
  • 【HarmonyOS】Ability Kit - Stage模型
  • 2023 年 5 月青少年软编等考 C 语言八级真题解析
  • 安装tomcat启动startup.bat出现闪退问题
  • 驾驭 Spring Boot 事件机制:8 个内置事件 + 自定义扩展实战
  • windows wsl ubuntu 如何安装 maven
  • 前端知识回顾-登录界面
  • 实现el-select下拉框,下拉时加载数据
  • 【RK3576】【Android14】摄像头MIPI开发调试
  • [Python] -实用技巧10- 时间处理:datetime 和 time 模块入门
  • 【数据结构初阶】--双向链表(二)
  • 跨境卖家紧急自查,Endryko Karmadi四季版画版权维权
  • 【嵌入式电机控制#16】电流环(三):过采样提高采集精度看门狗监测总线电压
  • 【Linux系统】进程控制
  • 从0开始学习R语言--Day51--PH检验
  • OpenCV 官翻 1 -介绍、安装、功能概览、核心操作
  • 云计算与 DevOps(开发与运维)
  • sqli-labs靶场通关笔记:第32-33关 宽字节注入
  • Java 中的继承与多态
  • 基于GEE与哨兵2号的土地覆盖分类方法及实现