留住瞬间感动……

这篇文章主要是分析在

a.手机的屏幕的状态拦上手机信号角标的左下方是否有”R”显示。

b.Setting—>Aboutphone—>Status—>Roming

当然这是最粗略的比较方法,通常全球的运营商对于漫游有互相签订协议,所以单纯用上面的方法是不够细致的,

手机注网是一个比较复杂的过程,当然漫游就在这个过程中,在这里,我重点分析漫游这个点,注网的话,后面再另发文。

首先需要看的一个类就是:

Android_L/frameworks/opt/telephony/src/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java

在这个类中有方法:

/*** Handle the result of one of the pollState()-related requests*/@Overrideprotected void handlePollStateResult (int what, AsyncResult ar) {int ints[];String states[];// Ignore stale requests from last pollif (ar.userObj != mPollingContext) return;if (ar.exception != null) {CommandException.Error err=null;if (ar.exception instanceof CommandException) {err = ((CommandException)(ar.exception)).getCommandError();}if (err == CommandException.Error.RADIO_NOT_AVAILABLE) {// Radio has crashed or turned offcancelPollState();return;}if (!mCi.getRadioState().isOn()) {// Radio has crashed or turned offcancelPollState();return;}if (err != CommandException.Error.OP_NOT_ALLOWED_BEFORE_REG_NW) {loge("RIL implementation has returned an error where it must succeed" +ar.exception);}} else try {switch (what) {case EVENT_POLL_STATE_REGISTRATION: {states = (String[])ar.result;int lac = -1;int cid = -1;int type = ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN;int regState = ServiceState.RIL_REG_STATE_UNKNOWN;int reasonRegStateDenied = -1;int psc = -1;if (states.length > 0) {try {regState = Integer.parseInt(states[0]);if (states.length >= 3) {if (states[1] != null && states[1].length() > 0) {lac = Integer.parseInt(states[1], 16);}if (states[2] != null && states[2].length() > 0) {cid = Integer.parseInt(states[2], 16);}// states[3] (if present) is the current radio technologyif (states.length >= 4 && states[3] != null) {type = Integer.parseInt(states[3]);}}if (states.length > 14) {if (states[14] != null && states[14].length() > 0) {psc = Integer.parseInt(states[14], 16);}}} catch (NumberFormatException ex) {loge("error parsing RegistrationState: " + ex);}}mGsmRoaming = regCodeIsRoaming(regState);mNewSS.setState(regCodeToServiceState(regState));mNewSS.setRilVoiceRadioTechnology(type);boolean isVoiceCapable = mPhoneBase.getContext().getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);if ((regState == ServiceState.RIL_REG_STATE_DENIED_EMERGENCY_CALL_ENABLED|| regState == ServiceState.RIL_REG_STATE_NOT_REG_EMERGENCY_CALL_ENABLED|| regState == ServiceState.RIL_REG_STATE_SEARCHING_EMERGENCY_CALL_ENABLED|| regState == ServiceState.RIL_REG_STATE_UNKNOWN_EMERGENCY_CALL_ENABLED)&& isVoiceCapable) {mEmergencyOnly = true;} else {mEmergencyOnly = false;}// LAC and CID are -1 if not availmNewCellLoc.setLacAndCid(lac, cid);mNewCellLoc.setPsc(psc);break;}case EVENT_POLL_STATE_GPRS: {states = (String[])ar.result;int type = 0;int regState = ServiceState.RIL_REG_STATE_UNKNOWN;mNewReasonDataDenied = -1;mNewMaxDataCalls = 1;if (states.length > 0) {try {regState = Integer.parseInt(states[0]);// states[3] (if present) is the current radio technologyif (states.length >= 4 && states[3] != null) {type = Integer.parseInt(states[3]);}if ((states.length >= 5 ) &&(regState == ServiceState.RIL_REG_STATE_DENIED)) {mNewReasonDataDenied = Integer.parseInt(states[4]);}if (states.length >= 6) {mNewMaxDataCalls = Integer.parseInt(states[5]);}} catch (NumberFormatException ex) {loge("error parsing GprsRegistrationState: " + ex);}}int dataRegState = regCodeToServiceState(regState);mNewSS.setDataRegState(dataRegState);mDataRoaming = regCodeIsRoaming(regState);mNewSS.setRilDataRadioTechnology(type);if (DBG) {log("handlPollStateResultMessage: GsmSST setDataRegState=" + dataRegState+ " regState=" + regState+ " dataRadioTechnology=" + type);}break;}case EVENT_POLL_STATE_OPERATOR: {String opNames[] = (String[])ar.result;if (opNames != null && opNames.length >= 3) {mNewSS.setOperatorName (opNames[0], opNames[1], opNames[2]);}break;}case EVENT_POLL_STATE_NETWORK_SELECTION_MODE: {ints = (int[])ar.result;mNewSS.setIsManualSelection(ints[0] == 1);break;}}} catch (RuntimeException ex) {loge("Exception while polling service state. Probably malformed RIL response." + ex);} mPollingContext[0]–;        if (mPollingContext[0] == 0) {            /**             * Since the roaming state of gsm service (from +CREG) and             * data service (from +CGREG) could be different, the new SS             * is set to roaming when either is true.             *             * There are exceptions for the above rule.             * The new SS is not set as roaming while gsm service reports             * roaming but indeed it is same operator.             * And the operator is considered non roaming.             *             * The test for the operators is to handle special roaming             * agreements and MVNO's.             */           <span style="color:#FF0000;"> boolean roaming = (mGsmRoaming || mDataRoaming);</span>            if ((mGsmRoaming && isSameNamedOperators(mNewSS)                        && !isSameNamedOperatorConsideredRoaming(mNewSS))                    || isOperatorConsideredNonRoaming(mNewSS)) {                roaming = false;            }            mNewSS.setRoaming(roaming);            mNewSS.setEmergencyOnly(mEmergencyOnly);            pollStateDone();        }    }

这个方法主要完成了三件事情:

1,RIL返回的查询结果异常处理;

2,根据返回的4种不同网络服务查询类型,作不同处理;

3,调用pollDtateDone方法完成后面的工作。

生气是拿别人做错的事来惩罚自己

留住瞬间感动……

相关文章:

你感兴趣的文章:

标签云: