进入Camera应用-->
切换至Video模式-->
开启闪光灯-->
按power键锁屏-->
再按一次power键,发现此时LED为亮的状态(解锁之前)
经过测试,发现插入SIM卡和不插入SIM卡,phone表现出不同的行为:
- 插入SIM卡:重复上述步骤,LED灯会亮(不正常行为)
- 无SIM卡:重复上述步骤,LED灯不亮(正常行为)
我睁大我的双眼,没错,你没有看错,Camera的行为居然和SIM卡扯上了关系。
我没有多想,便去分析framework层的锁屏相关的代码和电源管理相关的代码(这使得我后面泪流满面),越陷越深。
偶然的机会,我查看来以下VideoCamera中doOnResume()方法的super implementation,于是来到了ActivityBase类。此时想利用log分析一下运行的流程:
adb shell logcat | grep ActivityBase
运行之后,noting. 什么都没留下,太神奇了吧??没有走这里的代码,不可能吧!!最终发现,
private static final String TAG = "ActivityBase";
private static boolean LOGV = false;
...
if (LOGV) {
...
Log.v(TAG,...);
...
}
google 默认地将log关掉了,难怪我找不到你呀!亲....
分析这个类才知道,原来Camera真的和SIM卡有一腿,通过isKeyguardLocked()..
在ActivityBase的onResume()方法中有:
if (mCameraDevice == null && isKeyguardLocked()) {
mOnResumePending = true;
} else {
doOnResume();
mOnResumePending = false;
}
isKeyguardLocked()实现如下:
...
return (kgm != null) && kgm.isKeyguardLocked() && kgm.isKeyguardSecure();
...
isKeyguardSecure()原型:
/*
*Return whether the keyguard requires a password to unlock.
*@return true if in keyguard is secure
*/
public boolean isKeyguardSecure(){
try{
return mWM.isKeyguardSecure();
} catch(RemoteException ex) {
return false;
}
}
经过log分析:
- 插入SIM卡:kgm.isKeyguardSecure() 为 true
- 无SIM卡:kgm.isKeyguardSecure() 为 false
//isKeyguardSecure excludes the slide lock case
oh ,my god!!
好吧,我更改了isKeyguardLocked()的return,经过各种测试,发现行为正常。
我测试了three-third-party Camera应用,发现有的也存在这种行为,sorry我无能为力了!
到目前为止还没有测试出异常情况,如果您对这块比较熟悉,请不吝指教。