为什么80%的码农都做不了架构师?>>>
进入Camera应用-->
切换至Video模式-->
开启闪光灯-->
按power键锁屏-->
再按一次power键,发现此时LED为亮的状态(解锁之前)
经过测试,发现插入SIM卡和不插入SIM卡,phone表现出不同的行为:
- 插入SIM卡:重复上述步骤,LED灯会亮(不正常行为)
- 无SIM卡:重复上述步骤,LED灯不亮(正常行为)
我睁大我的双眼,没错,你没有看错,Camera的行为居然和SIM卡扯上了关系。
我没有多想,便去分析framework层的锁屏相关的代码和电源管理相关的代码(这使得我后面泪流满面),越陷越深。
偶然的机会,我查看来以下VideoCamera中doOnResume()方法的super implementation,于是来到了ActivityBase类。此时想利用log分析一下运行的流程:
复制代码
1adb shell logcat | grep ActivityBase
运行之后,noting. 什么都没留下,太神奇了吧??没有走这里的代码,不可能吧!!最终发现,
复制代码
1
2
3
4
5
6
7
8
private static final String TAG = "ActivityBase"; private static boolean LOGV = false; ... if (LOGV) { ... Log.v(TAG,...); ... }
google 默认地将log关掉了,难怪我找不到你呀!亲....
分析这个类才知道,原来Camera真的和SIM卡有一腿,通过isKeyguardLocked()..
在ActivityBase的onResume()方法中有:
复制代码
1
2
3
4
5
6
if (mCameraDevice == null && isKeyguardLocked()) { mOnResumePending = true; } else { doOnResume(); mOnResumePending = false; }
isKeyguardLocked()实现如下:
复制代码
1
2
3
... return (kgm != null) && kgm.isKeyguardLocked() && kgm.isKeyguardSecure(); ...
isKeyguardSecure()原型:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
/* *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
复制代码
1
//isKeyguardSecure excludes the slide lock case
oh ,my god!!
好吧,我更改了isKeyguardLocked()的return,经过各种测试,发现行为正常。
我测试了three-third-party Camera应用,发现有的也存在这种行为,sorry我无能为力了!
到目前为止还没有测试出异常情况,如果您对这块比较熟悉,请不吝指教。
转载于:https://my.oschina.net/jerikc/blog/82388
最后
以上就是优秀睫毛最近收集整理的关于Camera与SIM卡的全部内容,更多相关Camera与SIM卡内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复