(N)Telephony分析(四)之PhoneApp初始化分析

本文深入探讨PhoneApp的初始化过程,主要关注PhoneGlobals的创建及其onCreate方法。PhoneGlobals中调用了PhoneFactory的makeDefaultPhones方法,涉及SIM卡数据加载和Phone初始化。接着详细分析了PhoneSwitcher的构造方法和NetworkFactory的register方法,揭示了如何通过ConnectivityManager进行网络请求。此外,还提及了TelephonyNetworkFactory的构造方法,包括注册监听和数据连接模块。
摘要由CSDN通过智能技术生成

从上一篇中,分析到,调用了PhoneApp的onCreate方法,从此进入了PhoneApp的世界,那么就需要看看其onCreate方法中究竟做了什么

public void onCreate() {
        if (UserHandle.myUserId() == 0) {
            // We are running as the primary user, so should bring up the
            // global phone state.
            mPhoneGlobals = new PhoneGlobals(this);
            mPhoneGlobals.onCreate();

            mTelephonyGlobals = new TelephonyGlobals(this);
            mTelephonyGlobals.onCreate();
        }
    }
从这儿,我们可以看到,其主要做了

1. 新建了PhoneGlobals对象,并且调用了其onCreate方法

2. 新建了TelephonyGlobals对象,并且调用了其onCreate方法

那么,这篇就来分析一下第一个类,PhoneGlobals

public void onCreate() {
    if (VDBG) Log.v(LOG_TAG, "onCreate()...");

    ContentResolver resolver = getContentResolver();

    // Cache the "voice capable" flag.
    // This flag currently comes from a resource (which is
    // overrideable on a per-product basis):
    // Leo,固定值,默认为true,
   // 从字面上的意思来看,应该是语音通话功能是否支持?
    sVoiceCapable =
            getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
    // ...but this might eventually become a PackageManager "system
    // feature" instead, in which case we'd do something like:
    // sVoiceCapable =
    //   getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY_VOICE_CALLS);

    // Leo,当第一次进来后,mCM为null
    if (mCM == null) {
        // Initialize the telephony framework
    	// Leo,调用PhoneFactory的makeDefaultPhones方法
    	// 此方法初始化Telephony的framework部分的代码,并且加载SIM卡的一些信息
    	// 同时和底层RIL进行连接通信
        PhoneFactory.makeDefaultPhones(this);

        // Start TelephonyDebugService After the default phone is created.
        Intent intent = new Intent(this, TelephonyDebugService.class);
        startService(intent);

        // Leo,初始化CallManager对象
        mCM = CallManager.getInstance();
        // Leo,CallManager注册Phone
        for (Phone phone : PhoneFactory.getPhones()) {
            mCM.registerPhone(phone);
        }

        // Create the NotificationMgr singleton, which is used to display
        // status bar icons and control other status bar behavior.
        // Leo,初始化NotificationMgr对象,并且将当前对象传递给NotificationMgr
        notificationMgr = NotificationMgr.init(this);

        // If PhoneGlobals has crashed and is being restarted, then restart.
        mHandler.sendEmptyMessage(EVENT_RESTART_SIP);

        // Create an instance of CdmaPhoneCallState and initialize it to IDLE
        // Leo,初始化CdmaPhoneCallState对象,并初始化其状态
        cdmaPhoneCallState = new CdmaPhoneCallState();
        cdmaPhoneCallState.CdmaPhoneCallStateInit();

        // before registering for phone state changes
        mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
        mWakeLock = mPowerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, LOG_TAG);
        // lock used to keep the processor awake, when we don't care for the display.
        mPartialWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK
                | PowerManager.ON_AFTER_RELEASE, LOG_TAG);

        // Leo,初始化KeyguardManager对象
        mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);

        // Get UpdateLock to suppress system-update related events (e.g. dialog show-up)
        // during phone calls.
        mUpdateLock = new UpdateLock("phone");

        if (DBG) Log.d(LOG_TAG, "onCreate: mUpdateLock: " + mUpdateLock);

        CallLogger callLogger = new CallLogger(this, new CallLogAsync());

        // Leo,初始化CallGatewayManager对象
        callGatewayManager = CallGatewayManager.getInstance();

        // Create the CallController singleton, which is the interface
        // to the telephony layer for user-initiated telephony functionality
        // (like making outgoing calls.)
        // Leo,初始化CallController对象
        callController = CallController.init(this, callLogger, callGatewayManager);

        // Create the CallerInfoCache singleton, which remembers custom ring tone and
        // send-to-voicemail settings.
        //
        // The asynchronous caching will start just after this call.
        callerInfoCache = CallerInfoCache.init(this);

        // Leo,初始化PhoneInterfaceManager对象
        phoneMgr = PhoneInterfaceManager.init(this, PhoneFactory.getDefaultPhone());

        // Leo,初始化CarrierConfigLoader对象
        configLoader = CarrierConfigLoader.init(this);

        // Create the CallNotifer singleton, which handles
        // asynchronous events from the telephony layer (like
        // launching the incoming-call UI when an incoming call comes
        // in.)
        // Leo,初始化CallNotifier对象
        notifier = CallNotifier.init(this);

        PhoneUtils.registerIccStatus(mHandler, EVENT_SIM_NETWORK_LOCKED);

        // register for MMI/USSD
        mCM.registerForMmiComplete(mHandler, MMI_COMPLETE, null);

        // register connection tracking to PhoneUtils
        PhoneUtils.initializeConnectionHandler(mCM);

        // Register for misc other intent broadcasts.
        IntentFilter intentFilter =
                new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
        intentFilter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
        intentFilter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
        intentFilter.addAction(TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
        intentFilter.addAction(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED);
        intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
        registerReceiver(mReceiver, intentFilter);

        //set the default values for the preferences in the phone.
        PreferenceManager.setDefaultValues(this, R.xml.network_setting, false);

        PreferenceManager.setDefaultValues(this, R.xml.call_feature_setting, false);

        // Make sure the audio mode (along with some
        // audio-mode-related state of our own) is initialized
        // correctly, given the current state of the phone.
        PhoneUtils.setAudioMode(mCM);
    }

    cdmaOtaProvisionData = new OtaUtils.CdmaOtaProvisionData();
    cdmaOtaConfigData = new OtaUtils.CdmaOtaConfigData();
    cdmaOtaScreenState = new OtaUtils.CdmaOtaScreenState();
    cdmaOtaInCallScreenUiState = new OtaUtils.CdmaOtaInCallScreenUiState();

    simActivationManager = new SimActivationManager();

    // XXX pre-load the SimProvider so that it's ready
    resolver.getType(Uri.parse("content://icc/adn"));

    // TODO: Register for Cdma Information Records
    // phone.registerCdmaInformationRecord(mHandler, EVENT_UNSOL_CDMA_INFO_RECORD, null);

    // Read HAC settings and configure audio hardware
    if (getResources().getBoolean(R.bool.hac_enabled)) {
        int hac = android.provider.Settings.System.getInt(
                getContentResolver(),
                android.provider.Settings.System.HEARING_AID,
                0);
        AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        audioManager.setParameter(SettingsConstants.HAC_KEY,
                hac == SettingsConstants.HAC_ENABLED
                        ? SettingsConstants.HAC_VAL_ON : SettingsConstants.HAC_VAL_OFF);
    }
}
从这边的代码中,可以看到,在这个onCreate方法中,主要是做了

1. 调用了PhoneFactory的makeDefaultPhones方法

2. 初始化了一些类,这个初始化的操作相对较为简单,此地不再分析

PhoneFactory的makeDefaultPhones方法,在此前分析的SIM卡开机流程中有提到,此方法是在开机后,加载SIM卡数据和做一些Phone相关的初始化操作,这个方法也是本篇中将要分析的重点。

public static void makeDefaultPhones(Context context) {
    makeDefaultPhone(context);
}
public static void makeDefaultPhone(Context context) {
    synchronized (sLockProxyPhones) {
        if (!sMadeDefaults) {
            sContext = context;

            // create the telephony device controller.
            TelephonyDevController.create();

            int retryCount = 0;
            for(;;) {
               
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值