Camera与SIM卡

步骤:
进入Camera应用-->
切换至Video模式-->
开启闪光灯-->
按power键锁屏-->
再按一次power键,发现此时LED为亮的状态(解锁之前)

经过测试,发现插入SIM卡和不插入SIM卡,phone表现出不同的行为:
  • 插入SIM卡:重复上述步骤,LED灯会亮(不正常行为)
  • 无SIM卡:重复上述步骤,LED灯不亮(正常行为)
经过log分析,插入SIM卡,在再次按power键,解锁之前,发现在这期间,启动了VideoCamera的doOnResume()方法;而无SIM卡情况下,不会执行doOnResume()方法。

我睁大我的双眼,没错,你没有看错,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我无能为力了!

到目前为止还没有测试出异常情况,如果您对这块比较熟悉,请不吝指教。

 

 


 

 

 

 

转载于:https://my.oschina.net/jerikc/blog/82388

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值