R.layout.keyguard_host_view的创建流程以及KeyguardTransportControlView
注意:这些代码运行在什么环境下? SystemServer进程所属的Thread
-->SystemServer.java
public void run() {
Slog.i(TAG, "Window Manager");
wm = WindowManagerService.main(context, power, display, inputManager,
uiHandler, wmHandler,
factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL,
!firstBoot, onlyCore);
}
在SystemServer初始化时,会为WindowManagerService专门创建一个独立的HandlerThread。
调WindowManagerService.main()时,转而在这个HandlerThread中创建WindowManagerService 本身
另外,SystemServer有专门创建一个内部UI显示用的uiHandlerThread,用于WindowManagerPolicy,
KeyguardViewManager,DisplayManagerService
-->WindowManagerService.java
WindowManagerService(){
initPolicy(uiHandler);
}
注意是mPolicy.init()方法, mPolicy 是谁?是PhoneWindowManager !
final WindowManagerPolicy mPolicy = PolicyManager.makeNewWindowManager();
private void initPolicy(Handler uiHandler) {
uiHandler.runWithScissors(new Runnable() {
@Override
public void run() {
WindowManagerPolicyThread.set(Thread.currentThread(), Looper.myLooper());
mPolicy.init(mContext, WindowManagerService.this, WindowManagerService.this);
mAnimator.mAboveUniverseLayer = mPolicy.getAboveUniverseLayer()
* TYPE_LAYER_MULTIPLIER
+ TYPE_LAYER_OFFSET;
}
}, 0);
}
注意:这里mPolicy.init()已经在uiHandler里做了,所以后面涉及的inflate等UI操作都是安全的
-->PolicyManager.java
public static WindowManagerPolicy makeNewWindowManager() {
return sPolicy.makeNewWindowManager();
}
sPolicy就是Policy.java的实例
-->Policy.java
public WindowManagerPolicy makeNewWindowManager() {
return new PhoneWindowManager();
}
-->PhoneWindowManager.java
init(){
mKeyguardMediator = new KeyguardViewMediator(context, null);
}
-->KeyguardViewMediator.java
KeyguardViewMediator(){
mKeyguardViewManager = new KeyguardViewManager(context, wm, mViewMediatorCallback,
mLockPatternUtils);
}
到这里KeyguardViewManager已经创立,可以根据KeyguardViewMediator的要求来显示Keyguard lock与否
handleShow(){
mKeyguardViewManager.show(options);
}
-->KeyguardViewManager.java
show()
-->maybeCreateKeyguardLocked()
-->inflateKeyguardView()
View view = inflater.inflate(R.layout.keyguard_host_view, mKeyguardHost, true);
直接把keyguard_host_view加到mKeyguardHost(ViewManagerHost--FrameLayout)里,也就是加到了View系统里
问题:在哪个Thread里做的?跟SystemServer创建的那个uiHandlerThread是一致的吗?
-->KeyguardHostView.java
具体负责显示, 特别是跟Music播放有关的Remote Control View--KeyguardTransportControlView 也在这里处理
private void initializeTransportControl() {
mTransportControl =
(KeyguardTransportControlView) findViewById(R.id.keyguard_transport_control);
mTransportControl.setVisibility(View.GONE);
showAppropriateWidgetPage() -->显示RemoteControlView
-->KeyguardTransportControlView.java
onAttachedToWindow() -->mAudioManager.registerRemoteControlDisplay(mIRCD);
onDetachedFromWindow() -->mAudioManager.unregisterRemoteControlDisplay(mIRCD);
-->AudioService.java
private IRemoteControlDisplay mRcDisplay; 与Keyguard上显示的remote control view 有关。