- 浏览: 22523 次
- 性别:
- 来自: 北京
最新评论
page4
我们看一下ViewRootImpl对象的创建过程, ViewRootImpl类的声明如下:
public final class ViewRootImpl implements ViewParent,
View.AttachInfo.Callbacks, HardwareRenderer.HardwareDrawCallbacks
ViewRootImpl类的构造函数定义如下:
1 public ViewRootImpl(Context context, Display display) {
2 super();
3
4 if (MEASURE_LATENCY) {
5 if (lt == null) {
6 lt = new LatencyTimer(100, 1000);
7 }
8 }
9
10 // Initialize the statics when this class is first instantiated. This is
11 // done here instead of in the static block because Zygote does not
12 // allow the spawning of threads.
13 mWindowSession = WindowManagerGlobal.getWindowSession(context.getMainLooper());
14 mDisplay = display;
15
16 CompatibilityInfoHolder cih = display.getCompatibilityInfo();
17 mCompatibilityInfo = cih != null ? cih : new CompatibilityInfoHolder();
18
19 mThread = Thread.currentThread();
20 mLocation = new WindowLeaked(null);
21 mLocation.fillInStackTrace();
22 mWidth = -1;
23 mHeight = -1;
24 mDirty = new Rect();
25 mTempRect = new Rect();
26 mVisRect = new Rect();
27 mWinFrame = new Rect();
28 mWindow = new W(this);
29 mTargetSdkVersion = context.getApplicationInfo().targetSdkVersion;
30 mInputMethodCallback = new InputMethodCallback(this);
31 mViewVisibility = View.GONE;
32 mTransparentRegion = new Region();
33 mPreviousTransparentRegion = new Region();
34 mFirst = true; // true for the first time the view is added
35 mAdded = false;
36 mAccessibilityManager = AccessibilityManager.getInstance(context);
37 mAccessibilityInteractionConnectionManager =
38 new AccessibilityInteractionConnectionManager();
39 mAccessibilityManager.addAccessibilityStateChangeListener(
40 mAccessibilityInteractionConnectionManager);
41 mAttachInfo = new View.AttachInfo(mWindowSession, mWindow, display, this, mHandler, this);
42 mViewConfiguration = ViewConfiguration.get(context);
43 mDensity = context.getResources().getDisplayMetrics().densityDpi;
44 mNoncompatDensity = context.getResources().getDisplayMetrics().noncompatDensityDpi;
45 mFallbackEventHandler = PolicyManager.makeNewFallbackEventHandler(context);
46 mProfileRendering = Boolean.parseBoolean(
47 SystemProperties.get(PROPERTY_PROFILE_RENDERING, "false"));
48 mChoreographer = Choreographer.getInstance();
49
50 PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
51 mAttachInfo.mScreenOn = powerManager.isScreenOn();
52 loadSystemProperties();
53 }
第13行(ViewRootImpl->ViewRootImpl)会调用WindowManagerGlobal的getWindowSession函数, 关于getWindowSession函数的详细分析可以参考page5文件.
第28行(ViewRootImpl->ViewRootImpl)会创建一个W类型的对象, 并用该对象来初始化成员变量mWindow. 关于W类型的构造过程可以参考page7文件.
第41行(ViewRootImpl->ViewRootImpl)会创建一个AttachInfo对象, 表示ViewRootImpl所依附的Window的信息, 并用该AttachInfo对象初始化成员变量mAttachInfo.
page5
我们分析一下WindowManagerGlobal的getWindowSession函数的实现:
1 public static IWindowSession getWindowSession(Looper mainLooper) {
2 synchronized (WindowManagerGlobal.class) {
3 if (sWindowSession == null) {
4 try {
5 InputMethodManager imm = InputMethodManager.getInstance(mainLooper);
6 IWindowManager windowManager = getWindowManagerService();
7 sWindowSession = windowManager.openSession(
8 imm.getClient(), imm.getInputContext());
9 float animatorScale = windowManager.getAnimationScale(2);
10 ValueAnimator.setDurationScale(animatorScale);
11 } catch (RemoteException e) {
12 Log.e(TAG, "Failed to open window session", e);
13 }
14 }
15 return sWindowSession;
16 }
17 }
第5行(WindowManagerGlobal->getWindowSession)
第6行(WindowManagerGlobal->getWindowSession)会调用getWindowManagerService来得到WindowManager服务, 关于getWindowManagerService函数的详细分析可以参考page6文件.
第7-8行(WindowManagerGlobal->getWindowSession)会用刚刚获得的WindowManagerService调用openSession函数, 其实这会导致和WindowManagerService建立连接. 关于和WindowManagerService建立连接的部分可以参考相关系列的文章.
第15行(WindowManagerGlobal->getWindowSession)会返回和WindowManagerService的Session连接.
page6
WindowManagerGlobal的getWindowManagerService函数定义如下:
1 public static IWindowManager getWindowManagerService() {
2 synchronized (WindowManagerGlobal.class) {
3 if (sWindowManagerService == null) {
4 sWindowManagerService = IWindowManager.Stub.asInterface(
5 ServiceManager.getService("window"));
6 }
7 return sWindowManagerService;
8 }
9 }
WindowManagerGlobal的getWindowManagerService函数的主要逻辑就是通过Binder来获得"window"服务.
我们看一下ViewRootImpl对象的创建过程, ViewRootImpl类的声明如下:
public final class ViewRootImpl implements ViewParent,
View.AttachInfo.Callbacks, HardwareRenderer.HardwareDrawCallbacks
ViewRootImpl类的构造函数定义如下:
1 public ViewRootImpl(Context context, Display display) {
2 super();
3
4 if (MEASURE_LATENCY) {
5 if (lt == null) {
6 lt = new LatencyTimer(100, 1000);
7 }
8 }
9
10 // Initialize the statics when this class is first instantiated. This is
11 // done here instead of in the static block because Zygote does not
12 // allow the spawning of threads.
13 mWindowSession = WindowManagerGlobal.getWindowSession(context.getMainLooper());
14 mDisplay = display;
15
16 CompatibilityInfoHolder cih = display.getCompatibilityInfo();
17 mCompatibilityInfo = cih != null ? cih : new CompatibilityInfoHolder();
18
19 mThread = Thread.currentThread();
20 mLocation = new WindowLeaked(null);
21 mLocation.fillInStackTrace();
22 mWidth = -1;
23 mHeight = -1;
24 mDirty = new Rect();
25 mTempRect = new Rect();
26 mVisRect = new Rect();
27 mWinFrame = new Rect();
28 mWindow = new W(this);
29 mTargetSdkVersion = context.getApplicationInfo().targetSdkVersion;
30 mInputMethodCallback = new InputMethodCallback(this);
31 mViewVisibility = View.GONE;
32 mTransparentRegion = new Region();
33 mPreviousTransparentRegion = new Region();
34 mFirst = true; // true for the first time the view is added
35 mAdded = false;
36 mAccessibilityManager = AccessibilityManager.getInstance(context);
37 mAccessibilityInteractionConnectionManager =
38 new AccessibilityInteractionConnectionManager();
39 mAccessibilityManager.addAccessibilityStateChangeListener(
40 mAccessibilityInteractionConnectionManager);
41 mAttachInfo = new View.AttachInfo(mWindowSession, mWindow, display, this, mHandler, this);
42 mViewConfiguration = ViewConfiguration.get(context);
43 mDensity = context.getResources().getDisplayMetrics().densityDpi;
44 mNoncompatDensity = context.getResources().getDisplayMetrics().noncompatDensityDpi;
45 mFallbackEventHandler = PolicyManager.makeNewFallbackEventHandler(context);
46 mProfileRendering = Boolean.parseBoolean(
47 SystemProperties.get(PROPERTY_PROFILE_RENDERING, "false"));
48 mChoreographer = Choreographer.getInstance();
49
50 PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
51 mAttachInfo.mScreenOn = powerManager.isScreenOn();
52 loadSystemProperties();
53 }
第13行(ViewRootImpl->ViewRootImpl)会调用WindowManagerGlobal的getWindowSession函数, 关于getWindowSession函数的详细分析可以参考page5文件.
第28行(ViewRootImpl->ViewRootImpl)会创建一个W类型的对象, 并用该对象来初始化成员变量mWindow. 关于W类型的构造过程可以参考page7文件.
第41行(ViewRootImpl->ViewRootImpl)会创建一个AttachInfo对象, 表示ViewRootImpl所依附的Window的信息, 并用该AttachInfo对象初始化成员变量mAttachInfo.
page5
我们分析一下WindowManagerGlobal的getWindowSession函数的实现:
1 public static IWindowSession getWindowSession(Looper mainLooper) {
2 synchronized (WindowManagerGlobal.class) {
3 if (sWindowSession == null) {
4 try {
5 InputMethodManager imm = InputMethodManager.getInstance(mainLooper);
6 IWindowManager windowManager = getWindowManagerService();
7 sWindowSession = windowManager.openSession(
8 imm.getClient(), imm.getInputContext());
9 float animatorScale = windowManager.getAnimationScale(2);
10 ValueAnimator.setDurationScale(animatorScale);
11 } catch (RemoteException e) {
12 Log.e(TAG, "Failed to open window session", e);
13 }
14 }
15 return sWindowSession;
16 }
17 }
第5行(WindowManagerGlobal->getWindowSession)
第6行(WindowManagerGlobal->getWindowSession)会调用getWindowManagerService来得到WindowManager服务, 关于getWindowManagerService函数的详细分析可以参考page6文件.
第7-8行(WindowManagerGlobal->getWindowSession)会用刚刚获得的WindowManagerService调用openSession函数, 其实这会导致和WindowManagerService建立连接. 关于和WindowManagerService建立连接的部分可以参考相关系列的文章.
第15行(WindowManagerGlobal->getWindowSession)会返回和WindowManagerService的Session连接.
page6
WindowManagerGlobal的getWindowManagerService函数定义如下:
1 public static IWindowManager getWindowManagerService() {
2 synchronized (WindowManagerGlobal.class) {
3 if (sWindowManagerService == null) {
4 sWindowManagerService = IWindowManager.Stub.asInterface(
5 ServiceManager.getService("window"));
6 }
7 return sWindowManagerService;
8 }
9 }
WindowManagerGlobal的getWindowManagerService函数的主要逻辑就是通过Binder来获得"window"服务.
发表评论
-
Activity与WindowManagerService连接的过程(三)
2018-04-16 16:27 584page11 WindowManagerService ... -
Activity与WindowManagerService连接的过程(二)
2018-04-16 16:36 706page6 WindowManagerGlobal的getW ... -
Activity与WindowManagerService连接的过程(一)
2018-04-16 16:21 955page1 Activity组件在 ... -
Activity的ViewRoot的创建过程(三)
2017-11-06 14:25 707page7 在这篇文章里, 我们分析一下W类的构造过程. W ... -
Activity的ViewRoot的创建过程(一)
2017-11-06 14:27 1026page1 当一个Activity第一次激活的时候会为该Ac ... -
Activity的Window和WindowManager的创建过程(三)
2017-07-05 11:49 1299page9 在这里我们分析一下DisplayManager的 ... -
Activity的Window和WindowManager的创建过程(二)
2017-07-05 11:31 499page5 在这篇文章中, 我们分析一下ContextImp ... -
Activity的Window和WindowManager的创建过程(一)
2017-07-05 11:27 575page1 我们开始分析一下Activity的Window和 ... -
Acitivy创建Context的过程(二)
2017-06-21 14:11 452page4 在这里我们分析一下ContextImpl的ini ... -
Acitivy创建Context的过程(一)
2017-06-21 14:15 586page1 从本篇文章开始,我们分析一下Activity创建 ... -
应用程序进程与SurfaceFlinger的连接过程
2017-06-21 11:49 1025我们从SurfaceComposerClient对象的创建开始 ... -
Android源码之SurfaceFlinger的启动(三)
2017-04-20 11:09 1003page11 我们来看一下SurfaceFlinger ... -
Android源码之SurfaceFlinger的启动(二)
2017-04-18 15:15 813page6 我们看一下Thread的run函数的实现: ... -
Android源码之SurfaceFlinger的启动(一)
2017-04-17 10:07 909page1 在Android系统中, 显示系统在底层是通过S ... -
Android源码之Zygote
2015-12-15 11:45 481当ActivityManagerService启动一个应用程序 ... -
Android源码之Binder(五)
2015-12-04 09:19 1415Service组件在启动时,需要将自己注册到Service M ... -
Android源码之Binder(四)
2015-12-04 09:18 1803case BINDER_SET_MAX_THREADS: ... -
Android源码之Binder(三)
2015-12-04 09:17 881{ int ret; struct binder_pr ... -
Android源码之Binder(二)
2015-12-04 09:15 502分析完Binder驱动程序的打开和内存分配的过程之后,我们看一 ... -
Android源码之Binder(一)
2015-12-04 09:12 962在Android系统中,进程间通信使用的是Binder机制。B ...
相关推荐
关于Android Studio升级为V4.1.1Activity不能创建解决方法
主要包括activity、view 以及布局三大部分,其中包含activity之间的数据传递
反射获取顶层activity实例
activity view window viewgroup的关系
activity-oracle建表SQLactivity-oracle建表SQLactivity-oracle建表SQL
有几个情况下 Activity 会...者是 Activity 通过调用 finish()发出了停止信号。系统也有可能会在 Activity 处于 stop 状态且长时间不被使用、或在前台 Activity 需要更多系统资源的时候关闭后台进程以获取 更多的内存。
要分析Activity中的Window的创建过程就必须了解Activity的启动过程,详细的启动过程参考Activity的启动过程 。 Activity的启动过程很复杂, 最终会由ActivityThread中的performLaunchActivity()方法来完成整个启动...
掌握Activity的创建过程和配置。理解Activity的生命周期以及各个生命周期方法的使用。掌握页面切换的两种方法。 【实践要求】 1.理解Activity的组成结构和创建过程; 2.了解Activity的生命周期; 3.掌握Activity页面...
多activity的创建及其交互 demo
Activity2.1:创建并使用COM+服务组件 Creating and Using a COM+ Serviced Component
LocalActivityManager类是管理activity的,然后通过startActivity(String id, Intent intent)这个方法获取Window获取当前Window对象,再然后调用getDecorView()方法获取当前activity对应的view,这样就可以使用...
Activity和Service是应用程序的核心组件,程序框架层提供了一套完整的机制来协助应用程序启动Activity和Service
Android开发中activity的工作过程xmind,便于学习Android中activity。
轻松实现进入Activity或者Fragment的时候为view创建漂亮的过渡效果.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
Activity启动过程
Activity启动时候获取View宽高的四种方法,因为Activity的生命周期回调和view的measure过程不是同步执行的,所以无法在activity的onCreate、onStart和onResume里面准确的获取view的宽和高,可以通过以下四个方法来...
Activity6.0 默认不支持达梦数据库,需要进行适配,本文详细讲解了适配的过程
activity3activity3
如果在任务的栈顶正好存在该Activity的实例,就重用该实例,并且会调用实例的OnNewIntent()方法,否者就会创建新的实例并放入栈顶(即使栈中已经存在该Activity实例,只要不在栈顶,都会创建实例)。 3.singleTask ...
Activity 启动过程源码+分析过程