android 5.0 屏保唤醒源码分析,浅析android锁屏开机绘制流程(基于android4.0源码分析)...

本文从SystemServer的init2()方法开始,详细分析了Android系统开机时锁屏显示的流程,包括WindowManagerService、PhoneWindowManager、KeyguardViewMediator等关键类的调用关系。重点介绍了LockScreen和UnlockScreen的创建与显示,以及相关解锁方式的实现。最后强调了KeyguardViewMediator在锁屏机制中的核心作用。
摘要由CSDN通过智能技术生成

最近大体看了一下android源码锁屏模块,顺便把自己的收获在此记录下来,希望对研究锁屏的同行们有所帮助(对于锁屏模块,本人也没什么时间去真正的深究,只是摸清了个大概,若有奇异和错误之处,恳请指出)

好了,废话不多说了。

Android源码模块锁屏大体分为两种:

1.LockScreen: 系统默认的锁屏,就是我们所常见的系统原生波纹解锁(涉及MultiWaveView视图类)。如下图:

34977545_4.jpg

2.UnlockScreen: 进入手机的设置----->安全----->屏幕锁定。在列表中将看到的可选择项:图案,PIN,密码等锁屏都归为UnlockScreen。(可选择任意一项切换锁屏)

锁屏相关源码所在路径:

1.锁屏模块的框架源码所在路径为:frameworks\base\policy\src\com\android\internal\policy\impl(本文所涉及的代码都在这个目录里)

2.相关的锁屏自定义View类及与其关联类的源码所在路径为:frameworks\base\core\java\com\android\internal\widget

开机绘制锁屏流程代码分析:

手机开机时,在SystemServer类的init2()方法中会启动线程类ServerThread的run方法如下:

classServerThreadextendsThread

{

@Override

publicvoidrun()

{

WindowManagerService wm = null;

...

try

{

wm.systemReady();

} catch(Throwable e)

{

reportWtf("making Window Manager Service ready", e);

}

...

}

}

------>上述代码中的wm为WindowManagerService的引用,所以,wm.systemReady()为调用WindowManagerService的systemReady()方法,如下代码:

publicclassWindowManagerServiceextendsIWindowManager.StubimplementsWatchdog.Monitor, WindowManagerPolicy.WindowManagerFuncs

{

finalWindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();

...

publicvoidsystemReady() {

mPolicy.systemReady();

}

...

}

------>WindowManagerPolicy的实现类为PhoneWindowManager,所以,接着调用到PhoneWindowManager的systemReady,如下:

publicclassPhoneWindowManagerimplementsWindowManagerPolicy

{

KeyguardViewMediator mKeyguardMediator;

...

//手机开机后执行

publicvoidsystemReady() {

// tell the keyguard

mKeyguardMediator.onSystemReady(); //进行待机锁屏及解锁逻辑

android.os.SystemProperties.set("dev.bootcomplete","1");

synchronized(mLock) {

updateOrientationListenerLp();

mSystemReady = true;

mHandler.post(newRunnable() {

publicvoidrun() {

updateSettings();

}

});

}

}

...

}

------>接着,调用到KeyguardViewMediator类的onSystemReady()方法如下:

publicclassKeyguardViewMediatorimplementsKeyguardViewCallback,

KeyguardUpdateMonitor.InfoCallback, KeyguardUpdateMonitor.SimStateCallback

{

...

/**

* Let us know that the system is ready after startup.

*/

//开机显示锁屏入口

publicvoidonSystemReady() {

synchronized(this) {

if(DEBUG) Log.d(TAG,"onSystemReady");

mSystemReady = true;

doKeyguardLocked();

}

}

...

}

------>调用KeyguardViewMediator.doKeyguardLocked方法,在该方法中,先执行一些条件判断,若满足直接返回。若不直接返回,则紧接着调用KeyguardViewMediator. showLocked方法,代码如下:

...

/**

* Send message to keyguard telling it to show itself

* @see #handleShow()

*/

privatevoidshowLocked() {

if(DEBUG) Log.d(TAG,"showLocked");

// ensure we stay awake until we are finished displaying the keyguard

mShowKeyguardWakeLock.acquire(); //确保屏幕处于唤醒状态

Message msg = mHandler.obtainMessage(SHOW);

mHandler.sendMessage(msg);

}

...

----->通过handler发送消息SHOW到handleMessage处理,如下:

...

*

* This handler will be associated with the policy thread, which will also

* be the UI thread of the keyguard.  Since the apis of the policy, and therefore

* thisclass, can be called by other threads, any action that directly

* interacts with the keyguard ui should be posted to thishandler, rather

* than called directly.

*/

//Handler对象 , 异步处理

privateHandler mHandler =newHandler() {

@Override

publicvoidhandleMessage(Message msg) {//异步处理

switch(msg.what) {

caseTIMEOUT:

handleTimeout(msg.arg1);

return;

caseSHOW:

handleShow();

return;

caseHIDE:

handleHide();

return;

caseRESET:

handleReset();

return;

caseVERIFY_UNLOCK:

handleVerifyUnlock();

return;

caseNOTIFY_SCREEN_OFF:

handleNotifyScreenOff();

return;

caseNOTIFY_SCREEN_ON:

handleNotifyScreenOn((KeyguardViewManager.ShowListener)msg.obj);

return;

case

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值