Series index
Concurrent series: Thread locking
-
Why does CountDownlatch guarantee execution order?
-
Why can Concurrent Containers achieve efficient concurrency?
-
From ReentrientLock to see the correct use of lock posture
New series: Android11 system source code analysis
-
How to download Android source code for Mac environment?
-
Android11 Source code analysis: How does the application start?
-
Android11 source code analysis: How to start the Activity?
-
Android11 source code analysis: Service startup process analysis
-
Android11 source code analysis: Static broadcast is how to receive notifications?
-
Binder cross-process Implementation (In process of creation)
-
How do plug-in activities start?
-
Android11 source code analysis: why in the end will BE stuck UI?
-
How does SurfaceFlinger distribute vsync signals? (In process of creation)
Classic series: Android10 system startup process
-
Source code download and compilation
-
Overview of the Android system startup process
-
Init process source parsing
-
Zygote process source code analysis
-
SystemServer source code parsing
preface
As a basically can be said to start from 0 to read the source code, to now has completed a series of source code analysis of technical articles, I think my experience or have a certain reference
How to learn Framework source code in depth?
First of all, I am also an application layer developer, I think most of the “how to get into the framework source” question, should be mostly application layer development
That for us, the biggest problem with reading source code is that there is no application scenario, or in the short term, the cost is high, the bottom of the income, easy to give up halfway
one
Aiming at this problem, first is must have certain concentration and study spirit, which part of the source code analysis is going to win, even if no amount of problems, also want to find a way to solve, your goal, kneeling also want to complete Secondly, it is from what direction, as topic main said, many source, ndroid11 aosp the entire download, It’s about 150 gigabytes, so it’s important to find a place to start, otherwise you’ll just download the source code and leave it on your hard drive
For application layer development, HERE are a few common interview questions, but also easy to get started
- Four component startup processes
- Application Startup Process
- System Startup Process
- Audio related content
It takes at least half a year to start an Activity because it involves a lot of content and depth. For the first point, you can start an Activity for at least two weeks. ActivityThread,AMS,Zygote, Binder cross-process invocation, etc
One more thing, I don’t agree with Weishu’s reply that he should not pay attention to the tracking of various processes. Of course, this is just my opinion based on my own knowledge and cognition
For the developers of application layer is the same, we have to understand their own positioning, small white white path, bosses, walk the road of individual thinks, whether it is with all kinds of system process invocation chain, or according to the system service to the whole piece of carding, these are the “process”, and our goal, is the thorough framework source code, How can you go deep into the source code without even following the call chain?
Of course, I agree with Weishu about analyzing the ideas and principles behind it, but that’s level 2, and trying to do level 2 without building on level 1 is like building castles in the air
two
Now that we’ve figured out where to start, the second question is, what kind of foundation do we need to have in order to be able to read the source code, or be able to read the source code
Personally, when you ask the question of how to learn the source code of the Framework in depth, you already have the most basic conditions – the desire to explore and learn. Of course this thing is a little bit more imaginary, but let me do a little bit more real
So if you want to go to the Native layer, for example, the handler we most often talk about, there is also an implementation in the Native layer. When you fetch a message, it will wake up through a pipeline mechanism. Does that mean we have to have a C++ or C language background to read the source code? In my opinion, it is good to have the foundation of nature, and it will not have much impact. It may be more efficient to read the source code than to finish learning C++ and then continue to read it
Therefore, in my opinion, regardless of your foundation, as long as you have experience in application layer development and have an interest and desire to explore and explore the Framework, that’s enough. As long as the beginning, is progress
three
The third thing I want to talk about is how much depth is appropriate. I read the process of source code, often follow a single call chain dig deeper and deeper, such as in the study of system startup process, even to the virtual machine level and assembly level, but generally speaking, we do not need to dig so deep, one is not necessary, two really will spend a lot of energy, and it is difficult to see results
So when I’m looking at a point, I break it down into small questions. To give a specific example, I asked myself these questions when I was looking at SystemServer related processes
- How did SystemServer get forked out
- What does SystemServer do
- What is the SystemServiceManager responsible for?
- How is SystemServiceManager created?
- What does a ServiceManager do?
- How many ways are there to start a service? What’s the difference between them?
- What is the difference between SystemServiceManager and ServiceManager?
- What does LocalService do?
- SystemServer is the server process, so who is the client process? How did they communicate? What is the internal mechanism? (Binder related issues)
Will come in, of course, is not a problem, or don’t know which involve important class inside, we can read the article, a general train of thought, can put forward some basic questions at this time, and then in the process of reading the source code to ask questions and induction, this is also I write the source code analysis steps and the train of thought
four
The fourth thing I want to talk about is positive feedback. A lot of people don’t have concentration, but they just can’t read. A big reason is that there is no positive feedback. My positive feedback comes from the output of my articles, the number of articles read and blog attention, and the ability to communicate with my friends (but most of the time, the deeper you go, the less people you have to communicate with).
I also recommend that you communicate as you study the framework, produce articles and results, and motivate yourself to continue on this path
five
Fifth, I want to remind you
If your work involves related content (such as plug-ins, audio and video, launcher, setting, AudioManger, etc.), make it a priority to study relevant source code
If not, you can refer to the research points I mentioned above. Only if you have the ability to read and research, you can better complete more challenging tasks and even enter the ranks of Framework development
six
Finally, let’s talk about the benefits of reading the source code, which you’ll probably appreciate more when you’re done with a module or two
As Weishu says, the benefit of studying the framework isn’t in remembering the call flow, which isn’t the goal (but it’s an essential part of it!). Our goal is to take a deeper or more holistic view of our technology. For example, the big four components are the ones we use most in development, but fragment is also the one we use most in development. Why can’t it be called the “fifth component”?
When I finished studying the source code of the four components, I found the biggest characteristics of the four components — support cross-process, their startup process will involve whether my process is started, whether I need to communicate with Zygote to fork out the process, and then execute the startup logic of the component itself, so the weight of the four components is very heavy, Frament is just a part of the activity that relies on it, and is nowhere near as big as it is, so it is not a “fifth component”
Back to the benefits of reading the source code
- Is to have a deeper understanding of application layer development;
- When encountering some difficult problems, we have the ability to read the source code to dig deep into the cause of the problem, and finally solve the problem;
- In the overall ability to read source code to improve, when we look at the other three library source code, will be more handy, even AOSP this nearly 200G behemoth can be done, Okhttp in front of it is simply a brother
The last
Finally, if you want to start reading the source code, you can start by reading some related articles, such as my article (dog head).
If this article inspires you, please give me a thumbs up! See you in the next article!