android4.0网络服务状态或者信号量强度上报过程(RIL Framework Java 部分)

  网络服务状态或者网络信号量是通过Modem 主动上报信息来实现的,相关类有ServiceState,GsmServiceStateTracker,GSMPhone,TelephonyRegistry等。
  1.比如现在所处的网络发生变化,RILReciver 收到上报信息,处理 RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED 信息。
   case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED:
                if (RILJ_LOGD) unsljLog(response);

                mVoiceNetworkStateRegistrants
                    .notifyRegistrants(new AsyncResult(null, null, null));
            break;
  2.经分析 mVoiceNetworkStateRegistrants,是由 GsmServiceStateTracker 构造的。   
    public GsmServiceStateTracker(GSMPhone phone) {
        ...
        cm.registerForVoiceNetworkStateChanged(this, EVENT_NETWORK_STATE_CHANGED, null);
        ...
    }
  3.消息交给 EVENT_NETWORK_STATE_CHANGED 处理。GsmServiceStateTracker 处理 EVENT_NETWORK_STATE_CHANGED 消息
     case EVENT_NETWORK_STATE_CHANGED:
                pollState();
                break;
  4.调用 pollState();
    default:
                // Issue all poll-related commands at once
                // then count down the responses, which
                // are allowed to arrive out-of-order

                pollingContext[0]++;
                cm.getOperator(
                    obtainMessage(
                        EVENT_POLL_STATE_OPERATOR, pollingContext));

                pollingContext[0]++;
                cm.getDataRegistrationState(
                    obtainMessage(
                        EVENT_POLL_STATE_GPRS, pollingContext));

                pollingContext[0]++;
                cm.getVoiceRegistrationState(
                    obtainMessage(
                        EVENT_POLL_STATE_REGISTRATION, pollingContext));

                pollingContext[0]++;
                cm.getNetworkSelectionMode(
                    obtainMessage(
                        EVENT_POLL_STATE_NETWORK_SELECTION_MODE, pollingContext));
  5.再次向rild 发送消息,等待返回信息 ,信息返回后 GsmServiceStateTracker 处理 EVENT_POLL_STATE_OPERATOR,EVENT_POLL_STATE_GPRS,EVENT_POLL_STATE_REGISTRATION,EVENT_POLL_STATE_NETWORK_SELECTION_MODE
  6. GsmServiceStateTracker最后调用 pollStateDone();
  7.调用   phone.notifyServiceStateChanged(ss);
  8.调用 phoneBase 的 notifyServiceStateChanged
      protected void notifyServiceStateChangedP(ServiceState ss) {
        AsyncResult ar = new AsyncResult(null, ss, null);
        mServiceStateRegistrants.notifyRegistrants(ar);

        mNotifier.notifyServiceState(this);
    }
  9.DefaultPhoneNotifier的 notifyServiceState(this);
  10.public void notifyServiceState(Phone sender) {
        ServiceState ss = sender.getServiceState();
        if (ss == null) {
            ss = new ServiceState();
            ss.setStateOutOfService();
        }
        try {
            mRegistry.notifyServiceState(ss);
        } catch (RemoteException ex) {
            // system process is dead
        }
    }
  11. mRegistry 是 TelephonyRegistry.
  12.调用 TelephonyRegistry的 notifyServiceState
   public void notifyServiceState(ServiceState state) {
        if (!checkNotifyPermission("notifyServiceState()")){
            return;
        }
        synchronized (mRecords) {
            mServiceState = state;
            for (Record r : mRecords) {
                if ((r.events & PhoneStateListener.LISTEN_SERVICE_STATE) != 0) {
                    try {
                        r.callback.onServiceStateChanged(new ServiceState(state));
                    } catch (RemoteException ex) {
                        mRemoveList.add(r.binder);
                    }
                }
            }
            handleRemoveListLocked();
        }
        broadcastServiceStateChanged(state);
    }
  13.回调应用程序的 onServiceStateChanged方法 ,可能会有多个应用程序,现在选择状态栏的处理程序,NetworkController处理网络变化。
    public void onServiceStateChanged(ServiceState state) {
            if (DEBUG) {
                Slog.d(TAG, "onServiceStateChanged state=" + state);
            }
            mServiceState = state;
            if (SystemProperties.getBoolean("ro.config.combined_signal", true)) {
                /*
                 * if combined_signal is set to true only then consider data
                 * service state for signal display
                 */
                mDataServiceState = mServiceState.getDataState();
                if (DEBUG) {
                    Slog.d(TAG, "Combining data service state" + mDataServiceState + "for signal");
                }
            }
            updateTelephonySignalStrength();
            updateDataNetType();
            updateDataIcon();
            refreshViews();
        }
  
14. 信号量强度的传递也是类似,都需要状态栏应用(SystemUI)去更新数据。

你可能感兴趣的:(android4.0网络服务状态或者信号量强度上报过程(RIL Framework Java 部分))