Android Drive Learning-app call kernel driver process (Driver Framework Review)

Source: Internet
Author: User

After the examination has passed, Android-driven learning has been broken for more than half a year, and now pick up learning, review the general framework of Android Drive.

The core of the Android system is Java, which has a David virtual machine. Android-app operating hardware is also equivalent to Java operating hardware.

Operating hardware on a Linux system is implemented via open read Write, which is the operation of C libraries. If Java can directly invoke the function in C library, it will solve the problem of the app operating hardware.

The following article is a method for Java to call the C + + library.

1. Method 1--jni call the underlying driver

Writing to C + + in the Android framework directly calls the underlying Linux driver and provides the JNI interface up to the application:

Advantages: simple;

Disadvantage: Mainly in the driver, because in Linux need to follow the GPL protocol, need to open source, and many vendors of some code do not want to open source.

and devices like screens may require multiple apps to operate simultaneously, which can lead to a variety of problems.

2. Method 2--Add Hardware abstraction Layer

Split the driver into split, part open source in kernel, part not open source in Android frame:

Second, for example led Android drive:

From here we will see the direction of the entire application framework layer to the underlying drive. First, either way, we need to implement a Linux driver for the upper layer to access the LED resources.

It is also the use of JNI to load C library, so that by calling open and so on to achieve the operation of the hardware. Android in order to implement multiple apps can operate the same hardware, the hardware is not directly operated by the app, but with Systemserver to operate. The app needs to send the request through ServiceManager to Systemserver, and the Systemserver finally completes the operation of the hardware.

Here we turn to the process of an app operating hardware:

1, the app needs to apply for service and obtain service GetService.

And this service is done with interfaces. So the first step is to create an aidl file to generate the interface class.

Frameworks/base/core/java/android/os/iledservice.aidl

Also modify FRAMEWORKS/BASE/ANDROID.MK to add the new Aidl file.

2. Automatically generate Iledservice.java

Mmm frameworks/base/

Compile auto-Build

Out/target/common/obj/java_libraries/framework_intermediates/src/core/java/android/os/iledservice.java

Iledservice.java file obtained, now need to create a corresponding Java file, implementation of Java under the hardware operation function.

3. Create Ledservice.java to implement interface functions

After Ledservice.java is created, it is placed in frameworks/base/services/core/java/com/android/server/, and its upper android.mk automatically contains this Java file.

4. Registering Services with Service Manager

Modify Frameworks/base/services/java/com/android/server/systemserver.java

In this case, the app will be able to access the service, thus realizing the communication to the Systemserver, thus realizing the operation of the hardware. Now it is necessary to modify the Systemserver.

Systemserver is also a JNI for hardware operations, so it also needs to load C + + libraries. All of the JNI files for hardware operations have been packaged as a. So library in the Android system, so what we need to do is add our hardware support to the so library.

5. Realize Com_android_server_ledservice.cpp

Place the Jni file in the frameworks/base/services/core/jni/directory. Also register the native interface and modify it in the frameworks/base/services/core/jni/onload.cpp.

and modify the Android.mk file, add the Com_android_server_ledservice.cpp compilation.

In fact, it has almost achieved the operation of the hardware, because we implemented the CPP file calls and packaged into the system, CPP file can directly load C library, call Open and other functions to implement the operation of the hardware.

But there's a problem with that if the driver is a bit of a problem, we need to modify the Com_android_server_ledservice.cpp and recompile the system and write the system. This is not very convenient. We can then introduce the hardware abstraction layer (HAL), which is more conducive to building the entire system.

Android Drive Learning-app call kernel driver process (Driver Framework Review)

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.