Comprehensive understanding of Android OS

origin

A few days ago, CSDN had an article about Hongmeng OS. I think it is a very relevant article in the recent discussion of self-developed OS (the link is not given,...). I once introduced the Android OS in 2012, and it is still outdated. As a technical person, when we discuss the future of something, we should always have some understanding of it. This article is a very simple introduction to Android OS. Note that many of the knowledge involved in this article is not too rigorous in the strict sense, and the main thing is to convey the meaning in place.

In the first few years of Android (before 2011 and around), we also bet on Meego by Android , Intel and several manufacturers , and embedded OS based on Linux . At that time, China Mobile's OMS was also very popular, and even OMS created a company called Borqs. There are many talents in Borqs, many of whom come from Motorola, the Whampoa Military Academy in China's mobile phone industry. From this point of view, Android OS was also unpredictable in the early days, and no one thought it would definitely succeed.

Android finally succeeded. I personally feel that this is not entirely a technical factor, but several key factors are still related to technology:

  1. Using Java as a development language is definitely one of the key factors-after all, catering to developers is very important. After all, Java is simpler than C++/C and easy to learn.

  2. In addition, the bottom layer of Android is Linux, which has attracted most of the peripheral manufacturers. They originally developed drivers or related modules for Linux, and there was not much work involved in migrating to Android.

  3. Finally, there is the support of key chip manufacturers-Qualcomm. If only the Intel family were doing chips at the time, Meego would be a few more years away.

In the past, CSDN "Programmer" magazine often has an author's contribution. I see his personal introduction is very interesting, saying that he wants to wave the banner for Linux . Therefore, the reason why Android is successful is that too many people are chanting for it. Those engaged in software and hardware development, training...

After Android completely occupied the market, the H5-based OS had another wave of climax. There was a Firefox OS around 2013-2014, and many machines were installed abroad. FireFox OS is fully compatible with Android. The so-called compatibility means that the original functions belonging to the Android OS are retained, and then some function extensions are provided to the H5 APP.

Compared with Android, there are far fewer people shouting for Firefox OS. And it must be compatible with Android OS-then, every time Android OS is updated, Firefox must adapt and change. This workload is very, very large. Finally, Firefox OS stopped.

The above is the historical situation-it illustrates the fact that no OS is born a winner, and the situation is changing. In addition, many of us would like to thank Android for being able to experience an OS from zero to such a powerful process in a very short span of time, starting in seven or eight years .

Now we will introduce some popular science on Android OS.

Overall video

Video converted from PPT

There are 5 parts introduced in the above video, namely:

  1. Android system architecture-vertical perspective

  2. Android Framework-no hierarchy

  3. Android OS is a microkernel OS

  4. The process of Android phone release and update

Each part is not long. You can read the content below first, and then watch the PPT video above after reading the whole.

Android system architecture-vertical perspective

The figure below is the overall architecture of Android OS. 99.999% of people who engage in Android know:

640?wx_fmt=jpeg

From a vertical point of view, Android OS is divided into four levels (this is my division, other people's statements are similar, some of which are older, such as the Dalvik virtual machine has been replaced by ART, but it does not affect our understanding of this architecture understanding):

  • The bottom layer is the Linux Kernel layer . Please pay special attention to this point, it can't be emphasized ten thousand times-the cornerstone of Android OS is Linux kernel. In addition to the Kernel layer, things related to Linux Kernel in User Space are also copied by Android OS, such as ueventd, wpa_supplicant, etc.

  • The middle two layers from bottom to top are the Native Framework layer and the Java Framework layer. These two are unique to Android. We collectively refer to these two layers as the Android Framework .

  • The top layer is the application layer . It is based on the Android Framework that makes the application on Android so unique -in contrast, if you write an interfaceless program such as ls, find, they will run the same on all Linux/Unix-based systems . We generally think of such programs as Linux applications-certainly not as Android applications.

Among the above four levels, Kernel has the longest history, and today there are probably three giants of Windows, Linux, and MacOS (Unix is ​​related to Linux and Mac, and it is rarely seen in consumer electronics, so Unix is ​​not discussed) :

  • Windows is owned by Microsoft , and it has been involved in hundreds of thousands of equipment manufacturers and software developers for decades.

  • Linux : It is related to Unix, the open source Kernel, there are many distributions on it, such as Ubuntu, CentOS, etc., and so does the domestic Unikylin.

  • MacOS : It is also related to Unix, which is unique to Apple. There are hundreds of thousands of equipment manufacturers and software developers participating in the play together.

Only Linux is not exclusive to a company. Therefore, Android using Linux is an inevitable choice. If we want to make a domestically-made independent OS, the greatest possibility is also based on Linux, such as the current Unikylin and the previous red flags.

This is not a question of whether technology is good or bad, but Linux Kernel can be regarded as a software wealth shared by all mankind . Obey its requirements, don't engage in an independent kingdom, just use it together. Besides, Linux Kernel has been developed for decades, and many people (including many domestic companies) have made many great contributions to it. As the saying goes, the predecessors planted a tree, and the descendants can enjoy the shade. If you have to be "autonomous" from beginning to end, from top to bottom, you should not even use computer programming languages ​​invented abroad smiley_13.png.

Continue our discussion.

Android Framework-no hierarchy

In the eyes of most people, the architecture of Android OS is the vertical relationship as above-this understanding is not wrong, but it is not completely accurate. If we observe the Android Framework (collectively referred to as Native Framework and Java Framework) in functional modules , you will get a picture like this:

640?wx_fmt=jpeg

To observe the Android Framework in terms of function:

  • J ava Framework includes several major types of services , such as components related to the four major component scheduling functions in the application, components that specifically manage windows, and functional components related to application installation. There are also components related to the network and Bluetooth functions. I divided them into seven categories in "In-depth Understanding of Android Volume 2". This category has been increased in the latest version, for example, several vehicle-related functional modules have been added to Android Auto (for vehicle systems). In addition, please note that the above classification is purely my personal classification, and there is no standard.

  • Native Framework can also be divided by function like this , such as AudioFlinger and AudioPolicyService related to audio.

Through this section, you know:

  • There are actually many functional modules in the Android Framework.

  • These functional modules may be placed in the Java Framework, or they may be placed in the Native Framework.

  • What's more, these functional modules can be distributed among multiple processes, or interact with each other in a Binder mode to the application layer.

What is the use of knowing these things? Then look.

Android OS is a microkernel OS

Regarding the kernel, there has always been a distinction between a micro kernel and a macro kernel . Windows and Mac use microkernels, and Linux use macro kernels. So, what is a microkernel and what is a macrokernel? The following figure briefly explains the microkernel:

640?wx_fmt=jpeg

Let me briefly describe the difference between micro-kernel and macro-kernel ( click to stop, non-technical strict ):

  • The microkernel is the kernel that only performs some basic services (such as operating the CPU, process scheduling, memory management, device management, etc.). Then separate other functions into multiple processes other than the kernel. The biggest criticism of the microkernel is that the interaction between other processes and the kernel belongs to inter-process communication, and the overhead is relatively large .

  • The macro kernel is to stuff everything in the picture above into the kernel. This way everyone runs in the same process (mainly refers to sharing the same memory space-kernel address space), which can greatly reduce the overhead of interaction between modules, but the problem is that once a module has a problem, the entire kernel may hang Drop .

After understanding the difference between microkernel and macrokernel, let's look at Android again. If we think that Android is an OS (I will talk about why Android can be regarded as an OS later), is it a microkernel or a macrokernel? Then look at the picture below:

640?wx_fmt=jpeg

The above figure shows the interaction between the four levels of Android:

  • Both Native Framework and Java Framework interact with Linux.

  • Some modules in the Java Framework interact with some modules in the Native Framework.

  • There is interaction between APP and Java Framework. In some cases, it can also interact with the Native Framework module (the relevant arrow line is not drawn in the figure).

Combined with what we mentioned above , the functional modules in the Android Framework are not all squeezed in one process, but scattered in different processes, and the functional modules interact through inter-process communication . Therefore, from the perspective of applications, Android OS must be a microkernel.

Now, let’s take a look at why Android can be called an OS—the answer to this question has already been implicitly answered above, which is the sentence “ It’s based on the Android Framework that makes Android The application is so different ."

Yes, the reason why Android can say that it is an OS is that it has a new set of application development and interaction rules.

Regarding this rule, here are two very simple examples. One is the interaction process between the source Activity and Android Framework when the application is started:

640?wx_fmt=jpeg

For this picture, I am not asking everyone to understand the details of the specific interaction. A look at this picture, you will find that this thing is unique to Android.

Of course, you can also make an application that does not comply with this in Android. For example, the boot animation in a mobile phone is a Linux application-the program name is bootanimation. It does not have four major components and does not need a Manifest. It is a pure Linux program that plays animations/pictures.

I once practiced directly using libskia for UI control-related applications around 2010-those controls in Android use libskia as a two-dimensional graphics library (OpenGLES for 3D rendering). Libskia is now the underlying rendering engine of Flutter .

My idea was very simple at the time, that is, I wanted to use Android system for non-mobile devices (used on devices with relatively simple scenes, such as swiping a card to buy a soda. At that time, the performance of these devices was very simple and could not run. Full set of Android, must be cropped), you can use custom libskia image library-based controls to draw UI. Because in most cases, you only need to draw the UI, and the rest will call the driver. None of the four major components are needed.

Thanks to Flutter, libSkia now has some popularity, but its value is still underestimated by most people. So far I know that there is no professional book that introduces this. On-board system (which requires high latency, the use of a full set of Android has a great impact on speed, and often needs to be cut) or which company wants to engage in OS , it is very important to develop a set of two-dimensional rendering engine-to put it bluntly, a large part of application development The proportions are all UI. I remember there are several Linux distributions that make the interface look the same as Windows. BTW, the 3D rendering engine doesn’t need to care, because it’s too difficult and I’m afraid that everyone will mess around, so there is already an OpenGL standard...

Then look at another example-playing video and audio:

640?wx_fmt=jpeg

On Android, if an application wants to play video and audio, it depends on MediaPlayerService , SurfaceFlinger , AudioFlinger , hardware codec modules, etc. This set of things was not brought by Linux, but by Android.

I remember that when I used to make a player on Windows, the application needed to add codec and playback functions by itself, using DirectX. This is the exclusive cheat for each application. Whoever supports more formats will be the best.

Put it on Android, the encoding, decoding, and playback functions are all provided by the system, and the application no longer has to worry about these things. This is undoubtedly a great improvement.

I have cited two very simple examples above. Presumably now we can really call Android an OS freely. Because it does a lot of extraordinary, independent functions on top of Linux Kernel. To be honest, for Android applications, it doesn’t matter whether it is running on Linux or not, as long as the Android Framework is enough -as early as 2011, my CSDN blog post " Portable Random Talk "

(Https://blog.csdn.net/Innost/article/details/6954556), a buddy ported the entire Android Framework to Windows. Note that it is not the same as using the virtual machine in the current simulator! The video above seems to be still available, so everyone can take a look.

The process of Android phone release and update

Many people do not understand the release and update process of the Android mobile phone system, and it will take a long time for their mobile phones to be updated to the new version after the new version of AOSP is released. The explanation of this problem is shown in the figure below:

640?wx_fmt=jpeg

  • Google first released the version, which we call AOSP native code. The AOSP native code only supports very few mobile phones.

  • then the chip maker released its own version of the AOSP basis. Such as Qualcomm, Huawei, MTK. The process of ① and ② overlaps, mainly for speeding up the release speed. In this stage, each chip manufacturers will be superimposed on the AOSP own native code functions, such as the previous AOSP no dual card dual standby function, these functions have some chip manufacturers added their own. In addition, chip manufacturers have to do a lot of stability tests for their own versions.

  • ③Terminal manufacturers such as Huami OV do not directly use Google’s native code, they actually use the Android code provided by the chip manufacturer. Then, the equipment manufacturer has to make a magical change and add the characteristics of the terminal manufacturer. This is the function of MIUI, EMUI, ColorOS, etc.

  • ④Now most terminal manufacturers use the Turnkey solution of chip manufacturers, mainly CPU + communication module, chip + software packaged and sold to terminal manufacturers. A few companies, such as Meizu, use Samsung’s CPU, and the communication module does not know which one, so Meizu needs to integrate Samsung’s CPU with other communication modules, which is more difficult than using the Turnkey solution.

  • ⑤After the terminal manufacturer is integrated, it is necessary to consider the operator's customization, and then add the corresponding operator's customization function, and do the corresponding test.

After understanding the above situation, from a testing perspective, the source code is released from Google to the final mobile phone, the workload of the test is very large-so the speed to the end consumer will be much slower. The manufacturer's solution is to directly use the new version of the system on the new phones. Older phones often have to wait for a while before releasing the new version upgrade package.

In short, in the Android mobile phone world, Google, chip manufacturers, terminal manufacturers, and operators are all key players in the ecological chain, and the four influence each other. From the perspective of terminal manufacturers, I think the influence of chip manufacturers on terminal manufacturers is more critical and fatal. In simple terms, if Qualcomm does not update and better chips, many mobile phone manufacturers' products will stagnate.

Compared with Apple, people do everything from chips to OS by themselves, and don't take operators seriously. Therefore, Apple's release and coverage speed are relatively fast, and the fragmentation problem is definitely several orders of magnitude lower than that of Android. Of course, the communication chip is a big problem for Apple, so some people always complain about the bad iPhone signal. Can this problem be solved by Apple developing its own communication chip? In theory, it is possible, but it is not realistic, because there are many patent issues that are difficult to deal with.

Let me talk about some of my views and judgments on the domestic autonomous OS.

  • Not surprisingly, in the medium and long term (within ten years, if quantum computers have not become popular), Linux Kernel will still be the core (the OS for special scenarios, such as the real-time OS for industrial computers, etc.) . As long as Linux Kernel is used, most hardware manufacturers can adapt. Otherwise, if you come to a new OS, hardware manufacturers will have to develop drivers and do a lot of testing. The time and money costs required for this are huge.

  • If this domestic independent OS is compatible with Android, it means that the Android set of things will most likely be retained. This is from an application perspective. Of course, you can also modify the Anndroid Framework and replace the internal implementation with your own writing. But to be compatible, then it must apply no shadow ring - this goes back to the software industry the old saying, if a thing called together all walks like a duck, then it is a duck . From this perspective, the realization of autonomy is just to make things look the same as before. This is not significant, and this autonomy is difficult to be recognized. Of course, if the performance of the original system can be improved, it is another matter. This is optimization and improvement, not the same thing as we discussed.

  • Therefore, domestic independent OS must be based on Linux like Android, but the routine is completely different from Android. For example, like Meego and Tizen. Either expand the Android OS, engage in an H5 OS or something.

  • Finally, if you abandon Linux, you can refer to Google's Fuchsia, which is said to be a new microkernel OS architecture. However, the future of this OS is not clear. OS has never been a pure software affair, it also involves a large number of hardware manufacturers. They are even a life and death decision maker for OS.

"In-depth understanding of Android ART" promotion

Add a promotion for the book "In-depth understanding of Android ART". This book is by far the hardest book I have spent the most time on. There are several impressive memories:

  • The time span was as long as three years, and I was very lonely. Fortunately, I was accompanied by several reviewers.

  • I wanted to give up countless times in the middle. I didn't sign a contract anyway, and didn't promise anything, and few people even knew I was doing it. Give up and give up. Fortunately, I persisted.

  • The dex2oat chapter has been written to more than 100 pages, it is really impossible to write. Because I found that if you don't understand the compilation technology, you can't play it later. So I can only temporarily put down dex2oat, spent more than 8 months researching the compilation technology, finished the sixth chapter, and then gradually completed the subsequent chapters.

By the way, this "in-depth understanding of Android series" is used as a publicity. Eight years of Android journey, the authors of nine books are all striving for perfection and have made solid and visible efforts for the everlasting foundation. Thank you for your recognition.

640?wx_fmt=jpeg

Next step

After opening the official account, I got the attention of many friends, so I really want to give back to everyone. I plan to work with the publisher to sign and send the book "In-depth Understanding of Android ART". Winners can tell me what they have to say, and I personally write it in the book and express it to you. Those who don’t charge for express delivery can point to me by advertising. My handwriting is ugly, please don't dislike it smiley_13.png.

Essence Article

We teach Shen Nong Rikkyo three cornerstones of the article , more than content to teach any specific technical knowledge must have long-term value , they are:

  1. What is the goal of "in-depth understanding"?

  2. Three ultimate questions about Android learning

  3. One specialization, multiple abilities, deliberate practice and lifelong growth

last of the last

  • The result I expect is not what my friends have learned from my books, articles, and blogs, and what they have done, but rather, Shennong, I can step on your shoulders.

  • I have finished discussing the issue of learning. The following public account will learn and share some basic technologies and new technologies. Your contributions are also welcome. However, as I said in the "Contact Information" of the public account-Zheng Yuanjie has a sentence in the fairy tale King "Wisdom Teeth" that impressed me, to the effect that "I have the right to remain silent, but every word you say is May become my source of inspiration". Therefore, the impact is not one-way, it is possible that I learned more from you.

640?wx_fmt=jpeg

Collection of essays by Shennong and his friends

Long press to identify the QR code and follow us

Guess you like

Origin blog.csdn.net/Innost/article/details/93558200