Android Telephone初始化流程分析

Telephone 系统框图

在这里插入图片描述
在这里插入图片描述

Tel系统中的服务

从功能方面进行区分,Tel可以分为以下几部分:
1.TelecomLoaderService。这部分主要是处理上层app的关系
2.TelephonyRegistry。这部分主要是处理Phone状态的通知。
3.PhoneAPP 这部分是系统core app
4.lib库
4.1 libril.so的作用
这个库的作用有如下:
1.接受来自framework中的socket,建立连接之后,等待framework发送消息过来
2.接收到framework中的消息之后,分析,之后调用libreference-ril的接口进行查询
3.接受到libreference-ril中的response之后反馈给framework
这个文件是一个中间层,能够操作event list
4.2 libreference-ril.so
这个库的作用有
1.打开与驱动的socket,用来与moden进行通讯
2.接收来自libril.so的请求
3.将libril中的请求通过socket发送给底层moden
4.把底层moden的response反馈给libril.so
下面对前三部分进行分析

各个服务的启动

在Android中,系统服务的起点都是从SystemServer中启动的。Tel的服务也不例外。

private void run() {
    
	try {
    
    	startBootstrapServices();
        startCoreServices();
        startOtherServices();
    } catch (Throwable ex) {
    
    }
}

在Android中系统中的服务是按照上面的顺序启动的。Tel的服务是在startOtherServices中进行初始化和启动的。
下面看一下Tel的服务是如何初始化和启动的。

private void startBootstrapServices() {
    
mSystemServiceManager.startBootPhase(SystemService.PHASE_WAIT_FOR_DEFAULT_DISPLAY);
}
private void startOtherServices() {
    
...
	mSystemServiceManager.startService(TelecomLoaderService.class);
	Slog.i(TAG, "Telephony Registry");
    telephonyRegistry = new TelephonyRegistry(context);
    ServiceManager.addService("telephony.registry", telephonyRegistry);
...
	mSystemServiceManager.startBootPhase(SystemService.PHASE_LOCK_SETTINGS_READY);
	mSystemServiceManager.startBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
...
	mSystemServiceManager.startBootPhase(SystemService.PHASE_THIRD_PARTY_APPS_CAN_START);
...
	mActivityManagerService.systemReady(new Runnable() {
    
		@Override
		public void run() {
    
			Slog.i(TAG, "Making services ready");
			mSystemServiceManager.startBootPhase(
					SystemService.PHASE_ACTIVITY_MANAGER_READY);
	···
			try {
    
				if (telephonyRegistryF != null) telephonyRegistryF.systemRunning();
			} catch (Throwable e) {
    
				reportWtf("Notifying TelephonyRegistry running", e);
			}
	···
	}
}

TelecomLoaderService分析

Telecom相关启动流程

SystemServer TelecomLoa TelecomService TelecomSystem CallsManager CallIntentProcessor TelecomBroadcas TelecomServiceImpl startService PHASE_ACTIVITY_MANAGER_READY bindService initializeTelecomSystem new new new new SystemServer TelecomLoa TelecomService TelecomSystem CallsManager CallIntentProcessor TelecomBroadcas TelecomServiceImpl
public class TelecomLoaderService extends SystemService {
    
	private class TelecomServiceConnection implements ServiceConnection {
    
	
	}
	public void onBootPhase(int phase) {
    
        if (phase == PHASE_ACTIVITY_MANAGER_READY) {
    
            connectToTelecom();
        }
    }
	private void connectToTelecom() {
    
        synchronized (mLock) {
    
            //如果之前连接过,断开从新连接
            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_FOREGROUND_SERVICE
                    | Context.BIND_AUTO_CREATE;

            // Bind to Telecom and register the service
            if (mContext.bindServiceAsUser(intent, serviceConnection, flags, UserHandle.OWNER)) {
    
                mServiceConnection = serviceConnection;
            }
        }
    }
}

从上面的代码来看,TelecomLoaderService继承SystemService。当系统的ActivityManagerService启动完成之后,就bind TelecomService。
下面看一下在bind TelecomService之后又进行了什么动作

public class TelecomService extends Service implements TelecomSystem.Component {
    
    public IBinder onBind(Intent intent) {
    
        initializeTelecomSystem(this);
        synchronized (getTelecomSystem().getLock()) {
    
            return getTelecomSystem().getTelecomServiceImpl().getBinder();
        }
    }
	static void initializeTelecomSystem(Context context) {
    
		if (TelecomSystem.getInstance() == null) {
    
			TelecomSystem.setInstance(new TelecomSystem());
		}
	}
}

public final class TelecomSystem {
    
	    public TelecomSystem(
            Context context,
            MissedCallNotifier missedCallNotifier,
            CallerInfoAsyncQueryFactory callerInfoAsyncQueryFactory,
            HeadsetMediaButtonFactory headsetMediaButtonFactory,
            ProximitySensorManagerFactory proximitySensorManagerFactory,
            InCallWakeLockControllerFactory inCallWakeLockControllerFactory,
            ViceNotifier vicenotifier) {
    
   
        mCallsManager = new CallsManager();
        mCallIntentProcessor = new CallIntentProcessor(mContext, mCallsManager);
        mTelecomBroadcastIntentProcessor = new TelecomBroadcastIntentProcessor(
                mContext, mCallsManager);
        mTelecomServiceImpl = new TelecomServiceImpl(
                mContext, mCallsManager, mPhoneAccountRegistrar, mLock);
    }
}

从中可以看到,bind TelecomService之后,就开始初始化TelecomSystem。
在TelecomSystem中主要初始化了下面几个个对象:
1.CallsManager:用来处理多个通话之间的逻辑关系,以及接受CallIntentProcessor的call
2.CallIntentProcessor:用来处理CallIntent,并且调用将call 放入CallsManager中的队列中
3.TelecomBroadcastIntentProcessor:用来处理用户的操作(短信回复,从notifier中回复)
4.TelecomServiceImpl:用来处理账户信息,调用CallIntentProcessor处理intent

TelephonyRegistry的服务

上面看到只是初始化TelephonyRegistry之后调用systemRunning接口。下面看一下做了什么

    TelephonyRegistry(Context context) {
    
        CellLocation  location = CellLocation.getEmpty();

        mContext = context;
        mBatteryStats = BatteryStatsService.getService();

        int numPhones = TelephonyManager.getDefault().getPhoneCount();
        if (DBG) log("TelephonyRegistor: ctor numPhones=" + numPhones);
        mNumPhones = numPhones;
        //分配空间
        mConnectedApns = new ArrayList[numPhones]<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值