A good memory is better than a bad pen------button Light JNI use (upper)

Source: Internet
Author: User

The upper layer uses JNI (from the Java layer to the framework to the JNI usage process)

MTK Platform If you add a key light to the hardware, the framework layer wants to call, here is a brief introduction of my use of the process.

First, you need to add KEYLED.C and header files KeyLed.h two interface functions:

(\HARDWARE\LIBHARDWARE_LEGACY\KEY_LEDS\KEY_LEDS.C)

(\hardware\libhardware_legacy\include\hardware_legacy\keyled.h)

The next step is to write the interface up:

1, add the power to the lamp:

Go to the System/core/rootdir directory, there is a file named Ueventd.rc, add a line inside: /sys/devices/platform/key_leds/red1_leds_onoff 0666 root root /sys/devices/platform/key_leds/red2_leds_onoff 0666 root root /sys/devices/platform/key_leds/red3_leds_onoff 0666 root root

2, go to the Frameworks/base/services/jni directory and create a new com_android_server_keyledsservice.cpp file:

In the Com_android_server_keyledsservice.cpp file, implement the Jni method. Note the command method of the file, the Com_android_server prefix represents the package name, which indicates that the hardware service HelloService is placed in the Frameworks/base/services/java directory Com/android/ In the server directory, there is a class that has a command of Com.android.server.KeyLedsService. To put it simply, Keyledsservice is a hardware Access service class that provides Java interfaces.

The first is to include the corresponding header file:

The hardware access structure defined in the hardware abstraction layer,

Jni Method Table

Registering the Jni method

3, Modify the Onload.cpp file in the same directory, first add the Register_android_server_keyledsservice function declaration in namespace Android:

Namespace Android {

..............................................................................................

int Register_android_server_keyledsservice (jnienv *env);

};

Add Register_android_server_keyledsservice function call in Jni_onload: extern "C" Jint jni_onload (javavm* vm, void* reserved) {       ................................................................................................. Register_android_server_keyledsservice (env);        .................................................................................................      } This will automatically load the Jni method call table when the Android system is initialized.

4, modify the Android.mk file in the same directory, add a line to the Local_src_files variable:

Local_src_files:= ... ..... ..... ... ... ..... ..... ..... ..... ..... ..... ..... .................. Com_android_server_keyledsservice.cpp/Onload.cpp

Now that the code is compiled, the repackaged system.img image file contains the Jni method we just wrote, which is what we can do with the Android system application The frameworks layer provides the hardware service Keyledsservice to invoke these JNI methods, and then calls the lower level hardware abstraction layer interface to access the hardware.

With the rapid development of digital technology today, the perfect combination of software and hardware has created the popularity of smart mobile devices. The popularity of iOS and Android today is partly due to the variety of applications on both systems. Therefore, the relationship between software and hardware, to a certain extent, can be said that the hardware is for software services. Hardware engineers developed a hardware device that software engineers write drivers for, and the ultimate purpose of the driver is to enable top-level applications to use the services provided by these hardware to provide software functionality to the user. For the application software on the Android system, it is to provide the hardware service on the application frameworks layer of the system. The Linux kernel layer, the hardware abstraction layer, and the runtime library layer provide custom hardware service interfaces that are implemented through the C or C + + languages. Next, we will learn how to provide hardware services for the Java interface on the application frameworks layer of the Android system.

4.2,4.4,5.1 and other versions file path slightly different, here is using 4.4 version

1, increase ikeyledsmanager.aidl, (FRAMEWORK/BASE/CORE/JAVA/ANDROID/APP/IKEYLEDSMANAGER.AIDL)

Mainly defines the interface of Keyledsservice, the Ikeyledsmanager interface mainly provides the function of the device and obtains the value of the hardware register Val, which is realized by several specific functions.

2, return to the Frameworks/base directory, open the Android.mk file, modify the value of the local_src_files variable, increase the ikeyledsmanager.aidl source file:

Local_src_files + =/

....................................................................

Core/java/android/os/ivibratorservice.aidl/

Core/java/android/os/ikeyledsmanager.aidl/

Core/java/android/service/urlrenderer/iurlrendererservice.aidl/

.....................................................................

At this point, the corresponding Ikeyledsmanager.stub interface is generated based on the ikeyledsmanager.aidl .

3, Increase Keyledsmanager.java (Framework/base/core/java/android/app/keyledsmanager.java)

Keyledsmanager.java mainly provides hardware services by invoking the Jni method.

4, go to frameworks/base/services/java/com/android/server/directory, add Keyleds/keyledsservice.java file:

Keyledsservice mainly provides hardware services by invoking the Jni method.

5, modify the Systemserver.java file, add the code to load the Keyledsservice in the Serverthread::run function:

Reference Document: http://blog.csdn.net/poltroon/article/details/7978264

A good memory is better than a bad pen------button Light JNI use (upper)

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.