publicvoidhandleResumeActivity(IBinder token,boolean finalStateRequest,boolean isForward,
String reason){// Activity调用完onResume之后,会真正开始绘制界面if(r.window == null &&!a.mFinished && willBeVisible){
r.window = r.activity.getWindow();//PhoneWindow
View decor = r.window.getDecorView();// 1
decor.setVisibility(View.INVISIBLE);//Activity中的WindowMangerImp对象,它实现ViewManager接口
ViewManager wm = a.getWindowManager();//2
WindowManager.LayoutParams l = r.window.getAttributes();
a.mDecor = decor;//把phoneWindow里的DecorView赋值给Activity的decor
l.type = WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
l.softInputMode |= forwardBit;if(r.mPreserveWindow){
a.mWindowAdded =true;
r.mPreserveWindow =false;
ViewRootImpl impl = decor.getViewRootImpl();if(impl != null){
impl.notifyChildRebuilt();}}if(a.mVisibleFromClient){if(!a.mWindowAdded){
a.mWindowAdded =true;//将decor添加在WindowManager(WindowMangerImp)中
wm.addView(decor, l);//3 }else{// The activity will get a callback for this {@link LayoutParams} change// earlier. However, at that time the decor will not be set (this is set// in this method), so no action will be taken. This call ensures the// callback occurs with the decor set.
a.onWindowAttributesChanged(l);}}}
publicfinalclassWindowManagerGlobal{publicvoidaddView(View view, ViewGroup.LayoutParams params,
Display display, Window parentWindow){//...
root =newViewRootImpl(view.getContext(), display);// 1
view.setLayoutParams(wparams);
mViews.add(view);
mRoots.add(root);
mParams.add(wparams);// do this last because it fires off messages to start doing thingstry{
root.setView(view, wparams, panelParentView);// 2}catch(RuntimeException e){// BadTokenException or InvalidDisplayException, clean up.if(index >=0){removeViewLocked(index,true);}throw e;}}}
publicfinalclassViewRootImplimplementsViewParent,
View.AttachInfo.Callbacks, ThreadedRenderer.DrawCallbacks {// These can be accessed by any thread, must be protected with a lock.// Surface can never be reassigned or cleared (use Surface.clear()).publicfinal Surface mSurface =newSurface();}
publicintrelayoutWindow(Session session, IWindow client,int seq, LayoutParams attrs,int requestedWidth,int requestedHeight,int viewVisibility,int flags,long frameNumber, Rect outFrame, Rect outOverscanInsets, Rect outContentInsets,
Rect outVisibleInsets, Rect outStableInsets, Rect outOutsets, Rect outBackdropFrame,
DisplayCutout.ParcelableWrapper outCutout, MergedConfiguration mergedConfiguration,
Surface outSurface){//...try{
result =createSurfaceControl(outSurface, result, win, winAnimator);}catch(Exception e){
mInputMonitor.updateInputWindowsLw(true/*force*/);
Slog.w(TAG_WM,"Exception thrown when creating surface for client "+ client +" ("+ win.mAttrs.getTitle()+")",
e);
Binder.restoreCallingIdentity(origId);return0;}//...}//.....privateintcreateSurfaceControl(Surface outSurface,int result, WindowState win,
WindowStateAnimator winAnimator){if(!win.mHasSurface){
result |= RELAYOUT_RES_SURFACE_CHANGED;}
WindowSurfaceController surfaceController;try{
Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER,"createSurfaceControl");
surfaceController = winAnimator.createSurfaceLocked(win.mAttrs.type, win.mOwnerUid);// 1}finally{
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);}if(surfaceController != null){
surfaceController.getSurface(outSurface);// 2if(SHOW_TRANSACTIONS) Slog.i(TAG_WM," OUT SURFACE "+ outSurface +": copied");}else{// For some reason there isn't a surface. Clear the// caller's object so they see the same state.
Slog.w(TAG_WM,"Failed to create surface control for "+ win);
outSurface.release();}return result;}