Android framework and several call processes.

Source: Internet
Author: User

-- Extract some of the chapters in a book to help you understand the architecture of the entire android system .)

1.1.1 Android system architecture
To learn more about Android, you must first learn the Android system architecture. The architecture of Android is the same as that of its operating system,

The layered architecture is adopted, and the hierarchy is very clear. Therefore, it is not difficult to grasp its architecture. For the Android system architecture, if

You are familiar with the graph and understand the architecture shown in the graph. You can skip this section (or browse it quickly). If

This is the first time you see this image. I suggest you read this part in detail, because the entire book is based on this image. We will

Each module in the figure is analyzed in detail, so that you can understand the technical details of Android.


Android is divided into five layers: Application Layer (applications), application framework layer (Application Framework ),

System Runtime Library layer (libraries and Android runtime) and Linux kernel layer (Linux kernel ). Next, let's look at each layer as ours.

What functions are provided and how to use these functions.

1. Application Layer
Android will be released with the core application package. The package includes the home, e-mail client, and,

SMS/MMS Short Message programs, calendars, maps, browsers, and contact management programs. All applications are written in Java.

Call the APIS provided by the application framework. Of course, you can also use Java through JNI,

Using Android ndk to develop Native applications can improve application efficiency, but the difficulty is also greatly increased-you need to be proficient in C and

C ++ and other languages, and have a deep understanding of the few functions provided by Android ndk. Because Android ndk does not provide many functions,

To prevent you from discovering that ndk does not support a function after a long time, you can choose whether to develop Native programs based on your needs.

2. Application Framework Layer
The application framework layer provides developers with an API framework for full access to core applications. The architecture design of this application simplifies the group

Component Reuse. Any application (and any other application) can publish its own functional modules (subject to the security restrictions of the Framework ).

Similarly, this application reuse mechanism allows users to easily replace program components. Next, let's take a look at the components provided by each module at this layer,

See Table 1-1.

3. System runtime database layer
The system Runtime Library layer consists of the library and the android Runtime Library. The following describes the two parts respectively.
(1) Library
Android contains some C/C ++ libraries that can be used by different components in the Android system. They provide services to developers through the application framework,

Table 1-2 describes the functions of these core databases.

 

(2) Android Runtime Library
As shown in figure 1, the android Runtime Library is divided into the core library and the Dalvik virtual machine. The core library provides most of the functions of the core library of the Java language,

Here, we mainly use JNI to provide interfaces for calling the underlying Library to the application framework layer. The Dalvik virtual machine is implemented to run multiple VMS at the same time.

Dalvik virtual machine executes the Dalvik executable file of. Dex. The files in this format are optimized for the minimum memory usage. The Dalvik virtual machine is register-based and all classes are

Compiled by Java assembler, and then converted to. Dex format by using the DX tool in the SDK and executed by the virtual machine. The Dalvik virtual machine depends on some Linux functions, such as the thread mechanism.

And the underlying memory management mechanism. Every android application runs in its own process and has an independent Dalvik Virtual Machine instance. For this part,

This section briefly introduces the android SDK toolkit and the Dalvik virtual machine.
4. Linux kernel layer
Android depends on the core system services provided by the Linux 2.6 kernel, such as security, memory management, process management, network stack, and driver modules. Kernel as a pumping

The image layer exists between the software stack layer and the hardware layer. Android enhances the kernel in the following aspects:

Here, our analysis of the Android system architecture has come to an end. Now you should at least understand the architecture of the entire android system and

Modules to lay the foundation for further study. How is the Android system started? What do I need to initialize during the startup process?

If you do not know (or do not fully know) The answer to these questions, do not worry, the next section will analyze the initialization operations when the Android system starts.

1.1.2 Android initialization process
The previous section analyzes the Android system architecture and gives you an in-depth understanding of the Android system. However, the android system is very

Large. Before in-depth analysis of the specific functions of each module, it is necessary to analyze the startup process. We need to know that such a huge system is being started

Which initialization operations need to be performed. When the Android system is started, it will first start the basic Linux system, then boot the Linux kernel and

Start the initialization process (init), as shown in 1-1.

Then, start the Linux daemons ). In this process, you must start the following content, as shown in 1-2.
Start the USB daemon (usbd) to manage the USB connection.
Start the android debug bridge daemon (adbd) to manage the ADB connection.
Run the debug daemon (debugadh) to manage the debugging process requests (including memory conversion and so on ).
Initiate the wireless interface daemon (rild) to manage wireless communication.

Start the zygote process while starting the Linux daemon, as shown in figure 1-3. It mainly includes the following content that needs to be started and registered:
Initialize a Dalvik Virtual Machine instance.
Classes and listeners required for loading socket requests.
Processes that manage applications by creating Virtual Machine instances.

Next, you need to initialize the runtime process. The initialization process is 1-4. In this process, you need to handle the following operations:
Initialize the Service Manager.
Register the Service Manager as the context manager of the default binder service.

After the runtime process is initialized, the runtime process sends a request to zygote to start the system service. Then, zygote creates

Create a virtual machine instance and start system services, as shown in figure 1-5.

Then, the system service will start native system services, including surface flinger and audio flinger. These local system services will be registered to the service

Service Manager is the target of the IPC service, as shown in figure 1-6.

The system service starts the android Management Service, and the android Management Service is registered to the Service Manager, as shown in 1-7.

Finally, after the system loads all services, it will be in the waiting state and wait for the program to run. However, each application starts

A separate process. As shown in figure 1-8, the system starts a home process and a contacts process. Then, how do processes perform?

What about interaction? This requires the IPC Mechanism, which will be detailed later.

By now, the entire startup process of the system is over. You can run the application on it. You should also start the Android system

Each step has a deep understanding. In fact, this startup process is to load and

Register with the application framework layer and finally run our own application at the application layer. So what is the relationship between different levels? Application

How does a program call the underlying core service at the top? The next section analyzes the relationships between different layers.

1.1.3 relationship between different levels
The previous section describes the Startup Process of the Android system. This section describes how Android applications call the underlying hardware and

Service. If you do not have in-depth understanding of the content in the previous section, you can go back and read it carefully so that you can better understand the content in this section.

Okay. I believe you are ready. Let's get started. Applications running on Android are implemented in three ways:
‰ App → runtime service → lib
‰ App → runtime service → native service → lib
‰ App → runtime service → native daemon → lib
The following three methods are analyzed separately. We will use a flowchart to show them.
The flowchart 1-9 corresponding to the app → runtime service → lib method is shown.

From Figure 1-9, we can see that on the Android platform, the application first calls the application framework through the binder IPC at the application layer.

Runtime service of the layer, then bind with the native service in the Runtime Library through JNI, dynamically load the Hal library, and then call the Linux kernel layer

. For better understanding, we use a location manager to analyze the process, as shown in 1-10.

The above is the call process of the first method. Next, let's look at the second method (APP → runtime service → native service → Lib)

Is called. This method is usually used by Android native services. Let's take a look at the call flowchart, as shown in 1-11.

Figure 1-11 shows the call process of the android native service. It can be seen that, compared with the first method, only one more method is used to call the original

The process of generating services and performing dynamic loading. Therefore, we will not repeat it here, but we will give an example of audio, as shown in 1-12.

As shown in figure 1-12, the application calls the mediaplayer at the application framework layer, and then calls the mediaplaye at the system Runtime Library layer. Mediaplaye

Media framework and audioflinger are called respectively, and then the specified library (libaudio. So) is called through audioflinger, and then the kernel driver is called.

Next let's take a look at the last method "app → runtime service → native daemon → lib", as shown in 1-13. This method is usually used for daemon connection.

As shown in figure 1-13, this method is simpler than calling native services. It directly binds native services through JNI and then uses sockets to call the daemon process for dynamic loading.

The following is a simple example. Telephony Manager is called as a native daemon. The process is 1-14.

The call process is very simple. I believe that figure 1-14 is clear enough.
1.1.4 Android system development (transplantation) and application development
Through the previous study, we learned that android is a huge and complete system. What development work can we do based on Android?

What is the difference between each development task? What are the differences between technologies that need to be mastered in different development work? After learning the content of this section, you will know what to do

Use android to develop your desired products. Because Android is an open-source operating system, the following two development methods are available:
Android system development (transplantation)
‰ Android Application Development
1. Android system development (porting)
Android system development (transplantation) is the underlying development work. It mainly improves and migrates the Android system to other hardware platforms,

Therefore, you must master the Linux kernel layer and system Runtime Library layer in the Android system architecture, as shown in figure 1-15. Android system development mainly involves Libraries

And Android runtime. Generally, C/C ++ code is written locally, and the calling interface is provided through the JNI upstream layer, mainly for applications.

Develop and provide services. The Android system porting mainly involves the hardware abstraction layer and the Linux kernel layer. The main task of porting the driver to different hardware is,

So that it can run the Android system perfectly. These drivers mainly include device drivers and Android drivers.

Whether it is system development or system transplantation, the source code of Android is directly operated at the underlying layer. Therefore, before development, we must first prepare the source code of Android.

The next section describes how to obtain and compile the andorid source code and the structure of the android source code.
2. Android Application Development
Android Application development mainly writes various applications based on the APIS provided by the Android system. The APIs used belong to the Android Application Framework layer,

1-16. If the Android system does not provide some APIs, you can only write C/C ++ code at the underlying layer of the Android system to develop these APIs and

The Android Application Framework layer provides interfaces. However, I do not recommend this because it may cause incompatibility between your application and Other Android systems.

The applications we developed are running at the same level as those at the application layer. Therefore, we would like to remind you that you must follow these steps when developing applications.

Android API framework to avoid incompatibility between developed applications. In addition, application development belongs to upper-layer development and does not need to be exposed to the underlying C/C ++ code,

Therefore, before development, we only need to prepare the android SDK and simulator (of course, you may also need to use an IDE, and eclipse is recommended ).

Finally, the android SDK can be obtained by compiling the source code or download the compiled SDK from the official website of Android. The following describes how to compile

Source code to obtain the android SDK, as well as the SDK structure and development kit.

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.