您的位置:首页 > 移动开发 > Android开发

android 5.1 TelecomService启动过程

2016-01-19 10:23 375 查看
1. 在SystemServer.java启动流程中,有如下代码:
mSystemServiceManager.startService(TelecomLoaderService.class);
2.在TelecomLoaderService.java中,开机过程,onBootPhase函数将会被调用:
<pre name="code" class="java">    @Overridepublic void onBootPhase(int phase) {if (phase == PHASE_ACTIVITY_MANAGER_READY) {connectToTelecom();}}private void connectToTelecom() {if (mServiceConnection != null) {// TODO: Is unbinding worth doing or wait for system to rebind?mContext.unbindService(mServiceConnection);mServiceConnection = null;}TelecomServiceConnection serviceConnection = new TelecomServiceConnection();Intent intent = new Intent(SERVICE_ACTION);intent.setComponent(SERVICE_COMPONENT);int flags = Context.BIND_IMPORTANT | Context.BIND_AUTO_CREATE;// Bind to Telecom and register the serviceif (mContext.bindServiceAsUser(intent, serviceConnection, flags, UserHandle.OWNER)) {mServiceConnection = serviceConnection;}}
 
bind绑定到Telecom服务,并在<span style="font-family: Arial, Helvetica, sans-serif;">ServiceManager</span><span style="font-family: Arial, Helvetica, sans-serif;">中注册Telecom服务,方便调用:</span><pre name="code" class="java">        
<span style="white-space:pre">	</span>@Overridepublic void onServiceConnected(ComponentName name, IBinder service) {// Normally, we would listen for death here, but since telecom runs in the same process// as this loader (process="system") thats redundant here.try {service.linkToDeath(new IBinder.DeathRecipient() {@Overridepublic void binderDied() {connectToTelecom();}}, 0);ServiceManager.addService(Context.TELECOM_SERVICE, service);} catch (RemoteException e) {Slog.w(TAG, "Failed linking to death.");}}@Overridepublic void onServiceDisconnected(ComponentName name) {connectToTelecom();}
到此,Telecom服务已经启动完成并注册

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  TelecomService Telecom