1. 背景
智能座舱多屏项目,中控屏切换语言,后排屏闪黑屏问题
2. 详细分析过程
- 通过events log查看activity的生命周期:adb shell logcat -b events
com.android.rwhvac.view.behind.BehindActivity2 : displayId = 2 副屏app
com.android.carsettings.CarSettingActivity: displayId = 0 主屏app
从下面的log可以看出来,在主屏切换语言的时候,主,副屏的app都会relaunch,生命周期重走。
11-07 21:58:07.174 1435 3824 I wm_relaunch_resume_activity: [0,57528784,61,com.android.carsettings/.CarSettingActivity]
11-07 21:58:07.176 1435 3824 I wm_relaunch_resume_activity: [0,188588203,60,com.android.rwhvac/.view.behind.BehindActivity2]
11-07 21:58:07.178 5833 5833 I wm_on_top_resumed_lost_called: [188588203,com.android.rwhvac.view.behind.BehindActivity2,pausing]
11-07 21:58:07.180 5833 5833 I wm_on_paused_called: [188588203,com.android.rwhvac.view.behind.BehindActivity2,performPause]
11-07 21:58:07.187 5833 5833 I wm_on_stop_called: [188588203,com.android.rwhvac.view.behind.BehindActivity2,handleRelaunchActivity]
11-07 21:58:07.240 3154 3154 I wm_on_paused_called: [57528784,com.android.carsettings.CarSettingActivity,performPause]
11-07 21:58:07.241 5833 5833 I wm_on_destroy_called: [188588203,com.android.rwhvac.view.behind.BehindActivity2,performDestroy]
11-07 21:58:07.244 3154 3154 I wm_on_stop_called: [57528784,com.android.carsettings.CarSettingActivity,handleRelaunchActivity]
11-07 21:58:07.280 3154 3154 I wm_on_destroy_called: [57528784,com.android.carsettings.CarSettingActivity,performDestroy]
11-07 21:58:07.284 5833 5833 I wm_on_create_called: [188588203,com.android.rwhvac.view.behind.BehindActivity2,performCreate]
11-07 21:58:07.299 1435 1752 I wm_wallpaper_surface: [0,0,null]
11-07 21:58:07.387 5833 5833 I wm_on_start_called: [188588203,com.android.rwhvac.view.behind.BehindActivity2,handleStartActivity]
11-07 21:58:07.393 5833 5833 I wm_on_resume_called: [188588203,com.android.rwhvac.view.behind.BehindActivity2,RESUME_ACTIVITY]
11-07 21:58:07.400 5833 5833 I wm_on_top_resumed_gained_called: [188588203,com.android.rwhvac.view.behind.BehindActivity2,topWhenResuming]
11-07 21:58:07.400 3154 3154 I wm_on_create_called: [57528784,com.android.carsettings.CarSettingActivity,performCreate]
11-07 21:58:07.448 3154 3154 I wm_on_start_called: [57528784,com.android.carsettings.CarSettingActivity,handleStartActivity]
11-07 21:58:07.537 3154 3154 I wm_on_resume_called: [57528784,com.android.carsettings.CarSettingActivity,RESUME_ACTIVITY]
11-07 21:58:07.606 1435 1561 I wm_wallpaper_surface: [0,1,Window{3092928 u0 com.android.carsettings/com.android.carsettings.CarSettingActivity}]
2.通过堆栈信息可以知,切换语言----configchange----startFreezingScreen,通过log可知,当用户点击前排屏的时候,freezing的是前排屏,后排屏不会冻结,那么出现后排屏闪黑屏,一般是app relaunch 耗时导致的,需要app优化relaunch性能。
11-07 20:05:09.362 1534 4373 W xxx-frozen: startFreezingScreenLocked, app = ProcessRecord{3a565cd 5847:com.android.rwhvac.behindscreen/1000}, this = ActivityRecord{9059fb8 u0 com.android.rwhvac/.view.behind.BehindActivity2} t40}
11-07 20:05:09.362 1534 4373 W xxx-frozen: startFreezingScreen, overrideOriginalDisplayRotation = -1
11-07 20:05:09.366 1534 4373 W xxx-frozen: Set freezing of token = :Token{850ff64 ActivityRecord{9059fb8 u0 com.android.rwhvac/.view.behind.BehindActivity2} t40}} visible= true freezing= false visibleRequested= true, mDisplayContent = Display{#2 state=ON size=1024x274 ROTATION_0}, callstack =
11-07 20:05:09.366 1534 4373 W xxx-frozen: java.lang.Throwable: xxx
11-07 20:05:09.366 1534 4373 W xxx-frozen: at com.android.server.wm.ActivityRecord.startFreezingScreen(ActivityRecord.java:6532)
11-07 20:05:09.366 1534 4373 W xxx-frozen: at com.android.server.wm.ActivityRecord.startFreezingScreen(ActivityRecord.java:6519)
11-07 20:05:09.366 1534 4373 W xxx-frozen: at com.android.server.wm.ActivityRecord.startFreezingScreenLocked(ActivityRecord.java:6514)
11-07 20:05:09.366 1534 4373 W xxx-frozen: at com.android.server.wm.ActivityRecord.startFreezingScreenLocked(ActivityRecord.java:6493)
11-07 20:05:09.366 1534 4373 W xxx-frozen: at com.android.server.wm.ActivityRecord.ensureActivityConfiguration(ActivityRecord.java:9441)
11-07 20:05:09.366 1534 4373 W xxx-frozen: at com.android.server.wm.ActivityRecord.ensureActivityConfiguration(ActivityRecord.java:9297)
11-07 20:05:09.366 1534 4373 W xxx-frozen: at com.android.server.wm.ActivityTaskManagerService.ensureConfigAndVisibilityAfterUpdate(ActivityTaskManagerService.java:5099)
11-07 20:05:09.366 1534 4373 W xxx-frozen: at com.android.server.wm.ActivityTaskManagerService.updateConfigurationLocked(ActivityTaskManagerService.java:4385)
11-07 20:05:09.366 1534 4373 W xxx-frozen: at com.android.server.wm.ActivityTaskManagerService.updateConfigurationLocked(ActivityTaskManagerService.java:4358)
11-07 20:05:09.366 1534 4373 W xxx-frozen: at com.android.server.wm.ActivityTaskManagerService.updatePersistentConfiguration(ActivityTaskManagerService.java:4348)
11-07 20:05:09.366 1534 4373 W xxx-frozen: at com.android.server.am.ActivityManagerService.updatePersistentConfigurationWithAttribution(ActivityManagerService.java:15506)
11-07 20:05:09.366 1534 4373 W xxx-frozen: at com.android.server.am.ActivityManagerService.updatePersistentConfiguration(ActivityManagerService.java:15490)
11-07 20:05:09.366 1534 4373 W xxx-frozen: at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:3573)
11-07 20:05:09.366 1534 4373 W xxx-frozen: at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2678)
11-07 20:05:09.366 1534 4373 W xxx-frozen: at android.os.Binder.execTransactInternal(Binder.java:1280)
11-07 20:05:09.366 1534 4373 W xxx-frozen: at android.os.Binder.execTransact(Binder.java:1244)
当用户点击前排屏的时候,freezing的是前排屏。代码逻辑如下:
11-07 22:44:41.645 1453 1580 W xxx200: positionChildAt, this = com.android.server.wm.RootWindowContainer@b840de1 positionChildAt: container=Display 0 name="内置屏幕" is not a child of container=ROOT current parent=com.android.server.wm.RootWindowContainer@b840de1 position = 2147483647, callstack =
11-07 22:44:41.645 1453 1580 W xxx200: java.lang.Throwable: xxx
11-07 22:44:41.645 1453 1580 W xxx200: at com.android.server.wm.WindowContainer.positionChildAt(WindowContainer.java:931)
11-07 22:44:41.645 1453 1580 W xxx200: at com.android.server.wm.WindowState.handleTapOutsideFocusInsideSelf(WindowState.java:6296)
11-07 22:44:41.645 1453 1580 W xxx200: at com.android.server.wm.WindowManagerService.onPointerDownOutsideFocusLocked(WindowManagerService.java:8928)
11-07 22:44:41.645 1453 1580 W xxx200: at com.android.server.wm.WindowManagerService.-$$Nest$monPointerDownOutsideFocusLocked(Unknown Source:0)
11-07 22:44:41.645 1453 1580 W xxx200: at com.android.server.wm.WindowManagerService$H.handleMessage(WindowManagerService.java:5936)
11-07 22:44:41.645 1453 1580 W xxx200: at android.os.Handler.dispatchMessage(Handler.java:106)
11-07 22:44:41.645 1453 1580 W xxx200: at android.os.Looper.loopOnce(Looper.java:201)
11-07 22:44:41.645 1453 1580 W xxx200: at android.os.Looper.loop(Looper.java:288)
11-07 22:44:41.645 1453 1580 W xxx200: at android.os.HandlerThread.run(HandlerThread.java:67)
11-07 22:44:41.645 1453 1580 W xxx200: at com.android.server.ServiceThread.run(ServiceThread.java:44)