Android R: 记一次修复AOSP的Desktop(桌面模式)或者External Display(扩展投屏)点击最大化按钮,跳出其他应用App问题
原因分析:
抓取点击设置App的最大化按钮,窗口慢慢放大时的当时的log
log_click_Minimize_when_app_to_zoom_in__dumpsys_SurfaceFlinger.txt
此时发现设置App的层级已经跑到了桌面App和其他App的下面,壁纸的上面,
所以,就导致了该问题。
此时,发现设置App层级有两个:
一个是设置App layer层级,另一个是设置App的snapshot anim层级
"snapshot anim"层级动画是,点击最大化按钮时创建用于app最大化时的动画
然后,在frameworks/base/services/core/java/com/android/server/wm/SurfaceFreezer.java创建的:
最后,反复调试得出如下patch:
在这里插入代码片
void freeze(SurfaceControl.Transaction t, Rect startBounds) {
mFreezeBounds.set(startBounds);
mLeash = SurfaceAnimator.createAnimationLeash(mAnimatable, mAnimatable.getSurfaceControl(),
t, ANIMATION_TYPE_SCREEN_ROTATION, startBounds.width(), startBounds.height(),
startBounds.left, startBounds.top, false /* hidden */,
mWmService.mTransactionFactory);
mAnimatable.onAnimationLeashCreated(t, mLeash);
SurfaceControl freezeTarget = mAnimatable.getFreezeSnapshotTarget();
if (freezeTarget != null) {
GraphicBuffer snapshot = createSnapshotBuffer(freezeTarget, startBounds);
if (snapshot != null) {
mSnapshot = new Snapshot(mWmService.mSurfaceFactory, t, snapshot, mLeash);
}
}
}
->
Snapshot(Supplier<Surface> surfaceFactory, SurfaceControl.Transaction t,
GraphicBuffer thumbnailHeader, SurfaceControl parent) {
mSurfaceControl = mAnimatable.makeAnimationLeash()
.setName("snapshot anim: " + mAnimatable.toString())
.setBufferSize(width, height)
.setFormat(PixelFormat.TRANSLUCENT)
.setParent(parent)
.setCallsite("SurfaceFreezer.Snapshot")
.build();
// Transfer the thumbnail to the surface
drawSurface.copyFrom(mSurfaceControl);
drawSurface.attachAndQueueBuffer(thumbnailHeader);
drawSurface.release();
t.show(mSurfaceControl);
// We parent the thumbnail to the container, and just place it on top of anything else
// in the container.
t.setLayer(mSurfaceControl, Integer.MAX_VALUE);
// parent就是mLeash
// 在参考文档中找到Leash是什么?(SurfaceAnimator中有定义)
// 翻译:这个类可以针对那种存在多个child surface的对象进行动画,
// 在执行动画的过程中会创建一个没有Buffer的Surface—“Leash”,
// 将所有child surface绑定到leash上,leash同时也会绑定到原先这些child surface绑定的位置。
// 然后我们将leash给到AnimationAdapter去执行动画,
// 执行动画结束后会将所有child surface重新绑定到原先的父节点上
+ t.setLayer(parent, Integer.MAX_VALUE);
}
同时,还发现在Desktop同时,有两个app都最大化时,点击另一个app的最小化按钮时,后面的app会有动画切换的闪动问题。修改方法时在AppTransition.java中的loadAnimation(),打印transit的值时8,即TRANSIT_TASK_OPEN,修改TRANSIT_TASK_OPEN动画为没有动画解决该问题。
参考文档:
http://itpcb.com/a/94241
Android P——LockFreeAnimation
调试方法:
在开发者选项中:
把“窗口动画缩放”改成最大10x
把“过渡动画缩放”改成最大10x
把“Animator时长缩放”改成最大10x
dumpsys window w | grep “Window #”
或者
dumpsys window visible | grep “Window #”
或者
am stack list 观察点击最大化按钮,App的层级没有变,在其他app的上面。
但是: dumpsys SurfaceFlinger 观察到的是: 点击最大按键的App的层级却位于其他应用之下。
同时,打开设置App和便签App,让设置App在便签App上面
然后:抓取dumpsys SurfaceFlinger log 观察应用层级:
1,抓取点击设置App的最大化按钮之前的log
log_before_click_Minimize_dumpsys_SurfaceFlinger.txt
Display 19260733058351745 HWC layers:
-----------------------------------------------------------------------------------------------------------------------------------------------
Layer name
Z | Window Type | Layer Class | Comp Type | Transform | Disp Frame (LTRB) | Source Crop (LTRB) | Frame Rate (Explicit) [Focused]
-----------------------------------------------------------------------------------------------------------------------------------------------
com.android.systemui.ImageWallpaper#1
rel 0 | 2013 | 0 | DEVICE | 0 | 0 0 2560 1600 | 0.0 0.0 2560.0 1600.0 | [ ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
com.xxx.desktoplauncher/com.xxx.desktoplauncher.workmode.WorkLauncher#0
rel 0 | 1 | 0 | DEVICE | 0 | 0 0 2560 1600 | 0.0 0.0 2560.0 1600.0 | [ ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Task=15#0
rel 4 | 0 | 0 | CLIENT | 0 | 386 257 1786 1289 | 0.0 0.0 0.0 0.0 | [ ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
com.xxx.notes/com.xxx.notes.MainActivity#1
rel 0 | 1 | 0 | DEVICE | 0 | 386 257 1786 1289 | 0.0 0.0 1400.0 1032.0 | [ ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Task=14#0
rel 5 | 0 | 0 | CLIENT | 0 | 838 316 2238 1348 | 0.0 0.0 0.0 0.0 | [ ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
com.android.settings/com.android.settings.Settings#0
rel 0 | 1 | 0 | DEVICE | 0 | 838 316 2238 1348 | 0.0 0.0 1400.0 1032.0 | [*]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NavigationBar2#0
rel 0 | 2019 | 0 | DEVICE | 0 | 0 1504 2560 1600 | 0.0 0.0 2560.0 96.0 | [ ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ScreenRecordStatusbarFloatingPanel#0
rel 0 | 98736 | 0 | DEVICE | 0 | 2321 1203 2484 1292 | 0.0 0.0 163.0 89.0 | [ ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PointerLocation - display 2#0
rel 0 | 2015 | 0 | DEVICE | 0 | 0 0 2560 1600 | 0.0 0.0 2560.0 1600.0 | [ ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2,抓取点击设置App的最大化按钮,窗口慢慢放大时的当时的log
log_click_Minimize_when_app_to_zoom_in__dumpsys_SurfaceFlinger.txt
此时发现设置App的层级已经跑到了桌面App和其他App的下面,壁纸的上面,
所以,就导致了该问题。
Display 19260733058351745 HWC layers:
-----------------------------------------------------------------------------------------------------------------------------------------------
Layer name
Z | Window Type | Layer Class | Comp Type | Transform | Disp Frame (LTRB) | Source Crop (LTRB) | Frame Rate (Explicit) [Focused]
-----------------------------------------------------------------------------------------------------------------------------------------------
com.android.systemui.ImageWallpaper#1
rel 0 | 2013 | 0 | DEVICE | 0 | 0 0 2560 1600 | 0.0 0.0 2560.0 1600.0 | [ ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
com.android.settings/com.android.settings.Settings#0
rel 0 | 1 | 0 | DEVICE | 0 | 658 248 2307 1402 | 0.0 0.0 2034.0 1355.0 | [*]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
snapshot anim: Task{3c30fa3 #14 visi[...]roid.settings U=0 StackId=14 sz=1}#0
rel 2147483647 | 0 | 0 | DEVICE | 0 | 658 248 2307 1402 | 0.0 0.0 1389.0 1018.0 | [ ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
com.xxx.desktoplauncher/com.xxx.desktoplauncher.workmode.WorkLauncher#0
rel 0 | 1 | 0 | DEVICE | 0 | 0 0 2560 1600 | 0.0 0.0 2560.0 1600.0 | [ ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
com.xxx.notes/com.xxx.notes.MainActivity#1
rel 0 | 1 | 0 | DEVICE | 0 | 386 257 1786 1289 | 0.0 0.0 1400.0 1032.0 | [ ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NavigationBar2#0
rel 0 | 2019 | 0 | DEVICE | 0 | 0 1504 2560 1600 | 0.0 0.0 2560.0 96.0 | [ ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
xxxScreenRecordStatusbarFloatingPanel#0
rel 0 | 98736 | 0 | DEVICE | 0 | 2321 1203 2484 1292 | 0.0 0.0 163.0 89.0 | [ ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PointerLocation - display 2#0
rel 0 | 2015 | 0 | DEVICE | 0 | 0 0 2560 1600 | 0.0 0.0 2560.0 1600.0 | [ ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3,抓取点击设置App的最大化按钮,窗口已经最大后的log
log_click_Minimize_after_app_to_zoom_in_dumpsys_SurfaceFlinger.txt
Display 19260733058351745 HWC layers:
-----------------------------------------------------------------------------------------------------------------------------------------------
Layer name
Z | Window Type | Layer Class | Comp Type | Transform | Disp Frame (LTRB) | Source Crop (LTRB) | Frame Rate (Explicit) [Focused]
-----------------------------------------------------------------------------------------------------------------------------------------------
com.android.settings/com.android.settings.Settings#0
rel 0 | 1 | 0 | DEVICE | 0 | 0 0 2560 1600 | 0.0 0.0 2560.0 1600.0 | [*]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NavigationBar2#0
rel 0 | 2019 | 0 | DEVICE | 0 | 0 1504 2560 1600 | 0.0 0.0 2560.0 96.0 | [ ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ScreenRecordStatusbarFloatingPanel#0
rel 0 | 98736 | 0 | DEVICE | 0 | 2321 1203 2484 1292 | 0.0 0.0 163.0 89.0 | [ ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PointerLocation - display 2#0
rel 0 | 2015 | 0 | DEVICE | 0 | 0 0 2560 1600 | 0.0 0.0 2560.0 1600.0 | [ ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
在这里插入代码片