Description: This document describes how to compile and implement the system-level (Java) service and call for Android. 1. Add a java system-level service: There are many introductions on the website, but there are no detailed steps and procedures. The following is a summary: Taking alarmmanagerservice as an example, the Java layer service is a service provided from the Java layer as its name implies, unlike the service on the C ++ layer, the service process is maintained by the system (servicemanager. In the frameworks/base/services/Java/COM/Android/Server/systemserver. Java file, we can see the following: Code : Alarmmanagerservice alarm = new alarmmanagerservice (context); servicemanager. addservice (context. alarm_service, alarm); this operation is completed when the system is started. servicemanager is responsible for creating and running service processes. Ialarmmanager in the/frameworks/base/CORE/Java directory. aidl file. in the aidl implementation class of alarmmanagerservice in the directory frameworks/base/services/Java/COM/Android/server, add the service implementation file to the directory frameworks/base/services/Java/COM/Android/server. II. to add a java system-level service, perform the following steps: 1. add the aidl file to the directory/frameworks/base/CORE/Java/Android/APP and add idvbservice. aidl. package android. APP; interface idvbservice {int counttest (in int testvalue);} 2. in the directory frameworks/base/services/J Add dvbmanagerservice to Ava/COM/Android/server to implement idvbservice. aidl package COM. android. server; import android. content. context; import android. util. slog; import android. app. idvbservice; Class dvbmanagerservice extends idvbservice. stub {Private Static final string tag = "dvbmanagerservice"; Private Static final Boolean locallogv = false; private final context mcontext; Public dvbmanagerservice (context contex T) {super (); mcontext = context; slog. W (TAG, "dvbmanagerservice");} public int counttest (INT value) {return value * 2 ;}} 3. in the file frameworks/base/services/Java/COM/Android/Server/systemserver. add slog to the run () method in the Java class. I (TAG, "alarm dvbmanagerservice"); dvbmanagerservice DVB = new dvbmanagerservice (context); // DVB slog. I (TAG, "alarm dvbmanagerservice DVB =" + DVB); servicemanager. addservice (Context. Dvb_service, DVB); 4. in the file/frameworks/base/CORE/Java/Android/content/context. add public static final string dvb_service = "DVB"; // dvb5. add dvbmanager to the file/frameworks/base/CORE/Java/Android/app. javapackage android. APP; import android. content. context; import android. content. intent; import android. OS. remoteException; import android. OS. servicemanager; public class dvbmanager {// DVB private final idvbservice Mservice;/*** package private on purpose */dvbmanager (idvbservice Service) {mservice = service;} public int count (INT value) {try {return mservice. counttest (value);} catch (RemoteException ex) {} return-1 ;}} 6. in the file/frameworks/base/CORE/Java/Android/APP/contextimpl. add the Private Static dvbmanager sdvbmanager attribute in Java; // Add else if (dvb_service.equals (name) in getsystemservice (string name )){/ /DVB return getdvbmanager ();} added the private dvbmanager getdvbmanager () {// DVB log. E (TAG, "getdvbmanager ssync =" + ssync); log. E (TAG, "getdvbmanager sdvbmanager =" + sdvbmanager); synchronized (ssync) {If (sdvbmanager = NULL) {ibinder B = servicemanager. getservice (dvb_service); log. E (TAG, "getdvbmanager ibinder =" + B); idvbservice service = idvbservice. stub. asinterface (B); log. E (TAG, "getdvbman Ager idvbservice = "+ service); sdvbmanager = new dvbmanager (service) ;}return sdvbmanager;} 7. in/frameworks/base/android. add Core/Java/Android/APP/idvbservice under local_src_files + = \ In MK. aidl \ 8. the application calls the following: Import android. app. dvbmanager; usage: dvbmanager DVB = (dvbmanager) getsystemservice (dvb_service); int COUNT = DVB. count (9); toast. maketext (tvmainactivity. this, "DVB. count (9) Back = "+ count, toast. length_sh ORT ). show (); 9. compile as follows: (1) Compile frameworks first. build/envsetup. sh choosecombo make-J4 framework will generate framework after compilation. jar (2) then compile servicemake-J4 frameworks/base/services/Java of frameworks/services/Java to generate services. jar (3) Compile the application because the service is customized, all must be compiled in the Custom SDK for use.