Android待机锁屏流程分析


...
启动SystemServer之前在这里省略


SystemServer.java
1. main() //系统服务的入口函数
2. main会调用init1()本地方法
This method is called from Zygote to initialize the system. This will cause the native services (SurfaceFlinger, AudioFlinger, etc..) to be started. After that it will call back up into init2() to start the Android services.
3. init1()回调init2()
4. init2()调用(new ServerThread()).start()
5. 将执行ServerThread - run()方法
6. run()调用wm.systemReady();(WindowManagerService wm)

WindowManagerService.java
7. WindowManagerService.systemReady调用mPolicy.systemReady() //mPolicy = PolicyManager.makeNewWindowManager();


PolicyManager.java
8. 根据PolicyManager.makeNewWindowManager()
POLICY_IMPL_CLASS_NAME = "com.android.internal.policy.impl.Policy";
Class policyClass = Class.forName(POLICY_IMPL_CLASS_NAME);
            sPolicy = (IPolicy)policyClass.newInstance();

Policy.java
9. public PhoneWindowManager makeNewWindowManager() {
        return new PhoneWindowManager();
    }

PhoneWindowManager.java
10. 可知调用的是PhoneWindowManager中的systemReady()
11. 调用mKeyguardMediator.onSystemReady();


KeyguardViewMediator - 是整个待机解/锁屏业务的调度器,负责调度锁屏界面的相关动作及查询解锁屏状态
12. onSystemReady()
13. 调用doKeyguard();
14. showLocked();这句就把设备屏幕给锁住了
15. handleMessage() - handleShow() //把这句注释掉就不会锁屏了

附加:
关于锁屏的注意:
其他应用程序或者服务也可以请求禁止锁屏(通过调用KeyguardViewMediator的setKeyguardEnabled(boolean)方法)。例如接听来电界面。 

你可能感兴趣的:(Android待机锁屏流程分析)