android锁屏分析

工作原因,android的锁屏这个模块前前后后修改过多次。在AndroidL版本之前锁屏流程可参照网上的这篇博客,就不做过多解释了:http://blog.csdn.net/wdaming1986/article/details/7753206

略作补充,重要类分析。
1、PhoneWindowManager.java 该类控制的逻辑主要有:
1.1 横竖屏处理(屏幕旋转等)
@Override
public void setRotationLw(int rotation) {
mOrientationListener.setCurrentRotation(rotation);
}
1.2拦截Home键处理事件
//短按事件
private void handleShortPressOnHome() {
// If there’s a dream running then use home to escape the dream
// but don’t actually go home.
if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
mDreamManagerInternal.stopDream(false /immediate/);
return;
}
// Go home!
launchHomeFromHotKey();
}
//长按事件
private void handleLongPressOnHome() {
//…..

1.3是否显示状态条或者navigation_bar
private int updateSystemUiVisibilityLw() {
//…
}
1.4 锁屏事件处理和响应
@Override
public void systemReady() {
mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
mKeyguardDelegate.onSystemReady();
readCameraLensCoverState();
updateUiMode();
synchronized (mLock) {
updateOrientationListenerLp();
mSystemReady = true;
mHandler.post(new Runnable() {
@Override
public void run() {
updateSettings();
}
});
}
/// M:SmartBook @{
if (SystemProperties.get(“ro.mtk_smartbook_support”).equals(“1”)) {
if (mHDMI == null)
mHDMI = IMtkHdmiManager.Stub.asInterface(ServiceManager
.getService(Context.HDMI_SERVICE));
}
/// @}
}
2.KeyguardServiceDelegate.java和KeyguardServiceWrapper.java
这两个类是android 4.4新增加的,分别对KeyguardService进行了代理和包装,代理类里面有一个Scrim视图在keyguard崩溃时显示。包装类就是对keyguardService的简单包装,最终把调度都会传给keyguardServic
3.keyguardService.java
keyguard的入口,实例化了一个IKeyguardService.Stub供其他类bindservice时调用,并实例化了一个非常重要的类KeyguardViewMediator
4.KeyguardViewMediator.java
字面上的意思是keyguard视图调度者,功能上是负责处理keyguard视图的事件,比如完成锁屏和解锁这些动作的视图响应,它作为一个位高权重的调度使当然不会亲手去做这些,其中有个重要的内部对象KeyguardviewManager,所有的大小任务都会放权给它。(androidL版本中更名为StatusBarKeyguardviewManager.java)
4.1、mExternallyEnabled:用来管理是否开启锁屏,默认是开启的。根据定义可以知道希望应用程序修改这个值。
/**
* External apps (like the phone app) can tell us to disable the keygaurd.
*/
private boolean mExternallyEnabled = true;
修改此变量的函数:
/**
* Same semantics as {@link android.view.WindowManagerPolicy#enableKeyguard}; provide
* a way for external stuff to override normal keyguard behavior. For instance
* the phone app disables the keyguard when it receives incoming calls.
*/
public void setKeyguardEnabled(boolean enabled) {
synchronized (this) {
if (DEBUG) {
Log.d(TAG, “setKeyguardEnabled(” + enabled + “),” +
“called by pid = ” + Binder.getCallingPid());
}

        mExternallyEnabled = enabled;

        if (!enabled && mShowing) {
            if (mExitSecureCallback != null) {
                if (DEBUG) Log.d(TAG, "in process of verifyUnlock request, ignoring");
                // we're in the process of handling a request to verify the user
                // can get past the keyguard. ignore extraneous requests to disable / reenable
                return;
            }

            /// M: [ALPS01611497] to avoid 3rd party to disable keyguard when alarm view showing
            if (PowerOffAlarmManager.isAlarmBoot()) {
                if (DEBUG) {
                    Log.d(TAG, "disable Keyguard when alarm boot, ignoring");
                }
                return;
            }

            // hiding keyguard that is showing, remember to reshow later
            if (DEBUG) Log.d(TAG, "remembering to reshow, hiding keyguard, "
                    + "disabling status bar expansion");
            mNeedToReshowWhenReenabled = true;
            updateInputRestrictedLocked();
            hideLocked();
        } else if (enabled && mNeedToReshowWhenReenabled) {
            // reenabled after previously hidden, reshow
            if (DEBUG) {
                Log.d(TAG, "previously hidden, reshowing, reenabling "
                    + "status bar expansion");
            }
            mNeedToReshowWhenReenabled = false;
            updateInputRestrictedLocked();

            if (mExitSecureCallback != null) {
                if (DEBUG) {
                    Log.d(TAG, "onKeyguardExitResult(false), resetting");
                }
                try {
                    mExitSecureCallback.onKeyguardExitResult(false);
                } catch (RemoteException e) {
                    Slog.w(TAG, "Failed to call onKeyguardExitResult(false)", e);
                }
                mExitSecureCallback = null;
                resetStateLocked();
            } else {
                showLocked(null);

                // block until we know the keygaurd is done drawing (and post a message
                // to unblock us after a timeout so we don't risk blocking too long
                // and causing an ANR).
                mWaitingUntilKeyguardVisible = true;
                mHandler.sendEmptyMessageDelayed(KEYGUARD_DONE_DRAWING, KEYGUARD_DONE_DRAWING_TIMEOUT_MS);
                if (DEBUG) Log.d(TAG, "waiting until mWaitingUntilKeyguardVisible is false");
                while (mWaitingUntilKeyguardVisible) {
                    try {
                        wait();
                    } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                    }
                }
                if (DEBUG) Log.d(TAG, "done waiting for mWaitingUntilKeyguardVisible");
            }
        }
    }
}
由此得出结论,如果想取消系统锁可以有两种方法
a、mExternallyEnabled默认为false
b、应用程序中调用setKeyguardEnabled,将其赋值为false

5.KeyguardViewManager.java(androidL版本中为StatusBarKeyguardViewManager.java)
如果说mediator相当于总裁,那这个就是经理,而且是视图部门老大,它有一个类型为FrameLayout名叫ViewManagerHost的内部类,用来作为keyguard的viewroot。在viewroot里添加了KeyguardHostView,我们叫它mKeyguardView。Keyguard里任何的view细节和问题都能通过它找到蛛丝马迹。
6.KeyguardHostView.java
这里完成keyguardView布局,实例化。分析一个自定义的viewgroup,重点需要分析的是它的构造方法和onFinishInflate()方法:
7.KeyguardUpdateMonitor.java
说明:监听系统状态值的改变如时间、SIM卡状态、电池电量等,状态值的改变会回调监听了该状态信息的对象实例。如果只是关注功能的话只需要看hadle里面的每个消息调用的方法即可。
后面会将5.1的锁屏流程稍作分析

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值