Add a system service for Android

Source: Internet
Author: User

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

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.