Android添加一个系统service

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 of SRC_FILES):

  core/java/android/os/IEneaService.aidl

  Implementing the server

  The service spawns a worker thread that will do all the work, as part of 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.Looper;

  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 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;

第1页  第2页

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值