当前位置: 代码迷 >> Android >> Android 解锁屏起步过程
  详细解决方案

Android 解锁屏起步过程

热度:63   发布时间:2016-05-01 18:08:04.0
Android 解锁屏启动过程
Android 解锁屏启动过程 
一. 开机启动 
在开机过程中无线模块初始化时获取SIM卡,状态。在初始化完成后调用vm.systemReady()函数通知进入相应的Lock Screen进行解锁。 

1. 在hardware/ril/reference-ril/reference-ril.c中: 
通过 setRadioState (RADIO_STATE_SIM_NOT_READY) 来触发对无线模块的初始化。 
通过 static void onRadioPowerOn() 对无线模块初始化。 
首先通过pollSIMState(Null):轮询sim卡状态。 
由getSIMStatus()函数获取sim卡状态。 

2. 当系统初始化完成后 会调用wm.systemReady()函数,触发解锁界面。 
VM:WindowManagerService wm = null; 
由于WM为空,调用WindowManagerService中函数: 
public void systemReady () { 
mPolicy.systemReady(); 

mPolicy: final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager(); 

(以下文件在frameworks/policies/base/phone/com/android/internal/policy/impl中) 
3. PolicyManager.makeNewWindowManager(),调用文件 PolicyManagerer.java中函数: 
public static WindowManagerPolicy makeNewWindowManager() { 
  return sPolicy.makeNewWindowManager(); 


4. sPolicy.makeNewWindowManager 调用的是文件 Policy.java中函数: 
public PhoneWindowManager makeNewWindowManager() { 
return new PhoneWindowManagerwv 


5. PhoneWindowManager 继承自 WindowManagerPolicy 
  mPolicy.systemReady() 最终调用的是文件 PhoneWindowManager.java 中的函数: 
  public void systemReady(); 
  mKeyguardMediator.onSystemReady(); 
  doKeyguard(); 
  showLocked(); 
Message msg = mHandler.obtainMessage(Show); 
mHandler.sendMessage(msg); 
发送SHOW消息。 

6. public void handleMessage(Message msg) 对 SHOW 消息进行了处理。 
  如果 msg.what 等于 SHOW 那么执行: 
  handleShow(); 
  private void handleShow() 
  ... 
mCallback.onKeyguardShow(); 
mKeyguardViewManag.show() 
7. mKeyguardViewManager.show() 调用的是文件 KeyguardViewManager.java 中的函数: 
public synchronized void show() 
  ... 
mKeyguardView = mKeyguardViewProperties.createKeyguardView( mContext, mUpdateMonitor, this); 
 ... 

8. mKeyguardViewProperties.createKeyguardView 
调用的是文件 LockPatternKeyguardViewProperties.java中的函数: 
 public KeyguardViewBase createKeyguardView(Context context, 
  KeyguardUpdateMonitor updateMonitor, 
  KeyguardWindowController controller) { 
  return new LockPatternKeyguardView(context, updateMonitor, 
mLockPatternUtils, controller); 


9.  new LockPatternKeyguardView 调用了类 LockPatternKeyguardView 的构造函数: 
  public LockPatternKeyguardView( 
  Context context, 
  KeyguardUpdateMonitor updateMonitor, 
  LockPatternUtils lockPatternUtils, 
  KeyguardWindowController controller) 
  ... 
  mLockScreen = createLockScreen(); 
  addView(mLockScreen); 
  final UnlockMode unlockMode = getUnlockMode(); 
  mUnlockScreen = createUnlockScreenFor(unlockMode); 
mUnlockScreenMode =unlockMode; 
addView(mUnlockScreen); 
updateScreen(mMode); 

其中getUnlockMode 获得锁类型,通常有三种: 
  enum UnlockMode { 
  Pattern, 
  SinPIN, 
Account 

createUnlockScreenFor(unlockMode)根据相应的unlockMode而调用对应的解锁屏。 

二. 按红键启动 
点击结束通话键(红键),根据action: 
TelephonyManager.ACTION_PHONE_STATE_CHANGE和TelephonyManager.EXTRA_STATE_IDLE 
调用frameworks/policies/base/phone/com/android/internal/policy/impl/ 
KeyguardViewMediator.java中函数: 
doKeyguard(); 
private void showLocked() { 
        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); 

发送SHOW消息。 
之后转到“开机启动”的第六步。 
三. 其它方式 
1. SIM卡状态改变,当sim卡状态为ABSENT 
// only force lock screen in case of missing sim if user hasn't gone through setup wizard 
当sim卡状态为 PUK_REQUIRED :即输入PIN失败。(调用PUK解锁屏) 

2. 设置的自动锁屏时间out 
都是通过KeyguardViewMediator.java启动。 
  相关解决方案