图形系统:简简单单学习WindowManagerService的启动流程_windowmanagerservice 启动 开始

深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!


img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上鸿蒙开发知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化的资料的朋友,可以戳这里获取

2、SystemServer.run

如下所见,SystemServer先加载android_servers动态库,创建SystemServiceManager对象,将服务划分为三种类型的服务引导服务、核心服务、其他服务。

private void run() {

// 初始化本地服务
System.loadLibrary(“android_servers”);

//创建系统服务管理
mSystemServiceManager = new SystemServiceManager(mSystemContext);

//启动三种类型的服务
try {
startBootstrapServices(t);
startCoreServices(t);
startOtherServices(t);
} catch (Throwable ex) {

} finally {

}
}

3、SystemServer.startOtherServices

startOtherServices函数会创建非常多的服务,这里重点关注WMS的创建,先创建了InputManagerService,再调用WindowManagerService的main函数。


inputManager = new InputManagerService(context);

wm = WindowManagerService.main(context, inputManager, !mFirstBoot, mOnlyCore,
new PhoneWindowManager(), mActivityManagerService.mActivityTaskManager);

ServiceManager.addService(Context.WINDOW_SERVICE, wm, /* allowIsolated= */ false,
DUMP_FLAG_PRIORITY_CRITICAL | DUMP_FLAG_PROTO);
ServiceManager.addService(Context.INPUT_SERVICE, inputManager,

//初始化PhoneWindowManager和添加WatchDog监听
wm.onInitReady();

wm.displayReady();

wm.systemReady();

4、WindowManagerService.main

public static WindowManagerService main(final Context context, final InputManagerService im,
final boolean showBootMsgs, final boolean onlyCore, WindowManagerPolicy policy,
ActivityTaskManagerService atm, Supplier<SurfaceControl.Transaction> transactionFactory,
Supplier surfaceFactory,
Function<SurfaceSession, SurfaceControl.Builder> surfaceControlFactory) {
DisplayThread.getHandler().runWithScissors(() ->
sInstance = new WindowManagerService(context, im, showBootMsgs, onlyCore, policy,
atm, transactionFactory, surfaceFactory, surfaceControlFactory), 0);
return sInstance;
}

DisplayThread继承自ServiceThread类,ServiceThread又继承自HandlerThread类。是一个前台系统共享的单例线程,主要服务于WindowManager、DisplayManager、InputManager快速实时执行显示相关的操作。

5、Handler.runWithScissors

public final boolean runWithScissors(@NonNull Runnable r, long timeout) {
if (r == null) {
throw new IllegalArgumentException(“runnable must not be null”);
}
if (timeout < 0) {
throw new IllegalArgumentException(“timeout must be non-negative”);
}

if (Looper.myLooper() == mLooper) {
r.run();
return true;
}

BlockingRunnable br = new BlockingRunnable®;
return br.postAndWait(this, timeout);
}

当前代码是运行在SystemServer的主线程,runWithScissors函数使得Runable对象的run函数切换到DisplayThread代码执行。创建了BlockingRunnable类型的对象r,并调用其他postAndWait函数。此时参数timeout是0,this是自身Handler对象。

6、BlockingRunnable.postAndWait

//BlockingRunnable的postAndWait函数
public boolean postAndWait(Handler handler, long timeout) {
if (!handler.post(this)) {//1
return false;
}

synchronized (this) {
if (timeout > 0) {
while (!mDone) {

try {
wait(delay);
} catch (InterruptedException ex) {
}
}
} else {
while (!mDone) { //2
try {
wait(); //3
} catch (InterruptedException ex) {
}
}

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

sdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)**

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值