Android4.4 锁屏流程梳理
刚毕业不久由于项目需要就接触到锁屏,从2.2到4.1都解过bug,也定制过一些功能。4.1之前的锁屏工作不难,但很费时间,因为它的逻辑,视图,资源分别分布在不同的路径下,就像散落在海边沙滩上的珠子,想串起来还是蛮费劲的。最开始时锁屏就是改个字段也要全编译生成img。后来新技能get,会针对修改的地方进行单编译,但每次编译jar,导入手机,重启看效果也是不方便的。
一年前把锁屏交出去就没有再看过了,前些日子自己的谷歌四太子升到4.4,发现锁屏有很大变化,可以左右滑页,添加删除widget,添加删除分页。简直就是一个简化版的launcher。很好奇google是怎么改变的,于是费了很大的劲拉了google的最新源码。在android 4.4中这个模块的改动简直是巨大,这里略作整理。
1.文件目录:
a,锁屏代理是在Frameworks/base/policy/src/com/android/internal/policy/impl/keyguard下:
b,整个工程应用在framework/package下,结构和功能现在都和 systemUI类似:
c,keyguard的对外接口Frameworks/base/core/java/android/app/keyguardManager.java:
android4.2前做一些第三方锁屏软件都会用到该服务接口来控制系统锁屏(比如禁止系统锁屏),现在该接口已经不建议使用了,有更好的做法:
/**
* @deprecated使用{@link android.view.WindowManager.LayoutParams#FLAG_DISMISS_KEYGUARD}
* and/or {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED}
* 来代替; 利用该方式可以使应用达到禁用锁屏的效果而不需要额外的权限申请。this allows you to
* Enables you to lock or unlock thekeyboard. Get an instance of this class by
* calling {@link android.content.Context#getSystemService(java.lang.String)Context.getSystemService()}.
* This class is wrapped by {@link android.app.KeyguardManagerKeyguardManager}.
* @param tag A tag that informallyidentifies who you are (for debugging who
* is disabling he keyguard).
*
* @return A {@link KeyguardLock} handle to use todisable and reenable the
* keyguard.
*/
@Deprecated
public KeyguardLock newKeyguardLock(Stringtag) {
return new KeyguardLock(tag);
}
Keyguard锁屏流程图
Keyguard锁屏view层次图:
Keyguard锁屏重要类分析:
1.PhoneWindowManager.java
这个类很厉害也很重要,它由WindowManagerService派生,处理了phone的顶层逻辑,主要有以下几块:
a) 横竖屏处理(屏幕旋转等)
publicvoidsetCurrentOrientationLw(intnewOrientation){
synchronized (mLock){
if (newOrientation != mCurrentAppOrientation) {
mCurrentAppOrientation = newOrientation;
updateOrientationListenerLp();
}
}
}
b) 是否显示状态条或者navigation_bar。
privateintupdateSystemUiVisibilityLw() {
// If there is no window focused,there will be nobody to handle the events
// anyway, so just hang on inwhatever state we're in until things settle down.
WindowState win = mFocusedWindow != null ? mFocusedWindow :mTop