androidtelephonysim-cardairplane-mode

What is the value of SIM state when "airplane mode" is turned on


I wonder what is the value of SIM state returned by TelephonyManager.getSimState() when "airplane mode" is turned on? This seems to be not directly specified anywhere in the SDK specification.

Actually I need to get SIM operator code (i.e. MCC+MNC) using getSimOperator() method, but JavaDoc states that to use that method:

SIM state must be SIM_STATE_READY

UPDATE

I tested it under emulator and it returns SIM_STATE_UNKNOWN (which is described by javadoc as a "transition between states") after airplane mode is switched on. However I would like to know whether it is a common behavior on Android phones?


Solution

  • After searching Android 4.1 sources I found the following code in one of the private classes com.android.internal.telephony.IccCard:

    public State getState() {
      if (mState == null) {
          switch(mPhone.mCM.getRadioState()) {
              /* This switch block must not return anything in
               * State.isLocked() or State.ABSENT.
               * If it does, handleSimStatus() may break
               */
              case RADIO_OFF:
              case RADIO_UNAVAILABLE:
              case SIM_NOT_READY:
              case RUIM_NOT_READY:
                  return State.UNKNOWN;
              case SIM_LOCKED_OR_ABSENT:
              case RUIM_LOCKED_OR_ABSENT:
                  //this should be transient-only
                  return State.UNKNOWN;
              case SIM_READY:
              case RUIM_READY:
              case NV_READY:
                  return State.READY;
              case NV_NOT_READY:
                  return State.ABSENT;
          }
      } else {
          return mState;
      }
    
      Log.e(mLogTag, "IccCard.getState(): case should never be reached");
      return State.UNKNOWN;
    }  
    

    So State.UNKNOWN would be returned whenever radio state is one of RADIO_OFF or RADIO_UNAVAILABLE. Then State.UNKNOWN will be converted to SIM_STATE_UNKNOWN constant by TelephonyManager.getSimState() method.

    As the conclusion: when airplane mode is turned on getSimState will return SIM_STATE_UNKNOWN.