添加一个系统service
来源:互联网 发布:linux 查arp 编辑:程序博客网 时间:2024/05/22 13:00
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;
msg.arg1 = val;
mHandler.sendMessage(msg);
}
private class EneaWorkerThread extends Thread{
public EneaWorkerThread(String name) {
super(name);
}
public void run() {
Looper.prepare();
mHandler = new EneaWorkerHandler();
Looper.loop();
}
}
private class EneaWorkerHandler extends Handler {
private static final int MESSAGE_SET = 0;
@Override
public void handleMessage(Message msg) {
try {
if (msg.what == MESSAGE_SET) {
Log.i(TAG, "set message received: " + msg.arg1);
}
} catch (Exception e) {
// Log, don't crash!
Log.e(TAG, "Exception in EneaWorkerHandler.handleMessage:", e);
}
}
}
}
Add to the system server
services/java/com/android/server/SystemServer.java
try {
Log.i(TAG, "Enea Service");
ServiceManager.addService(Context. ENEA_SERVICE, new EneaService(context));
} catch (Throwable e) {
Log.e(TAG, "Failure starting Enea Service", e);
}
Add a constant value to Context
./core/java/android/content/Context.java
public static final String ENEA_SERVICE = "enea";
最后
make update-api
make
分析IBinder体系中getService的流程
http://hi.baidu.com/liuhuman/blog/item/1e3071d940c9002010df9b6c.html
添加一个系统service
http://xxw8393.blog.163.com/blog/static/3725683420105223209275/
http://blog.csdn.net/dotphoenix/article/details/6332559
remoteservice code
http://download.csdn.net/download/listening_music/3751349
remoteservice 深入分析
http://blog.csdn.net/maxleng/article/details/5504485/
- 添加一个系统service
- Android添加一个系统service
- 添加一个系统服务sytem service
- android 5.1 如何添加一个系统service
- Android系统添加一个自己的service
- Android添加系统service
- 如何添加一个Native Service
- Android添加一个Native Service
- Android添加一个Native Service
- Android让一个Service成为系统Service
- 自己添加一个系统调用
- linux 添加一个系统调用
- 如何增加一个系统服务service
- Android系统开发之七:添加Android Native Service方法
- 添加nginx为系统服务(service nginx start/stop/restart)
- 添加通知栏,使得service不被系统回收
- android系统添加service与android层次分析
- 添加nginx为系统服务(service nginx start/stop/restart)
- XFD6410 uboot支持DM9000驱动
- Drools 规则语言详解(上)
- hi test
- Linux系统信息查看命令大全
- 获取IP地址
- 添加一个系统service
- java把一个文件转化为byte字节
- 关于 重写 printf
- Android学习之Sharedpreference保存
- 年终奖之痛在于隐性剥夺
- 打印系统日志(使用API)(转)
- firebird中文字符集问题 malformed string问题
- windows脚本学习中文手册的在线手册
- FreeMediaType与DeleteMediaType