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