This answer is to the point on how to add a system service in android: https://stackoverflow.com/a/7434249/1993710
However, i am too lazy to wait for hours each time the android makesystem builds my stuff, so i deploy my service through android-studio as a regular apk into /system/app and then inside an app that is supposed to use the service i do:
private ServiceConnection myAidlConnection = new ServiceConnection(){
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
// do stuff
}
}
public void bindService(Context context){
Intent intent = new Intent();
intent.setClassName("my.service","my.service.Service");
intent.setAction("my.service.TOAST");
intent.putExtra("text", "stulle");
context.bindService(intent, myAidlConnection, Context.BIND_AUTO_CREATE);
}
This works fine, as long as that app is also a system apk. If it's not a system apk, myAidlConnection.onServiceConnected is just never called. I suppose that's some sort of security thing so you can't bind arbitrary system services from non-privileged apps.
Is there any way to allow my system service to be bound by anyone, or does it really have to pass the binder through getSystemService()?