背景:
上一篇文章有分享一个学员作业恢复出厂设置后第一次开机时候fallbackhome有出现黑屏闪黑问题,具体复现点击下面文章
针对这样一类问题,应该如何修改呢?下面来看看第一种修改方案
修改方案设计
核心思路:既然是因为开机动画退出后,fallbackhome显示期间有黑屏,正常launcher显示时候没有黑屏,那么就考虑把开机动画的退出时间延长,延长到正常桌面显示以后才退出。
正常流程图
因为正常bootanimation图层肯定比Fallbackhome高,所以完全可以遮盖住Fallbackhome
黑屏时候Fallbackhome属于有黑情况
设计的修改成如下
代码实现:
修改代码主要涉及两个部分:
注意代码基于aosp14
1、让正常system_server的performEnableScreen流程不进行SystemProperties.set(“service.bootanim.exit”, “1”)
frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java
(注意这里只针对设备没有锁屏的场景,有锁屏等考虑其他方案,不可以直接屏蔽)
private void performEnableScreen() {
//省略部分
//屏蔽掉这一块由performEnableScreen触发设置动画结束属性
/* if (!mBootAnimationStopped) {
Trace.asyncTraceBegin(TRACE_TAG_WINDOW_MANAGER, "Stop bootanim", 0);
// stop boot animation
// formerly we would just kill the process, but we now ask it to exit so it
// can choose where to stop the animation.
SystemProperties.set("service.bootanim.exit", "1");
mBootAnimationStopped = true;
}
if (!mForceDisplayEnabled && !checkBootAnimationCompleteLocked()) {
ProtoLog.i(WM_DEBUG_BOOT, "performEnableScreen: Waiting for anim complete");
return;
}
if (!SurfaceControl.bootFinished()) {
ProtoLog.w(WM_ERROR, "performEnableScreen: bootFinished() failed.");
return;
}*/
EventLogTags.writeWmBootAnimationDone(SystemClock.uptimeMillis());
Trace.asyncTraceEnd(TRACE_TAG_WINDOW_MANAGER, "Stop bootanim", 0);
mDisplayEnabled = true;
ProtoLog.i(WM_DEBUG_SCREEN_ON, "******************** ENABLING SCREEN!");
// Enable input dispatch.
mInputManagerCallback.setEventDispatchingLw(mEventDispatchingEnabled);
}
//省略部分
}
2、上面屏蔽了正常开机动画结束流程,但是开机动画具体哪里进行合适的结束呢?
答案就是:在Launcher显示以后要触发正常开机动画结束的属性设置
具体代码如下
/** Called when the windows associated app window container are drawn. */
private void onWindowsDrawn() {
//省略
//add for delay boot animation gone
if (isHomeIntent(intent) && shortComponentName != null && !shortComponentName.contains("FallbackHome")) {
android.os.SystemProperties.set("service.bootanim.exit", "1");
if (!SurfaceControl.bootFinished()) {
Log.w("WM_ERROR", "performEnableScreen: bootFinished() failed.");
return;
}
}
}
一般每个Activity显示后会回调onWindowsDrawn方法,所以可以在这里进行检测是不是launcher已经绘制了,如果绘制了既可以启动调用相关的开机动画结束的属性设置。
相关完整实战视频链接:
https://www.bilibili.com/video/BV1BDqwYTE1t/
更多framework实战干货,请关注下面“千里马学框架”