1. 在SystemServer.java启动流程中,有如下代码:
到此,Telecom服务已经启动完成并注册
mSystemServiceManager.startService(TelecomLoaderService.class);
2.在TelecomLoaderService.java中,开机过程,onBootPhase函数将会被调用:
<pre name="code" class="java"> @Override
public 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 service
if (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>@Override
public 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() {
@Override
public void binderDied() {
connectToTelecom();
}
}, 0);
ServiceManager.addService(Context.TELECOM_SERVICE, service);
} catch (RemoteException e) {
Slog.w(TAG, "Failed linking to death.");
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
connectToTelecom();
}
到此,Telecom服务已经启动完成并注册