Android SystemService的启动流程
2016-05-16 20:39
393 查看
SystemServer.java(由init进程起来)之后会调用:
startService() 方法:
publishBinderService():
//authenticate()为什么要用mhander.post 调用startAuthentication()方法,不可以直接调用
mHandler.post(new Runnable() {
@Override
public void run() {
startAuthentication(token, opId, effectiveGroupId, receiver, flags, restricted);
}
});
mSystemServiceManager.startService(FingerprintService.class);
startService() 方法:
public <T extends SystemService> T startService(Class<T> serviceClass) { final String name = serviceClass.getName(); Slog.i(TAG, "Starting " + name); // Create the service. if (!SystemService.class.isAssignableFrom(serviceClass)) { throw new RuntimeException("Failed to create " + name + ": service must extend " + SystemService.class.getName()); } final T service; try { Constructor<T> constructor = serviceClass.getConstructor(Context.class); service = constructor.newInstance(mContext); } catch (InstantiationException ex) { throw new RuntimeException("Failed to create service " + name + ": service could not be instantiated", ex); } catch (IllegalAccessException ex) { throw new RuntimeException("Failed to create service " + name + ": service must have a public constructor with a Context argument", ex); } catch (NoSuchMethodException ex) { throw new RuntimeException("Failed to create service " + name + ": service must have a public constructor with a Context argument", ex); } catch (InvocationTargetException ex) { throw new RuntimeException("Failed to create service " + name + ": service constructor threw an exception", ex); } // Register it. mServices.add(service); // Start it. try { <strong><span style="font-size:24px;">service.onStart();//很关键的方法,会把自己添加到SystemManager中</span></strong> } catch (RuntimeException ex) { throw new RuntimeException("Failed to start service " + name + ": onStart threw an exception", ex); } return service; }onStart():
@Override public void onStart() { publishBinderService(Context.FINGERPRINT_SERVICE, new FingerprintServiceWrapper()); IFingerprintDaemon daemon = getFingerprintDaemon(); if (DEBUG) Slog.v(TAG, "Fingerprint HAL id: " + mHalDeviceId); listenForUserSwitches(); }
publishBinderService():
/** * Publish the service so it is accessible to other services and apps. */ protected final void publishBinderService(String name, IBinder service, boolean allowIsolated) { ServiceManager.addService(name, service, allowIsolated); }
//authenticate()为什么要用mhander.post 调用startAuthentication()方法,不可以直接调用
mHandler.post(new Runnable() {
@Override
public void run() {
startAuthentication(token, opId, effectiveGroupId, receiver, flags, restricted);
}
});
相关文章推荐
- Android视图状态及重绘流程分析,带你一步步深入了解View(三)
- Android视图绘制流程完全解析,带你一步步深入了解View(二)
- Android studio常用快捷键
- Android studio 没有SDK location设置选项
- Android LayoutInflater原理分析,带你一步步深入了解View(一)
- ubuntu安装android studio时出错unable to run mksdcard sdk tool的解决方法
- Android基础——IntentService
- Android开发指南——绑定Service
- Android开发指南——进程间通信AIDL
- 我的Android进阶之旅------>RxJava学习资料汇总
- AndroidManifest.xml配置文件详解
- Android小知识点速记
- Android开发指南——Service
- Retrofit分析-漂亮的解耦套路
- android学习之路---java部分 I/O流
- Android基础——广播接收者BroadcastReceiver
- Android Studio常用快捷键
- Android基础——AsyncTask
- Android 支付宝API使用流程(一)
- Android基础——Service