Overview and learning plan of Windows Management Service for Android

Source: Internet
Author: User

In the previous series of articles, we analyzed the implementation framework of the android application window from an individual perspective. In fact, from the overall perspective, the implementation of Android Application windows is more complicated because they have different types and functions and affect each other. In the Android system, managing all windows in the system is the responsibility of Windows Management Service. In this article, we will briefly introduce the functions of windowmanagerservice and the preparation of learning plans.

We know that in the Android system, only one activity window is activated at the same time. However, for the windowmanagerservice service, this does not mean that it only needs to manage one activity window at a time. For example, during the switching of the two activity windows, the first and second activity windows are actually visible. Even if only one activity window is visible, the windowmanagerservice still needs to manage multiple windows at the same time, because the visible activity window may also be set with the wallpaper window (wallpaper winodw) or a sub window is displayed, and the status bar and Input Method window may appear, as shown in 1.

Figure 1 activity window and Its subwindow, wallpaper window, input window, and Position Structure of the status bar

Therefore, the windowmanagerservice cannot assume that it only needs to manage a window at the same time, it uses the position and size of each window on the screen to determine which windows need to be displayed and where to display them. This is to calculate the visible area of each window.

The surfaceflinger service of the surface mechanism of the Android system analyzes the process of rendering the UI of the application. We can see that when the surfaceflinger service renders the UI of the entire screen, the visibility of each window is calculated. Therefore, the windowmanagerservice only needs to inform surfaceflinger of the location and size of each window it manages, the latter can help it calculate the visible area of each window. Note: here, the window position includes the position of the window in the X, Y, and Z axes.

Windowmanagerservice controls which windows need to be displayed and where to display them in the following ways:

1. the size of each activity window is equal to the screen size. Therefore, you only need to set a different Z axis position for each activity window, and then you can make it at the top of the screen, that is, the currently activated activity window is visible.

2. The zaxis position of each subwindow is larger than that of its parent window, but the size is smaller than that of the parent window. At this time, the activity window and its pop-up subwindows can be displayed simultaneously.

3. For a non-full screen activity window, it leaves an area above the screen to display the status bar. This area is called a decoration for the screen, and content inset for the activity window ).

4. The input method window appears only when necessary. It also appears in the decoration area of the screen or the content Edge Area of the activity window.

5. For the wallpaper window, it appears at the bottom of the activity window that requires the wallpaper. At this time, the activity window is required to be translucent, so that the wallpaper window behind it can be displayed together.

6. the switching process of the two activity windows is actually the process in which the previous window is displayed, the animation is exited, And the animation is started. In the animation display process, the window size changes, in this way, the size of the two activity windows is no longer equal to the screen size, so they may be both visible at the same time. In fact, the switching process of the activity window is quite complex, because the activity window to be displayed may also be set as a start window ). An activity window with a startup window configured can be displayed only after its startup window is displayed.

From the above six points, we can see that the position and size of the window in the X, Y, and Z axes are very important. They jointly determine whether a window is visible as a whole or partially, or the whole is invisible. In the Android system, the windowmanagerservice calculates the position and size of a window through a policy class that implements the windowmanagerpolicy interface. For example, on the phone platform, this policy class is phonewindowmanager. The advantage of this is that different policies are implemented for different platforms to achieve different window control modes.

From the above description, we can see that in addition to dealing with the application process running in the activity window, windowmanagerservice also needs to interact with surfaceflinger service and phonewindowmanager in the window management strategy class, as shown in figure 2.

Figure 2 Relationship Between windowmanagerservice and activity window, surfaceflinger service, and phonewindowmanager Policy

In a series of articles about the implementation framework of the android application window (activity) and the learning plan, we have analyzed the interaction process between the application process and the windowmanagerservice. Therefore, in this series of articles, we will mainly analyze the implementation of the windowmanagerservice service and its interaction with surfaceflinger service and phonewindowmanager strategy.

In general, the implementation of the windowmanagerservice is quite complex. For example, the core member function of the windowmanagerservice class contains more than 1200 lines of code, it is even worse than the core member function of the viewroot class of the 600-line code, namely, javasmtraversals. However, the complexity of implementing the windowmanagerservice is expected. After all, it manages the UI of all windows in the system. In any system, the window management subsystem is extremely complex. Based on the above reasons, the implementation of the windowmanagerservice is an attack. Therefore, this series of articles will split the windowmanagerservice and then break it down one by one, this is the same idea of divide and conquer in algorithms.

Specifically, we will analyze the implementation of the windowmanagerservice according to the following scenarios:

1. Calculation of window size and position (X axis and Y axis.

2. How the window is organized.

3. Adjust the input method window.

4. Adjust the wallpaper window.

5. Calculation and adjustment of the Z axis position of the window.

6. display the startup window of the activity window.

7. Switch the activity window.

8. animation display process in the activity window.

Thirdly, because the implementation of the windowmanagerservice is too complex, the above eight scenarios may not be enough to describe the implementation of the windowmanagerservice. In this case, we will make adjustments during the analysis. I believe that we can have a deep understanding of the UI architecture of the Android system after the implementation of the windowmanagerservice is analyzed separately and governed! Please pay attention to the following articles!

Lao Luo's Sina Weibo: http://weibo.com/shengyangluo. welcome to the attention!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.