CaptureLayer的另外一个调用例子TaskSnapshot

2023-05-16

在前一篇讨论中,我们查找了系统中调用captureLayers的地方
1323 public static GraphicBuffer captureLayers(IBinder layerHandleToken, Rect sourceCrop,

找到了2个调用的地方
/frameworks/base/services/core/java/com/android/server/wm/
H A D TaskSnapshotController.java 268 final GraphicBuffer buffer = SurfaceControl.captureLayers(
H A D WallpaperController.java 719 GraphicBuffer wallpaperBuffer = SurfaceControl.captureLayers(

上一篇里查看了WallpaperController.java的例子,这里我们再看看TaskSnapshotController里的例子

private TaskSnapshot snapshotTask(Task task) {
223 final AppWindowToken top = task.getTopChild();
224 if (top == null) {
225 return null;
226 }
227 final WindowState mainWindow = top.findMainWindow();
228 if (mainWindow == null) {
229 return null;
230 }
231 if (!mService.mPolicy.isScreenOn()) {
232 if (DEBUG_SCREENSHOT) {
233 Slog.i(TAG_WM, “Attempted to take screenshot while display was off.”);
234 }
235 return null;
236 }
237 if (task.getSurfaceControl() == null) {
238 return null;
239 }
240
241 if (top.hasCommittedReparentToAnimationLeash()) {
242 if (DEBUG_SCREENSHOT) {
243 Slog.w(TAG_WM, "Failed to take screenshot. App is animating " + top);
244 }
245 return null;
246 }
247
248 final boolean hasVisibleChild = top.forAllWindows(
249 // Ensure at least one window for the top app is visible before attempting to take
250 // a screenshot. Visible here means that the WSA surface is shown and has an alpha
251 // greater than 0.
252 ws -> (ws.mAppToken == null || ws.mAppToken.isSurfaceShowing())
253 && ws.mWinAnimator != null && ws.mWinAnimator.getShown()
254 && ws.mWinAnimator.mLastAlpha > 0f, true);
255
256 if (!hasVisibleChild) {
257 if (DEBUG_SCREENSHOT) {
258 Slog.w(TAG_WM, "Failed to take screenshot. No visible windows for " + task);
259 }
260 return null;
261 }
262
263 final boolean isLowRamDevice = ActivityManager.isLowRamDeviceStatic();
264 final float scaleFraction = isLowRamDevice ? REDUCED_SCALE : 1f;
265 task.getBounds(mTmpRect);
266 mTmpRect.offsetTo(0, 0);
267
268 final GraphicBuffer buffer = SurfaceControl.captureLayers(
269 task.getSurfaceControl().getHandle(), mTmpRect, scaleFraction);
270 final boolean isWindowTranslucent = mainWindow.getAttrs().format != PixelFormat.OPAQUE;
271 if (buffer == null || buffer.getWidth() <= 1 || buffer.getHeight() <= 1) {
272 if (DEBUG_SCREENSHOT) {
273 Slog.w(TAG_WM, "Failed to take screenshot for " + task);
274 }
275 return null;
276 }
277 return new TaskSnapshot(buffer, top.getConfiguration().orientation,
278 getInsets(mainWindow), isLowRamDevice /* reduced /, scaleFraction / scale /,
279 true /
isRealSnapshot */, task.getWindowingMode(), getSystemUiVisibility(task),
280 !top.fillsParent() || isWindowTranslucent);
281 }

TaskSnapshotController中也通过获取layer的方式获取了graphicBuffer,这样按recent按键的时候就可以看到每个应用的快照截图,
并且保存了图像信息到手机data/system_ce/0/snapshots中,这样,手机重启后,点击recent任务按键,还可以看到关机前的任务快照截图
我们可以编辑data/system_ce/0/snapshots里面的图片,涂鸦一下,再重启手机,会发现截图变化了。

快照可以设置安全级别来进行不同的显示处理。

iPhone 中是采用了模糊处理,如下图
在這裡插入圖片描述

参考资料

《ActivityManagerService解读之Activity启动闲聊–以TaskSnapshot为点切入AndroidView绘制原理分析》
https://blog.csdn.net/abm1993/article/details/88818361?utm_source=app&app_version=4.5.2

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CaptureLayer的另外一个调用例子TaskSnapshot 的相关文章

  • CSS3 动画效果总结

    CSS3添加了几个动画效果的属性 xff0c 通过设置这些属性 xff0c 可以做出一些简单的动画效果而不需要再去借助JavaScript CSS3动画的属性主要分为三类 xff1a transform transition以及animat
  • Javassist学习总结

    要想将编译时不存在的类在运行时动态创建并加载 xff0c 通常有两种策略 xff1a 1 动态编译 2 动态生成二进制字节码 xff08 class xff09 对于第二种策略 xff0c 实际上已经有诸多比较成熟的开源项目提供支持 xff
  • viewstub学习笔记

    当需要在运行时动态改变布局的情况下 xff0c 使用viewstub来进行动态的布局架构是逻辑简单控制灵活的 xff0c 并且相比于设置view gone来说viewstub更加的轻量化 xff0c 只有当调用了viewstub infla
  • 程序员的酸甜苦辣——告别Coding

    程序员的酸甜苦辣 告别Coding lt script language 61 34 javascript 34 type 61 34 text javascript 34 gt document title 61 34 程序员的酸甜苦辣
  • 基于参考注释的RNA-seq分析

    Step 1 构建参考序列索引 xff1a mkdirbti 在 stuXX 目录下新建文件夹 cd bti ln s database peixun2015 ref ath fa 在当前目录 xff0c 建立参考序列文件的超链接 bowt
  • maddpg 复现过程中遇到的问题

    最近在复现论文Multi Agent Actor Critic for Mixed Cooperative Competitive Environments https github com openai multiagent partic
  • "error while loading shared libraries: xxx.so.x" 错误的原因和解决办法

    一般我们在Linux下执行某些外部程序的时候可能会提示找不到共享库的错误 比如 tmux error while loading shared libraries libevent 1 4 so 2 cannot open shared o
  • SUN VirtualBox 的命令行启动/关闭方法简介

    我们可以使用VBxManager 命令行管理工具来查看当前的虚拟基设置 和状态 QHo 64 qhoferrari1k VBoxManage list vms 下面通过实例来说明如何从命令行启动和关闭VirtualBox 虚拟机的两种常用方
  • 运维日记011 - Ubuntu下更改初始用户名的方法

    运维日记011 Ubuntu下更改初始用户名的方法 引子 Ubuntu每两年一次发布的LTS版本都会倍加引人关注 xff0c 因为LTS版本有长达五年的支持周期 xff0c 对于我等不是太喜欢折腾尝鲜而是希望几年之内不用重装系统的用户颇有吸
  • SWIG学习记录(一)SWIG基础

    SWIG学习记录 1 什么是SWIG 1 2 特性1 2 1 预处理 2 SWIG安装3 SWIG基础介绍3 1 运行SWIG3 1 1 输入格式3 1 2 输出3 1 3 注释3 1 4 预编译3 1 5 SWIG指令3 1 6 解析器的
  • Cpp--重载全局的new和delete

    include lt iostream gt include lt process h gt include lt string h gt include lt stdio h gt define MAX SIZE 30000 char M
  • 国外知名音频库一站式资料和简介

    Speex Speex http blog csdn net xyz lmn article details 8013490 简介 Speex是一套主要针对语音的开源免费 xff0c 无专利保护的音频压缩格式 Speex工程着力于通过提供一
  • 一张图进阶 RocketMQ - 整体架构

    前 言 三此君看了好几本书 xff0c 看了很多遍源码整理的 一张图进阶 RocketMQ 图片链接 xff0c 关于 RocketMQ 你只需要记住这张图 xff01 如果你第一次看到这个系列 xff0c 墙裂建议你打开链接 觉得不错的话
  • LUbuntu装向日葵后不能自动登录,lightdm改回sddm

    最近换了LUbuntu xff0c 很喜欢它简洁快速的风格 装了向日葵远控 xff0c 然后就不能登录桌面了 台式机上 xff0c 还可以手动登录 xff0c 笔记本手动也不行 xff0c 得开一个终端输入startx 研究了下 xff0c
  • 牛人 就是这样锤炼出来的,中兴资深工程师,嵌入式专家韦东山是这样炼成的!

    导读 xff1a 还在大学的你 xff0c 不知道未来何去何从 xff1f 都说迷茫是大事做不了 xff0c 小事不想做 还在做程序袁的你 xff0c 是不是也想创业 xff1f 程序袁好创业吗 xff1f Linux好学吗 xff1f 学
  • ethtool---查看网卡以及修改网卡配置工具

    ethtool 命令详解 命令描述 xff1a ethtool 是用于查询及设置网卡参数的命令 使用概要 xff1a ethtool ethx 查询ethx网口基本设置 xff0c 其中 x 是对应网卡的编号 xff0c 如eth0 eth
  • 开源网络模拟器ns-3 架构与实践

  • KBQA相关知识

    码下来 xff0c 慢慢看 xff0c 谢谢各位的分享 1 小象学院 xff1a 王昊奋 2 总结 xff1a https cloud tencent com developer article 1088066 3 KBQA入门 xff1a
  • Android system.img 编辑、增删APK与修改系统配置

    1 环境配置 Debian或Ubuntu系统 xff0c 配置Android开发工具 apt get update apt get install android tools adb android tools fastboot andro
  • SpringMVC接收json字符串转为List对象(数组对象)

    本来项目中的springmvc已配置好的 xff0c 没有问题 xff0c 但是今天突然有个需求 xff0c 需要写一个接口接收json字符串自动转换为List对象 xff0c 查了一下用 64 RequestBody就可以 xff0c 但

随机推荐