Specifying the interface.
This example uses aidl, so the first step is to add an Interface
Definition
File:
Frameworks/base/CORE/Java/Android/OS/ieneaservice. aidl
Package Android. OS;
Interface ieneaservice {
/**
* {@ Hide}
*/
Void setvalue (INT Val );
}
The interface file will need to be added to the build system:
Frameworks/base/Android. mk
Add the following around line 165 (the end of the list
Src_files ):
Core/Java/Android/OS/ieneaservice. aidl
Implementing the server
The service spawns a worker thread that will do all the work,
Part
The system server process. Since the service is created by the System
Server, it
Will need to be located somewhere where the system server can find it.
Frameworks/base/services/Java/COM/Android/Server/eneaservice. Java
Package com. Android. server;
Import Android. content. context;
Import Android. OS. Handler;
Import Android. OS. ieneaservice;
Import Android. OS. logoff;
Import Android. OS. message;
Import Android. OS. process;
Import Android. util. log;
Public class eneaservice extends ieneaservice. Stub {
Private Static final string tag = "eneaservice ";
Private eneaworkerthread mworker;
Private eneaworkerhandler mhandler;
Private context mcontext;
Public eneaservice (context ){
Super ();
Mcontext = context;
Mworker = new eneaworkerthread ("eneaserviceworker ");
Mworker. Start ();
Log. I (TAG, "spawned worker thread ");
}
Public void setvalue (INT Val)
{
Log. I (TAG, "setvalue" + val );
Message MSG = message. Obtain ();
MSG. What = eneaworkerhandler. message_set;
Page 1
Page 1