在 8295 上多次启动车辆中心或地图等使用 SurfaceView 的应用,再退后台,SurfaceFlinger 中的相关 layer 无法回收。在 8155 无此问题。
多次执行如下命令。
adb shell am start-activity -n com.lixiang.car.carcenter/.MainActivity
adb shell input keyevent HOME
执行如下命令查看 layer 状态。
adb shell dumpsys SurfaceFlinger
Offscreen Layers 中可查看 SurfaceView layer 没有销毁。
Offscreen Layers:
Layer SurfaceView[com.lixiang.car.carcenter/com.lixiang.car.carcenter.MainActivity]#0 (ContainerLayer) callingPid:29810 callingUid:10019 ownerUid:10019
Layer Background for SurfaceView[com.lixiang.car.carcenter/com.lixiang.car.carcenter.MainActivity]#0 (EffectLayer) callingPid:29810 callingUid:10019 ownerUid:10019
Layer SurfaceView[com.lixiang.car.carcenter/com.lixiang.car.carcenter.MainActivity](BLAST)#0 (BufferStateLayer) callingPid:29810 callingUid:10019 ownerUid:10019
Layer SurfaceView[com.lixiang.car.carcenter/com.lixiang.car.carcenter.MainActivity](BLAST)#0 (BufferStateLayer) callingPid:29810 callingUid:10019 ownerUid:10019
Layer SurfaceView[com.lixiang.car.carcenter/com.lixiang.car.carcenter.MainActivity]#0 (ContainerLayer) callingPid:29810 callingUid:10019 ownerUid:10019
Layer SurfaceView[com.lixiang.car.carcenter/com.lixiang.car.carcenter.MainActivity]#0 (ContainerLayer) callingPid:29810 callingUid:10019 ownerUid:10019
Layer SurfaceView[com.lixiang.car.carcenter/com.lixiang.car.carcenter.MainActivity](BLAST)#0 (BufferStateLayer) callingPid:29810 callingUid:10019 ownerUid:10019
Layer SurfaceView[com.lixiang.car.carcenter/com.lixiang.car.carcenter.MainActivity]#0 (ContainerLayer) callingPid:29810 callingUid:10019 ownerUid:10019
Layer SurfaceView[com.lixiang.car.carcenter/com.lixiang.car.carcenter.MainActivity](BLAST)#0 (BufferStateLayer) callingPid:29810 callingUid:10019 ownerUid:10019
Layer Surface(name=dd5f07 InputMethod)/@0xa40465d - animation-leash of insets_animation#0 (EffectLayer) callingPid:1207 callingUid:1000 ownerUid:1000
我们使用 Demo 应用尝试复现问题,代码如下。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
addContentView(new SurfaceView(this), params);
}
执行一次如下命令后,查看 layer 状态。
adb shell am start-activity -n com.example.noactivity/.MainActivity
adb shell input keyevent HOME
adb shell dumpsys SurfaceFlinger