[Android]RIL的启动流程

 

 
RIL模块加载后,会主动上报:
[UNSL]<  UNSOL_RESPONSE_RADIO_STATE_CHANGED  {RADIO_OFF}
Ril.java收到这个主动上报后会调用 setRadioStateFromRILInt, setRadioStateFromRILInt 将通过 setRadioState上报给 GsmServiceStateTracker
GsmServiceStateTracker 在初始化时注册EVENT_RADIO_STATE_CHANGED用来监听Radio的状态变化。收到EVENT_RADIO_STATE_CHANGED后,调用setPowerStateToDesired再通知RIJD是否打开radio。setPowerStateToDesired中通过mDesiredPowerState 判定是否打开radio。mDesiredPowerState 的值将在GsmServiceStateTracker 初始化时获取。
可以在 GsmServiceStateTracker 获取 mDesiredPowerState 之前就把当前的模式设置为飞行模式。
 
下面是这个流程的相关函数。
 
RIL.java
private void  setRadioStateFromRILInt(int state) {
        RadioState newState;
         setRadioState(newState);
      }
 
GsmServiceStateTracker
cm.registerForRadioStateChanged(this,  EVENT_RADIO_STATE_CHANGED, null);
            case EVENT_RADIO_STATE_CHANGED:
                // This will do nothing in the radio not
                // available case
                Log.d("GSM","handleMessage:EVENT_RADIO_STATE_CHANGED");
                 setPowerStateToDesired();
                pollState();
 
     int airplaneMode = Settings.System.getInt(
                phone.getContext().getContentResolver(),
                Settings.System.AIRPLANE_MODE_ON, 0);
         mDesiredPowerState = ! (airplaneMode > 0);//获取是否为飞行模式
          
    protected void  setPowerStateToDesired() {
           if ( mDesiredPowerState
            && cm.getRadioState() == CommandsInterface.RadioState.RADIO_OFF) {
            Log.d(LOG_TAG,"power on radio");
             cm.setRadioPower(true, null);//通知RILD是否开radio
        }     
    }
        
 
BaseCommands
    public void  registerForRadioStateChanged(Handler h, int what, Object obj) {
        Registrant r = new Registrant (h, what, obj);
        synchronized (mStateMonitor) {
             mRadioStateChangedRegistrants.add(r);
            r.notifyRegistrant();
        }
    }
 
    protected void  setRadioState(RadioState newState) {
        RadioState oldState;
        synchronized (mStateMonitor) {
            if (Config.LOGV) {
                Log.v(LOG_TAG, "setRadioState old: " + mState
                    + " new " + newState);
            }
            oldState = mState;
            mState = newState;
            if (oldState == mState) {
                // no state transition
                return;
            }
             mRadioStateChangedRegistrants.notifyRegistrants();//通知 GsmServiceStateTracker

你可能感兴趣的:(Android)