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

雨燕双飞 提交于 2020-01-24 09:48:05

问题


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?


回答1:


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.




回答2:


yes, this is the common behavior on android phones. see the implementation of the getSimState() method from the TelephonyManager class:

public int getSimState() {
    String prop = SystemProperties.get(TelephonyProperties.PROPERTY_SIM_STATE);
    if ("ABSENT".equals(prop)) {
        return SIM_STATE_ABSENT;
    }
    else if ("PIN_REQUIRED".equals(prop)) {
        return SIM_STATE_PIN_REQUIRED;
    }
    else if ("PUK_REQUIRED".equals(prop)) {
        return SIM_STATE_PUK_REQUIRED;
    }
    else if ("NETWORK_LOCKED".equals(prop)) {
        return SIM_STATE_NETWORK_LOCKED;
    }
    else if ("READY".equals(prop)) {
        return SIM_STATE_READY;
    }
    else {
        return SIM_STATE_UNKNOWN;
    }
}


来源:https://stackoverflow.com/questions/7849192/what-is-the-value-of-sim-state-when-airplane-mode-is-turned-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!