Original website: http://jingyan.baidu.com/article/574c5219ca78ed6c8d9dc12a.html
Working on the Android system for a while, often encounter problems in the topic, the following to say my opinion:
1, need to find a beginning, and the UI is directly related to the most common activity, I began to dissect from it. From the creation of activity to find the actual activity of the creation location, Setcontentview This method is obviously related to the UI, these two aspects of a combination, I found viewroot and WindowManager figure, Along the WM and WMS I found surface, and the draw function, which actually paints things on the decorview that appear when activity is created. With source Insight I summarize the horizontal static diagram of the UI Java layer. To complete this static UML, I think I can start the feature implementation on the trace, this part is mainly C + + code, I follow the draw function, see the relationship of each level, surfacesession control and transaction processing, Sharedbuffer read and write control, The Surfaceflinger dominate everything, OpenGL es's god pen Ma Liang. Image output of framebuffer and Framebufferdevice. The one go is finished.
2. Eclipse is not a good tool to read Android source code, not fluent, search inefficient, inheritance relationship/call relationship can not be effectively viewed. Recommended source Insight, with the help of this tool, you can control the vast number of Android source code, you can easily navigate between the java,c++,c, you can quickly find the inheritance you need. I have always been a Windows+linux+samba mode of work.
3. Android source code is divided into features to achieve on the vertical, and functional expansion on the landscape. In reading the source code, you need to grasp the two ideas.
For example, you need to study the implementation principle of the audio system, portrait: You need to play from the beginning of a music track, all the way down, you find JNI call decoding library, the creation and use of shared memory, routing switching, audio input device opening, audio streaming start. You want to see what the audio system includes, landscape: from the interface of the framework, you will find that the audio system mainly includes: playback, recording, routing switching, sound processing and so on.
4. Most of the Android module is C/s architecture, you must have this level of relationship, you need to clearly find the location of the server, it is you need to break the city. Then you can discover that HAL and kernel are stripped off layer by layer.
< > How to read and understand Android source efficiently and quickly