Android from hardware to application: Step-by-step 5--Add hardware services at the frameworks layer

Source: Internet
Author: User

Android Frameworks layer provides hardware services, Android system app can call these hardware services, so as to complete the hardware control, to achieve the desired function. Next, this article provides the Java Interface Hardware service for the application on the frameworks layer. CD to Frameworks/base/core/java/android/os directory, add Igpioservice.aidl:

Package Android.os;  Interface Igpioservice {  void setval (int val);  int Getval ();  }  
We go through the setval to set the led to light out, Getval has been omitted

Open the android.mk under Frameworks/base, modify the Local_src_files, add:

CORE/JAVA/ANDROID/OS/IGPIOSERVICE.AIDL \
Compile Igpioservice.aidl Interface: (under the premise of successfully compiling source code)

Mmm frameworks/base

Generated:

install:out/target/product/generic/system/framework/framework.odexinstall:out/target/product/generic/system/ Framework/framework.jar
After successful CD to Frameworks/base/services/java/com/android/server directory, add Gpioservice.java file:

Package com.android.server;  Import Android.content.Context;  Import Android.os.IGpioService;  Import Android.util.Slog;  public class Gpioservice extends Igpioservice.stub {  private static final String TAG = "Gpioservice";  Gpioservice () {      init_native ();  }  public void Setval (int val) {      setval_native (val);  }     public int getval () {      return getval_native ();  }    private static native Boolean init_native ();  private static native void setval_native (int val);  private static native int getval_native ();  };  
Modify the Systemserver.java file in the current directory to add Gpioservice in Serverthread::run:

            try {                slog.i (TAG, "Recognition Service");                Recognition = new Recognitionmanagerservice (context);            } catch (Throwable e) {                reportwtf ("Starting recognition Service", e);            }            try {                slog.i (TAG, "Diskstats Service");                Servicemanager.addservice ("Diskstats", new Diskstatsservice (context));            catch (Throwable e) {                reportwtf ("Starting Diskstats Service", e);            }            try {                slog.i (TAG, "Gpio Service");                Servicemanager.addservice ("Gpio", New Gpioservice ());            } catch (Throwable e) {                slog.e (TAG, "Failure starting Gpio Service", e);            }
Compile Gpioservice:

Mmm Frameworks/base/services/java

Generated:

install:out/target/product/generic/system/framework/services.odexinstall:out/target/product/generic/system/ Framework/services.jar
The frameworks layer already contains the hardware services we write, and the applications can access the hardware services through these Java interfaces.

Android from hardware to application: Step-by-step 5--Add hardware services at the frameworks layer

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.