Android is a huge system, the Android Framework is just a package of the system, which also involves JNI, C++, Java virtual machine, Linux system kernel, instruction set and so on. With such a large system, we had to have the discipline to read the source code, otherwise we would miss the forest for the trees and get bogged down in lots of details and pettiness.
We should be good at grasping the main line and branch line. The main line refers to each module of the Android system. The branch line is the important element in each level of the module from the upper value to the lower level.
The Android Framework is written by people, and there are good things and bad things. Not every line of code you need to ask why, and many times there aren’t that many whys, just the way it was designed at the time. But for key functions we need to dig into the implementation details.
Said some technical stuff. Any real stuff to share? Yes, I’ve been staying up all night for a month putting together a copy of the Android Framework Elaboration kernel Analysis. Part of the knowledge chapter has been published on Zhihu and has gained more than 1000 likes. Today, I will share it with you here.
This note explains the main modules of the Framework, from the deployment of the environment to the application of technology, and then to the actual project, so that we can not only learn the use of the Framework technology, but also learn how to use the Framework to solve the actual problem, from simple to deep, detailed analysis of the Framework, so that you can simply and efficiently learn this knowledge!
Chapter 1: In-depth analysis of Binder
Binder mechanisms as a means of interprocess communication permeate almost all of the Andorid framework layer. The basic communication mechanism of Android Binder must be understood first.
Knowledge in this chapter
-
Binder series – Introduction
-
Binder Driver a preliminary
-
Binder Driver Overview
-
Binder core method
...Copy the code
-
Binder Driver revisited
-
Introduction to Binder Communication
-
Binder Communication protocol
-
Scenario summary
-
Binder Memory mechanism
-
Binder start ServiceManager
-
The boot process
-
Core work
-
Get ServiceManager
-
Get the ProcessState object
-
Get the BpBinder object
-
Get BpServiceManager
-
Registration Service (addService)
-
ProcessState
-
The service registry
-
Binder Driver
-
ServiceManager
-
GetService (getService)
-
The Framework layer analysis
-
Binder architecture
-
Binder class diagram
-
Binder class stratification
-
Initialize the
-
The registration service
-
Access to services
-
How to use Binder
-
How do I use AIDL
-
Binder to summarize
-
Binder interview questions
Chapter 2: Parsing Handler in depth
There are so many articles on the web analyzing the principles of the Handler mechanism, why do we need to add to this note? It is not that the articles written by the former people are not good, I just feel that they are not fine, some points are not clear, logic is difficult to flow smoothly, every time I learn something when this situation is sad.
This chapter first macro theoretical analysis and Message source code analysis, and then to MessageQueue source code analysis, Looper source code analysis, handler source code analysis, handler mechanism implementation principle summary. Finally, we also sorted out and handled all the interview questions.
Handler is a long, step-by-step chapter that I’m sure won’t disappoint you if you stick with it.
Chapter 3: Dalvik VM process system
Andorid system startup, init process, Zygote, SystemServer startup process, application creation and use, Activity creation, destruction Handler and Looper.
Chapter 4 analyzes WMS in depth
Window management frame system animation frame View working principle.
The fifth chapter PackagerManagerService
Package management services. Resource management related classes
If you guys need a copy ofAndroid Framework intensive kernel parsing“,Click here toYou can get it for free!
The last
How to learn the Android Framework? There is only one way: Read the F *cking source code. As for how to “smooth” the transition, I don’t think the learning curve is that steep — isn’t the Android Framework code code? Don’t understand because there is no overall grasp.
Whether you’re reading a book or a blog, your ultimate goal is “learn to read source code”, not “learn source code”. It’s not an easy problem to read source code, and I’ve learned a few things:
1. Read more if you don’t understand. As it has been said, no one learns quickly; Especially for beginners, you just read the system source, certainly confused; All things are difficult at the beginning, when you feel difficult and obscure, you will be back to the text; The Android Framework is written in a certain way. If you memorize one text and then read another, you’ll probably know what you’re going to talk about halfway through, even if you don’t understand it either. After memorizing, you can think of the meaning of each sentence; And the above “paragraph”, “sentence” is not ordinary code? In this way, step by step in series, every little makes a mica, and it will come naturally. This is what we say when we read a book a hundred times. If you really want to learn the Framework, read a lot, stick to it, and don’t give up, otherwise it’s bullshit.
2. Read less of what isn’t important. It’s easy to know what it is, so how do you know which code isn’t important? There are two meanings: first, it emphasizes the big picture. When you first learn a module, you need to grasp the whole first and then understand the parts. In this scenario, all the details are unimportant. Second, the logic that really doesn’t matter; When you start learning, there’s no way to know which logic is going to be less impactful, so you need to follow books, blogs, and others to lead the way. If you follow their footsteps through the road, then you walk alone, by this time you are sure to get lost, and then you track, try, and get to the end; You know what’s important and what’s not.
3. Read and think. Learning without thought is labor lost; thought without learning is idle. What does it mean to read the source code with questions? Why do we need to do this? Is this implementation elegant or cliche? Is there a better way to do that? If I were to write it, how would I write it? And so on, with thinking, you have your own understanding.
4. Not everything needs thinking. Connected to the article, the Framework code is also written by people, there is essence, natural dregs, there are tasteless food. You don’t have to ask a hundred thousand why’s for every piece of code. There are usually many solutions to a problem, and the designers at the time chose the current implementation for historical reasons and its own understanding of compatibility issues; Not all implementations are good implementations now, so asking these questions is often pointless, so don’t read too much into it. For example, with Android’s IPC mechanism, why Binder? Perhaps some people say that Socket is not secure and efficient enough; Shared memory is inconvenient to use, and so on. But look at the question: Why did Android adopt Binder as an IPC mechanism? – Android development as you know, most of the time there is not so much why.
5. Take notes. The importance of note-taking is that it allows you to write down your own understanding at one stage, and then when you go further and look back at that understanding and think about what went right and what went wrong, it’s quite an interesting process. I think everyone looks at their previous code and feels like Shabbi somewhere. Summarize your learning process so that you can improve your metacognitive skills.
Finally, civilize communication and refuse to quarrel.