因需要开机启动一个service,使用接受开机广播的模式发现不管什么权限都要延时一段时间才能启动。在系统中自定义一个广播开机时发送,竟然也不行。
看了下SystemServer.java文件发现其中启动systemUI故直接开机时启动service
修改SystemServer.java
try {
startSystemUi(context, windowManagerF);
//begin
starttestMenu(context);
// end
} catch (Throwable e) {
reportWtf("starting System UI", e);
}
static final void starttestMenu(Context context){
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.src.test",
"com.src.test.service.testService"));
intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
//Slog.d(TAG, "Starting service: " + intent);
context.startServiceAsUser(intent, UserHandle.SYSTEM);
}