1.获取IWindowManager代理
IWindowManager 就是一个接口,拿到代理,也就是通常的binder转接口
WindowManagerGlobal
sWindowManagerService = IWindowManager.Stub.asInterface(
ServiceManager.getService("window"));
2 openSession
客户端是直接调用上面那个接口的方法。
实现是WMS里面有一个Session返回
@Override
public IWindowSession openSession(IWindowSessionCallback callback, IInputMethodClient client,
IInputContext inputContext) {
if (client == null) throw new IllegalArgumentException("null client");
if (inputContext == null) throw new IllegalArgumentException("null inputContext");
Session session = new Session(this, callback, client, inputContext);
return session;
}
final class Session extends IWindowSession.Stub
又来一个接口IWindowSession
实现类找一下IWindowSession.Stub子类就是Session
3.1 ViewRootImpl.setView
客户端获取的Session代理addView实现,客户端只能到这里
---
看看binder服务端Session中addToDisplay
@Override
public int addToDisplay(IWindow window, int seq, WindowManager.LayoutParams attrs,
int viewVisibility, int displayId, Rect outContentInsets,
InputChannel outInputChannel) {
return mService.addWindow(this, window, seq, attrs, viewVisibility, displayId,
outContentInsets, outInputChannel);
}
mService指的是WMS
WMS addVWindow
public int addWindow(Session session, IWindow client, int seq,
WindowManager.LayoutParams attrs, int viewVisibility, int displayId,
Rect outContentInsets, InputChannel outInputChannel) {
int[] appOp = new int[1];
int res = mPolicy.checkAddPermission(attrs, appOp);
if (res != WindowManagerGlobal.ADD_OKAY) {
return res;
}
boolean reportNewConfig = false;
WindowState attachedWindow = null;
WindowState win = null;
long origId;
final int type = attrs.type;
synchronized(mWindowMap) {、
...
梳理一下setContentView是Activity方法,其实是调用Window的方法,然后调用
ViewRootImpl方法,它是先拿到WMS代理获取Session然后调用Session方法。
binder另一头是Session调用WMS方法。