在framework添加system service

在Context.java添加服务名称

1
2
3
4
5
6
7
//--->frameworks/base/core/java/android/content/Context.java
public static final String THREEKEY_SERVICE = "threekey";

@StringDef {
...
THREEKEY_SERVICE
}

在SystemServicer注册服务

1
2
3
4
5
6
//--->frameworks/base/services/java/com/android/server/SystemServer.java
private void startOtherServices() {
...
ServiceManager.addService("ThreeKeyService", new ThreeKeyService);
...
}

在ContextImpl.java添加获取服务管理接口

1
2
3
4
5
6
7
8
9
10
//--->frameworks/base/core/java/android/app/ContextImpl.java
static {
....
registerService(Context.THREEKEY_SERVICE,ThreeKeyManager.class,
new CachedServiceFetcher<ThreeKeyManager>() {
@Override
public ThreeKeyManager createService(ContextImpl ctx) {
return new ThreeKeyManager(ctx);
}});
}

Service的aidl

1
2
3
interface IThreeKeyExService {

}

Service 本体

1
2
3
public class ThreeKeyService extends IThreeKeyService.Stub {

}

Manager

1
2
3
4
5
6
7
8
9
10
11
12
public class ThreeKeyManager {
public ThreeKeyManager(Context context) {

}

static public IThreeKeyService getService()
{
IBinder b = ServiceManager.getService("notification");
return IThreeKeyService.Stub.asInterface(b);
}

}